All Products
Search
Document Center

Cloud Monitor:API & SDK user guide

Last Updated:Jun 23, 2026

Use the UModel API and SDK to manage Workspaces, operate on UModel data, and manage EntityStores.

Comparison of operation methods

UModel provides three operation methods:

Operation method

Scenarios

Pros

Cons

SDK

Application development

Type-safe, full-featured, direct calls

Programming skills required

umctl

Command-line operations

Simple, easy to use, supports batch operations, YAML-friendly

Limited features

Console

Visual queries

User-friendly interface, good visualization

Only query features

SDK download and configuration

1. Download the SDK

Java SDK

<!-- Maven dependency -->
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>cms20240330</artifactId>
    <version>${latest}</version>
</dependency>
Note

For the latest version number, see https://mvnrepository.com/artifact/com.aliyun/cms20240330

Python SDK

pip install alibabacloud_cms20240330

Go SDK

go get github.com/alibabacloud-go/cms-20240330/v3

SDKs for other languages are also available.

  • C++ SDK: Supports all features.

  • NodeJS SDK: Supports all features.

2. Initialize the client

Java example:

import com.aliyun.cms20240330.Client;
import com.aliyun.cms20240330.models.*;

// Configure the client
Config config = new Config()
        .setAccessKeyId(accessKeyId)
        .setAccessKeySecret(accessKeySecret)
        .setEndpoint("cms.cn-hangzhou.aliyuncs.com");

Client client = new Client(config);

Python example:

from alibabacloud_cms20240330.client import Client
from alibabacloud_tea_openapi.models import Config
from alibabacloud_cms20240330 import models as cms_models

# Configure the client
config_model = open_api_models.Config(
    access_key_id=access_key_id,
    access_key_secret=access_key_secret,
    endpoint='cms.cn-hangzhou.aliyuncs.com'
)

client = Client(config_model)

3. Environment configuration

Endpoint

Example

cms.{regionId}.aliyuncs.com

cms.cn-hangzhou.aliyuncs.com
cms.rus-west-1.aliyuncs.com

Note

For more information about region IDs, see Endpoints.

Workspace management

A Workspace is the basic container in UModel. All operations are performed within a specific Workspace.

1. Create a Workspace

// Create a workspace
PutWorkspaceRequest createWorkspaceRequest = new PutWorkspaceRequest()
       .setSlsProject(SLS_PROJECT_NAME)
       .setDescription("test workspace")
       .setDisplayName("test_workspace");
PutWorkspaceResponse workspaceResponse = client.putWorkspace(WORKSPACE_NAME, createWorkspaceRequest);
System.out.println("Create workspace: " + workspaceResponse.getStatusCode() + " " + JSONObject.toJSONString(workspaceResponse));
from alibabacloud_cms20240330.client import Client
from alibabacloud_cms20240330 import models as cms_models

# Create a workspace
create_workspace_request = cms_models.PutWorkspaceRequest(
    sls_project=SLS_PROJECT_NAME,
    description="test workspace",
    display_name="test_workspace"
)
response = client.put_workspace(WORKSPACE_NAME, create_workspace_request)
print(f"Create workspace: {response}")

2. Query a Workspace

// Get a workspace
GetWorkspaceResponse getWorkspaceResponse = client.getWorkspace(WORKSPACE_NAME);
System.out.println("Get workspace: " + getWorkspaceResponse.getStatusCode()  + " " + JSONObject.toJSONString(getWorkspaceResponse));

// List workspaces
ListWorkspacesRequest listWorkspacesRequest = new ListWorkspacesRequest()
       .setMaxResults(10)
       .setWorkspaceName("test");
ListWorkspacesResponse listWorkspacesResponse = client.listWorkspaces(listWorkspacesRequest);
System.out.println("List workspaces: " + listWorkspacesResponse.getStatusCode() + " " + JSONObject.toJSONString(listWorkspacesResponse));
# Get a workspace
response = client.get_workspace(WORKSPACE_NAME)
print(f"Get workspace: {response}")

# List workspaces
response = client.list_workspaces(cms_models.ListWorkspacesRequest(
    max_results=10,
    workspace_name='test'
))
print(f"List workspaces: {response}")

3. Delete a Workspace

