def run(self, projectId, modelId, storageDataLocation, modelType): result = service.trainedmodels().insert(project=projectId, body={ "id": modelId, "storageDataLocation": storageDataLocation, "modelType": modelType }).execute() checked = yield Check(modelId) with pipeline.After(checked): result = service.trainedmodels().analyze(project=projectId, id=modelId).execute() return result
def run(self, job_name, bucket_name, filenames): sort_mappers = [] for i in range(len(filenames)): filenames_only = util.strip_prefix_from_items( "/%s/" % bucket_name, filenames[i]) sort_mapper = yield mapper_pipeline.MapperPipeline( "%s-shuffle-sort-%s" % (job_name, str(i)), __name__ + "._sort_records_map", __name__ + "._BatchGCSRecordsReader", None, { "input_reader": { "bucket_name": bucket_name, "objects": filenames_only, }, }, shards=1) sort_mappers.append(sort_mapper) with pipeline.After(*sort_mappers): job_ids = yield pipeline_common.Append( *[mapper.job_id for mapper in sort_mappers]) result = yield _CollectOutputFiles(job_ids) with pipeline.After(result): yield _CleanupOutputFiles(job_ids) yield pipeline_common.Return(result)
def run(self, projectId, jobId, delays=10): jobs = service.jobs() status = jobs.get(projectId=projectId, jobId=jobId).execute() if status['status']['state'] == 'PENDING' or status['status'][ 'state'] == 'RUNNING': delay = yield pipeline_common.Delay(seconds=delays) with pipeline.After(delay): yield Check(projectId, jobId, delays) else: if status['status']['state'] == "DONE": if 'errorResult' in status['status']: logger.error("bq failed %s " % status) else: logger.info("bq success %s" % status) return status
def run(self, job_name, mapper_params, filenames, shards=None): bucket_name = mapper_params["bucket_name"] hashed_files = yield _HashPipeline(job_name, bucket_name, filenames, shards=shards) sorted_files = yield _SortChunksPipeline(job_name, bucket_name, hashed_files) temp_files = [hashed_files, sorted_files] merged_files = yield _MergePipeline(job_name, bucket_name, sorted_files) with pipeline.After(merged_files): all_temp_files = yield pipeline_common.Extend(*temp_files) yield _GCSCleanupPipeline(all_temp_files) yield pipeline_common.Return(merged_files)
class MapreducePipeline(pipeline_base._OutputSlotsMixin, pipeline_base.PipelineBase): """Pipeline to execute MapReduce jobs. The Shuffle stage uses Google Cloud Storage (GCS). For newly created projects, GCS is activated automatically. To activate GCS follow these instructions: https://cloud.google.com/storage/docs/signup#activate Args: job_name: job name as string. mapper_spec: specification of mapper to use. reducer_spec: specification of reducer to use. input_reader_spec: specification of input reader to read data from. output_writer_spec: specification of output writer to save reduce output to. mapper_params: parameters to use for mapper phase. reducer_params: parameters to use for reduce phase. shards: number of shards to use as int. combiner_spec: Optional. Specification of a combine function. If not supplied, no combine step will take place. The combine function takes a key, list of values and list of previously combined results. It yields combined values that might be processed by another combiner call, but will eventually end up in reducer. The combiner output key is assumed to be the same as the input key. Returns: result_status: one of model.MapreduceState._RESULTS. Check this to see if the job is successful. default: a list of filenames if the mapreduce was successful and was outputting files. An empty list otherwise. """ def run(self, job_name, mapper_spec, reducer_spec, input_reader_spec, output_writer_spec=None, mapper_params=None, reducer_params=None, shards=None, combiner_spec=None): # Check that you have a bucket_name set in the mapper_params and set it # to the default if not. if mapper_params.get("bucket_name") is None: try: mapper_params["bucket_name"] = ( app_identity.get_default_gcs_bucket_name()) except Exception, e: raise errors.Error( "Unable to get the GCS default bucket name. " "Check to see that GCS is properly activated. " + str(e)) if mapper_params["bucket_name"] is None: raise errors.Error("There is no GCS default bucket name. " "Check to see that GCS is properly activated.") # TODO(user): Check that the bucket is indeed writable. map_pipeline = yield MapPipeline(job_name, mapper_spec, input_reader_spec, params=mapper_params, shards=shards) shuffler_pipeline = yield ShufflePipeline(job_name, mapper_params, map_pipeline) reducer_pipeline = yield ReducePipeline(job_name, reducer_spec, output_writer_spec, reducer_params, mapper_params["bucket_name"], shuffler_pipeline, combiner_spec=combiner_spec) with pipeline.After(reducer_pipeline): all_temp_files = yield pipeline_common.Extend( map_pipeline, shuffler_pipeline) yield CleanupPipeline(all_temp_files) yield _ReturnPipeline(map_pipeline.result_status, reducer_pipeline.result_status, reducer_pipeline)