def expect_start(self, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code, message='test')
     response.result = Result(acquireLockResult=AcquireLockResult(
         lock=self._lock))
     self._scheduler.acquireLock(LockKey(job=self._job_key),
                                 self._session_key).AndReturn(response)
 def expect_populate(self, job_config, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     resp = Response(responseCode=response_code, message='test')
     result = set([deepcopy(job_config.taskConfig)])
     resp.result = Result(populateJobResult=PopulateJobResult(
         populated=result))
     self._scheduler.populateJobConfig(
         job_config, JobConfigValidation.RUN_FILTERS).AndReturn(resp)
Beispiel #3
0
 def expect_get_tasks(self, tasks, ignore_ids=None, response_code=None):
   response_code = ResponseCode.OK if response_code is None else response_code
   response = Response(responseCode=response_code, message='test')
   scheduled = []
   for index, task in enumerate(tasks):
     if not ignore_ids or index not in ignore_ids:
       scheduled.append(ScheduledTask(assignedTask=AssignedTask(task=task, instanceId=index)))
   response.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=scheduled))
   query = TaskQuery(
       owner=Identity(role=self._job_key.role),
       environment=self._job_key.environment,
       jobName=self._job_key.name,
       statuses=ACTIVE_STATES)
   self._scheduler.getTasksStatus(query).AndReturn(response)
 def expect_get_tasks(self, tasks, ignore_ids=None, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code, message='test')
     scheduled = []
     for index, task in enumerate(tasks):
         if not ignore_ids or index not in ignore_ids:
             scheduled.append(
                 ScheduledTask(assignedTask=AssignedTask(task=task,
                                                         instanceId=index)))
     response.result = Result(scheduleStatusResult=ScheduleStatusResult(
         tasks=scheduled))
     query = TaskQuery(owner=Identity(role=self._job_key.role),
                       environment=self._job_key.environment,
                       jobName=self._job_key.name,
                       statuses=ACTIVE_STATES)
     self._scheduler.getTasksStatus(query).AndReturn(response)
 def _expect_get_jobs(self, *envs):
     self._api.get_jobs(self.ROLE).AndReturn(
         Response(responseCode=ResponseCode.OK,
                  message='Mock OK',
                  result=Result(getJobsResult=GetJobsResult(configs=set(
                      JobConfiguration(key=JobKey(
                          role=self.ROLE, environment=env, name=self.NAME))
                      for env in envs)))))
 def expect_add(self, instance_ids, task_config, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code, message='test')
     add_config = AddInstancesConfig(key=self._job_key,
                                     taskConfig=task_config,
                                     instanceIds=frozenset(
                                         [int(s) for s in instance_ids]))
     self._scheduler.addInstances(add_config, self._lock,
                                  self._session_key).AndReturn(response)
 def expect_kill(self, instance_ids, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code, message='test')
     query = TaskQuery(owner=Identity(role=self._job_key.role),
                       environment=self._job_key.environment,
                       jobName=self._job_key.name,
                       statuses=ACTIVE_STATES,
                       instanceIds=frozenset([int(s)
                                              for s in instance_ids]))
     self._scheduler.killTasks(query, self._lock,
                               self._session_key).AndReturn(response)
Beispiel #8
0
    def test_init(self):
        result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=[]))
        response = Response(responseCode=ResponseCode.OK,
                            message="test",
                            result=result)
        query = TaskQuery(owner=Identity(role=ROLE),
                          environment=ENV,
                          jobName=JOB_NAME)

        self.mock_scheduler.getTasksStatus(query).AndReturn(response)

        self.mox.ReplayAll()

        JobMonitor(self.mock_api, ROLE, ENV, JOB_NAME)
 def expect_finish(self, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code, message='test')
     self._scheduler.releaseLock(self._lock, LockValidation.CHECKED,
                                 self._session_key).AndReturn(response)
Beispiel #10
0
 def expect_restart(self, instance_ids, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     response = Response(responseCode=response_code, message='test')
     self._scheduler.restartShards(self._job_key, instance_ids, self._lock,
                                   self._session_key).AndReturn(response)
Beispiel #11
0
 def expect_cron_replace(self, job_config, response_code=None):
     response_code = ResponseCode.OK if response_code is None else response_code
     resp = Response(responseCode=response_code, message='test')
     self._scheduler.replaceCronTemplate(job_config, self._lock,
                                         self._session_key).AndReturn(resp)
Beispiel #12
0
 def _failed_response(self, message):
     return Response(responseCode=ResponseCode.ERROR, message=message)
Beispiel #13
0
 def expect_start(self, response_code=None):
   response_code = ResponseCode.OK if response_code is None else response_code
   response = Response(responseCode=response_code, message='test')
   response.result = Result(acquireLockResult=AcquireLockResult(lock=self._lock))
   self._scheduler.acquireLock(LockKey(job=self._job_key), self._session_key).AndReturn(response)
Beispiel #14
0
 def expect_populate(self, job_config, response_code=None):
   response_code = ResponseCode.OK if response_code is None else response_code
   resp = Response(responseCode=response_code, message='test')
   result = set([deepcopy(job_config.taskConfig)])
   resp.result = Result(populateJobResult=PopulateJobResult(populated=result))
   self._scheduler.populateJobConfig(job_config, JobConfigValidation.RUN_FILTERS).AndReturn(resp)
 def test_start_maintenance(self, mock_api):
   mock_api.return_value = Response(responseCode=ResponseCode.OK)
   maintenance = MesosMaintenance(DEFAULT_CLUSTER, 'quiet')
   maintenance.start_maintenance(MOCK_TEST_HOSTS)