def create_scheduled_tasks(cls): tasks = [] for name in ['foo', 'bar', 'baz']: task = ScheduledTask() task.failure_count = 0 task.assignedTask = AssignedTask() task.assignedTask.taskId = 1287391823 task.assignedTask.slaveHost = 'slavehost' task.assignedTask.task = TaskConfig() task.assignedTask.task.maxTaskFailures = 1 task.assignedTask.task.executorConfig = ExecutorConfig() task.assignedTask.task.executorConfig.data = Mock() task.assignedTask.task.metadata = [] task.assignedTask.task.job = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name) task.assignedTask.task.owner = Identity(role=cls.TEST_ROLE) task.assignedTask.task.environment = cls.TEST_ENV task.assignedTask.task.jobName = name task.assignedTask.task.numCpus = 2 task.assignedTask.task.ramMb = 2 task.assignedTask.task.diskMb = 2 task.assignedTask.instanceId = 4237894 task.assignedTask.assignedPorts = {} task.status = ScheduleStatus.RUNNING event = TaskEvent() event.timestamp = 28234726395 event.status = ScheduleStatus.RUNNING event.message = "Hi there" task.taskEvents = [event] tasks.append(task) return tasks
def create_task_events(start_time): """Create a list of task events, tracing the task from pending to assigned to running""" return [ TaskEvent(timestamp=start_time, status=0, message="looking for a host"), TaskEvent(timestamp=start_time + 10, status=9, message="found a host"), TaskEvent(timestamp=start_time + 20, status=2, message="running") ]
def create_scheduled_tasks(cls): tasks = [] for name in ['foo', 'bar', 'baz']: task = ScheduledTask( failureCount=0, assignedTask=AssignedTask( taskId=1287391823, slaveHost='slavehost', task=TaskConfig( maxTaskFailures=1, executorConfig=ExecutorConfig(data='fake data'), metadata=[], job=JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name), owner=Identity(role=cls.TEST_ROLE), environment=cls.TEST_ENV, jobName=name, numCpus=2, ramMb=2, diskMb=2), instanceId=4237894, assignedPorts={}), status=ScheduleStatus.RUNNING, taskEvents=[ TaskEvent(timestamp=28234726395, status=ScheduleStatus.RUNNING, message="Hi there") ]) tasks.append(task) return tasks
def create_scheduled_task(cls, instance_id, status=ScheduleStatus.RUNNING, task_id=None, initial_time=None): task = ScheduledTask( status=status, assignedTask=AssignedTask(instanceId=instance_id, taskId=task_id or "Task%s" % instance_id, slaveId="Slave%s" % instance_id, slaveHost="Slave%s" % instance_id, task=TaskConfig()), taskEvents=[TaskEvent(timestamp=initial_time or 1000)]) return task
def create_task(self, duration, id, host=None, name=None, prod=None): return ScheduledTask(assignedTask=AssignedTask( instanceId=id, slaveHost=host, task=TaskConfig(production=prod if prod is not None else True, job=JobKey(role=self._role, environment=self._env, name=name or self._name))), status=ScheduleStatus.RUNNING, taskEvents=[ TaskEvent(status=ScheduleStatus.RUNNING, timestamp=(time.time() - duration) * 1000) ])
def create_inactive_tasks(cls): instance = 0 INACTIVE_STATUSES = [ScheduleStatus.KILLED, ScheduleStatus.FINISHED, ScheduleStatus.FAILED] tasks = cls.create_scheduled_tasks() for task in tasks: events = [] for i in range(3): event = TaskEvent( timestamp=28234726395 + (273 * i), status=INACTIVE_STATUSES[i], message="Hi there") events.append(event) task.taskEvents = events task.status = INACTIVE_STATUSES[instance] task.assignedTask.instanceId = instance instance += 1 return set(tasks)
def create_scheduled_tasks(cls): tasks = [] for name in ['foo', 'bar', 'baz']: task = ScheduledTask(failureCount=0, assignedTask=AssignedTask( taskId=1287391823, slaveHost='slavehost', task=cls.create_task_config(name), instanceId=4237894, assignedPorts={}), status=ScheduleStatus.RUNNING, taskEvents=[ TaskEvent(timestamp=28234726395, status=ScheduleStatus.RUNNING, message="Hi there") ]) tasks.append(task) return tasks
def create_task(self, status, id): return ScheduledTask( assignedTask=AssignedTask(instanceId=id, taskId=id), status=status, taskEvents=[TaskEvent(status=status, timestamp=10)])