本文整理汇总了Python中pymesos.MesosSchedulerDriver.reviveOffers方法的典型用法代码示例。如果您正苦于以下问题:Python MesosSchedulerDriver.reviveOffers方法的具体用法?Python MesosSchedulerDriver.reviveOffers怎么用?Python MesosSchedulerDriver.reviveOffers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymesos.MesosSchedulerDriver
的用法示例。
在下文中一共展示了MesosSchedulerDriver.reviveOffers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_revive_offers
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import reviveOffers [as 别名]
def test_revive_offers(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._stream_id = str(uuid.uuid4())
driver.reviveOffers()
driver._send.assert_called_once_with({
'type': 'REVIVE',
'framework_id': {
'value': ID
},
})
示例2: ProcScheduler
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import reviveOffers [as 别名]
#.........这里部分代码省略.........
def _call_finished(self, proc_id, success, message, data, slave_id=None):
with self._lock:
proc = self.procs_launched.pop(proc_id)
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")
示例3: MesosScheduler
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import reviveOffers [as 别名]
#.........这里部分代码省略.........
self.task_per_node, self.out_logger, self.err_logger,
self.logLevel, env.environ
)
))
return info
@safe
def submitTasks(self, tasks):
if not tasks:
return
job = SimpleJob(self, tasks, self.cpus, tasks[0].rdd.mem or self.mem)
self.activeJobs[job.id] = job
self.activeJobsQueue.append(job)
self.jobTasks[job.id] = set()
logger.info(
'Got job %d with %d tasks: %s',
job.id,
len(tasks),
tasks[0].rdd)
need_revive = self.started
if not self.started:
self.start_driver()
while not self.isRegistered:
self.lock.release()
time.sleep(0.01)
self.lock.acquire()
if need_revive:
self.requestMoreResources()
def requestMoreResources(self):
logger.debug('reviveOffers')
self.driver.reviveOffers()
@safe
def resourceOffers(self, driver, offers):
rf = Dict()
if not self.activeJobs:
rf.refuse_seconds = 60 * 5
for o in offers:
driver.declineOffer(o.id, rf)
return
start = time.time()
random.shuffle(offers)
cpus = [self.getResource(o.resources, 'cpus') for o in offers]
mems = [self.getResource(o.resources, 'mem')
- (o.agent_id.value not in self.agentTasks
and EXECUTOR_MEMORY or 0)
for o in offers]
logger.debug('get %d offers (%s cpus, %s mem), %d jobs',
len(offers), sum(cpus), sum(mems), len(self.activeJobs))
tasks = {}
for job in self.activeJobsQueue:
while True:
launchedTask = False
for i, o in enumerate(offers):
sid = o.agent_id.value
group = (
self.getAttribute(
o.attributes,
'group') or 'None')
if (self.group or group.startswith(
示例4:
# 需要导入模块: from pymesos import MesosSchedulerDriver [as 别名]
# 或者: from pymesos.MesosSchedulerDriver import reviveOffers [as 别名]
from rfoo.utils import rconsole
rconsole.spawn_server(locals(), 0)
except ImportError:
pass
start = time.time()
try:
while not sched.stopped:
time.sleep(0.1)
now = time.time()
sched.check(driver)
if (not sched.started and sched.next_try > 0 and
now > sched.next_try):
sched.next_try = 0
driver.reviveOffers()
if not sched.started and now > sched.last_offer_time + \
60 + random.randint(0, 5):
logger.warning('too long to get offer, reviving...')
sched.last_offer_time = now
driver.reviveOffers()
if now - start > options.timeout:
logger.warning('job timeout in %d seconds', options.timeout)
sched.stop(2)
break
except KeyboardInterrupt:
logger.warning('stopped by KeyboardInterrupt')
sched.stop(4)