本文整理汇总了Java中org.apache.mesos.SchedulerDriver.declineOffer方法的典型用法代码示例。如果您正苦于以下问题:Java SchedulerDriver.declineOffer方法的具体用法?Java SchedulerDriver.declineOffer怎么用?Java SchedulerDriver.declineOffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.SchedulerDriver
的用法示例。
在下文中一共展示了SchedulerDriver.declineOffer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resourceOffers
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) {
synchronized (_offersLock) {
if (_offers == null) {
return;
}
LOG.debug("resourceOffers: Currently have {} offers buffered {}",
_offers.size(), (_offers.size() > 0 ? (":" + offerMapToString(_offers)) : ""));
for (Protos.Offer offer : offers) {
if (isHostAccepted(offer.getHostname())) {
LOG.debug("resourceOffers: Recording offer from host: {}, offerId: {}",
offer.getHostname(), offer.getId().getValue());
_offers.put(offer.getId(), offer);
} else {
LOG.debug("resourceOffers: Declining offer from host: {}, offerId: {}",
offer.getHostname(), offer.getId().getValue());
driver.declineOffer(offer.getId());
}
}
LOG.debug("resourceOffers: After processing offers, now have {} offers buffered: {}",
_offers.size(), offerMapToString(_offers));
}
}
示例2: resourceOffers
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@Override
public void resourceOffers(SchedulerDriver driver, List<Offer> offers) {
lastOfferTimestamp = Optional.of(System.currentTimeMillis());
if (!isRunning()) {
LOG.info(String.format("Scheduler is in state %s, declining %s offer(s)", state.name(), offers.size()));
for (Protos.Offer offer : offers) {
driver.declineOffer(offer.getId());
}
return;
}
final long start = System.currentTimeMillis();
lock.lock();
try {
scheduler.resourceOffers(driver, offers);
} catch (Throwable t) {
handleUncaughtSchedulerException(t);
} finally {
lock.unlock();
LOG.debug("Handled {} resource offers in {}", offers.size(), JavaUtils.duration(start));
}
}
示例3: slaveLost
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@Override
public void slaveLost(SchedulerDriver driver, Protos.SlaveID slaveId) {
LOG.warn("Slave lost: {}", slaveId.getValue());
for (Map.Entry<String, List<Protos.SlaveID>> entry : slaves.entrySet()) {
List<Protos.SlaveID> list = entry.getValue();
for (Protos.SlaveID s : list) {
if (s.getValue().equals(slaveId.getValue())) {
list.remove(s);
}
}
slaves.put(entry.getKey(), list);
}
// TODO: remove **ONLY** tasks that is running on the failed slave
Stanchion.schedule(() -> reconcileAllRunningJobs(driver));
// There is a potential race between offerRescinded/slaveLost and using offer stocks;
// in case handleAll trying to schedule tasks, offers are removed from offerStock
// but being used to schedule tasks - this message can't be in time ...
// The task with rescinded offer (slave) might fail in advance; TASK_FAILED or TASK_LOST?
// any way in this case it should be retried...
//
// Clean up stocked offers from lost slave, or kept long dead
// TODO: add tests on github #153 bug, this is a quick patch
synchronized (offerStock) {
Protos.Offer offer = offerStock.remove(slaveId.getValue());
if (offer != null) {
driver.declineOffer(offer.getId());
}
}
updateOfferStats();
}
示例4: doRegistration
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
public void doRegistration(final SchedulerDriver driver, Protos.FrameworkID id) {
_driver = driver;
_state.put(FRAMEWORK_ID, id.getValue());
Number filterSeconds = Optional.fromNullable((Number) _conf.get(CONF_MESOS_OFFER_FILTER_SECONDS)).or(120);
final Protos.Filters filters = Protos.Filters.newBuilder()
.setRefuseSeconds(filterSeconds.intValue())
.build();
_offers = new RotatingMap<>(
new RotatingMap.ExpiredCallback<Protos.OfferID, Protos.Offer>() {
@Override
public void expire(Protos.OfferID key, Protos.Offer val) {
driver.declineOffer(
val.getId(),
filters
);
}
}
);
Number lruCacheSize = Optional.fromNullable((Number) _conf.get(CONF_MESOS_OFFER_LRU_CACHE_SIZE)).or(1000);
final int intLruCacheSize = lruCacheSize.intValue();
_usedOffers = Collections.synchronizedMap(new LinkedHashMap<Protos.TaskID, Protos.Offer>(intLruCacheSize + 1, .75F, true) {
// This method is called just after a new entry has been added
public boolean removeEldestEntry(Map.Entry eldest) {
return size() > intLruCacheSize;
}
});
Number offerExpired = Optional.fromNullable((Number) _conf.get(Config.NIMBUS_MONITOR_FREQ_SECS)).or(10);
Number expiryMultiplier = Optional.fromNullable((Number) _conf.get(CONF_MESOS_OFFER_EXPIRY_MULTIPLIER)).or(2.5);
_timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
synchronized (_offersLock) {
_offers.rotate();
}
} catch (Throwable t) {
LOG.error("Received fatal error Halting process...", t);
Runtime.getRuntime().halt(2);
}
}
}, 0, Math.round(1000 * expiryMultiplier.doubleValue() * offerExpired.intValue()));
}
示例5: declineOffer
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
public int declineOffer(SchedulerDriver driver, Protos.Filters filters) {
for (Protos.Offer offer : offers) {
driver.declineOffer(offer.getId(), filters);
}
return offers.size();
}
示例6: resourceOffers
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@Override
public void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> offers) {
loggerWrapper.debug("Resource offers with " + offers.size() + " offers" );
for (Protos.Offer offer : offers) {
if (!constraints.constraintsAllow(offer) ||
runningInstances.size() + pendingInstances.size() >= desiredInstances) {
schedulerDriver.declineOffer(offer.getId());
schedulerDriver.suppressOffers();
continue;
}
Double offerCpus = 0d;
Double offerMem = 0d;
for (Resource resource : offer.getResourcesList()) {
if (resource.getName().equals("cpus")) {
offerCpus += resource.getScalar().getValue();
} else if (resource.getName().equals("mem")) {
offerMem += resource.getScalar().getValue();
}
}
if (offerCpus < cpu || offerMem < memory) {
schedulerDriver.declineOffer(offer.getId());
continue;
}
List<Protos.TaskInfo> tasks = new ArrayList<>();
// generate a unique task ID
Protos.TaskID taskId = Protos.TaskID.newBuilder()
.setValue(TaskIdGeneratorHelper.getTaskId(context)).build();
loggerWrapper.debug("Launching task " + taskId.getValue());
pendingInstances.add(taskId.getValue());
// docker image info
Protos.ContainerInfo.DockerInfo.Builder dockerInfoBuilder = Protos.ContainerInfo.DockerInfo.newBuilder();
dockerInfoBuilder.setImage(imageName);
dockerInfoBuilder.setNetwork(Protos.ContainerInfo.DockerInfo.Network.BRIDGE);
dockerInfoBuilder.setForcePullImage(forcePullImage);
if (!parameters.isEmpty()) {
dockerInfoBuilder.addAllParameters(parameters);
}
// container info
Protos.ContainerInfo.Builder containerInfoBuilder = Protos.ContainerInfo.newBuilder();
containerInfoBuilder.setType(Protos.ContainerInfo.Type.DOCKER);
containerInfoBuilder.setDocker(dockerInfoBuilder.build());
if (!volumes.isEmpty()) {
containerInfoBuilder.addAllVolumes(volumes);
}
// create task to run
Protos.TaskInfo task = Protos.TaskInfo.newBuilder()
.setName("task " + taskId.getValue())
.setTaskId(taskId)
.setSlaveId(offer.getSlaveId())
.addResources(Protos.Resource.newBuilder()
.setName("cpus")
.setType(Protos.Value.Type.SCALAR)
.setScalar(Protos.Value.Scalar.newBuilder().setValue(cpu)))
.addResources(Protos.Resource.newBuilder()
.setName("mem")
.setType(Protos.Value.Type.SCALAR)
.setScalar(Protos.Value.Scalar.newBuilder().setValue(memory)))
.setContainer(containerInfoBuilder)
.setCommand(commandInfoBuilder)
.build();
tasks.add(task);
loggerWrapper.task = task;
loggerWrapper.stoptMesosTailWait();
// Only accept offer when tasks size greater than 0.
Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build();
schedulerDriver.launchTasks(offer.getId(), tasks, filters);
}
}
示例7: resourceOffers
import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@Override
public void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> list) {
for (Protos.Offer offer : list) {
Protos.SlaveID slaveId = offer.getSlaveId();
if (needMoreNodes() && !slaveContainsHazelcastNode(slaveId)) {
System.out.println("Launching Hazelcast on slaveId = " + slaveId.getValue());
Protos.TaskID.Builder taskId = Protos.TaskID.newBuilder().setValue("node-" + slaveId.getValue());
HazelcastMessages.HazelcastServerProcessTask processTask = HazelcastMessages.HazelcastServerProcessTask
.newBuilder()
.setVersion(getHazelcastVersion())
.addCommand("java")
.addCommand("-server")
.addCommand("-Xms" + getMinHeap())
.addCommand("-Xmx" + getMaxHeap())
.addCommand("-Djava.net.preferIPv4Stack=true")
.addCommand("-cp")
.addCommand("hazelcast-" + getHazelcastVersion() + ".jar:hazelcast-zookeeper.jar")
.addCommand("com.hazelcast.core.server.StartServer")
.build();
Protos.TaskInfo.Builder builder = Protos.TaskInfo.newBuilder()
.setSlaveId(slaveId)
.setName("Hazelcast node")
.addResources(resource("cpus", getCpuPerNode()))
.addResources(resource("mem", getMemoryPerNode()))
.setData(processTask.toByteString())
.setTaskId(taskId);
Protos.ExecutorInfo executor = buildExecutor();
Protos.TaskInfo taskInfo = builder.setExecutor(executor).build();
schedulerDriver.launchTasks(singletonList(offer.getId()), singletonList(taskInfo));
HazelcastNode hazelcastNode = new HazelcastNode(offer.getHostname(), slaveId.getValue(), taskId.getValue());
activeNodes.add(hazelcastNode);
} else if (needLessNodes() && slaveContainsHazelcastNode(slaveId)) {
Protos.TaskID taskID = Protos.TaskID.newBuilder().setValue("node-" + slaveId.getValue()).build();
schedulerDriver.killTask(taskID);
removeNodeFromActiveNodesWithTaskID(taskID);
} else {
schedulerDriver.declineOffer(offer.getId());
}
}
}