本文整理汇总了Java中org.apache.mesos.Protos.TaskInfo类的典型用法代码示例。如果您正苦于以下问题:Java TaskInfo类的具体用法?Java TaskInfo怎么用?Java TaskInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TaskInfo类属于org.apache.mesos.Protos包,在下文中一共展示了TaskInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTaskInfoList
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
private List<Protos.TaskInfo> getTaskInfoList(final Collection<String> integrityViolationJobs, final VMAssignmentResult vmAssignmentResult, final String hostname, final Protos.Offer offer) {
List<Protos.TaskInfo> result = new ArrayList<>(vmAssignmentResult.getTasksAssigned().size());
for (TaskAssignmentResult each: vmAssignmentResult.getTasksAssigned()) {
TaskContext taskContext = TaskContext.from(each.getTaskId());
String jobName = taskContext.getMetaInfo().getJobName();
if (!integrityViolationJobs.contains(jobName) && !facadeService.isRunning(taskContext) && !facadeService.isJobDisabled(jobName)) {
Protos.TaskInfo taskInfo = getTaskInfo(offer, each);
if (null != taskInfo) {
result.add(taskInfo);
facadeService.addMapping(taskInfo.getTaskId().getValue(), hostname);
taskScheduler.getTaskAssigner().call(each.getRequest(), hostname);
}
}
}
return result;
}
示例2: buildCustomizedExecutorTaskInfo
import org.apache.mesos.Protos.TaskInfo; //导入依赖的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();
}
示例3: prepTask
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
protected SingularityTask prepTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, boolean separateHosts) {
SingularityPendingTask pendingTask = buildPendingTask(request, deploy, launchTime, instanceNo);
SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
Offer offer;
if (separateHosts) {
offer = createOffer(125, 1024, String.format("slave%s", instanceNo), String.format("host%s", instanceNo));
} else {
offer = createOffer(125, 1024);
}
SingularityTaskId taskId = new SingularityTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, offer.getHostname(), "rack1");
TaskID taskIdProto = TaskID.newBuilder().setValue(taskId.toString()).build();
TaskInfo taskInfo = TaskInfo.newBuilder()
.setSlaveId(offer.getSlaveId())
.setTaskId(taskIdProto)
.setName("name")
.build();
SingularityTask task = new SingularityTask(taskRequest, taskId, offer, taskInfo, Optional.of("rack1"));
taskManager.savePendingTask(pendingTask);
return task;
}
示例4: matchResourceTypes
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
/**
* Ensures that the revocable setting on the executor and task CPU resources match.
*
* @param task Task to check for resource type alignment.
* @return A possibly-modified task, with aligned CPU resource types.
*/
public static TaskInfo matchResourceTypes(TaskInfo task) {
TaskInfo.Builder taskBuilder = task.toBuilder();
Optional<Resource> revocableTaskCpu = taskBuilder.getResourcesList().stream()
.filter(r -> r.getName().equals(CPUS.getMesosName()))
.filter(Resource::hasRevocable)
.findFirst();
ExecutorInfo.Builder executorBuilder = taskBuilder.getExecutorBuilder();
Consumer<Builder> matchRevocable = builder -> {
if (revocableTaskCpu.isPresent()) {
builder.setRevocable(revocableTaskCpu.get().getRevocable());
} else {
builder.clearRevocable();
}
};
executorBuilder.getResourcesBuilderList().stream()
.filter(r -> r.getName().equals(CPUS.getMesosName()))
.forEach(matchRevocable);
return taskBuilder.build();
}
示例5: assign
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
private TaskInfo assign(
MutableStoreProvider storeProvider,
Offer offer,
Set<String> requestedPorts,
String taskId) {
String host = offer.getHostname();
Set<Integer> selectedPorts = Resources.from(offer).getPorts(requestedPorts.size());
Preconditions.checkState(selectedPorts.size() == requestedPorts.size());
final Iterator<String> names = requestedPorts.iterator();
Map<String, Integer> portsByName = FluentIterable.from(selectedPorts)
.uniqueIndex(input -> names.next());
IAssignedTask assigned = stateManager.assignTask(
storeProvider,
taskId,
host,
offer.getSlaveId(),
portsByName);
LOG.info(
"Offer on slave {} (id {}) is being assigned task for {}.",
host, offer.getSlaveId().getValue(), taskId);
return taskFactory.createFrom(assigned, offer);
}
示例6: testTaskInfoRevocable
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
@Test
public void testTaskInfoRevocable() {
expect(tierManager.getTier(TASK_CONFIG)).andReturn(REVOCABLE_TIER);
taskFactory = new MesosTaskFactoryImpl(config, tierManager, SERVER_INFO);
Resource revocableCPU = OFFER_THERMOS_EXECUTOR.getResources(0).toBuilder()
.setRevocable(Resource.RevocableInfo.getDefaultInstance())
.build();
Offer withRevocable = OFFER_THERMOS_EXECUTOR.toBuilder()
.removeResources(0)
.addResources(0, revocableCPU)
.build();
control.replay();
TaskInfo task = taskFactory.createFrom(TASK, withRevocable);
checkTaskResources(TASK.getTask(), task);
assertTrue(task.getResourcesList().stream().anyMatch(Resource::hasRevocable));
checkDiscoveryInfoUnset(task);
}
示例7: checkDiscoveryInfo
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
private void checkDiscoveryInfo(
TaskInfo taskInfo,
Map<String, Integer> assignedPorts,
IJobKey job) {
assertTrue(taskInfo.hasDiscovery());
Protos.DiscoveryInfo.Builder expectedDiscoveryInfo = Protos.DiscoveryInfo.newBuilder()
.setVisibility(Protos.DiscoveryInfo.Visibility.CLUSTER)
.setLocation(CLUSTER_NAME)
.setEnvironment(job.getEnvironment())
.setName(getInverseJobSourceName(job));
for (Map.Entry<String, Integer> entry : assignedPorts.entrySet()) {
expectedDiscoveryInfo.getPortsBuilder().addPorts(
Protos.Port.newBuilder()
.setName(entry.getKey())
.setProtocol(DEFAULT_PORT_PROTOCOL)
.setNumber(entry.getValue()));
}
assertEquals(expectedDiscoveryInfo.build(), taskInfo.getDiscovery());
}
示例8: pack
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
/**
* Packs the TaskInfo in preparation for sending it to the Executor. For a description of how the packing works
* (and why it exists), see the class-level javadoc.
*
* @see #unpack(TaskInfo)
*/
public static TaskInfo pack(TaskInfo taskInfo) {
if (!taskInfo.hasExecutor()) {
return taskInfo;
} else {
ExecutorInfo.Builder executorInfoBuilder = ExecutorInfo.newBuilder()
.setExecutorId(ExecutorID.newBuilder().setValue(COMMAND_DATA_PACKAGE_EXECUTORID));
if (taskInfo.hasCommand()) {
executorInfoBuilder.setCommand(taskInfo.getCommand());
}
if (taskInfo.hasData()) {
executorInfoBuilder.setData(taskInfo.getData());
}
return TaskInfo.newBuilder(taskInfo)
.setData(executorInfoBuilder.build().toByteString())
.clearCommand()
.build();
}
}
示例9: testGlobalMounts
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
@Test
public void testGlobalMounts() {
config = new ExecutorSettings(
new ExecutorConfig(
TestExecutorSettings.THERMOS_EXECUTOR_INFO,
ImmutableList.of(
Volume.newBuilder()
.setHostPath("/host")
.setContainerPath("/container")
.setMode(Mode.RO)
.build())),
false);
expect(tierManager.getTier(TASK_WITH_DOCKER.getTask())).andReturn(DEV_TIER);
taskFactory = new MesosTaskFactoryImpl(config, tierManager, SERVER_INFO);
control.replay();
TaskInfo taskInfo = taskFactory.createFrom(TASK_WITH_DOCKER, OFFER_THERMOS_EXECUTOR);
assertEquals(
config.getExecutorConfig().getVolumeMounts(),
taskInfo.getExecutor().getContainer().getVolumesList());
}
示例10: testMetadataLabelMapping
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
@Test
public void testMetadataLabelMapping() {
expect(tierManager.getTier(TASK.getTask())).andReturn(DEV_TIER);
taskFactory = new MesosTaskFactoryImpl(config, tierManager, SERVER_INFO);
control.replay();
TaskInfo task = taskFactory.createFrom(TASK, OFFER_THERMOS_EXECUTOR);
ImmutableSet<String> labels = task.getLabels().getLabelsList().stream()
.map(l -> l.getKey() + l.getValue())
.collect(GuavaUtils.toImmutableSet());
ImmutableSet<String> metadata = TASK.getTask().getMetadata().stream()
.map(m -> METADATA_LABEL_PREFIX + m.getKey() + m.getValue())
.collect(GuavaUtils.toImmutableSet());
assertEquals(labels, metadata);
checkDiscoveryInfoUnset(task);
}
示例11: testDockerTaskWithoutExecutor
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
@Test
public void testDockerTaskWithoutExecutor() {
AssignedTask builder = TASK.newBuilder();
builder.getTask()
.setContainer(Container.docker(new DockerContainer()
.setImage("hello-world")))
.unsetExecutorConfig();
TaskInfo task = getDockerTaskInfo(IAssignedTask.build(builder));
assertTrue(task.hasCommand());
assertFalse(task.getCommand().getShell());
assertFalse(task.hasData());
ContainerInfo expectedContainer = ContainerInfo.newBuilder()
.setType(Type.DOCKER)
.setDocker(DockerInfo.newBuilder()
.setImage("hello-world"))
.build();
assertEquals(expectedContainer, task.getContainer());
checkDiscoveryInfoUnset(task);
}
示例12: testPopulateDiscoveryInfoNoPort
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
@Test
public void testPopulateDiscoveryInfoNoPort() {
config = new ExecutorSettings(THERMOS_CONFIG, true);
AssignedTask builder = TASK.newBuilder();
builder.getTask().unsetRequestedPorts();
builder.unsetAssignedPorts();
IAssignedTask assignedTask = IAssignedTask.build(builder);
expect(tierManager.getTier(assignedTask.getTask())).andReturn(DEV_TIER);
taskFactory = new MesosTaskFactoryImpl(config, tierManager, SERVER_INFO);
control.replay();
TaskInfo task = taskFactory.createFrom(IAssignedTask.build(builder), OFFER_THERMOS_EXECUTOR);
checkTaskResources(ITaskConfig.build(builder.getTask()), task);
checkDiscoveryInfo(task, ImmutableMap.of(), assignedTask.getTask().getJob());
}
示例13: testExpectedPermanentlyFailedVolume
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
@Test
public void testExpectedPermanentlyFailedVolume() {
TaskInfo failedTask = TaskTestUtils.withFailedFlag(TASK_INFO_2);
when(mockStateStore.fetchTasks()).thenReturn(Arrays.asList(TASK_INFO_1, failedTask));
ResourceCleaner cleaner = new DefaultResourceCleaner(mockStateStore);
List<Offer> offers = OfferTestUtils.getOffers(EXPECTED_RESOURCE_2);
List<OfferRecommendation> recommendations = cleaner.evaluate(offers);
assertEquals("Got: " + recommendations, 2, recommendations.size());
OfferRecommendation rec = recommendations.get(0);
assertEquals(Operation.Type.DESTROY, rec.getOperation().getType());
rec = recommendations.get(1);
assertEquals(Operation.Type.UNRESERVE, rec.getOperation().getType());
}
示例14: record
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
public void record(
Protos.Offer.Operation operation,
Protos.Offer offer) throws Exception {
if (operation.getType() == Protos.Offer.Operation.Type.LAUNCH) {
LOGGER.info("Persisting Launch Operation: {}", TextFormat.shortDebugString(operation));
for (TaskInfo taskInfo : operation.getLaunch().getTaskInfosList()) {
LOGGER.debug("Recording operation: {} for task: {}", operation, taskInfo);
try {
cassandraState.update(TaskUtils.unpackTaskInfo(taskInfo), offer);
} catch (Exception e) {
LOGGER.error("Error updating task in recorder with exception: ", e);
throw e;
}
}
}
}
示例15: LaunchOfferRecommendation
import org.apache.mesos.Protos.TaskInfo; //导入依赖的package包/类
public LaunchOfferRecommendation(
Offer offer,
TaskInfo originalTaskInfo,
Protos.ExecutorInfo executorInfo,
boolean shouldLaunch,
boolean useDefaultExecutor) {
this.offer = offer;
this.shouldLaunch = shouldLaunch;
this.useDefaultExecutor = useDefaultExecutor;
TaskInfo.Builder taskBuilder = originalTaskInfo.toBuilder();
if (!shouldLaunch) {
new TaskLabelWriter(taskBuilder).setTransient();
taskBuilder.getTaskIdBuilder().setValue("");
}
taskBuilder.setSlaveId(offer.getSlaveId());
this.taskInfo = taskBuilder.build();
this.executorInfo = executorInfo;
this.operation = getLaunchOperation();
}