Microservices
Getβ
Get a microservice by nameβ
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices get --id helloworld
c8y microservices get --id helloworld
Get-Microservice -Id helloworld
| id | name | key | type | manifest.version | availability | resources | owner.tenant.id | requiredRoles.0 |
|------------|----------------|----------------|-------------------|------------------|--------------|------------|-----------------|---------------------------|
| 14114 | helloworld | helloworld | MICROSERVICE | | MARKET | | t12345 | ROLE_INVENTORY_ADMIN |
Get a list of microservicesβ
List microservices being hosted in the platform
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices list
c8y microservices list
Get-MicroserviceCollection
| id | name | key | type | manifest.version | availability | resources | owner.tenant.id |
|------------|------------|--------------|-------------------|------------------|--------------|------------|-----------------|
| 12 | cep | cep-key | MICROSERVICE | 1007.1.0 | MARKET | | management |
| 14114 | helloworld | helloworld | MICROSERVICE | | MARKET | | t12345 |
| 18 | device-si⦠| device-simu⦠| MICROSERVICE | 1007.1.0 | MARKET | | management |
| 25 | report-ag⦠| report-agen⦠| MICROSERVICE | 1007.1.0 | MARKET | | management |
| 29 | smartrule | smartrule-k⦠| MICROSERVICE | 1007.1.0 | MARKET | | management |
Get a list of microservices with names starting with smart*β
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices list --pageSize 100 --filter "name like smart*"
c8y microservices list --pageSize 100 --filter "name like smart*"
Get-MicroserviceCollection -PageSize 100 -Filter "name like smart*"
| id | name | key | type | manifest.version | availability | resources | owner.tenant.id |
|------------|----------------|--------------------|-------------------|------------------|--------------|------------|-----------------|
| 29 | smartrule | smartrule-key | MICROSERVICE | 1007.1.0 | MARKET | | management |
Createβ
Create a new microserviceβ
The following command will create a new microservice, upload it's binary, and also subscribe to it on the current tenant:
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices create --file helloworld.zip
c8y microservices create --file helloworld.zip
New-Microservice -File helloworld.zip
If you don't want to subscribe to the microservice immediately then use the skipSubscription
parameter:
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
# Create microservice but don't subscribe to it
c8y microservices create --file helloworld.zip --skipSubscription
# Enable/Subscribe to the microservice when you're ready
c8y microservices enable --id helloworld
# Create microservice but don't subscribe to it
c8y microservices create --file helloworld.zip --skipSubscription
# Enable/Subscribe to the microservice when you're ready
c8y microservices enable --id helloworld
# Create microservice but don't subscribe to it
New-Microservice -File helloworld.zip -SkipSubscription
# Enable/Subscribe to the microservice when you're ready
Enable-Microservice -Id helloworld
Updateβ
Update the availability of the microservice to MARKETβ
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices update --id helloworld --availability MARKET
c8y microservices update --id helloworld --availability MARKET
Update-Microservice -Id helloworld -Availability MARKET
| id | name | key | type | manifest.version | availability | resources | owner.tenant.id |
|------------|------------|--------------|-------------------|------------------|--------------|------------|-----------------|
| 14114 | mytestapp | mytestapp | MICROSERVICE | | MARKET | | t12345 |
Adding custom data to the applicationβ
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices update --id helloworld --template "{c8y_application_details: { branch: 'master' }}"
c8y microservices update --id helloworld --template "{c8y_application_details: { branch: 'master' }}"
Update-Microservice -Id helloworld -Template "{c8y_application_details: { branch: 'master' }}"
| id | name | key | type | manifest.version | availability | resources | owner.tenant.id |
|------------|------------|--------------|-------------------|------------------|--------------|------------|-----------------|
| 14114 | mytestapp | mytestapp | MICROSERVICE | | MARKET | | t12345 |
The full response can be printed to the console by setting the output
to json
or using the raw
option
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices get --id helloworld --raw
c8y microservices get --id helloworld --raw
Get-Microservice -Id helloworld -Raw
{
"owner": {
"self": "https://mytenant.example.com/tenant/tenants/goc8yci01",
"tenant": {
"id": "goc8yci01"
}
},
"requiredRoles": [],
"manifest": {
"noAppSwitcher": true,
"settingsCategory": null
},
"roles": [],
"contextPath": "helloworld",
"availability": "MARKET",
"type": "MICROSERVICE",
"name": "helloworld",
"self": "https://mytenant.example.com/application/applications/9994",
"id": "9994",
"key": "helloworld-microservice-key",
"c8y_application_details": {
"branch": "master"
}
}
Delete/Removeβ
Remove microserviceβ
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices delete --id helloworld
c8y microservices delete --id helloworld
Delete-Microservice -Id helloworld
β Deleted /application/applications/9994 => 204 No Content
Remove microservices with starting with "citest"β
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices list --pageSize 100 --filter "name like citest*" |
c8y microservices delete
c8y microservices list --pageSize 100 --filter "name like citest*" |
c8y microservices delete
Get-MicroserviceCollection -PageSize 100 -Filter "name like citest*" | batch |
Remove-Microservice
β Deleted /application/applications/97388 => 204 No Content
Enable/Disable a microserviceβ
Enabling a microservice can be done using:
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices enable --id helloworld
c8y microservices enable --id helloworld
Enable-Microservice -Id helloworld
| application.id | application.name | application.type | self |
|----------------|------------------|-------------------|----------------------------------------------------------------------------------|
| 97388 | helloworld | MICROSERVICE | https://t12345.latest.stage.c8y.io/http://t12345.latest.stage.c8y.io/tenant⦠|
Once the microservice has started up (this can take a few minutes), then any endpoints made available by it, then it can be reached using the following:
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y api GET /service/helloworld/health --raw
c8y api GET /service/helloworld/health --raw
Invoke-ClientRequest -Method "Get" -Uri "/service/helloworld/health" -Raw
{
"status": "UP"
}
To disable/unsubscribe a microservice from the current tenant use the following:
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices disable --id helloworld
c8y microservices disable --id helloworld
Disable-Microservice -Id helloworld
β Deleted /tenant/tenants/t12345/applications/97388 => 204 No Content
Advanced use casesβ
Create a new microservice that will be hosted outside of Cumulocity (in private docker/kubernetes host)β
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices create --file helloworld.zip --skipUpload
c8y microservices create --file helloworld.zip --skipUpload
New-Microservice -File helloworld.zip -SkipUpload
The skipUpload
parameter tells the command to skip the binary upload, however it will still parse the cumulocity.json manifest file which is used to update the microservice's required roles.
Then the microservice's bootstrap credentials can be retrieved using:
- Shell
- PowerShell (native)
- PowerShell (PSc8y)
c8y microservices getBootstrapUser --id helloworld --raw
c8y microservices getBootstrapUser --id helloworld --raw
Get-MicroserviceBootstrapUser -Id helloworld -Raw
{
"name": "servicebootstrap_helloworld",
"password": "1dkd8ajd8DJ8djd9sk)lpoyHGGOpai8s",
"tenant": "t12345"
}