use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.
the class DefaultConfigurationUpdater method cleanupDuplicateAndUnusedConfigs.
/**
* Searches for any task configurations which are already identical to the target configuration
* and updates the embedded config version label in those tasks to point to the current target
* configuration.
*/
private void cleanupDuplicateAndUnusedConfigs(ServiceSpec targetConfig, UUID targetConfigId) throws ConfigStoreException {
List<Protos.TaskInfo> taskInfosToUpdate = new ArrayList<>();
Set<UUID> neededConfigs = new HashSet<>();
neededConfigs.add(targetConfigId);
// Search task labels for configs which need to be cleaned up.
for (Protos.TaskInfo taskInfo : stateStore.fetchTasks()) {
final UUID taskConfigId;
try {
taskConfigId = new TaskLabelReader(taskInfo).getTargetConfiguration();
} catch (TaskException e) {
LOGGER.warn(String.format("Unable to extract configuration ID from task %s: %s", taskInfo.getName(), TextFormat.shortDebugString(taskInfo)), e);
continue;
}
if (taskConfigId.equals(targetConfigId)) {
LOGGER.info("Task {} configuration ID matches target: {}", taskInfo.getName(), taskConfigId);
} else {
try {
final ServiceSpec taskConfig = configStore.fetch(taskConfigId);
if (!needsConfigUpdate(taskInfo, targetConfig, taskConfig)) {
// Task is effectively already on the target config. Update task's config ID to match target,
// and allow the duplicate config to be dropped from configStore.
TaskInfo.Builder taskBuilder = taskInfo.toBuilder();
taskBuilder.setLabels(new TaskLabelWriter(taskInfo).setTargetConfiguration(targetConfigId).toProto());
taskInfosToUpdate.add(taskBuilder.build());
} else {
// Config isn't the same as the target. Refrain from updating task, mark config as 'needed'.
neededConfigs.add(taskConfigId);
}
} catch (Exception e) {
LOGGER.error(String.format("Failed to fetch configuration %s for task %s", taskConfigId, taskInfo.getName()), e);
// Cannot read this task's config. Do not delete the config.
neededConfigs.add(taskConfigId);
}
}
}
if (!taskInfosToUpdate.isEmpty()) {
LOGGER.info("Updating {} tasks in StateStore with target configuration ID {}", taskInfosToUpdate.size(), targetConfigId);
stateStore.storeTasks(taskInfosToUpdate);
}
Collection<UUID> configIds = configStore.list();
LOGGER.info("Testing deserialization of {} listed configurations before cleanup:", configIds.size());
for (UUID configId : configIds) {
try {
configStore.fetch(configId);
LOGGER.info("- {}: OK", configId);
} catch (Exception e) {
LOGGER.info("- {}: FAILED, leaving as-is: {}", configId, e.getMessage());
neededConfigs.add(configId);
}
}
clearConfigsNotListed(neededConfigs);
}
use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.
the class PodInfoBuilder method setReadinessCheck.
private void setReadinessCheck(Protos.TaskInfo.Builder taskInfoBuilder, String serviceName, PodInstance podInstance, TaskSpec taskSpec, GoalStateOverride override, SchedulerConfig schedulerConfig) {
Optional<ReadinessCheckSpec> readinessCheckSpecOptional = getReadinessCheck(taskSpec, override);
if (!readinessCheckSpecOptional.isPresent()) {
LOGGER.debug("No readiness check defined for taskSpec: {}", taskSpec.getName());
return;
}
ReadinessCheckSpec readinessCheckSpec = readinessCheckSpecOptional.get();
if (useDefaultExecutor) {
// Default executors supports the newer TaskInfo.check field:
Protos.CheckInfo.Builder builder = taskInfoBuilder.getCheckBuilder().setType(Protos.CheckInfo.Type.COMMAND).setDelaySeconds(readinessCheckSpec.getDelay()).setIntervalSeconds(readinessCheckSpec.getInterval()).setTimeoutSeconds(readinessCheckSpec.getTimeout());
builder.getCommandBuilder().getCommandBuilder().setValue(readinessCheckSpec.getCommand()).setEnvironment(EnvUtils.toProto(getTaskEnvironment(serviceName, podInstance, taskSpec, schedulerConfig)));
} else {
// Custom executor implies older Mesos where TaskInfo.check doesn't exist yet. Fall back to label hack:
Protos.HealthCheck.Builder builder = Protos.HealthCheck.newBuilder().setDelaySeconds(readinessCheckSpec.getDelay()).setIntervalSeconds(readinessCheckSpec.getInterval()).setTimeoutSeconds(readinessCheckSpec.getTimeout());
builder.getCommandBuilder().setValue(readinessCheckSpec.getCommand()).setEnvironment(EnvUtils.toProto(getTaskEnvironment(serviceName, podInstance, taskSpec, schedulerConfig)));
taskInfoBuilder.setLabels(new TaskLabelWriter(taskInfoBuilder).setReadinessCheck(builder.build()).toProto());
}
}
use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.
the class LaunchEvaluationStage method evaluate.
@Override
public EvaluationOutcome evaluate(MesosResourcePool mesosResourcePool, PodInfoBuilder podInfoBuilder) {
Protos.ExecutorInfo.Builder executorBuilder = podInfoBuilder.getExecutorBuilder().get();
Protos.Offer offer = mesosResourcePool.getOffer();
Protos.TaskInfo.Builder taskBuilder = podInfoBuilder.getTaskBuilder(taskName);
taskBuilder.setTaskId(CommonIdUtils.toTaskId(serviceName, taskBuilder.getName()));
// Store metadata in the TaskInfo for later access by placement constraints:
TaskLabelWriter writer = new TaskLabelWriter(taskBuilder);
writer.setOfferAttributes(offer).setType(podInfoBuilder.getType()).setIndex(podInfoBuilder.getIndex()).setHostname(offer);
if (offer.hasDomain() && offer.getDomain().hasFaultDomain()) {
writer.setRegion(offer.getDomain().getFaultDomain().getRegion());
writer.setZone(offer.getDomain().getFaultDomain().getZone());
}
taskBuilder.setLabels(writer.toProto());
updateFaultDomainEnv(taskBuilder, offer);
if (!useDefaultExecutor) {
taskBuilder.setExecutor(executorBuilder);
}
return pass(this, Arrays.asList(new LaunchOfferRecommendation(offer, taskBuilder.build(), executorBuilder.build(), shouldLaunch, useDefaultExecutor)), "Added launch information to offer requirement").build();
}
use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.
the class MaxPerAttributeRuleTest method getTask.
private static TaskInfo getTask(String id, Offer offer) {
TaskInfo.Builder taskBuilder = TaskTestUtils.getTaskInfo(Collections.emptyList()).toBuilder();
taskBuilder.getTaskIdBuilder().setValue(id);
try {
taskBuilder.setName(CommonIdUtils.toTaskName(taskBuilder.getTaskId()));
} catch (Exception e) {
throw new IllegalStateException(e);
}
taskBuilder.setLabels(new TaskLabelWriter(taskBuilder).setOfferAttributes(offer).toProto());
return taskBuilder.build();
}
use of com.mesosphere.sdk.offer.taskdata.TaskLabelWriter in project dcos-commons by mesosphere.
the class PersistentLaunchRecorderTest method testUpdateResourcesOneSharedTaskInStateStore.
@Test
public void testUpdateResourcesOneSharedTaskInStateStore() throws TaskException {
Protos.Resource targetResource = Protos.Resource.newBuilder().setName("cpus").setType(Protos.Value.Type.SCALAR).setScalar(Protos.Value.Scalar.newBuilder().setValue(1.0)).build();
Protos.Resource previousResource = Protos.Resource.newBuilder().setName("cpus").setType(Protos.Value.Type.SCALAR).setScalar(Protos.Value.Scalar.newBuilder().setValue(2.0)).build();
String initTaskName = "pod-0-init";
Protos.TaskInfo initTaskInfo = baseTaskInfo.toBuilder().setLabels(new TaskLabelWriter(baseTaskInfo).setType("pod").setIndex(0).toProto()).setName(initTaskName).addAllResources(Arrays.asList(previousResource)).build();
String serverTaskName = "pod-0-server";
Protos.TaskInfo serverTaskInfo = baseTaskInfo.toBuilder().setLabels(new TaskLabelWriter(baseTaskInfo).setType("pod").setIndex(0).toProto()).setName(serverTaskName).addAllResources(Arrays.asList(targetResource)).build();
stateStore.storeTasks(Arrays.asList(initTaskInfo, serverTaskInfo));
Assert.assertEquals(2, stateStore.fetchTaskNames().size());
serverTaskInfo = stateStore.fetchTask(serverTaskName).get();
Assert.assertFalse(stateStore.fetchTask(initTaskName).get().getResources(0).equals(stateStore.fetchTask(serverTaskName).get().getResources(0)));
persistentLaunchRecorder.updateTaskResourcesWithinResourceSet(persistentLaunchRecorder.getPodInstance(serverTaskInfo).get(), serverTaskInfo);
Assert.assertEquals(2, stateStore.fetchTaskNames().size());
Assert.assertEquals(targetResource, stateStore.fetchTask(initTaskName).get().getResources(0));
Assert.assertEquals(targetResource, stateStore.fetchTask(serverTaskName).get().getResources(0));
}
Aggregations