• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. JAVA
  6. MaaS Java SDK Demo

MaaS Java SDK Demo

Object Storage Migration Service (MaaSOBS) online migrates OBS of another cloud service provider to the destination cloud platform. This migration service offers secure object authentication, encrypted data transmission, and reliable interruption recovery.

Obtaining the Service Version

You can obtain the current MaaS service version using OpenStack4j based on the following code:

Version[] version = osclient.maas().version().get();

Creating a Migration Task

You can create a migration task using OpenStack4j based on the following code. After the migration task is created, it is added to the task queue and waits for execution.

Node srcNode = Node.builder().region(srcRegion).ak(srcAk).sk(srcSk)
.objectKey(srcObjectKey).bucket(srcBucket).build();
Node dstNode = Node.builder().region(dstRegion).ak(dstAk).sk(dstSk)
.objectKey(dstObjectKey).bucket(dstBucket).build();
TaskCreateBuilder taskBuilder = TaskCreate.builder().srcNode(srcNode).dstNode(dstNode).enableKMS(isKMS).threadNum(threadNum).description("description");
TaskCreate create = taskBuilder.build();
TaskCreateResp resp = osclient.maas().task().create(create);
taskId = resp.getId();
Table 1 Parameter description

Parameter

Description

Example Value

srcRegion

Specifies the source region ID. Note that this parameter is not the region name.

us-east-1

srcAk

Specifies the access key ID on the source end. In most cases, the value is a string of 20 characters consisting of digits and letters.

AKTAI72RCUBV4AHQO46C

srcSk

Specifies the secret access key ID on the source end. In most cases, the value is a string of 40 characters consisting of digits and letters.

32o6vpFgj76zII1HOad7SrbygHChx9TbwWpDzsHo

srcObjectKey

Specifies the JSON character string of the migration object on the source end. In most cases, the value is in the path+keys array.

path indicates the parent path of the object on the source end.

keys indicates the object array in the path. If the migration object is a folder, the value ends with a slash (/).

{

path: "test-01/",

keys: ["10000-files/","rmb001"]

}

srcBucket

Specifies the bucket name on the source end. In most cases, the value is the name of a bucket created by the provider of the public cloud supporting service migration.

Filp-srouce-bucket

dstRegion

Specifies the region ID of OBS on the destination end. Note that this parameter is not the region name.

test-region-1

dstAk

Specifies the access key ID on the destination end. In most cases, the value is a string of 20 characters consisting of digits and letters.

KEIIFOFUCVDQJ0E0NW4S

dstSk

Specifies the secret access key ID on the destination end. In most cases, the value is a string of 40 characters consisting of digits and letters.

32o6vpOg376zII1HOad7SrbyfHChx9TbwwprzsHN

dstObjectKey

Specifies the path on the destination end. The value ends with a slash (/).

"test-dir/"

dstBucket

Specifies the bucket name on the destination end. In most cases, the value is the name of a bucket created in the region of OBS.

Bucket-maasobs

isKMS

Specifies whether to enable the KMS function to encrypt the object data after the migration. The value is a boolean type.

True/False

threadNum

Specifies the number of threads used for migration. The default value is 5.

5

description

Provides supplementary information about the migration task. This parameter is optional.

"this is test"

Pausing a Migration Task

You can pause a migration task using OpenStack4j based on the following code by specifying the task ID:

waitTaskToState(State.EXECUTE);
ActionResponse resp = osclient.maas().task().stop(taskId);
Table 2 Parameter description

Parameter

Description

Example Value

taskId

Specifies the ID of the migration task to be paused. The value is a string of digits.

172315251263

Continuing a Migration Task

You can continue a paused or failed migration task using OpenStack4j based on the following code by specifying required parameters, including the respective AKs and SKs on the source end and destination end:

waitTaskToState(State.STOP);
TaskStart task = TaskStart.builder().sourceAk(srcAk).sourceSk(srcSk)
.targetAk(dstAk).targetSk(dstSk).build();
ActionResponse resp = osclient.maas().task().start(taskId, task);
Table 3 Parameter description

Parameter

Description

Example Value

srcAk

Specifies the access key ID on the source end for the migration task. In most cases, the value is a string of 20 characters consisting of digits and letters.

AKTAI72RCUBV4AHQO46C

srcSk

Specifies the secret access key ID on the source end for the migration task. In most cases, the value is a string of 40 characters consisting of digits and letters.

32o6vpFgj76zII1HOad7SrbygHChx9TbwWpDzsHo

dstAk

Specifies the access key ID on the destination end for the migration task. In most cases, the value is a string of 20 characters consisting of digits and letters.

KEIIFOFUCVDQJ0E0NW4S

dstSk

Specifies the secret access key ID on the destination end for the migration task. In most cases, the value is a string of 40 characters consisting of digits and letters.

32o6vpOg376zII1HOad7SrbyfHChx9TbwwprzsHN

Deleting a Migration Task

You can delete an executed or waiting migration task using OpenStack4j based on the following code by specifying the task ID:

waitTaskToState(State.STOP);
ActionResponse resp = osclient.maas().task().delete(taskId);
Table 4 Parameter description

Parameter

Description

Example Value

taskId

Specifies the ID of the migration task to be deleted. The value is a string of digits.

172315251263

Querying Details of a Migration Task

You can query details of a migration task using OpenStack4j based on the following code by specifying the task ID:

Task task = osclient.maas().task().get(taskId);
Table 5 Parameter description

Parameter

Description

Example Value

taskId

Specifies the ID of the migration task to be queried. The value is a string of digits.

172315251263

Querying All Tasks of a Tenant

You can query details of a specified number of migration tasks using OpenStack4j based on the following code by specifying three parameters. The first parameter specifies the start number of the migration tasks to be queried, the second parameter specifies the total number of migration tasks to be queried, and the third parameter specifies the status of the migration tasks to be queried. If the task status is not specified, migration tasks of all states will be queried.

TaskListOptions options = TaskListOptions.create().start(startNum).limit(limitCount).state(Status);
Task[] list = osclient.maas().task().list(options);
Table 6 Parameter description

Parameter

Description

Example Value

startNum

Specifies the start serial number.

1

limitCount

Specifies the maximum number of returned tasks, which cannot exceed 100. Otherwise, the query fails.

5

Status

Specifies the status of the tasks to be queried. If this parameter is left blank, the tasks of all states will be queried.

State.SUCCESS

State.EXECUTE

State.FAILED

State.STOP

State.WAIT

Querying the Total Number of Migration Tasks

You can query either the total number of migration tasks in a specified state or the total number of migration tasks in all states using OpenStack4j based on the following code.

Querying the total number of migration tasks in all states:

long count = osclient.maas().task().count();

Querying the total number of migration tasks in a specified state:

long count = osclient.maas().task().count(Status);
Table 7 Parameter description

Parameter

Description

Example Value

Status

Specifies the status of the tasks to be queried. If this parameter is left blank, the tasks of all states will be queried.

State.SUCCESS

State.EXECUTE

State.FAILED

State.STOP

State.WAIT