def SetUp(self): self.queue_name = ( 'projects/{}/locations/us-central1/queues/my-queue'.format( self.Project())) resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation('us-central1').SelfLink()) self.task_create_time = time_util.CalculateExpiration(10) self.task_schedule_time = time_util.CalculateExpiration(20)
def SetUp(self): self.location = 'projects/{}/locations/us-central1'.format( self.Project()) self.yaml_file_path = self.Resource( 'tests', 'unit', 'surface', 'tasks', 'queues', 'test_data', 'queue.yaml') resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation('us-central1').SelfLink()) properties.VALUES.core.user_output_enabled.Set(False) self._GetQueues()
def DeployCronYamlFile(scheduler_api, config, existing_jobs): """Perform a deployment based on the parsed 'cron.yaml' file. For every job defined in the cron.yaml file, we will create a new cron job for any job that did not already exist in our backend. We will also delete those jobs which are not present in the YAML file but exist in our backend. Note: We do not update any jobs. The only operations are Create and Delete. So if we modify any attribute of an existing job in the YAML file, the old job gets deleted and a new job is created based on the new attributes. Args: scheduler_api: api_lib.scheduler.<Alpha|Beta|GA>ApiAdapter, Cloud Scheduler API needed for doing jobs based operations. config: A yaml_parsing.ConfigYamlInfo object for the parsed YAML file we are going to process. existing_jobs: A list of jobs that already exist in the backend. Each job maps to an apis.cloudscheduler.<ver>.cloudscheduler<ver>_messages.Job instance. Returns: A list of responses received from the Cloud Scheduler APIs representing job states for every call made to create a job. """ cron_yaml = config.parsed jobs_client = scheduler_api.jobs app_location = app.ResolveAppLocation( parsers.ParseProject(), locations_client=scheduler_api.locations) region_ref = parsers.ParseLocation(app_location).RelativeName() project = os.path.basename(str(parsers.ParseProject())) existing_jobs_dict = _BuildJobsMappingDict(existing_jobs, project) # Create a new job for any job that does not map exactly to jobs that already # exist in the backend. responses = [] if cron_yaml.cron: for yaml_job in cron_yaml.cron: _ReplaceDefaultRetryParamsForYamlJob(yaml_job) job_key = _CreateUniqueJobKeyForYamlJob(yaml_job) if job_key in existing_jobs_dict and existing_jobs_dict[job_key]: # If the job already exists then we do not need to do anything. # TODO(b/169069379): Enhance to pop based on oldest/newest existing_jobs_dict[job_key].pop() continue job = CreateJobInstance(scheduler_api, yaml_job) responses.append(jobs_client.Create(region_ref, job)) # TODO(b/169069379): Preserve next job execution for jobs whose only change # is description # Delete the jobs which are no longer in the YAML file for jobs_list in existing_jobs_dict.values(): for yaml_job in jobs_list: jobs_client.Delete(yaml_job.name) return responses
def SetUp(self): self.queue_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations.queues', locationsId='us-central1', projectsId=self.Project(), queuesId='my-queue') self.queue_name = self.queue_ref.RelativeName() resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation('us-central1').SelfLink()) properties.VALUES.core.user_output_enabled.Set(False)
def FetchCurrentJobsData(scheduler_api): """Fetches the current jobs data stored in the database. Args: scheduler_api: api_lib.scheduler.<Alpha|Beta|GA>ApiAdapter, Cloud Scheduler API needed for doing jobs based operations. Returns: A list of currently existing jobs in the backend. """ jobs_client = scheduler_api.jobs app_location = app.ResolveAppLocation( parsers.ParseProject(), locations_client=scheduler_api.locations) region_ref = parsers.ParseLocation(app_location).RelativeName() return list(x for x in jobs_client.List(region_ref))
def SetUp(self): self.queue_type = self.messages.Queue.TypeValueValuesEnum.PULL self.location_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations', locationsId='us-central1', projectsId=self.Project()) self.queue_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations.queues', locationsId='us-central1', projectsId=self.Project(), queuesId='my-queue') self.queue_name = self.queue_ref.RelativeName() resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation('us-central1').SelfLink())
def FetchCurrentQueuesData(tasks_api): """Fetches the current queues data stored in the database. Args: tasks_api: api_lib.tasks.<Alpha|Beta|GA>ApiAdapter, Cloud Tasks API needed for doing queue based operations. Returns: A dictionary with queue names as keys and corresponding protobuf Queue objects as values apis.cloudtasks.<ver>.cloudtasks_<ver>_messages.Queue """ queues_client = tasks_api.queues app_location = app.ResolveAppLocation(parsers.ParseProject()) region_ref = parsers.ParseLocation(app_location) all_queues_in_db_dict = { os.path.basename(x.name): x for x in queues_client.List(region_ref) } return all_queues_in_db_dict
def SetUp(self): self.queue_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations.queues', locationsId='us-central1', projectsId=self.Project(), queuesId='my-queue') self.queue_name = self.queue_ref.RelativeName() self.task_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations.queues.tasks', locationsId='us-central1', projectsId=self.Project(), queuesId='my-queue', tasksId='my-task') self.task_name = self.task_ref.RelativeName() resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation('us-central1').SelfLink()) self.schedule_time = time_util.CalculateExpiration(20)
def SetUp(self): self.location_id = 'us-central1' self.location_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations', locationsId=self.location_id, projectsId=self.Project()) self.queue_id = 'my-queue' self.task_id = 'my-task' self.task_ref = resources.REGISTRY.Create( 'cloudtasks.projects.locations.queues.tasks', locationsId=self.location_id, projectsId=self.Project(), queuesId=self.queue_id, tasksId=self.task_id) self.resolve_loc_mock = self.StartObjectPatch( app, 'ResolveAppLocation', return_value=parsers.ParseLocation('us-central1').SelfLink()) properties.VALUES.core.user_output_enabled.Set(False)
def Run(self, args): locations_client = GetApiAdapter(self.ReleaseTrack()).locations location_ref = parsers.ParseLocation(args.location) return locations_client.Get(location_ref)
def Run(self, args): queues_client = GetApiAdapter(self.ReleaseTrack()).queues app_location = args.location or app.ResolveAppLocation() region_ref = parsers.ParseLocation(app_location) return queues_client.List(region_ref, args.limit, args.page_size)
def Run(self, args): queues_client = queues.Queues() app_location = args.location or app.ResolveAppLocation() region_ref = parsers.ParseLocation(app_location) return queues_client.List(region_ref, args.limit, args.page_size)
def Run(self, args): locations_client = locations.Locations() location_ref = parsers.ParseLocation(args.location) return locations_client.Get(location_ref)
def SetUp(self): resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation('us-central1').SelfLink())
def SetUp(self): self.location_name = 'projects/{}/locations/us-central1'.format( self.Project()) resolve_loc_mock = self.StartObjectPatch(app, 'ResolveAppLocation') resolve_loc_mock.return_value = ( parsers.ParseLocation(self.location_name).SelfLink())
def testParseLocationUri_DifferentProject(self): expected_self_link = ('{}/projects/other-project/locations/us-central'. format(_SELF_LINK_PREFIX)) actual_location_ref = parsers.ParseLocation(expected_self_link) self.assertEqual(actual_location_ref.SelfLink(), expected_self_link)
def testParseLocationRelative(self): expected_self_link = '{}/projects/my-project/locations/us-central'.format( _SELF_LINK_PREFIX) actual_location_ref = parsers.ParseLocation( 'projects/my-project/locations/us-central') self.assertEqual(actual_location_ref.SelfLink(), expected_self_link)