本文整理汇总了Python中pymesos.MesosSchedulerDriver.killTask方法的典型用法代码示例。如果您正苦于以下问题:Python MesosSchedulerDriver.killTask方法的具体用法?Python MesosSchedulerDriver.killTask怎么用?Python MesosSchedulerDriver.killTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymesos.MesosSchedulerDriver
的用法示例。
在下文中一共展示了MesosSchedulerDriver.killTask方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_kill_task
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import killTask [as 别名]
def test_kill_task(mocker):
ID = str(uuid.uuid4())
sched = mocker.Mock()
framework = {'id': {'value': ID}}
master = mocker.Mock()
driver = MesosSchedulerDriver(sched, framework, master)
driver._send = mocker.Mock()
driver.killTask({"value": "my-task"})
driver._send.assert_not_called()
driver._stream_id = str(uuid.uuid4())
driver.killTask({"value": "my-task"})
driver._send.assert_called_once_with({
'type': 'KILL',
'framework_id': {'value': ID},
'kill': {
'task_id': {'value': 'my-task'},
}
})
示例2: ProcScheduler
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import killTask [as 别名]
#.........这里部分代码省略.........
if slave_id is not None:
if slave_id in self.slave_to_proc:
self.slave_to_proc[slave_id].remove(proc_id)
else:
for slave_id, procs in self.slave_to_proc.iteritems():
if proc_id in procs:
procs.remove(proc_id)
proc._finished(success, message, data)
def statusUpdate(self, driver, update):
with self._lock:
proc_id = int(update.task_id.value)
logger.info("Status update for proc, id=%s, state=%s" % (proc_id, update.state))
if update.state == mesos_pb2.TASK_RUNNING:
if update.slave_id.value in self.slave_to_proc:
self.slave_to_proc[update.slave_id.value].add(proc_id)
else:
self.slave_to_proc[update.slave_id.value] = set([proc_id])
proc = self.procs_launched[proc_id]
proc._started()
elif update.state >= mesos_pb2.TASK_FINISHED:
slave_id = update.slave_id.value
success = update.state == mesos_pb2.TASK_FINISHED
message = update.message
data = update.data and pickle.loads(update.data)
self._call_finished(proc_id, success, message, data, slave_id)
driver.reviveOffers()
def offerRescinded(self, driver, offer_id):
with self._lock:
if self.procs_pending:
logger.info("Revive offers for pending procs")
driver.reviveOffers()
def slaveLost(self, driver, slave_id):
with self._lock:
for proc_id in self.slave_to_proc.pop(slave_id, []):
self._call_finished(proc_id, False, "Slave lost", None, slave_id)
def error(self, driver, message):
with self._lock:
for proc in self.procs_pending.values():
self._call_finished(proc.id, False, "Stopped", None)
for proc in self.procs_launched.values():
self._call_finished(proc.id, False, "Stopped", None)
self.stop()
def start(self):
self.driver.start()
def stop(self):
assert not self.driver.aborted
self.driver.stop()
def submit(self, proc):
if self.driver.aborted:
raise RuntimeError("driver already aborted")
with self._lock:
if proc.id not in self.procs_pending:
logger.info("Try submit proc, id=%s", (proc.id,))
self.procs_pending[proc.id] = proc
if len(self.procs_pending) == 1:
logger.info("Revive offers for pending procs")
self.driver.reviveOffers()
else:
raise ValueError("Proc with same id already submitted")
def cancel(self, proc):
if self.driver.aborted:
raise RuntimeError("driver already aborted")
with self._lock:
if proc.id in self.procs_pending:
del self.procs_pending[proc.id]
elif proc.id in self.procs_launched:
del self.procs_launched[proc.id]
self.driver.killTask(mesos_pb2.TaskID(value=str(proc.id)))
for slave_id, procs in self.slave_to_proc.items():
procs.pop(proc.id)
if not procs:
del self.slave_to_proc[slave_id]
def send_data(self, pid, type, data):
if self.driver.aborted:
raise RuntimeError("driver already aborted")
msg = pickle.dumps((pid, type, data))
for slave_id, procs in self.slave_to_proc.iteritems():
if pid in procs:
self.driver.sendFrameworkMessage(self.executor.executor_id, mesos_pb2.SlaveID(value=slave_id), msg)
return
raise RuntimeError("Cannot find slave for pid %s" % (pid,))
示例3: MesosScheduler
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import killTask [as 别名]
#.........这里部分代码省略.........
if len(task.data) > 1000 * 1024:
logger.warning('task too large: %s %d',
t, len(task.data))
resources = task.resources = []
cpu = Dict()
resources.append(cpu)
cpu.name = 'cpus'
cpu.type = 'SCALAR'
cpu.scalar.value = t.cpus
mem = Dict()
resources.append(mem)
mem.name = 'mem'
mem.type = 'SCALAR'
mem.scalar.value = t.mem
return task
@safe
def statusUpdate(self, driver, status):
tid = status.task_id.value
state = status.state
logger.debug('status update: %s %s', tid, state)
jid = self.taskIdToJobId.get(tid)
_, task_id, tried = map(int, tid.split(':'))
if state == 'TASK_RUNNING':
if jid in self.activeJobs:
job = self.activeJobs[jid]
job.statusUpdate(task_id, tried, state)
else:
logger.debug('kill task %s as its job has gone', tid)
self.driver.killTask(Dict(value=tid))
return
self.taskIdToJobId.pop(tid, None)
if jid in self.jobTasks:
self.jobTasks[jid].remove(tid)
if tid in self.taskIdToAgentId:
agent_id = self.taskIdToAgentId[tid]
if agent_id in self.agentTasks:
self.agentTasks[agent_id] -= 1
del self.taskIdToAgentId[tid]
if jid not in self.activeJobs:
logger.debug('ignore task %s as its job has gone', tid)
return
job = self.activeJobs[jid]
data = status.get('data')
if state in ('TASK_FINISHED', 'TASK_FAILED') and data:
try:
reason, result, accUpdate = cPickle.loads(
decode_data(data))
if result:
flag, data = result
if flag >= 2:
try:
data = urllib.urlopen(data).read()
except IOError:
# try again
data = urllib.urlopen(data).read()
flag -= 2
data = decompress(data)