def Delete(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        mdl = documents.ModelApis.objects(deleted=False).get(id=data['id'])
        # delete pvc
        if mdl.state in ["STOPPED", "CREATED"]:
            mdl.deleted = True
            mdl.last_update = datetime.datetime.now()
            mdl.save()
            return status_serializer.dump({"status": 200, "message": "Successfully delete modelapis."})

        return status_serializer.dump({"status": 400, "message": "Cannot delete starting or running modelapis."})
    def Delete(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        workspace = documents.Workspace.objects(deleted=False).get(id=data['id'])
        # delete pvc
        if workspace.state in ["STOPPED", "CREATED"]:
            utils.clean_kubernetes_pvc("data-{}".format(utils.get_k8s_name(workspace)))
            workspace.deleted = True
            workspace.last_update = datetime.datetime.now()
            workspace.save()
            return status_serializer.dump({"status": 200, "message": "Successfully delete workspace."})

        return status_serializer.dump({"status": 400, "message": "Cannot delete starting or running workspace."})
    def DeleteHardwareTier(self, request, context):
        data = id_serializer.load(request)
        hw = documents.HardwareTier.objects(deleted=False).get(id=data["id"])
        hw.deleted = True
        hw.save()

        return status_serializer.dump({"status": 200,
                                       "message": "HardwareTier successfully deleted."})
Exemple #4
0
    def DeleteDataset(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        dataset = documents.Dataset.objects(deleted=False).get(id=data['id'])
        dataset.deleted = True
        dataset.save()

        return status_serializer.dump({"status": 200, "message": "Successfully delete dataset."})
    def Stop(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        experiment = documents.Experiment.objects(deleted=False).get(id=data['id'])

        if experiment.state not in ["STARTING", "RUNNING"]:
            return status_serializer.dump({"status": 400,
                                           "message": "Cannot stop not running or starting experiment."})

        # stop and clean all resources
        utils.clean_kubernetes_job(utils.get_k8s_name(experiment))
        experiment.state = "ABORTED"
        delta = datetime.datetime.utcnow() - experiment.create_at
        experiment.uptime += int(delta.total_seconds())
        experiment.last_update = datetime.datetime.now()
        experiment.save()

        return status_serializer.dump({"status": 200,
                                       "message": "Successfully stopped Experiment."})
    def Stop(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        mdl = documents.ModelApis.objects(deleted=False).get(id=data['id'])

        if mdl.state not in ["STARTING", "RUNNING"]:
            return status_serializer.dump({"status": 400,
                                           "message": "Cannot stop not running or starting modelapis."})

        # stop and clean all resources
        utils.clean_kubernetes_deployment(utils.get_k8s_name(mdl))
        mdl.state = "STOPPED"
        delta = datetime.datetime.utcnow() - mdl.last_start
        mdl.uptime += int(delta.total_seconds())
        mdl.last_update = datetime.datetime.now()
        mdl.save()

        return status_serializer.dump({"status": 200,
                                       "message": "Successfully stopped modelapis."})
    def Start(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        mdl = documents.ModelApis.objects.get(id=data['id'])
        # prepare configurations
        if mdl.state not in ["STARTING", "RUNNING"]:
            utils.spawn_modelapis(mdl)
            mdl.state = "STARTING"
            mdl.last_start = datetime.datetime.now()
            mdl.last_update = datetime.datetime.now()
            mdl.save()

        return status_serializer.dump({"status": 200,
                                       "message": "Successfully start modelapis."})
    def Start(self, request, context):
        # validate request payload
        data = id_serializer.load(request)
        workspace = documents.Workspace.objects(deleted=False).get(id=data['id'])
        # prepare configurations
        if workspace.state not in ["STARTING", "RUNNING"]:
            utils.spawn_workspace(workspace)
            workspace.state = "STARTING"
            workspace.last_start = datetime.datetime.now()
            workspace.last_update = datetime.datetime.now()
            workspace.save()

        return status_serializer.dump({"status": 200,
                                       "message": "Successfully start workspace."})
    def Submit(self, request, context):
        # validate request payload
        data = experiment_serializer.load(request)
        # validate hardware and environment
        env = documents.Environment.objects.get(id=data["spec"]["environment"])
        if env.deployment:
            raise InvalidArgument("Invalid environment provided.")

        experiment = documents.Experiment(
            metadata=data['metadata'],
            state=data['state'],
            spec=data["spec"]
        ).save()
        utils.spawn_experiment(experiment)
        experiment.state = "STARTING"
        experiment.save()

        return status_serializer.dump({"status": 200,
                                       "message": "Successfully submit experiment."})