Orchestrator REST API
4 minute read
Create and read entities
The Orchestrator REST API enables to create and read all the different kinds of Digital Twin entities described in Model section.
This API is available through a dedicated Swagger interface for each Clawdite instance. Furthermore, it is possible to
generate API clients for several languages, such as Python, Java and JavaScript. The mentioned clients are already
generated and available within each Clawdite instance and make it possible to interact with Clawdite’s Orchestrator
from
external components.
In the following a few examples on entities management will be provided.
Install the Orchestrator client dependencies
In order to use the generated API clients inside external components it is needed to correctly setup and install the dependencies. Note that you need a personal GitLab token for accessing the registries. In case you don’t have it please contact the project’s maintainers.
pip install orchestrator-python-client --index-url https://__token__:<your_personal_token>@gitlab-core.supsi.ch/api/v4/projects/86/packages/pypi/simple<dependencies>
<dependency>
<groupId>ch.supsi.dti.isteps.hdt</groupId>
<artifactId>orchestrator-java-client</artifactId>
<version>0.2.3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab-core.supsi.ch/api/v4/projects/86/packages/maven</url>
</repository>
</repositories>Create a Worker
In order to create a Worker entity (or a FactoryEntity in general) it is mandatory to define the
associated FactoryEntityModelCategoty and FactoryEntityModel in advance.
import os
from datetime import datetime
import orchestrator_python_client as hdt_client
from orchestrator_python_client import ApiClient, FactoryEntityModelCategoryDto, FactoryEntityModelDto, WorkerDto
# NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
configuration = hdt_client.Configuration(host=os.getenv('HDT_ENDPOINT'))
configuration.api_key['apiKeyAuth'] = os.getenv('HDT_API_KEY')
api_client = hdt_client.ApiClient(configuration)
factory_entity_model_category_api = hdt_client.FactoryEntityModelCategoryApi(api_client)
factory_entity_model_api = hdt_client.FactoryEntityModelApi(api_client)
worker_api = hdt_client.WorkerApi(api_client)
operator_category = factory_entity_model_category_api.create_factory_entity_model_category(
FactoryEntityModelCategoryDto(name="Operator",
description="description")).payload
worker_model = factory_entity_model_api.create_factory_entity_model(
FactoryEntityModelDto(name="Worker",
description="description",
factory_entity_model_categories_id=[operator_category.id])).payload
worker = worker_api.create_worker(
WorkerDto(creation_date=datetime.now().isoformat(),
factory_entity_model_id=worker_model.id)).payloadimport java.util.Collections;
import java.time.LocalDateTime;
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.FactoryEntityModelCategoryApi;
import org.openapitools.client.api.FactoryEntityModelApi;
import org.openapitools.client.api.WorkerApi;
import org.openapitools.client.model.FactoryEntityModelCategoryDto;
import org.openapitools.client.model.FactoryEntityModelDto;
import org.openapitools.client.model.WorkerDto;
private void createWorker() {
// NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
ApiClient apiClient = new ApiClient().setBasePath(System.getenv("HDT_ENDPOINT"));
String apiKey = System.getenv("HDT_API_KEY");
if(apiKey != null && !apiKey.isEmpty())
apiClient.addDefaultHeader("x-api-key", apiKey);
final FactoryEntityModelCategoryApi factoryEntityModelCategoryApi = new FactoryEntityModelCategoryApi(apiClient);
final FactoryEntityModelApi factoryEntityModelApi = new FactoryEntityModelApi(apiClient);
final WorkerApi workerApi = new WorkerApi(apiClient);
FactoryEntityModelCategoryDto operatorCategory = factoryEntityModelCategoryApi.createFactoryEntityModelCategory(
new FactoryEntityModelCategoryDto()
.setName("Operator")
.setDescription("description"));
FactoryEntityModelDto workerModel = factoryEntityModelApi.createFactoryEntityModel(
new FactoryEntityModelDto()
.setName("Worker")
.setDescription("description")
.setFactoryEntityModelCategoriesId(Collections.singletonList(operatorCategory.getId())));
WorkerDto worker = workerApi.createWorker(
new WorkerDto()
.setCreationDate(LocalDateTime.now().toString())
.setFactoryEntityModelId(workerModel.getId()));
}Read a Worker
In order to retrieve a Worker entity (or an entity in general) it is mandatory to specify the associated entity ID.
import os
import orchestrator_python_client as hdt_client
from orchestrator_python_client import ApiClient, WorkerDto
# NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
configuration = hdt_client.Configuration(host=os.getenv('HDT_ENDPOINT'))
configuration.api_key['apiKeyAuth'] = os.getenv('HDT_API_KEY')
api_client = hdt_client.ApiClient(configuration)
worker_api = hdt_client.WorkerApi(api_client)
# NOTE: you need to specify the worker_id UUID
worker_id = "3fa85f64-5717-4562-b3fc-2c963f66afa6"
worker = worker_api.get_worker_by_id(worker_id)import java.util.Collections;
import java.time.LocalDateTime;
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.WorkerApi;
import org.openapitools.client.model.WorkerDto;
private void readWorker() {
// NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
ApiClient apiClient = new ApiClient().setBasePath(System.getenv("HDT_ENDPOINT"));
String apiKey = System.getenv("HDT_API_KEY");
if(apiKey != null && !apiKey.isEmpty())
apiClient.addDefaultHeader("x-api-key", apiKey);
final WorkerApi workerApi = new WorkerApi(apiClient);
// NOTE: you need to specify the workerId UUID
workerId = "3fa85f64-5717-4562-b3fc-2c963f66afa6";
WorkerDto worker = workerApi.getWorkerById(workerId);
}Create a FunctionalModule
Despite the creation of a FunctionalModule entity in not dependent on other entities, it is important to define the
associated FunctionalModuleInput, FunctionalModuleOutput and Block in order to correctly create
the StateDescriptor related to the FunctionalModule (i.e. its output that will be sent to the IIoT Middleware).
import os
from datetime import datetime
import orchestrator_python_client as hdt_client
from orchestrator_python_client import ApiClient, FunctionalModuleDto, FunctionalModuleInputDto,
FunctionalModuleOutputDto, NumberBasedDto, StateDescriptorDto
# NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
configuration = hdt_client.Configuration(host=os.getenv('HDT_ENDPOINT'))
configuration.api_key['apiKeyAuth'] = os.getenv('HDT_API_KEY')
api_client = hdt_client.ApiClient(configuration)
functional_module_api = hdt_client.FunctionalModuleApi(api_client)
functional_module_input_api = hdt_client.FunctionalModuleInputApi(api_client)
functional_module_output_api = hdt_client.FunctionalModuleOutputApi(api_client)
number_based_api = hdt_client.NumberBasedApi(api_client)
state_descriptor_api = hdt_client.StateDescriptorApi(api_client)
custom_module = functional_module_api.create_functional_module(
FunctionalModuleDto(name="CustomModule", description="description")).payload
custom_module_input = functional_module_input_api.create_functional_module_input(
FunctionalModuleInputDto(input_param_name="hr", path="HR", functional_module_id=custom_module.id,
descriptor_id=hr_descriptor.id)).payload
custom_module_output = functional_module_output_api.create_functional_module_output(
FunctionalModuleOutputDto(functional_module_id=custom_module.id,
output_param_name="CustomPrediction")).payload
number_based_dto = number_based_api.create_number_based(NumberBasedDto()).payload
custom_module_state_descriptor = state_descriptor_api.create_state_descriptor(
StateDescriptorDto(functional_module_output_id=custom_module_output.id, # to know the origin of the State
blockId=number_based_dto.id, # link the data structure
name="CustomModuleState",
description="prediction",
factory_entity_model_id=worker_model.id) # the prediction is related workers
).payloadimport java.util.Collections;
import java.time.LocalDateTime;
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.FactoryEntityModelCategoryApi;
import org.openapitools.client.api.FactoryEntityModelApi;
import org.openapitools.client.api.WorkerApi;
import org.openapitools.client.model.FactoryEntityModelCategoryDto;
import org.openapitools.client.model.FactoryEntityModelDto;
import org.openapitools.client.model.WorkerDto;
private void createFunctionalModule() {
// NOTE: you need to specify the HDT_ENDPOINT and HDT_API_KEY environment variables
ApiClient apiClient = new ApiClient().setBasePath(System.getenv("HDT_ENDPOINT"));
String apiKey = System.getenv("HDT_API_KEY");
if(apiKey != null && !apiKey.isEmpty())
apiClient.addDefaultHeader("x-api-key", apiKey);
final FunctionalModuleApi functionalModuleApi = new FunctionalModuleApi(apiClient);
final FunctionalModuleInputApi functionalModuleInputApi = new FunctionalModuleInputApi(apiClient);
final FunctionalModuleOutputApi functionalModuleOutputApi = new FunctionalModuleOutputApi(apiClient);
final NumberBasedApi numberBasedApi = new NumberBasedApi(apiClient);
final StateDescriptorApi = new StateDescriptorApi(apiClient);
FunctionalModuleDto customModule = FunctionalModuleApi.createFunctionalModule(
new FunctionalModuleDto()
.setName("CustomName")
.setDescription("description"));
FunctionalModuleInputDto customModuleInput = FunctionalModuleInputApi.createFunctionalModuleInput(
new FunctionalModuleInputDto()
.setInputParameterName("hr")
.setPath("HR")
.setFunctionalModuleId(customModule.getId())
.setDescriptorId(hrDescriptor.getId()));
FunctionalModuleOutputDto customModuleOutput = FunctionalModuleOutputApi.createFunctionalModuleOutput(
new FunctionalModuleOutputDto()
.setFunctionalModuleId(customModule.getId())
.setOutputParameterName("CustomPrediction"));
NumberBasedDto numberBased = NumberBasedApi.createNumberBased(new NumberBasedDto());
StateDescriptorDto customModuleStateDescriptor = StateDescriptorApi.createStateDescriptor(
new FunctionalModuleOutputDto()
.setFunctionalModuleOutputId(customModuleOutput.getId()) // to know the origin of the State
.setBlockId(numberBased.getId()) // link the data structure
.setName("CustomModuleState")
.setDescription("prediction")
.setFactoryEntityModelId(workerModel.getId())); // the prediction is related workers
}