// Delete a workspace
DeleteWorkspaceResponse deleteWorkspaceResponse = client.deleteWorkspace(WORKSPACE_NAME);
System.out.println("Delete workspace: " + deleteWorkspaceResponse.getStatusCode() + " " + JSONObject.toJSONString(deleteWorkspaceResponse));
# Delete a workspace
response = client.delete_workspace(WORKSPACE_NAME)
print(f"Delete workspace: {response}")

Resource management

When you create a Workspace, Cloud Monitor 2.0 automatically creates the corresponding UModel and EntityStore.

You can also use the API to manage the UModel and EntityStore as sub-resources of the Workspace.

UModel Management

When you create a UModel, a corresponding EntityStore is automatically created.

// create umodel
try {
   CreateUmodelRequest createUmodelRequest = new CreateUmodelRequest()
           .setDescription("test umodel");
   CreateUmodelResponse createUmodelResponse = client.createUmodel(WORKSPACE_NAME, createUmodelRequest);
   System.out.println("Create umodel: " + createUmodelResponse.getStatusCode() + " " + JSONObject.toJSONString(createUmodelResponse));
} catch (TeaException e) {
   System.out.println("Create umodel error: " + e.getMessage());
}

// get umodel
try {
   GetUmodelResponse getUmodelResponse = client.getUmodel(WORKSPACE_NAME);
   System.out.println("Get umodel: " + getUmodelResponse.getStatusCode() + " " + JSONObject.toJSONString(getUmodelResponse));
} catch (TeaException e) {
   System.out.println("Get umodel error: " + e.getMessage());
}

// delete umodel
try {
   DeleteUmodelResponse deleteUmodelResponse = client.deleteUmodel(WORKSPACE_NAME);
   System.out.println("Delete umodel: " + deleteUmodelResponse.getStatusCode() + " " + JSONObject.toJSONString(deleteUmodelResponse));
} catch (TeaException e) {
   System.out.println("Delete umodel error: " + e.getMessage());
}
from Tea.exceptions import TeaException
# create umodel
try:
    response = client.create_umodel(WORKSPACE_NAME, cms_models.CreateUmodelRequest(
        description="test umodel"
    ))
    print(f"Create umodel: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Create umodel error: {e}")

# get umodel
try:
    response = client.get_umodel(WORKSPACE_NAME)
    print(f"Get umodel: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Get umodel error: {e}")

# delete umodel
try:
    response = client.delete_umodel(WORKSPACE_NAME)
    print(f"Delete umodel: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Delete umodel error: {e}")

EntityStore management

To delete an EntityStore, you must first call the DeleteUmodel API operation.

// create entitystore
try {
   CreateEntityStoreResponse createEntityStoreResponse = client.createEntityStore(WORKSPACE_NAME);
   System.out.println("Create entitystore: " + createEntityStoreResponse.getStatusCode() + " " + JSONObject.toJSONString(createEntityStoreResponse));
} catch (TeaException e) {
   System.out.println("Create entitystore error: " + e.getMessage());
}

// get entitystore
try {
   GetEntityStoreResponse getEntityStoreResponse = client.getEntityStore(WORKSPACE_NAME);
   System.out.println("Get entitystore: " + getEntityStoreResponse.getStatusCode() + " " + JSONObject.toJSONString(getEntityStoreResponse));
} catch (TeaException e) {
   System.out.println("Get entitystore error: " + e.getMessage());
}

// delete entitystore
try {
   DeleteEntityStoreResponse deleteEntityStoreResponse = client.deleteEntityStore(WORKSPACE_NAME);
   System.out.println("Delete entitystore: " + deleteEntityStoreResponse.getStatusCode() + " " + JSONObject.toJSONString(deleteEntityStoreResponse));
} catch (TeaException e) {
   System.out.println("Delete entitystore error: " + e.getMessage());
}
# create entitystore
try:
    response = client.create_entity_store(WORKSPACE_NAME)
    print(f"Create entitystore: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Create entitystore error: {e}")
    
# get entitystore
try:
    response = client.get_entity_store(WORKSPACE_NAME)
    print(f"Get entitystore: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Get entitystore error: {e}")

# delete entitystore
try:
    response = client.delete_entity_store(WORKSPACE_NAME)
    print(f"Delete entitystore: {response.status_code} {response.body}")
except TeaException as e:
        print(f"Delete entitystore error: {e}")

