Skip to content

Project deployer: update some PDPL methods #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 18, 2021
108 changes: 91 additions & 17 deletions dataikuapi/dss/apideployer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from .future import DSSFuture

from ..utils import CallableStr

class DSSAPIDeployer(object):
"""
Expand Down Expand Up @@ -60,7 +60,7 @@ def list_stages(self):
"""
Lists infrastructure stages of the API Deployer

:rtype: a list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description.
:rtype: list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description.
:rtype: list
"""
return self.client._perform_json("GET", "/api-deployer/stages")
Expand Down Expand Up @@ -152,16 +152,27 @@ def get_service(self, service_id):

class DSSAPIDeployerInfra(object):
"""
A Deployment infrastructure on the API Deployer
An API Deployer infrastructure.

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployer.get_infra`
"""
def __init__(self, client, infra_id):
self.client = client
self.infra_id = infra_id

@property
def id(self):
return self.infra_id
return CallableStr(self.infra_id)

def get_status(self):
"""
Returns status information about this infrastructure

:rtype: :class:`dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus`
"""
light = self.client._perform_json("GET", "/api-deployer/infras/%s" % (self.infra_id))

return DSSAPIDeployerInfraStatus(self.client, self.infra_id, light)

def get_settings(self):
"""
Expand All @@ -186,7 +197,8 @@ def delete(self):


class DSSAPIDeployerInfraSettings(object):
"""The settings of an API Deployer Infra.
"""
The settings of an API Deployer infrastructure

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_settings`
"""
Expand Down Expand Up @@ -238,6 +250,35 @@ def save(self):
body = self.settings)


class DSSAPIDeployerInfraStatus(object):
"""
The status of an API Deployer infrastructure.

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_status`
"""
def __init__(self, client, infra_id, light_status):
self.client = client
self.infra_id = infra_id
self.light_status = light_status

def get_deployments(self):
"""
Returns the deployments that are deployed on this infrastructure

:returns: a list of deployments
:rtype: list of :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeployment`
"""
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]]

def get_raw(self):
"""
Gets the raw status information. This returns a dictionary with various information about the infrastructure

:rtype: dict
"""
return self.light_status


###############################################
# Deployments
###############################################
Expand All @@ -252,11 +293,13 @@ def __init__(self, client, deployment_id):
self.client = client
self.deployment_id = deployment_id

@property
def id(self):
return self.deployment_id
return CallableStr(self.deployment_id)

def get_status(self):
"""Returns status information about this deployment
"""
Returns status information about this deployment

:rtype: dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentStatus
"""
Expand Down Expand Up @@ -302,7 +345,8 @@ def delete(self):


class DSSAPIDeployerDeploymentSettings(object):
"""The settings of an API Deployer deployment.
"""
The settings of an API Deployer deployment.

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_settings`
"""
Expand All @@ -321,7 +365,9 @@ def get_raw(self):
return self.settings

def set_enabled(self, enabled):
"""Enables or disables this deployment"""
"""
Enables or disables this deployment
"""
self.settings["enabled"] = enabled

def set_single_version(self, version):
Expand All @@ -336,14 +382,17 @@ def set_single_version(self, version):
}

def save(self):
"""Saves back these settings to the deployment"""
"""
Saves back these settings to the deployment
"""
self.client._perform_empty(
"PUT", "/api-deployer/deployments/%s/settings" % (self.deployment_id),
body = self.settings)


class DSSAPIDeployerDeploymentStatus(object):
"""The status of an API Deployer deployment.
"""
The status of an API Deployer deployment.

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_status`
"""
Expand All @@ -365,12 +414,15 @@ def get_light(self):
def get_heavy(self):
"""
Gets the 'heavy' (full) status. This returns a dictionary with various information about the deployment

