本文整理汇总了Java中org.apache.mesos.Protos.Label方法的典型用法代码示例。如果您正苦于以下问题:Java Protos.Label方法的具体用法?Java Protos.Label怎么用?Java Protos.Label使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.Protos
的用法示例。
在下文中一共展示了Protos.Label方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateConfig
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public CassandraDaemonTask updateConfig(CassandraConfig cassandraConfig,
ExecutorConfig executorConfig,
UUID targetConfigName) {
LOGGER.info("Updating config for task: {} to config: {}", getTaskInfo().getName(), targetConfigName.toString());
final Protos.Label label = Protos.Label.newBuilder()
.setKey("config_target")
.setValue(targetConfigName.toString())
.build();
return new CassandraDaemonTask(getBuilder()
.setExecutor(getExecutor().update(executorConfig).getExecutorInfo())
.setTaskId(createId(getName()))
.setData(getData().withNewConfig(cassandraConfig).getBytes())
.clearResources()
.addAllResources(TaskUtils.updateResources(
cassandraConfig.getCpus(),
cassandraConfig.getMemoryMb(),
getTaskInfo().getResourcesList()
))
.clearLabels()
.setLabels(Protos.Labels.newBuilder().addLabels(label).build()).build());
}
示例2: getTaskConfigs
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Set<UUID> getTaskConfigs() {
final Collection<Protos.TaskInfo> taskInfos = stateStore.fetchTasks();
final Set<UUID> activeConfigs = new HashSet<>();
try {
for (Protos.TaskInfo taskInfo : taskInfos) {
final Protos.Labels labels = taskInfo.getLabels();
for(Protos.Label label : labels.getLabelsList()) {
if (label.getKey().equals(PersistentOfferRequirementProvider.CONFIG_TARGET_KEY)) {
activeConfigs.add(UUID.fromString(label.getValue()));
}
}
}
} catch (Exception e) {
LOGGER.error("Failed to fetch configurations from taskInfos.", e);
}
return activeConfigs;
}
示例3: updateConfigLabel
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private static Protos.TaskInfo updateConfigLabel(String configName, Protos.TaskInfo taskInfo) {
final Protos.Labels.Builder labelsBuilder = Protos.Labels.newBuilder();
final Protos.Labels labels = taskInfo.getLabels();
for (Protos.Label label : labels.getLabelsList()) {
final String key = label.getKey();
if (!CONFIG_TARGET_KEY.equals(key)) {
labelsBuilder.addLabels(label);
}
}
labelsBuilder.addLabels(Protos.Label.newBuilder()
.setKey(CONFIG_TARGET_KEY)
.setValue(configName));
return Protos.TaskInfo.newBuilder(taskInfo)
.clearLabels()
.setLabels(labelsBuilder.build())
.build();
}
示例4: testCreateVipLabel
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testCreateVipLabel() {
Protos.Port.Builder portBuilder = newPortBuilder();
AuxLabelAccess.setVIPLabels(portBuilder, newVIPSpec("vip", 5));
Collection<Protos.Label> labels = portBuilder.getLabels().getLabelsList();
assertEquals(1, labels.size());
Label label = labels.iterator().next();
assertTrue(label.getKey().startsWith("VIP_"));
assertEquals("vip:5", label.getValue());
Collection<EndpointUtils.VipInfo> vips =
AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, portBuilder.build());
assertEquals(1, vips.size());
EndpointUtils.VipInfo vip = vips.iterator().next();
assertEquals("vip", vip.getVipName());
assertEquals(5, vip.getVipPort());
}
示例5: testCreateVipLabelOnOverlay
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testCreateVipLabelOnOverlay() {
Protos.Port.Builder portBuilder = newPortBuilder();
AuxLabelAccess.setVIPLabels(portBuilder, newVIPSpec("vip", 5, "dcos"));
Collection<Protos.Label> labels = portBuilder.getLabels().getLabelsList();
assertEquals(2, labels.size());
assertEquals(1, labels.stream()
.filter(label -> label.getKey().startsWith("VIP_") && label.getValue().equals("vip:5"))
.collect(Collectors.toList()).size());
assertEquals(1, labels.stream()
.filter(label -> label.getKey().equals(LabelConstants.VIP_OVERLAY_FLAG_KEY) &&
label.getValue().equals(LabelConstants.VIP_OVERLAY_FLAG_VALUE))
.collect(Collectors.toList()).size());
Collection<EndpointUtils.VipInfo> vips =
AuxLabelAccess.getVIPsFromLabels(TestConstants.TASK_NAME, portBuilder.build());
assertEquals(1, vips.size());
EndpointUtils.VipInfo vip = vips.iterator().next();
assertEquals("vip", vip.getVipName());
assertEquals(5, vip.getVipPort());
}
示例6: testExistingFromResourceSpec
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testExistingFromResourceSpec() {
Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
ResourceSpec resourceSpec = new DefaultResourceSpec(
"cpus",
value,
TestConstants.ROLE,
Constants.ANY_ROLE,
TestConstants.PRINCIPAL);
ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, resourceId);
Protos.Resource resource = resourceBuilder.build();
validateScalarResoure(resource);
Protos.Resource.ReservationInfo reservationInfo = Capabilities.getInstance().supportsPreReservedResources() ?
resource.getReservations(0) :
resource.getReservation();
Protos.Label label = reservationInfo.getLabels().getLabels(0);
Assert.assertEquals(resourceId.get(), label.getValue());
}
示例7: move
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public CassandraDaemonTask move(
CassandraDaemonTask currentDaemon, CassandraTaskExecutor executor) {
final List<Protos.Label> labelsList =
currentDaemon.getTaskInfo().getLabels().getLabelsList();
String configName = "";
for (Protos.Label label : labelsList) {
if ("config_target".equals(label.getKey())) {
configName = label.getValue();
}
}
if (StringUtils.isBlank(configName)) {
throw new IllegalStateException("Task should have 'config_target'");
}
CassandraDaemonTask replacementDaemon = new CassandraDaemonTask(
currentDaemon.getName(),
configName,
executor,
currentDaemon.getConfig(),
capabilities,
currentDaemon.getData().replacing(currentDaemon.getData().getHostname()));
Protos.TaskInfo taskInfo = Protos.TaskInfo.newBuilder(replacementDaemon.getTaskInfo())
.setTaskId(currentDaemon.getTaskInfo().getTaskId())
.build();
return new CassandraDaemonTask(taskInfo);
}
示例8: getTaskConfig
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Optional<String> getTaskConfig(CassandraDaemonTask task) {
final Protos.TaskInfo taskInfo = task.getTaskInfo();
if (!taskInfo.hasLabels() || CollectionUtils.isEmpty(taskInfo.getLabels().getLabelsList())) {
return Optional.empty();
}
for (Protos.Label label : taskInfo.getLabels().getLabelsList()) {
final String key = label.getKey();
if (PersistentOfferRequirementProvider.CONFIG_TARGET_KEY.equals(key)) {
return Optional.ofNullable(label.getValue());
}
}
return Optional.empty();
}
示例9: replaceDuplicateConfig
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private void replaceDuplicateConfig(Protos.TaskInfo taskInfo,
StateStore stateStore,
List<String> duplicateConfigs,
UUID targetName) throws ConfigStoreException {
try {
final String taskConfigName = getConfigName(taskInfo);
final String targetConfigName = targetName.toString();
for(String duplicateConfig : duplicateConfigs) {
if (duplicateConfig.equals(taskConfigName)) {
final Protos.Label configTargetKeyLabel = Protos.Label.newBuilder()
.setKey(PersistentOfferRequirementProvider.CONFIG_TARGET_KEY)
.setValue(targetConfigName)
.build();
final Protos.Labels labels = Protos.Labels.newBuilder()
.addLabels(configTargetKeyLabel)
.build();
final Protos.TaskInfo updatedTaskInfo = Protos.TaskInfo.newBuilder(taskInfo)
.setLabels(labels).build();
stateStore.storeTasks(Arrays.asList(updatedTaskInfo));
LOGGER.info("Updated task: {} from duplicate config: {} to current target: {}",
updatedTaskInfo.getName(), taskConfigName, targetConfigName);
return;
}
}
LOGGER.info("Task: {} is update to date with target config: {}", taskInfo.getName(), targetConfigName);
} catch (Exception e) {
LOGGER.error("Failed to replace duplicate config for task: {} Reason: {}", taskInfo, e);
throw new ConfigStoreException(e);
}
}
示例10: getConfigName
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private static String getConfigName(Protos.TaskInfo taskInfo) {
for (Protos.Label label : taskInfo.getLabels().getLabelsList()) {
if (label.getKey().equals("config_target")) {
return label.getValue();
}
}
return null;
}
示例11: testExistingFromRootVolumeSpec
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testExistingFromRootVolumeSpec() {
VolumeSpec volumeSpec = new DefaultVolumeSpec(
10,
VolumeSpec.Type.ROOT,
TestConstants.CONTAINER_PATH,
TestConstants.ROLE,
Constants.ANY_ROLE,
TestConstants.PRINCIPAL);
Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
Optional<String> persistenceId = Optional.of(UUID.randomUUID().toString());
ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(
volumeSpec,
resourceId,
persistenceId,
Optional.empty());
Protos.Resource resource = resourceBuilder.build();
validateScalarResoure(resource);
validateDisk(resource);
Protos.Resource.ReservationInfo reservationInfo = Capabilities.getInstance().supportsPreReservedResources() ?
resource.getReservations(0) :
resource.getReservation();
Protos.Label label = reservationInfo.getLabels().getLabels(0);
Assert.assertEquals(resourceId.get(), label.getValue());
Assert.assertEquals(persistenceId.get(), resource.getDisk().getPersistence().getId());
}
示例12: testExistingFromMountVolumeSpec
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testExistingFromMountVolumeSpec() {
VolumeSpec volumeSpec = new DefaultVolumeSpec(
10,
VolumeSpec.Type.MOUNT,
TestConstants.CONTAINER_PATH,
TestConstants.ROLE,
Constants.ANY_ROLE,
TestConstants.PRINCIPAL);
Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
Optional<String> persistenceId = Optional.of(UUID.randomUUID().toString());
ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(
volumeSpec,
resourceId,
persistenceId,
Optional.of(TestConstants.MOUNT_SOURCE_ROOT));
Protos.Resource resource = resourceBuilder.build();
validateScalarResoure(resource);
validateDisk(resource);
Protos.Resource.DiskInfo diskInfo = resource.getDisk();
Assert.assertTrue(diskInfo.hasSource());
Protos.Resource.DiskInfo.Source source = diskInfo.getSource();
Assert.assertEquals("MOUNT", source.getType().toString());
Assert.assertTrue(source.hasMount());
Assert.assertEquals(TestConstants.MOUNT_SOURCE_ROOT, source.getMount().getRoot());
Protos.Resource.ReservationInfo reservationInfo = Capabilities.getInstance().supportsPreReservedResources() ?
resource.getReservations(0) :
resource.getReservation();
Protos.Label label = reservationInfo.getLabels().getLabels(0);
Assert.assertEquals(resourceId.get(), label.getValue());
Assert.assertEquals(persistenceId.get(), resource.getDisk().getPersistence().getId());
}
示例13: labelsAreCorrect
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void labelsAreCorrect() {
stage.evaluate(
new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)),
podInfoBuilder);
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
// labels are sorted alphabetically (see LabelUtils):
Protos.Label label = taskBuilder.getLabels().getLabels(0);
Assert.assertEquals("goal_state", label.getKey());
Assert.assertEquals(GoalState.RUNNING.name(), label.getValue());
label = taskBuilder.getLabels().getLabels(1);
Assert.assertEquals("index", label.getKey());
Assert.assertEquals(Integer.toString(TestConstants.TASK_INDEX), label.getValue());
label = taskBuilder.getLabels().getLabels(2);
Assert.assertEquals("offer_attributes", label.getKey());
Assert.assertEquals("", label.getValue());
label = taskBuilder.getLabels().getLabels(3);
Assert.assertEquals("offer_hostname", label.getKey());
Assert.assertEquals(TestConstants.HOSTNAME, label.getValue());
label = taskBuilder.getLabels().getLabels(4);
Assert.assertEquals("target_configuration", label.getKey());
Assert.assertEquals(36, label.getValue().length());
label = taskBuilder.getLabels().getLabels(5);
Assert.assertEquals(label.getKey(), "task_type");
Assert.assertEquals(TestConstants.POD_TYPE, label.getValue());
}
示例14: testDiscoveryInfoPopulated
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testDiscoveryInfoPopulated() throws Exception {
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(10000, Collections.emptyList(), Optional.empty());
// Evaluate stage
NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(10000, Optional.empty(), Optional.empty());
EvaluationOutcome outcome = vipEvaluationStage.evaluate(
new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)),
podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
String observedName = discoveryInfo.getName();
Assert.assertEquals(expectedName, observedName);
Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
Protos.Port port = discoveryInfo.getPorts().getPorts(0);
Assert.assertEquals(port.getNumber(), 10000);
Assert.assertEquals(port.getProtocol(), "sctp");
Assert.assertEquals(1, port.getLabels().getLabelsCount());
Protos.Label vipLabel = port.getLabels().getLabels(0);
Assert.assertEquals("pod-type-0-test-task-name", discoveryInfo.getName());
Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
Assert.assertEquals(vipLabel.getValue(), "test-vip:80");
}
示例15: testDiscoveryInfoOnBridgeNetwork
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testDiscoveryInfoOnBridgeNetwork() throws Exception {
Protos.Resource offeredPorts = ResourceTestUtils.getUnreservedPorts(10000, 10000);
Protos.Offer offer = OfferTestUtils.getOffer(offeredPorts);
Integer containerPort = 10000; // non-offered port
String bridgeNetwork = "mesos-bridge";
PodInfoBuilder podInfoBuilder = getPodInfoBuilderOnNetwork(
containerPort, Collections.emptyList(), Optional.of(bridgeNetwork));
NamedVIPEvaluationStage vipEvaluationStage = getEvaluationStageOnNetwork(
containerPort, Optional.empty(), Optional.of(bridgeNetwork));
EvaluationOutcome outcome = vipEvaluationStage.evaluate(
new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
Protos.DiscoveryInfo discoveryInfo = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getDiscovery();
String expectedName = TestConstants.POD_TYPE + "-0-" + TestConstants.TASK_NAME;
String observedName = discoveryInfo.getName();
Assert.assertEquals(expectedName, observedName);
Assert.assertEquals(DiscoveryInfo.Visibility.CLUSTER, discoveryInfo.getVisibility());
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME);
Assert.assertEquals(1, taskBuilder.getResourcesCount()); // expect that bridge uses ports
Protos.Port port = discoveryInfo.getPorts().getPorts(0);
Assert.assertEquals(port.getNumber(), containerPort.longValue());
Assert.assertEquals(port.getProtocol(), "sctp");
Assert.assertEquals(2, port.getLabels().getLabelsCount());
Protos.Label vipLabel = port.getLabels().getLabels(0);
Assert.assertTrue(vipLabel.getKey().startsWith("VIP_"));
Assert.assertEquals(vipLabel.getValue(), "test-vip:80");
assertIsBridgeLabel(port.getLabels().getLabels(1));
}