UModel data operations

Before you perform data operations, make sure the UModel and EntityStore resources exist.

Example UModel:

[
  {
    "kind": "entity_set",
    "schema": {
      "url": "umodel.aliyun.com",
      "version": "v0.1.0"
    },
    "metadata": {
      "name": "people",
      "display_name": {
        "en_us": "people"
      },
      "domain": "custom"
    },
    "spec": {
      "default_order": "asc",
      "fields": [
        {
          "display_name": {
            "en_us": "name"
          },
          "name": "name",
          "type": "string"
        },
        {
          "display_name": {
            "en_us": "age of people"
          },
          "name": "age",
          "type": "integer"
        },
        {
          "display_name": {
            "en_us": "id of people"
          },
          "name": "id_of_people",
          "type": "string"
        }
      ],
      "name_fields": [
        "name"
      ],
      "ordered_fields": [
        "name"
      ],
      "time_field": "__time__",
      "first_observed_time_field": "__time__",
      "last_observed_time_field": "__time__",
      "primary_key_fields": [
        "id_of_people"
      ]
    }
  },
  {
    "kind": "entity_set_link",
    "schema": {
      "url": "umodel.aliyun.com",
      "version": "v0.1.0"
    },
    "metadata": {
      "name": "link1",
      "display_name": {
        "en_us": "eat"
      },
      "domain": "custom"
    },
    "spec": {
      "src": {
        "domain": "custom",
        "kind": "entity_set",
        "name": "people"
      },
      "dest": {
        "domain": "custom",
        "kind": "entity_set",
        "name": "foods"
      },
      "entity_link_type": "eat"
    }
  },
  {
    "kind": "entity_set",
    "schema": {
      "url": "umodel.aliyun.com",
      "version": "v0.1.0"
    },
    "metadata": {
      "name": "foods",
      "display_name": {
        "en_us": "foods"
      },
      "domain": "custom"
    },
    "spec": {
      "default_order": "asc",
      "fields": [
        {
          "display_name": {
            "en_us": "name"
          },
          "name": "name",
          "type": "string"
        },
        {
          "display_name": {
            "en_us": "id of foods"
          },
          "name": "id_of_foods",
          "type": "string"
        }
      ],
      "name_fields": [
        "name"
      ],
      "ordered_fields": [
        "name"
      ],
      "time_field": "__time__",
      "first_observed_time_field": "__time__",
      "last_observed_time_field": "__time__",
      "primary_key_fields": [
        "id_of_foods"
      ]
    }
  }
]

1. Add or update UModel data

 // Read UModel elements data
String jsonFilePath = "src/main/java/org/example/data/functionTest.json";
List<Map<String, Object>> elementsData = loadUmodelElements(jsonFilePath);
System.out.println("load " + elementsData.size() + " umodel elements");

// Upsert the UModel
try {
    UpsertUmodelDataRequest upsertRequest = new UpsertUmodelDataRequest()
            .setMethod("upsert")
            .setElements(elementsData);
    UpsertUmodelDataResponse upsertResponse = client.upsertUmodelData(WORKSPACE_NAME, upsertRequest);
    System.out.println("Upsert umodel: " + upsertResponse.getStatusCode() + " " + JSONObject.toJSONString(upsertResponse));
} catch (TeaException e) {
    System.out.println("Upsert umodel error: " + e.getMessage());
}
# Read UModel elements data
json_file_path = "<your_data_path>"
elements_data = load_umodel_elements(json_file_path)
print(f"load {len(elements_data)} umodel elements")

# Upsert the UModel
try:
    response = client.upsert_umodel_data(WORKSPACE_NAME, cms_models.UpsertUmodelDataRequest(
        method="upsert",
        elements=elements_data
    ))
    print(f"Upsert umodel: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Upsert umodel error: {e}")

2. Query UModel data

// Get UModel data
try {
  GetEntityStoreDataRequest getRequest = new GetEntityStoreDataRequest()
          .setFrom(1729224800)
          .setTo(1730273861)
          .setQuery(".umodel");
  GetEntityStoreDataResponse getResponse = client.getEntityStoreData(WORKSPACE_NAME, getRequest);
  System.out.println("Get umodel data: " + getResponse.getStatusCode() + " " + JSONObject.toJSONString(getResponse));
} catch (TeaException e) {
  System.out.println("Get umodel data error: " + e.getMessage());
}
# Get UModel data
try:
    response = client.get_entity_store_data(WORKSPACE_NAME, cms_models.GetEntityStoreDataRequest(
        from_=1729224800,
        to=1730273861,
        query=f".umodel"
    ))
    print(f"Get umodel data: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Get umodel data error: {e}")

