예제 #1
0
class AbstractClusterAdapter(ModelImporter):
    """
    This defines the interface to be used by all cluster adapters.
    """
    def __init__(self, cluster):
        self.cluster = cluster
        self._state_machine = ClusterStatus(self)
        self._model = self.model('cluster', 'cumulus')

    @property
    def status(self):
        return self._state_machine.status

    @status.setter
    def status(self, status):
        self._state_machine.to(
            status,
            RestException(
                'Cluster is in state %s and cannot transition to state %s' %
                (self._state_machine.status, status),
                code=400))

        self._model.update_status(self.cluster['_id'], status)

    def validate(self):
        """
        Adapters may implement this if they need to perform any validation
        steps whenever the cluster info is saved to the database. It should
        return the document with any necessary alterations in the success case,
        or throw an exception if validation fails.
        """
        return self.cluster

    def start(self, request_body):
        """
        Adapters may implement this if they support a start operation.
        """
        raise ValidationException(
            'This cluster type does not support a start operation')

    def terminate(self):
        """
        Adapters may implement this if they support a terminate operation.
        """
        raise ValidationException(
            'This cluster type does not support a terminate operation')

    def update(self, request_body):
        """
        Adapters may implement this if they support a update operation.
        """
        raise ValidationException(
            'This cluster type does not support a update operation')

    def delete(self):
        """
        Adapters may implement this if they support a delete operation.
        """
        # If an assetstore was created for this cluster then try to remove it
        if 'assetstoreId' in self.cluster:
            try:
                assetstore = self.model('assetstore').load(
                    self.cluster['assetstoreId'])
                self.model('assetstore').remove(assetstore)
            except ValidationException:
                # If we still have files associated with the assetstore then
                # leave it.
                pass

    def submit_job(self, job):
        log_url = '%s/jobs/%s/log' % (cumulus.config.girder.baseUrl,
                                      job['_id'])

        girder_token = get_task_token()['_id']
        cumulus.tasks.job.submit(
            girder_token,
            self._model.filter(self.cluster,
                               getCurrentUser(),
                               passphrase=False), job, log_url)
예제 #2
0
class AbstractClusterAdapter(ModelImporter):
    """
    This defines the interface to be used by all cluster adapters.
    """
    def __init__(self, cluster):
        self.cluster = cluster
        self._state_machine = ClusterStatus(self)
        self._model = self.model('cluster', 'cumulus')

    @property
    def status(self):
        return self._state_machine.status

    @status.setter
    def status(self, status):
        self._state_machine.to(
            status, RestException(
                'Cluster is in state %s and cannot transition to state %s' %
                (self._state_machine.status, status), code=400))

        self._model.update_status(self.cluster['_id'], status)

    def validate(self):
        """
        Adapters may implement this if they need to perform any validation
        steps whenever the cluster info is saved to the database. It should
        return the document with any necessary alterations in the success case,
        or throw an exception if validation fails.
        """
        return self.cluster

    def start(self, request_body):
        """
        Adapters may implement this if they support a start operation.
        """
        raise ValidationException(
            'This cluster type does not support a start operation')

    def terminate(self):
        """
        Adapters may implement this if they support a terminate operation.
        """
        raise ValidationException(
            'This cluster type does not support a terminate operation')

    def update(self, request_body):
        """
        Adapters may implement this if they support a update operation.
        """
        raise ValidationException(
            'This cluster type does not support a update operation')

    def delete(self):
        """
        Adapters may implement this if they support a delete operation.
        """
        # If an assetstore was created for this cluster then try to remove it
        if 'assetstoreId' in self.cluster:
            try:
                assetstore = self.model('assetstore').load(
                    self.cluster['assetstoreId'])
                self.model('assetstore').remove(assetstore)
            except ValidationException:
                # If we still have files associated with the assetstore then
                # leave it.
                pass

    def submit_job(self, job):
        log_url = '%s/jobs/%s/log' % (getApiUrl(), job['_id'])

        girder_token = get_task_token()['_id']
        cumulus.tasks.job.submit(
            girder_token,
            self._model.filter(self.cluster, getCurrentUser(), passphrase=False),
            job, log_url)