本文整理汇总了Java中org.apache.mesos.Protos.CommandInfo方法的典型用法代码示例。如果您正苦于以下问题:Java Protos.CommandInfo方法的具体用法?Java Protos.CommandInfo怎么用?Java Protos.CommandInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.Protos
的用法示例。
在下文中一共展示了Protos.CommandInfo方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCustomizedExecutorTaskInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Protos.TaskInfo buildCustomizedExecutorTaskInfo(final TaskContext taskContext, final CloudAppConfiguration appConfig, final CloudJobConfiguration jobConfig,
final ShardingContexts shardingContexts, final Protos.Offer offer, final Protos.CommandInfo command) {
Protos.TaskInfo.Builder result = Protos.TaskInfo.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(taskContext.getId()).build())
.setName(taskContext.getTaskName()).setSlaveId(offer.getSlaveId())
.addResources(buildResource("cpus", jobConfig.getCpuCount(), offer.getResourcesList()))
.addResources(buildResource("mem", jobConfig.getMemoryMB(), offer.getResourcesList()))
.setData(ByteString.copyFrom(new TaskInfoData(shardingContexts, jobConfig).serialize()));
Protos.ExecutorInfo.Builder executorBuilder = Protos.ExecutorInfo.newBuilder().setExecutorId(Protos.ExecutorID.newBuilder()
.setValue(taskContext.getExecutorId(jobConfig.getAppName()))).setCommand(command)
.addResources(buildResource("cpus", appConfig.getCpuCount(), offer.getResourcesList()))
.addResources(buildResource("mem", appConfig.getMemoryMB(), offer.getResourcesList()));
if (env.getJobEventRdbConfiguration().isPresent()) {
executorBuilder.setData(ByteString.copyFrom(SerializationUtils.serialize(env.getJobEventRdbConfigurationMap()))).build();
}
return result.setExecutor(executorBuilder.build()).build();
}
示例2: setCommand
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public TaskBuilder setCommand(Job job, Application application, String defaultUnixUser) {
Protos.CommandInfo commandInfo = appToCommandInfo(application, job, assigned.ports(), defaultUnixUser);
builder.setCommand(commandInfo);
if (application.container() instanceof DockerContainer) {
Protos.ContainerInfo containerInfo = appToContainerInfo(application);
builder.setContainer(containerInfo);
} else if (!(application.container() instanceof MesosContainer)) {
LOG.error("Unknown container: {}", application.container());
throw new AssertionError();
}
if (application.getGracePeriod() > 0) {
// seconds to nanoseconds
long d = 1000000000L * application.getGracePeriod();
builder.setKillPolicy(Protos.KillPolicy.newBuilder()
.setGracePeriod(Protos.DurationInfo.newBuilder().setNanoseconds(d)));
}
return this;
}
示例3: testReserveStaticPort
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testReserveStaticPort() throws Exception {
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);
List<OfferRecommendation> recommendations =
evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getCompleteOffers(offeredPorts));
Assert.assertEquals(5, recommendations.size());
Protos.Offer.Operation launchOperation = recommendations.get(4).getOperation();
Protos.TaskInfo taskInfo = launchOperation.getLaunchGroup().getTaskGroup().getTasks(0);
Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
Protos.CommandInfo command = TaskPackingUtils.unpack(taskInfo).getCommand();
Map<String, String> envvars = EnvUtils.toMap(command.getEnvironment());
Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555"));
}
示例4: testReserveStaticPortCustomExecutor
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testReserveStaticPortCustomExecutor() throws Exception {
useCustomExecutor();
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(555, 555);
List<OfferRecommendation> recommendations =
evaluator.evaluate(podInstanceRequirement, OfferTestUtils.getOffers(offeredPorts));
Assert.assertEquals(2, recommendations.size());
Protos.Offer.Operation launchOperation = recommendations.get(1).getOperation();
Protos.TaskInfo taskInfo = launchOperation.getLaunch().getTaskInfos(0);
Protos.Resource fulfilledPortResource = taskInfo.getResources(0);
Assert.assertFalse(getResourceId(fulfilledPortResource).isEmpty());
Protos.CommandInfo command = TaskPackingUtils.unpack(taskInfo).getCommand();
Map<String, String> envvars = EnvUtils.toMap(command.getEnvironment());
Assert.assertEquals(String.valueOf(555), envvars.get(TestConstants.PORT_ENV_NAME + "_555"));
}
示例5: validate
import org.apache.mesos.Protos; //导入方法依赖的package包/类
/**
* Custom Executors are responsible for implementing HealthChecks. This Custom Executor implements a subset of
* all possible Health Checks describable by a HealthCheckInfo object.
* <p>
* They must be command HealthChecks as HTTP is not recommended by Mesos yet and is unneeded from a completeness
* perspective. `curl -f` normally is sufficient. Since all HealthChecks as currently implemented by this Custom
* Executor are excuted as sub-processes we further require that the HealthCheck specifies that it is a "shell"
* command to avoid unexpected behavior.
*
* @param healthCheck The HealthCheck to be executed
* @throws CheckValidationException when a HealthCheck does not adhere to the HealthChecks supported
* by this Custom Executor
*/
private void validate(Protos.HealthCheck healthCheck) throws CheckValidationException {
// Validate HealthCheck
if (healthCheck.hasHttp()) {
throw new CheckValidationException(String.format(
"The following %s check contains an unsupported HTTP configuration: %s", checkType, healthCheck));
}
if (!healthCheck.hasCommand()) {
throw new CheckValidationException(String.format(
"The following %s check does not contain a Command: %s", checkType, healthCheck));
}
// Validate Command
Protos.CommandInfo commandInfo = healthCheck.getCommand();
if (!Boolean.valueOf(commandInfo.getShell())) {
throw new CheckValidationException(String.format(
"Only shell based %s checks are supported for commmand: %s", checkType, commandInfo));
}
}
示例6: getTaskInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Protos.TaskInfo getTaskInfo(final Protos.Offer offer, final TaskAssignmentResult taskAssignmentResult) {
TaskContext taskContext = TaskContext.from(taskAssignmentResult.getTaskId());
Optional<CloudJobConfiguration> jobConfigOptional = facadeService.load(taskContext.getMetaInfo().getJobName());
if (!jobConfigOptional.isPresent()) {
return null;
}
CloudJobConfiguration jobConfig = jobConfigOptional.get();
Optional<CloudAppConfiguration> appConfigOptional = facadeService.loadAppConfig(jobConfig.getAppName());
if (!appConfigOptional.isPresent()) {
return null;
}
CloudAppConfiguration appConfig = appConfigOptional.get();
taskContext.setSlaveId(offer.getSlaveId().getValue());
ShardingContexts shardingContexts = getShardingContexts(taskContext, appConfig, jobConfig);
boolean isCommandExecutor = CloudJobExecutionType.TRANSIENT == jobConfig.getJobExecutionType() && JobType.SCRIPT == jobConfig.getTypeConfig().getJobType();
String script = appConfig.getBootstrapScript();
if (isCommandExecutor) {
script = ((ScriptJobConfiguration) jobConfig.getTypeConfig()).getScriptCommandLine();
}
Protos.CommandInfo.URI uri = buildURI(appConfig, isCommandExecutor);
Protos.CommandInfo command = buildCommand(uri, script, shardingContexts, isCommandExecutor);
if (isCommandExecutor) {
return buildCommandExecutorTaskInfo(taskContext, jobConfig, shardingContexts, offer, command);
} else {
return buildCustomizedExecutorTaskInfo(taskContext, appConfig, jobConfig, shardingContexts, offer, command);
}
}
示例7: buildCommandExecutorTaskInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Protos.TaskInfo buildCommandExecutorTaskInfo(final TaskContext taskContext, final CloudJobConfiguration jobConfig, final ShardingContexts shardingContexts,
final Protos.Offer offer, final Protos.CommandInfo command) {
Protos.TaskInfo.Builder result = Protos.TaskInfo.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(taskContext.getId()).build())
.setName(taskContext.getTaskName()).setSlaveId(offer.getSlaveId())
.addResources(buildResource("cpus", jobConfig.getCpuCount(), offer.getResourcesList()))
.addResources(buildResource("mem", jobConfig.getMemoryMB(), offer.getResourcesList()))
.setData(ByteString.copyFrom(new TaskInfoData(shardingContexts, jobConfig).serialize()));
return result.setCommand(command).build();
}
示例8: buildCommand
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Protos.CommandInfo buildCommand(final Protos.CommandInfo.URI uri, final String script, final ShardingContexts shardingContexts, final boolean isCommandExecutor) {
Protos.CommandInfo.Builder result = Protos.CommandInfo.newBuilder().addUris(uri).setShell(true);
if (isCommandExecutor) {
CommandLine commandLine = CommandLine.parse(script);
commandLine.addArgument(GsonFactory.getGson().toJson(shardingContexts), false);
result.setValue(Joiner.on(" ").join(commandLine.getExecutable(), Joiner.on(" ").join(commandLine.getArguments())));
} else {
result.setValue(script);
}
return result.build();
}
示例9: main
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public static void main(String[] args) {
String path = System.getProperty("user.dir") + "/target/scala-2.10/mesos-pi-assembly-1.0.jar";
Protos.CommandInfo.URI uri = Protos.CommandInfo.URI.newBuilder().setValue(path).setExtract(false).build();
String commandPi = "java -cp mesos-pi-assembly-1.0.jar PiExecutor";
Protos.CommandInfo piCommandInfo = Protos.CommandInfo.newBuilder().setValue(commandPi).addUris(uri)
.build();
Protos.ExecutorInfo piExecutorInfo = Protos.ExecutorInfo.newBuilder()
.setExecutorId(Protos.ExecutorID.newBuilder()
.setValue("CalculatePi")).setCommand(piCommandInfo)
.setName("PiExecutor").setSource("java").build();
Protos.FrameworkInfo.Builder frameworkBuilder = Protos.FrameworkInfo.newBuilder()
.setFailoverTimeout(120000).setUser("")
.setName("PiFramework")
.setPrincipal("test-framework-java");
if (System.getenv("MESOS_CHECKPOINT") != null) {
System.out.println("Enabling checkpoint for the framework");
frameworkBuilder.setCheckpoint(true);
}
Scheduler scheduler = new PiScheduler(piExecutorInfo, 1);
MesosSchedulerDriver schedulerDriver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), args[0]);;
int status = schedulerDriver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;
schedulerDriver.stop();
System.exit(status);
}
示例10: getExecutorInfoBuilder
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private static Protos.ExecutorInfo.Builder getExecutorInfoBuilder() {
Protos.CommandInfo cmd = Protos.CommandInfo.newBuilder().build();
return Protos.ExecutorInfo.newBuilder()
.setExecutorId(Protos.ExecutorID.newBuilder().setValue(""))
.setName(TestConstants.EXECUTOR_NAME)
.setCommand(cmd);
}
示例11: testGetNewOfferRequirement
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testGetNewOfferRequirement() throws Exception {
OfferRequirement requirement = provider.getNewOfferRequirement(
CassandraTask.TYPE.CASSANDRA_DAEMON.name(),
testTaskInfo);
Protos.TaskInfo taskInfo = requirement.getTaskRequirements().iterator().next().getTaskInfo();
Assert.assertEquals(taskInfo.getName(), "test-daemon");
Assert.assertTrue(taskInfo.getTaskId().getValue().contains("test-daemon"));
Assert.assertEquals(taskInfo.getSlaveId().getValue(), "");
List<Protos.Resource> resources = taskInfo.getResourcesList();
Assert.assertEquals(4, resources.size());
Protos.Resource cpusResource = resources.get(0);
Assert.assertEquals("cpus", cpusResource.getName());
Assert.assertEquals(Protos.Value.Type.SCALAR, cpusResource.getType());
Assert.assertEquals(testCpus, cpusResource.getScalar().getValue(), 0.0);
Assert.assertEquals(testRole, cpusResource.getRole());
Assert.assertEquals(testPrincipal, cpusResource.getReservation().getPrincipal());
Assert.assertEquals("resource_id", cpusResource.getReservation().getLabels().getLabelsList().get(0).getKey());
Assert.assertEquals(testResourceId, cpusResource.getReservation().getLabels().getLabelsList().get(0).getValue());
Protos.Resource memResource = resources.get(1);
Assert.assertEquals("mem", memResource.getName());
Assert.assertEquals(Protos.Value.Type.SCALAR, memResource.getType());
Assert.assertEquals(testMem, memResource.getScalar().getValue(), 0.0);
Assert.assertEquals(testRole, memResource.getRole());
Assert.assertEquals(testPrincipal, memResource.getReservation().getPrincipal());
Assert.assertEquals("resource_id", memResource.getReservation().getLabels().getLabelsList().get(0).getKey());
Assert.assertEquals(testResourceId, memResource.getReservation().getLabels().getLabelsList().get(0).getValue());
Protos.Resource diskResource = resources.get(2);
Assert.assertEquals("disk", diskResource.getName());
Assert.assertEquals(Protos.Value.Type.SCALAR, diskResource.getType());
Assert.assertEquals(testDisk, diskResource.getScalar().getValue(), 0.0);
Assert.assertEquals(testRole, diskResource.getRole());
Assert.assertEquals(testPrincipal, diskResource.getReservation().getPrincipal());
Assert.assertEquals("resource_id", diskResource.getReservation().getLabels().getLabelsList().get(0).getKey());
Assert.assertEquals(testResourceId, diskResource.getReservation().getLabels().getLabelsList().get(0).getValue());
Protos.Resource portsResource = resources.get(3);
Assert.assertEquals("ports", portsResource.getName());
Assert.assertEquals(Protos.Value.Type.RANGES, portsResource.getType());
Assert.assertTrue(portsResource.getRanges().getRangeList().get(0).getBegin() >= testPortBegin);
Assert.assertTrue(portsResource.getRanges().getRangeList().get(0).getEnd() >= testPortBegin);
Assert.assertEquals(testRole, portsResource.getRole());
Assert.assertEquals(testPrincipal, portsResource.getReservation().getPrincipal());
Assert.assertEquals("resource_id", portsResource.getReservation().getLabels().getLabelsList().get(0).getKey());
Assert.assertEquals(testResourceId, portsResource.getReservation().getLabels().getLabelsList().get(0).getValue());
final Protos.ExecutorInfo executorInfo = requirement.getExecutorRequirementOptional().get().getExecutorInfo();
Protos.CommandInfo cmd = executorInfo.getCommand();
Assert.assertEquals(4, cmd.getUrisList().size());
List<Protos.CommandInfo.URI> urisList = new ArrayList<>(cmd.getUrisList());
urisList.sort((a, b) -> a.getValue().compareTo(b.getValue()));
Assert.assertEquals(
config.getExecutorConfig().getLibmesosLocation().toString(),
urisList.get(0).getValue());
Assert.assertEquals(
config.getExecutorConfig().getJreLocation().toString(),
urisList.get(1).getValue());
Assert.assertEquals(
config.getExecutorConfig().getCassandraLocation().toString(),
urisList.get(2).getValue());
Assert.assertEquals(
config.getExecutorConfig().getExecutorLocation().toString(),
urisList.get(3).getValue());
}
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:71,代码来源:ClusterTaskOfferRequirementProviderTest.java
示例12: run
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Override
public void run() {
if (launchedTask.isDone()) {
// The task has exited (and emitted a TaskStatus about itself). Stop pending health checks against it.
String message = String.format("Disabling %s check for task '%s': task process has exited",
checkType, taskInfo.getName());
LOGGER.info(message);
throw new CheckRuntimeException(message, healthCheckStats);
}
Protos.CommandInfo commandInfo = healthCheck.getCommand();
try {
LOGGER.info("Running {} check process for task {}: {}",
checkType, taskInfo.getName(), commandInfo.getValue());
int exitValue = processRunner.run(
ProcessBuilderUtils.buildProcess(commandInfo), healthCheck.getTimeoutSeconds());
if (exitValue != 0) {
healthCheckStats.failed();
LOGGER.error("{} check failed with exit code {}: {}",
checkType, exitValue, commandInfo.getValue());
} else {
LOGGER.info("{} check succeeded: {}", checkType, commandInfo.getValue());
healthCheckStats.succeeded();
}
LOGGER.debug("{} check stats: {}", checkType, healthCheckStats);
} catch (Throwable t) {
LOGGER.error(String.format(
"%s check failed with exception: %s", checkType, TextFormat.shortDebugString(commandInfo)),
t);
healthCheckStats.failed();
}
// Health checks have a positive consecutive failure count, readiness
// checks do not.
if (healthCheck.getConsecutiveFailures() > 0) {
handleHealthCheck();
} else {
handleReadinessCheck();
}
}
示例13: createCommandInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private static Protos.CommandInfo createCommandInfo() {
Protos.CommandInfo.Builder commandInfoBuilder = Protos.CommandInfo.newBuilder()
.setValue("date");
commandInfoBuilder.getEnvironmentBuilder().addVariablesBuilder().setName(TASK_TYPE).setValue(TEST);
return commandInfoBuilder.build();
}
示例14: buildProcess
import org.apache.mesos.Protos; //导入方法依赖的package包/类
/**
* Returns a {@link ProcessBuilder} instance which has been initialized with the provided
* {@link Protos.CommandInfo}'s command and environment.
*/
public static ProcessBuilder buildProcess(Protos.CommandInfo cmd) {
return buildProcess(cmd.getValue(), EnvUtils.toMap(cmd.getEnvironment()));
}