Help Center/ DataArts Studio/ Best Practices/ Incremental Migration on CDM Supported by DLF
Updated on 2023-03-03 GMT+08:00

Incremental Migration on CDM Supported by DLF

The Data Lake Factory (DLF) component of DataArts Studio is a one-stop big data collaboration development platform. With DLF's online script editing, CDM jobs can be scheduled to implement incremental migration.

This section describes how DLF works with CDM to implement incremental migration from DWS to OBS.
  1. Obtaining the CDM Job JSON
  2. Modifying JSON
  3. Creating a DLF Job

Obtaining the CDM Job JSON

  1. On the CDM console, create a table/file migration job from DWS to OBS.
  2. On the Table/File Migration tab page of the Job Management page, locate the created job, click More in the Operation column, and select View Job JSON from the drop-down list.

    You can also view JSON of any other CDM job.

    Figure 1 Viewing job JSON
  3. The job JSON is the request body template for creating a CDM job. Replace [Endpoint], {project_id}, and {cluster_id} in the URL with the actual values.
    • [Endpoint]: indicates the endpoint.

      An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. You can obtain endpoints of the service from Endpoints.

    • {project_id}: indicates the project ID.
    • {cluster_id}: Indicates the cluster ID. You can click the cluster name on the Cluster Management page to view the cluster ID.

Modifying JSON

You can modify the JSON body as required. In this example, the period is one day, and the WHERE clause is used for filtering the incremental data to be migrated (generally, the time range is used for filtering data). The data generated on the previous day is migrated every day.
  1. Modify the WHERE clause to add incremental data in a certain period.
         {
            "name": "fromJobConfig.whereClause",
            "value": "_timestamp >= '${startTime}' and _timestamp < '${currentTime}'"
         }
    • If the source database is DWS or MySQL, the value can be set to:
      _timestamp >= '2018-10-10 00:00:00' and _timestamp < '2018-10-11 00:00:00'
      Or
      _timestamp between '2018-10-10 00:00:00' and '2018-10-11 00:00:00'
    • If the source database is Oracle, the value should be set to:
      _timestamp >= to_date (2018-10-10 00:00:00' , 'yyyy-mm-dd hh24:mi:ss' ) and _timestamp < to_date (2018-10-10 00:00:00' , 'yyyy-mm-dd hh24:mi:ss' )
  2. Import incremental data in each period to different directories.
         {
            "name": "toJobConfig.outputDirectory",
            "value": "dws2obs/${currentTime}"
         }
  3. Change the job name to a dynamic one. Otherwise, the job cannot be created because the job name is duplicate.
        "to-connector-name": "obs-connector",
        "from-link-name": "dws_link",
        "name": "dws2obs-${currentTime}"
For details about how to modify more parameters, see Cloud Data Migration API Reference. The following is an example of the modified JSON file:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{
  "jobs": [
    {
      "job_type": "NORMAL_JOB",
      "to-config-values": {
        "configs": [
          {
            "inputs": [
              {
                "name": "toJobConfig.bucketName",
                "value": "cdm-test"
              },
              {
                "name": "toJobConfig.outputDirectory",
                "value": "dws2obs/${currentTime}"
              },
              {
                "name": "toJobConfig.outputFormat",
                "value": "CSV_FILE"
              },
              {
                "name": "toJobConfig.fieldSeparator",
                "value": ","
              },
              {
                "name": "toJobConfig.writeToTempFile",
                "value": "false"
              },
              {
                "name": "toJobConfig.validateMD5",
                "value": "false"
              },
              {
                "name": "toJobConfig.encodeType",
                "value": "UTF-8"
              },
              {
                "name": "toJobConfig.duplicateFileOpType",
                "value": "REPLACE"
              },
              {
                "name": "toJobConfig.kmsEncryption",
                "value": "false"
              }
            ],
            "name": "toJobConfig"
          }
        ]
      },
      "from-config-values": {
        "configs": [
          {
            "inputs": [
              {
                "name": "fromJobConfig.schemaName",
                "value": "dws_database"
              },
              {
                "name": "fromJobConfig.tableName",
                "value": "dws_from"
              },
              {
                "name": "fromJobConfig.whereClause",
                "value": "_timestamp >= '${startTime}' and _timestamp < '${currentTime}'"
              },
              {
                "name": "fromJobConfig.columnList",
                "value": "_tiny&_small&_int&_integer&_bigint&_float&_double&_date&_timestamp&_char&_varchar&_text"
              }
            ],
            "name": "fromJobConfig"
          }
        ]
      },
      "from-connector-name": "generic-jdbc-connector",
      "to-link-name": "obs_link",
      "driver-config-values": {
        "configs": [
          {
            "inputs": [
              {
                "name": "throttlingConfig.numExtractors",
                "value": "1"
              },
              {
                "name": "throttlingConfig.submitToCluster",
                "value": "false"
              },
              {
                "name": "throttlingConfig.numLoaders",
                "value": "1"
              },
              {
                "name": "throttlingConfig.recordDirtyData",
                "value": "false"
              },
              {
                "name": "throttlingConfig.writeToLink",
                "value": "obs_link"
              }
            ],
            "name": "throttlingConfig"
          },
          {
            "inputs": [],
            "name": "jarConfig"
          },
          {
            "inputs": [],
            "name": "schedulerConfig"
          },
          {
            "inputs": [],
            "name": "transformConfig"
          },
          {
            "inputs": [],
            "name": "smnConfig"
          },
          {
            "inputs": [],
            "name": "retryJobConfig"
          }
        ]
      },
      "to-connector-name": "obs-connector",
      "from-link-name": "dws_link",
      "name": "dws2obs-${currentTime}"
    }
  ]
}

