本文整理汇总了Java中org.apache.mesos.Protos.Resource方法的典型用法代码示例。如果您正苦于以下问题:Java Protos.Resource方法的具体用法?Java Protos.Resource怎么用?Java Protos.Resource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.Protos
的用法示例。
在下文中一共展示了Protos.Resource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRefineStaticResource
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testRefineStaticResource() {
ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
try {
ResourceSpec resourceSpec = new DefaultResourceSpec(
"cpus",
value,
TestConstants.ROLE,
TestConstants.PRE_RESERVED_ROLE,
TestConstants.PRINCIPAL);
ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, Optional.empty());
Protos.Resource resource = resourceBuilder.build();
Assert.assertEquals(2, resource.getReservationsCount());
validateScalarResourceRefined(resource);
Assert.assertEquals(Protos.Resource.ReservationInfo.Type.STATIC, resource.getReservations(0).getType());
Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE, resource.getReservations(0).getRole());
} finally {
context.reset();
}
}
示例2: testLaunchExpectedStaticPortCustomExecutor
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testLaunchExpectedStaticPortCustomExecutor() throws Exception {
useCustomExecutor();
// Launch for the first time: get port 555
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirementTestUtils.getPortRequirement(555);
Resource reserveResource = recordLaunchWithOfferedResources(
podInstanceRequirement,
ResourceTestUtils.getUnreservedPorts(555, 555)).get(0);
String resourceId = getResourceId(reserveResource);
// Launch on previously reserved resources
List<OfferRecommendation> recommendations = evaluator.evaluate(
podInstanceRequirement,
OfferTestUtils.getOffers(ResourceTestUtils.getReservedPorts(555, 555, resourceId)));
Assert.assertEquals(1, recommendations.size());
// Validate LAUNCH Operation
Protos.Offer.Operation launchOperation = recommendations.get(0).getOperation();
Assert.assertEquals(Protos.Offer.Operation.Type.LAUNCH, launchOperation.getType());
Protos.Resource launchResource = launchOperation.getLaunch().getTaskInfos(0).getResources(0);
Assert.assertEquals(resourceId, getResourceId(launchResource));
}
示例3: getUnreservedResource
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@SuppressWarnings("deprecation") // for Resource.setRole()
private static Protos.Resource getUnreservedResource(String name, Protos.Value value, String role) {
Protos.Resource.Builder resBuilder = Protos.Resource.newBuilder()
.setName(name)
.setType(value.getType())
.setRole(role);
if (!role.equals(Constants.ANY_ROLE)) {
// Fill in the prereserved role info:
resBuilder.addReservationsBuilder()
.setRole(role)
.setPrincipal(TestConstants.PRINCIPAL);
}
switch (value.getType()) {
case SCALAR:
return resBuilder.setScalar(value.getScalar()).build();
case RANGES:
return resBuilder.setRanges(value.getRanges()).build();
case SET:
return resBuilder.setSet(value.getSet()).build();
default:
return null;
}
}
示例4: buildResource
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Protos.Resource buildResource(final String type, final double resourceValue, final List<Protos.Resource> resources) {
return Protos.Resource.newBuilder().mergeFrom(Iterables.find(resources, new Predicate<Protos.Resource>() {
@Override
public boolean apply(final Protos.Resource input) {
return input.getName().equals(type);
}
})).setScalar(Protos.Value.Scalar.newBuilder().setValue(resourceValue)).build();
}
示例5: create
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Override
public Protos.TaskInfo create(String taskId, Protos.Offer offer, List<Protos.Resource> resources, ExecutionParameters executionParameters) {
logger.debug("Creating Mesos task for taskId={}", taskId);
return Protos.TaskInfo.newBuilder()
.setName(applicationName + ".task")
.setSlaveId(offer.getSlaveId())
.setTaskId(Protos.TaskID.newBuilder().setValue(taskId))
.addAllResources(resources)
.setData(ByteString.copyFromUtf8(String.join(";", humioHost, humioDataspace, humioIngesttoken,
humioDataDir, defaultIfEmpty(filebeatConfigUrl, " "), defaultIfEmpty(metricbeatConfigUrl, " "))))
.setLabels(Protos.Labels.newBuilder().addLabels(createLabel("HUMIO_IGNORE", "true")).build())
.setDiscovery(Protos.DiscoveryInfo.newBuilder()
.setName(applicationName)
.setVisibility(Protos.DiscoveryInfo.Visibility.FRAMEWORK)
.build())
.setExecutor(Protos.ExecutorInfo.newBuilder()
.setName("humioexecutor")
.setData(ByteString.copyFromUtf8(dcosAuthToken.concat(";").concat(enableContainerMetrics.toString())))
.setExecutorId(Protos.ExecutorID.newBuilder().setValue("humioexecutor." + offer.getSlaveId()
.getValue()).build())
.setCommand(Protos.CommandInfo.newBuilder()
.setValue("jre*/bin/java -jar executor-*.jar")
.addAllUris(mesosConfig.getUri().stream().map(uri -> Protos.CommandInfo.URI
.newBuilder().setValue(uri).build()).collect(Collectors.toList()))
.build())
.build())
.build();
}
示例6: expectRanges
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private void expectRanges(Set<Pair<Long, Long>> expected, Set<Integer> values) {
Protos.Resource resource = makeMesosRangeResource(PORTS, values);
assertEquals(Protos.Value.Type.RANGES, resource.getType());
assertEquals(PORTS.getMesosName(), resource.getName());
Set<Pair<Long, Long>> actual = ImmutableSet.copyOf(Iterables.transform(
resource.getRanges().getRangeList(),
range -> Pair.of(range.getBegin(), range.getEnd())));
assertEquals(expected, actual);
}
示例7: getCpuResource
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private static Protos.Resource getCpuResource(boolean revocable, double value) {
Protos.Resource.Builder builder = Protos.Resource.newBuilder()
.setName(ResourceType.CPUS.getMesosName())
.setType(Protos.Value.Type.SCALAR)
.setScalar(Protos.Value.Scalar.newBuilder().setValue(value));
if (revocable) {
builder.setRevocable(Protos.Resource.RevocableInfo.newBuilder());
}
return builder.build();
}
示例8: validateDisk
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private void validateDisk(Protos.Resource resource) {
Assert.assertTrue(resource.hasDisk());
Protos.Resource.DiskInfo diskInfo = resource.getDisk();
Assert.assertTrue(diskInfo.hasPersistence());
Protos.Resource.DiskInfo.Persistence persistence = diskInfo.getPersistence();
Assert.assertEquals(36, persistence.getId().length());
Assert.assertEquals(TestConstants.PRINCIPAL, persistence.getPrincipal());
Assert.assertTrue(diskInfo.hasVolume());
Protos.Volume volume = diskInfo.getVolume();
Assert.assertEquals(TestConstants.CONTAINER_PATH, volume.getContainerPath());
Assert.assertEquals(Protos.Volume.Mode.RW, volume.getMode());
}
示例9: testOfferPassesPlacementRule
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testOfferPassesPlacementRule() throws Exception {
String agent = "test-agent";
Protos.Resource offered = ResourceTestUtils.getUnreservedCpus(1.0);
PlacementRule rule = AgentRule.require(agent);
Protos.Offer offer = offerWithAgent(agent, offered);
MesosResourcePool mesosResourcePool = new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE));
PodSpec podSpec = PodInstanceRequirementTestUtils.getCpuRequirement(1.0).getPodInstance().getPod();
DefaultPodSpec.newBuilder(podSpec)
.placementRule(rule);
PodInstance podInstance = new DefaultPodInstance(podSpec, 0);
List<String> taskNames = TaskUtils.getTaskNames(podInstance);
PodInstanceRequirement podInstanceRequirement = PodInstanceRequirement
.newBuilder(podInstance, taskNames)
.build();
PlacementRuleEvaluationStage placementRuleEvaluationStage = new PlacementRuleEvaluationStage(
Collections.emptyList(), rule);
EvaluationOutcome outcome = placementRuleEvaluationStage.evaluate(
mesosResourcePool,
new PodInfoBuilder(
podInstanceRequirement,
TestConstants.SERVICE_NAME,
UUID.randomUUID(),
SchedulerConfigTestUtils.getTestSchedulerConfig(),
Collections.emptyList(),
TestConstants.FRAMEWORK_ID,
true,
Collections.emptyMap()));
Assert.assertTrue(outcome.isPassing());
Assert.assertEquals(3, mesosResourcePool.getUnreservedMergedPool().size());
Assert.assertTrue(
Math.abs(mesosResourcePool.getUnreservedMergedPool().get("cpus").getScalar().getValue() - 1.1) < 0.01);
}
示例10: buildDisk
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public static Protos.Resource buildDisk(int sizeMB) {
return Protos.Resource.newBuilder()
.setName("disk")
.setScalar(Protos.Value.Scalar.newBuilder().setValue(sizeMB))
.setType(Protos.Value.Type.SCALAR)
.build();
}
示例11: buildResourceList
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public static List<Protos.Resource> buildResourceList(double cpus, double mem, double reservedCpu, double reservedMem) {
List<Protos.Resource> resourceList = new ArrayList<>();
resourceList.addAll(
Arrays.asList(
buildScalarResource("cpus", cpus),
buildScalarResource("mem", mem),
buildScalarResourceWithRole("cpus", reservedCpu, "reserved"),
buildScalarResourceWithRole("mem", reservedMem, "reserved")
)
);
return resourceList;
}
示例12: buildRangeResourceWithRole
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public static Protos.Resource buildRangeResourceWithRole(String name, int begin, int end, String role) {
return Protos.Resource.newBuilder()
.setType(Protos.Value.Type.RANGES)
.setRanges(
Protos.Value.Ranges.newBuilder()
.addRange(Protos.Value.Range.newBuilder()
.setBegin(begin)
.setEnd(end)
.build())
.build()
)
.setName(name)
.setRole(role)
.build();
}
示例13: validateDaemonTaskInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private void validateDaemonTaskInfo(Protos.TaskInfo daemonTaskInfo) throws TaskException {
Assert.assertEquals(testDaemonName, daemonTaskInfo.getName());
Assert.assertEquals(4, daemonTaskInfo.getResourcesCount());
Assert.assertEquals(testDaemonName, TaskUtils.toTaskName(daemonTaskInfo.getTaskId()));
Assert.assertTrue(daemonTaskInfo.getSlaveId().getValue().isEmpty());
for (Protos.Resource resource : daemonTaskInfo.getResourcesList()) {
Assert.assertTrue(ResourceUtils.getResourceId(resource).isEmpty());
}
}
示例14: testNewFromResourceSpec
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testNewFromResourceSpec() {
ResourceSpec resourceSpec = new DefaultResourceSpec(
"cpus",
value,
TestConstants.ROLE,
Constants.ANY_ROLE,
TestConstants.PRINCIPAL);
ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, Optional.empty());
Protos.Resource resource = resourceBuilder.build();
validateScalarResoure(resource);
}
示例15: getUnreservedPorts
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public static Protos.Resource getUnreservedPorts(long begin, long end) {
Protos.Value.Builder builder = Protos.Value.newBuilder()
.setType(Protos.Value.Type.RANGES);
builder.getRangesBuilder().addRangeBuilder()
.setBegin(begin)
.setEnd(end);
return getUnreservedResource("ports", builder.build(), Constants.ANY_ROLE);
}