Ejemplo n.º 1
0
 def execute(self, context):
     hook = CloudMLHook(
         gcp_conn_id=self._gcp_conn_id, delegate_to=self._delegate_to)
     if self._operation == 'create':
         hook.create_model(self._project_id, self._model)
     elif self._operation == 'get':
         hook.get_model(self._project_id, self._model['name'])
     else:
         raise ValueError('Unknown operation: {}'.format(self._operation))
Ejemplo n.º 2
0
    def execute(self, context):
        hook = CloudMLHook(self.gcp_conn_id, self.delegate_to)

        try:
            finished_prediction_job = hook.create_job(
                self.project_id,
                self.prediction_job_request)
        except errors.HttpError:
            raise

        if finished_prediction_job['state'] != 'SUCCEEDED':
            logging.error(
                'Batch prediction job failed: %s',
                str(finished_prediction_job))
            raise RuntimeError(finished_prediction_job['errorMessage'])

        return finished_prediction_job['predictionOutput']
Ejemplo n.º 3
0
    def execute(self, context):
        hook = CloudMLHook(
            gcp_conn_id=self._gcp_conn_id, delegate_to=self._delegate_to)

        if self._operation == 'create':
            assert self._version is not None
            return hook.create_version(self._project_name, self._model_name,
                                       self._version)
        elif self._operation == 'set_default':
            return hook.set_default_version(
                self._project_name, self._model_name,
                self._version['name'])
        elif self._operation == 'list':
            return hook.list_versions(self._project_name, self._model_name)
        elif self._operation == 'delete':
            return hook.delete_version(self._project_name, self._model_name,
                                       self._version['name'])
        else:
            raise ValueError('Unknown operation: {}'.format(self._operation))
Ejemplo n.º 4
0
    def execute(self, context):
        job_id = _normalize_cloudml_job_id(self._job_id)
        training_request = {
            'jobId': job_id,
            'trainingInput': {
                'scaleTier': self._scale_tier,
                'packageUris': self._package_uris,
                'pythonModule': self._training_python_module,
                'region': self._region,
                'args': self._training_args,
            }
        }

        if self._mode == 'DRY_RUN':
            logging.info('In dry_run mode.')
            logging.info(
                'CloudML Training job request is: {}'.format(training_request))
            return

        hook = CloudMLHook(gcp_conn_id=self._gcp_conn_id,
                           delegate_to=self._delegate_to)

        # Helper method to check if the existing job's training input is the
        # same as the request we get here.
        def check_existing_job(existing_job):
            return existing_job.get('trainingInput', None) == \
                training_request['trainingInput']

        try:
            finished_training_job = hook.create_job(self._project_id,
                                                    training_request,
                                                    check_existing_job)
        except errors.HttpError:
            raise

        if finished_training_job['state'] != 'SUCCEEDED':
            logging.error('CloudML training job failed: {}'.format(
                str(finished_training_job)))
            raise RuntimeError(finished_training_job['errorMessage'])
Ejemplo n.º 5
0
 def execute(self, context):
     hook = CloudMLHook(gcp_conn_id=self._gcp_conn_id,
                        delegate_to=self._delegate_to)
     if self._operation == 'create':
         hook.create_model(self._project_id, self._model)
     elif self._operation == 'get':
         hook.get_model(self._project_id, self._model['name'])
     else:
         raise ValueError('Unknown operation: {}'.format(self._operation))
Ejemplo n.º 6
0
    def execute(self, context):
        job_id = _normalize_cloudml_job_id(self._job_id)
        training_request = {
            'jobId': job_id,
            'trainingInput': {
                'scaleTier': self._scale_tier,
                'packageUris': self._package_uris,
                'pythonModule': self._training_python_module,
                'region': self._region,
                'args': self._training_args,
            }
        }

        if self._mode == 'DRY_RUN':
            logging.info('In dry_run mode.')
            logging.info(
                'CloudML Training job request is: {}'.format(training_request))
            return

        hook = CloudMLHook(
            gcp_conn_id=self._gcp_conn_id, delegate_to=self._delegate_to)

        # Helper method to check if the existing job's training input is the
        # same as the request we get here.
        def check_existing_job(existing_job):
            return existing_job.get('trainingInput', None) == \
                training_request['trainingInput']
        try:
            finished_training_job = hook.create_job(
                self._project_id, training_request, check_existing_job)
        except errors.HttpError:
            raise

        if finished_training_job['state'] != 'SUCCEEDED':
            logging.error('CloudML training job failed: {}'.format(
                str(finished_training_job)))
            raise RuntimeError(finished_training_job['errorMessage'])
Ejemplo n.º 7
0
    def execute(self, context):
        hook = CloudMLHook(gcp_conn_id=self._gcp_conn_id,
                           delegate_to=self._delegate_to)

        if self._operation == 'create':
            assert self._version is not None
            return hook.create_version(self._project_id, self._model_name,
                                       self._version)
        elif self._operation == 'set_default':
            return hook.set_default_version(self._project_id, self._model_name,
                                            self._version['name'])
        elif self._operation == 'list':
            return hook.list_versions(self._project_id, self._model_name)
        elif self._operation == 'delete':
            return hook.delete_version(self._project_id, self._model_name,
                                       self._version['name'])
        else:
            raise ValueError('Unknown operation: {}'.format(self._operation))