Java Code Examples for org.apache.mesos.Protos#Labels

The following examples show how to use org.apache.mesos.Protos#Labels . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultConfigurationManager.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: PersistentOfferRequirementProvider.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
private Protos.TaskInfo buildNativeTask(Protos.Offer offer, Configuration configuration, Clock clock, Long elasticSearchNodeId) {
    final List<Integer> ports = getPorts(offer, configuration);
    final List<Protos.Resource> resources = getResources(configuration, ports);
    final Protos.DiscoveryInfo discovery = getDiscovery(ports, configuration);
    final Protos.Labels labels = getLabels(configuration);

    final String hostAddress = resolveHostAddress(offer, ports);

    LOGGER.info("Creating Elasticsearch task with resources: " + resources.toString());

    final List<String> args = configuration.esArguments(clusterState, discovery, offer.getSlaveId());

    return Protos.TaskInfo.newBuilder()
            .setName(configuration.getTaskName())
            .setData(toData(offer.getHostname(), hostAddress, clock.nowUTC()))
            .setTaskId(Protos.TaskID.newBuilder().setValue(taskId(offer, clock)))
            .setSlaveId(offer.getSlaveId())
            .addAllResources(resources)
            .setDiscovery(discovery)
            .setLabels(labels)
            .setCommand(nativeCommand(configuration, args, elasticSearchNodeId))
            .build();
}
 
Example 4
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
private Protos.TaskInfo buildDockerTask(Protos.Offer offer, Configuration configuration, Clock clock, Long elasticSearchNodeId) {
    final List<Integer> ports = getPorts(offer, configuration);
    final List<Protos.Resource> resources = getResources(configuration, ports);
    final Protos.DiscoveryInfo discovery = getDiscovery(ports, configuration);
    final Protos.Labels labels = getLabels(configuration);

    final String hostAddress = resolveHostAddress(offer, ports);

    LOGGER.info("Creating Elasticsearch task with resources: " + resources.toString());

    final Protos.TaskID taskId = Protos.TaskID.newBuilder().setValue(taskId(offer, clock)).build();
    final List<String> args = configuration.esArguments(clusterState, discovery, offer.getSlaveId());
    final Protos.ContainerInfo containerInfo = getContainer(configuration, taskId, elasticSearchNodeId, offer.getSlaveId());

    return Protos.TaskInfo.newBuilder()
            .setName(configuration.getTaskName())
            .setData(toData(offer.getHostname(), hostAddress, clock.nowUTC()))
            .setTaskId(taskId)
            .setSlaveId(offer.getSlaveId())
            .addAllResources(resources)
            .setDiscovery(discovery)
            .setLabels(labels)
            .setCommand(dockerCommand(configuration, args, elasticSearchNodeId))
            .setContainer(containerInfo)
            .build();
}
 
Example 5
Source File: DefaultConfigurationManager.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: AuxLabelAccess.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static Optional<String> getLabel(Protos.Labels labels, String key) {
  if (labels.getLabelsCount() == 0) {
    // Shortcut/optimization
    return Optional.empty();
  }
  return Optional.ofNullable(LabelUtils.toMap(labels).get(key));
}
 
Example 7
Source File: TaskInfoFactory.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
private Protos.Labels getLabels(Configuration configuration) {
  Protos.Labels.Builder builder = Protos.Labels.newBuilder();
  Map<String, String> labels = configuration.getTaskLabels();
  for (Map.Entry<String, String> kvp : labels.entrySet()) {
    Protos.Label label = Protos.Label.newBuilder()
      .setKey(kvp.getKey())
      .setValue(kvp.getValue())
      .build();

    builder.addLabels(label);
  }

  return builder.build();
}
 
Example 8
Source File: AuxLabelAccess.java    From dcos-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a copy of the provided {@link Protos.Labels} instance with the provided label added to the list.
 * If the provided label key already exists, it is updated with the new value.
 * <p>
 * This should only be used for custom label locations. If you're editing {@link Protos.TaskInfo} labels you should
 * use {@code TaskLabelWriter}.
 */
private static Protos.Labels withLabel(Protos.Labels labels, String key, String value) {
  Map<String, String> map = LabelUtils.toMap(labels);
  map.put(key, value);
  return LabelUtils.toProto(map);
}