:rtype: dict
"""
return self.heavy_status

def get_service_urls(self):
"""Returns service-level URLs for this deployment (ie without the enpdoint-specific suffix)"""
"""
Returns service-level URLs for this deployment (ie without the enpdoint-specific suffix)
"""

if "deployedServiceId" in self.light_status["deploymentBasicInfo"]:
service_id = self.light_status["deploymentBasicInfo"]["deployedServiceId"]
Expand All @@ -385,7 +437,8 @@ def get_service_urls(self):
raise ValueError("PublicURL not available for this deployment. It might still be initializing")

def get_health(self):
"""Returns the health of this deployment as a string
"""
Returns the health of this deployment as a string

:returns: HEALTHY if the deployment is working properly, various other status otherwise
:rtype: string
Expand All @@ -411,8 +464,9 @@ def __init__(self, client, service_id):
self.client = client
self.service_id = service_id

@property
def id(self):
return self.service_id
return CallableStr(self.service_id)

def get_status(self):
"""
Expand Down Expand Up @@ -452,6 +506,7 @@ def get_settings(self):
def delete_version(self, version):
"""
Deletes a version from this service

:param string version: The version to delete
"""
self.client._perform_empty(
Expand All @@ -468,7 +523,8 @@ def delete(self):


class DSSAPIDeployerServiceSettings(object):
"""The settings of an API Deployer Service.
"""
The settings of an API Deployer Service.

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_settings`
"""
Expand All @@ -487,14 +543,17 @@ def get_raw(self):
return self.settings

def save(self):
"""Saves back these settings to the API service"""
"""
Saves back these settings to the API service
"""
self.client._perform_empty(
"PUT", "/api-deployer/services/%s/settings" % (self.service_id),
body = self.settings)


class DSSAPIDeployerServiceStatus(object):
"""The status of an API Deployer Service.
"""
The status of an API Deployer Service.

Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_status`
"""
Expand All @@ -503,6 +562,20 @@ def __init__(self, client, service_id, light_status):
self.service_id = service_id
self.light_status = light_status

def get_deployments(self, infra_id=None):
"""
Returns the deployments that have been created from this published project

:param str infra_id: Identifier of an infra, allows to only keep in the returned list the deployments on this infra.
If not set, the list contains all the deployments using this published project, across every infra of the Project Deployer.

:returns: a list of deployments
:rtype: list of :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeployment`
"""
if infra_id is None:
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]]
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"] if infra_id == deployment["infraId"]]

def get_versions(self):
"""
Returns the versions of this service that have been published on the API Service
Expand All @@ -517,6 +590,7 @@ def get_versions(self):
def get_raw(self):
"""
Gets the raw status information. This returns a dictionary with various information about the service,

:rtype: dict
"""
return self.light_status
22 changes: 20 additions & 2 deletions dataikuapi/dss/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ def get_api_service(self, service_id):
return DSSAPIService(self.client, self.project_key, service_id)

########################################################
# Bundles / Export (Design node)
# Bundles / Export and Publish (Design node)
########################################################

def list_exported_bundles(self):
Expand All @@ -958,7 +958,8 @@ def get_exported_bundle_archive_stream(self, bundle_id):
def download_exported_bundle_archive_to_file(self, bundle_id, path):
"""
Download a bundle archive that can be deployed in a DSS automation Node into the given output file.
@param path if "-", will write to /dev/stdout

:param path if "-", will write to /dev/stdout
"""
if path == "-":
path= "/dev/stdout"
Expand All @@ -971,6 +972,23 @@ def download_exported_bundle_archive_to_file(self, bundle_id, path):
f.flush()
stream.close()

def publish_bundle(self, bundle_id, published_project_key=None):
"""
Publish a bundle on the Project Deployer.

:param string bundle_id: The identifier of the bundle
:param string published_project_key: The key of the project on the Project Deployer where the bundle will be published.
A new published project will be created if none matches the key.
If the parameter is not set, the key from the current :class:`DSSProject` is used.

:rtype: dict
:return: a dict with info on the bundle state once published. It contains the keys "publishedOn" for the publish date,
"publishedBy" for the user who published the bundle, and "publishedProjectKey" for the key of the Project Deployer project used.
"""
params = None
if published_project_key is not None:
params = {"publishedProjectKey": published_project_key}
return self.client._perform_json("GET", "/projects/%s/bundles/%s/publish" % (self.project_key, bundle_id), params=params)

########################################################
# Bundles / Import (Automation node)
Expand Down
Loading