This example runs an unconditional query on the UModel. For advanced queries that use filters or graph traversal, see the UModel query documentation.

3. Delete UModel data

// Delete UModel data
try {
    DeleteUmodelDataRequest deleteRequest = new DeleteUmodelDataRequest()
            .setDomain("custom")
            .setKind("entity_set")
            .setName("link1");
    DeleteUmodelDataResponse deleteResponse = client.deleteUmodelData(WORKSPACE_NAME, deleteRequest);
    System.out.println("Delete umodel data: " + deleteResponse.getStatusCode() + " " + JSONObject.toJSONString(deleteResponse));
} catch (TeaException e) {
    System.out.println("Delete umodel data error: " + e.getMessage());
}
# Delete UModel data
try:
    response = client.delete_umodel_data(WORKSPACE_NAME, cms_models.DeleteUmodelDataRequest(
        domain="custom",
        kind="entity_set",
        name="link1"
    ))
    print(f"Delete umodel data: {response.status_code} {response.body}")
except TeaException as e:
    print(f"Delete umodel data error: {e}")

Error handling and best practices

1. Exception handling pattern

public class UModelOperationHelper {
    
    private final Client client;
    
    public UModelOperationHelper(Client client) {
        this.client = client;
    }
    
    public boolean safeCreateWorkspace(String workspaceName, String description) {
        try {
            PutWorkspaceRequest request = new PutWorkspaceRequest();
            request.setSlsProject(workspaceName);
            request.setDescription(description);
            
            PutWorkspaceResponse response = client.putWorkspace(workspaceName, request);
            
            // Check the response status
            if (response.getStatusCode() == 200) {
                System.out.println("Workspace created successfully: " + workspaceName);
                return true;
            } else {
                System.err.println("Failed to create. Status code: " + response.getStatusCode());
                return false;
            }
            
        } catch (com.aliyun.teautil.models.RuntimeOptions.RuntimeException e) {
            System.err.println("Runtime exception: " + e.getMessage());
            return false;
        } catch (Exception e) {
            System.err.println("Unknown exception: " + e.getMessage());
            return false;
        }
    }
}

2. Performance optimization suggestions

Batch operations

// Create UModel data in batches
List<Object> batchElements = new ArrayList<>();
// Add multiple elements to the batch...

UpsertUmodelRequest batchRequest = new UpsertUmodelRequest();
batchRequest.setMethod("upsert");
batchRequest.setElements(batchElements);

// Process multiple elements in a single request to improve efficiency

3. Debugging tips

Enable detailed logs

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UModelClient {
    private static final Logger logger = LoggerFactory.getLogger(UModelClient.class);
    
    private void logRequest(String operation, Object request) {
        if (logger.isDebugEnabled()) {
            logger.debug("Executing operation: {}, Request parameters: {}", operation, 
                        JSONObject.toJSONString(request, true));
        }
    }
}

Check response content

private void validateResponse(String operation, Object response) {
    if (response == null) {
        throw new RuntimeException(operation + " returned an empty response");
    }
    
    // Log the response for debugging
    logger.info("{} response: {}", operation, JSONObject.toJSONString(response, true));
}

Additional console operations

  • In addition to the SDK, UModel provides a console for visual operations.

  • Console URL: https://cloudmonitor.console.alibabacloud.com/next/

  • The console supports the following tasks:

    • Visual queries: USearch, Graph Query, and Cypher queries.

    • Data browsing: Browse UModel data, entity data, and relational data.

    • Debugging and verification: Verify API call results and explore data.

Summary

This guide covers the following topics:

  1. Basic configuration: Download the SDK, initialize the client, and configure the environment.

  2. Core operations: Manage Workspaces, work with UModel data, and manage EntityStores.

  3. Advanced features: Manage UModel resources and perform CommonSchema operations.

  4. Best practices: Error handling, performance optimization, and debugging.

You can now start using UModel for data modeling and management operations.