Cloning Workspaces in GoodData.CN

  • 27 April 2021
  • 0 replies
  • 26 views

Overview

Sometimes, you may need to clone a workspace. For example, you may need to clone a development workspace to use in production or clone a production workspace for testing purposes. Or, you may want to create a new workspace that utilizes many of the components you have already created in a previous workspace. 

 

The GoodData.CN API provides an easy, programmatic way to do so. This article describes how to clone a workspace using the GoodData.CN API. For more information on working with Workspaces, please reference our documentation.

 

How to Clone a Workspace

First, you will need to create a copy of the layout of the existing workspace that you want to clone (the source workspace). This is done by issuing a GET request to the /layout/workspaces API. 

Run the following command in your terminal (or issue the API call using a tool such as Postman):

curl -H "Authorization: Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz" \
-H "Content-Type: application/json" \
-X GET \
http://localhost:3000/api/layout/workspaces/my-workspace \
| jq > workspace-backup.json

This command issues a GET request to our endpoint. This example is using the GoodData.CN Community Edition installed locallyyou may have to update the URL and Authorization token accordingly. In the URL, “my-workspace” is the workspace’s ID that you are cloning (the source workspace). It then pipes the response through jq to format the json response in a readable format and saves it to a file called workspace-backup.json in the current directory.

 

Next, create a new workspacethis will be the target workspace. You can do so either through the front-end of your application or via API.

To do so through the API, issue the following POST request:

curl http://localhost:3000/api/entities/workspaces \
-H "Content-Type: application/vnd.gooddata.api+json" \
-H "Accept: application/vnd.gooddata.api+json" \
-H "Authorization: Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz" \
-X POST \
-d '{
"data": {
"attributes": {
"name": "My New Workspace"
},
"id": "my-new-workspace",
"type": "workspace"
}
}'

Remember to update the URL and authorization token as necessary. Choose an appropriate workspace name and ID (consider establishing naming conventions for your object IDs and names). 

 

Since the workspace layout includes the logical data model (LDM), you do not necessarily need to connect data or publish the LDM in your new workspace. If you are creating a new workspace within the same instance of GoodData.CN, then you may be able to simply create a new empty workspace. However, be aware that the LDM in the layout includes explicit references to the data source used in the source workspace. So, you will need to ensure that your target workspace is able to establish a connection to the same data source (that means a data source with the same ID, that contains the same tables and columns as the original one did). 

 

Finally, issue a PUT request to the /layout/workspaces API with your newly created json layout file to the target workspace’s ID:

curl -H "Authorization: Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X PUT \
-d @workspace-backup.json \
http://localhost:3000/api/layout/workspaces/my-new-workspace

Remember to update the URL and authorization token as necessary, including replacing “my-new-workspace” with your target workspace ID.  

 

As simple as that, you’ve just cloned a workspace! Using your browser, navigate to your application’s Home page to see your new workspace. 

 


0 replies

Be the first to reply!

Reply