Creating a DLF Job

  1. In DLF, create the jobs shown in Figure 2. For details, see Creating a Job in DataArts Studio User Guide.
    For details about how to configure the nodes and the job, see the following steps.
    Figure 2 DLF job
  2. Configure the CreatingJob node.
    DLF uses a RestAPI node to call a RESTful API to create a CDM migration job. Configure the properties of the RestAPI node.
    1. Node Name: Enter a custom name, for example, CreatingJob. Note that the CDM job is only used as a node in the DLF job.
    2. URL Address: Set it to the URL obtained in Obtaining the CDM Job JSON. The format is https://{Endpoint}/cdm/v1.0/{project_id}/clusters/{cluster_id}/cdm/job.
    3. HTTP Method: Enter POST.
    4. Add the following request headers:
      • Content-Type = application/json
      • X-Language = en-us
    5. Request Body: Enter the modified JSON of the CDM job in Modifying JSON.
    Figure 3 Properties of the node for creating the CDM job
  3. Configure the StartingJob node.
    After configuring the RESTful API node for creating a CDM job, you must add the RESTful API node for running the CDM job. For details, see section "Starting a Job" in Cloud Data Migration API Reference. Configure the properties of the RestAPI node.
    1. Node Name: Enter the name of the node where the job is to be run.
    2. URL Address: Keep the values of project_id and cluster_id consistent with those in 2. Set the job name to dws2obs-${currentTime}. The format is https://{Endpoint}/cdm/v1.0/{project_id}/clusters/{cluster_id}/cdm/job/{job_name}/start.
    3. HTTP Method: Enter PUT.
    4. Request Header:
      • Content-Type = application/json
      • X-Language = en-us
    Figure 4 Properties of the node for running the CDM job
  4. Configure the WaitingJobCompletion node.

    CDM jobs are run asynchronously. Therefore, even if the REST request for running the job returns 200, it does not mean that the data has been migrated successfully. If a computing job depends on the CDM job, a RestAPI node is required to periodically check whether the migration is successful. Computing is performed only when the migration is successful. For details about the API used to check whether the CDM migration is successful, see section "Querying Job Status" in Cloud Data Migration API Reference.

    After configuring the RestAPI node for running the CDM job, add the node for waiting for the CDM job completion. The node properties are as follows:
    1. Node Name: Wait until the job is complete.
    2. URL Address: The format is https://{Endpoint}/cdm/v1.0/{project_id}/clusters/{cluster_id}/cdm/job/{job_name}/status. Keep the values of project_id and cluster_id consistent with those in 2. Set the job name to dws2obs-${currentTime}.
    3. HTTP Method: Enter GET.
    4. Request Header:
      • Content-Type = application/json
      • X-Language = en-us
    5. Check Return Value: Select YES.
    6. Property Path: Enter submissions[0].status.
    7. Request Success Flag: Set this parameter to SUCCEEDED.
    8. Retain default values for other parameters.
  5. (Optional) Configure the DeletingJob node.

    You can delete jobs as required. DLF periodically creates CDM jobs to implement incremental migration. Therefore, a large number of jobs exist in the CDM cluster. After the migration is successful, you can delete the jobs that have been successfully executed. To delete a CDM job, add a RestAPI node for deleting CDM jobs after the node for querying the CDM job status. DLF calls the API for deleting a job described in Cloud Data Migration API Reference.

    Properties of the node for deleting the CDM job are as follows:
    1. Node Name: Enter DeletingJob.
    2. URL Address: The format is https://{Endpoint}/cdm/v1.0/{project_id}/clusters/{cluster_id}/cdm/job/{job_name}. Keep the values of project_id and cluster_id consistent with those in 2. Set the job name to dws2obs-${currentTime}.
    3. HTTP Method: Enter DELETE.
    4. Request Header:
      • Content-Type = application/json
      • X-Language = en-us
    5. Retain default values for other parameters.
    Figure 5 Properties of the node for deleting the CDM job
  6. To perform computing operations after the migration is complete, you can add various computing nodes.
  7. Configure DLF job parameters.
    1. Configure the DLF job parameters shown in Figure 6.
      • startTime = $getTaskPlanTime(plantime,@@yyyyMMddHHmmss@@,-24*60*60)
      • currentTime = $getTaskPlanTime(plantime,@@yyyyMMdd-HHmm@@,0)
      Figure 6 Configuring DLF job parameters
    2. After saving the DLF job, choose Scheduling Configuration > Periodic Scheduling and set the scheduling period to one day.

      In this way, DLF works with CDM to migrate data generated on the previous day every day.