API Client represents a low level interface for Service API. All API operation can be performed using this.
A low-level client for Service API
from abeja.services import APIClient
api_client = APIClient()
create a service
API reference: POST /organizations/{organization_id}/deployments/{deployment_id}/services
organization_id = "1111111111111"
deployment_id = "9999999999999"
version_id = "ver-abc3333333333333"
model_id = "3333333333333"
environment = {
"EXAMPLE_ENV": "abc"
}
response = api_client.create_service(
organization_id, deployment_id, version_id,
model_id=model_id, environment=environment)
organization_id (str): organization identifier
deployment_id (str): deployment identifier
version_id (str): version identifier of paired model
model_id (str): training model identifier
environment (dict): env variable of running environment
instance_type (str): instance type of running environment
instance_number (str): number of instance
min_instance_number (str): number of minimum instance
max_instance_number (str): number of maximum instance
enable_autoscale (str): enable auto scaling
dict
{
"service_id": "ser-abc1111111111111",
"deployment_id": "9999999999999",
"models": {
"alias": "3333333333333"
},
"model_version": "0.0.1",
"model_version_id": "ver-abc1111111111111",
"status": "IN_PROGRESS",
"instance_number": 1,
"min_instance_number": 1,
"max_instance_number": 2,
"enable_autoscale": true,
"instance_type": "cpu-0.25",
"metrics_url": "https://p.datadoghq.com/sb/aaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"user_env_vars": {
"EXAMPLE_ENV": "abc"
},
"created_at": "2018-06-05T13:07:49.602076Z",
"modified_at": "2018-06-05T13:07:50.771671Z",
}
BadRequest: the resource already exists or parameters is insufficient or invalid.
Unauthorized: Authentication failed
InternalServerError
delete a service
API reference: DELETE /organizations/<organization_id>/deployments/<deployment_id>/services/<service_id>
response = api_client.delete_service(organization_id='1111111111111', deployment_id='9999999999999', service_id='ser-abc1111111111111')
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
dict
{
"message": "ser-abc1111111111111 deleted"
}
NotFound: service not found
Unauthorized: Authentication failed
InternalServerError
get a service
API reference: GET /organizations/<organization_id>/deployments/<deployment_id>/services/<service_id>
response = api_client.get_service(organization_id='1111111111111', deployment_id='9999999999999',
service_id='ser-abc1111111111111')
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
dict
{
"service_id": "ser-abc1111111111111",
"deployment_id": "9999999999999",
"models": {
"alias": "3333333333333"
},
"model_version": "0.0.1",
"model_version_id": "ver-abc1111111111111",
"status": "READY",
"instance_number": 1,
"instance_type": "cpu-0.25",
"metrics_url": "https://p.datadoghq.com/sb/aaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"user_env_vars": {
"EXAMPLE_ENV": "abc"
},
"created_at": "2018-06-05T12:34:33.485329Z",
"modified_at": "2018-06-05T12:34:34.568985Z"
}
NotFound: service not found
Unauthorized: Authentication failed
InternalServerError
get recent logs of the service
API reference: GET /organizations/<organization_id>/deployments/<deployment_id>/services/<service_id>/recentlogs
organization_id = "1234567890123"
deployment_id = "1111111111111"
service_id = "ser-3333333333333333"
response = api_client.get_service_recent_logs(organization_id, deployment_id, service_id)
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
next_forward_token (str): [optional] token for the next page of logs
next_backward_token (str): [optional] token for the next previous of logs
start_time (datetime): [optional] specifies the start utc datetime included in data series
end_time (datetime): [optional] specifies the end utc datetime included in data series
dict
Response Syntax:
{
"events": [
{
"message": "...",
"timestamp": "2018-01-01T00:00:00.000000Z"
}
],
"next_backward_token": "...",
"next_forward_token": "..."
}
Response Structure:
events (list): list of messages emitted from the service. the messages are sorted in descending order.
next_backward_token (str): token for the previous page of logs. If no more logs, this key exists and returns empty list.
next_forward_token (str): token for the next page of logs. If no more logs, this key exists and returns empty list.
Unauthorized: Authentication failed
NotFound:
Forbidden:
InternalServerError:
Get services entries
API reference: GET /organizations/<organization_id>/deployments/<deployment_id>/services
response = api_client.list_services(organization_id='1111111111111', deployment_id='9999999999999')
organization_id (str): organization_id
deployment_id (str): deployment identifier
dict
{
"entries": [
{
"service_id": "ser-abc1111111111111",
"deployment_id": "9999999999999",
"models": {
"alias": "3333333333333"
},
"model_version": "0.0.1",
"model_version_id": "ver-abc1111111111111",
"status": "READY",
"instance_number": 1,
"instance_type": "cpu-0.25",
"metrics_url": "https://p.datadoghq.com/sb/aaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"user_env_vars": {
"EXAMPLE_ENV": "abc"
},
"created_at": "2018-06-05T12:34:33.485329Z",
"modified_at": "2018-06-05T12:34:34.568985Z"
}
]
}
Unauthorized: Authentication failed
InternalServerError
post request to the service
API reference: POST https://<organization_id>.api.abeja.io/deployments/<deployment_id>/services/<service_id>
organization_id = "1234567890123"
deployment_id = "1111111111111"
service_id = "ser-3333333333333333"
# send json data
json_data = {
"foo": "bar",
"baz": "qux"
}
response = api_client.request_service(organization_id, deployment_id, service_id, json=json_data)
# send image data
with open('./foo.png', 'rb') as f:
response = api_client.request_service(organization_id, deployment_id, service_id, data=f, content_type='image/png')
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
data (Union[str, bytes, typing.IO]): [optional] a request payload of something other than json
json (typing.Any): [optional] a request payload of json
content_type (str): [optional] MIME-Type. Specify if you want to send data using data to the service
requests.Response
Unauthorized: Authentication failed
NotFound:
Forbidden:
InternalServerError:
start a service
API reference: POST /organizations/<organization_id>/deployments/<deployment_id>/services/<service_id>/start
response = api_client.stop_service(organization_id='1111111111111',deployment_id='9999999999999', service_id='ser-abc1111111111111')
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
dict
{
"message": "ser-abc1111111111111 started"
}
BadRequest: service is already running
NotFound: service not found
Unauthorized: Authentication failed
InternalServerError
stop a service
API reference: POST /organizations/<organization_id>/deployments/<deployment_id>/services/<service_id>/stop
response = api_client.stop_service(organization_id='1111111111111',deployment_id='9999999999999', service_id='ser-abc1111111111111')
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
dict
{
"message": "ser-abc1111111111111 stopped"
}
BadRequest: service is not running
NotFound: service not found
Unauthorized: Authentication failed
InternalServerError
update a service
API reference: PATCH /organizations/<organization_id>/deployments/<deployment_id>/services/<service_id>
payload = {
"instance_number": 4,
"min_instance_number": 2,
"max_instance_number": 6,
"enable_autoscale": 'true'
}
response = api_client.update_service(organization_id='1111111111111', deployment_id='9999999999999',
service_id='ser-abc1111111111111', payload=payload)
organization_id (str): organization_id
deployment_id (str): deployment identifier
service_id (str): service identifier
payload (dict): payload of service [optional]
dict
{
"deployment_id": "1408443944117",
"instance_number": 1,
"instance_type": "cpu-1",
"metrics_url": "https://p.datadoghq.com/sb/xxxxxxxxx-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
"models": {
"alias": "3333333333333"
},
"model_version": "1.0.0",
"model_version_id": "ver-1cfab7455c8e43a7",
"service_id": "ser-abc1111111111111",
"status": "IN_PROGRESS",
"record_channel_id": "5678901234567",
"user_env_vars": {
"EXAMPLE_ENV2": "exmaple2"
},
"merged_env_vars": {
"EXAMPLE_ENV": "deployment_example",
"EXAMPLE_ENV2": "exmaple2"
},
"service_process_type": "multi",
"modified_at": "2018-01-01T00:00:00.102289Z",
"created_at": "2018-01-01T00:00:00.102289Z"
}
NotFound: service not found
Unauthorized: Authentication failed
InternalServerError