Search in sources :

Example 1 with TwoLevelResource

use of com.netflix.titus.api.jobmanager.model.job.TwoLevelResource in project titus-control-plane by Netflix.

the class JobStoreFitAction method handleDuplicatedEni.

private <T> T handleDuplicatedEni(T result, boolean storeOnly) {
    if (!(result instanceof Task)) {
        return result;
    }
    Task task = (Task) result;
    if (task.getTwoLevelResources().isEmpty()) {
        return result;
    }
    TwoLevelResource original = task.getTwoLevelResources().get(0);
    synchronized (twoLevelResourceAssignments) {
        // Store current assignment
        ConcurrentMap<Integer, TwoLevelResource> agentAssignments = twoLevelResourceAssignments.computeIfAbsent(task.getTaskContext().getOrDefault(TaskAttributes.TASK_ATTRIBUTES_AGENT_HOST, "DEFAULT"), k -> new ConcurrentHashMap<>());
        agentAssignments.put(original.getIndex(), original);
        if (storeOnly) {
            return result;
        }
        // Find another assignment on the same agent with different resource value
        Optional<Task> taskOverride = agentAssignments.values().stream().filter(a -> !a.getValue().equals(original.getValue())).findFirst().map(match -> {
            TwoLevelResource override = original.toBuilder().withIndex(match.getIndex()).build();
            return task.toBuilder().withTwoLevelResources(override).build();
        });
        return (T) taskOverride.orElse(task);
    }
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) TwoLevelResource(com.netflix.titus.api.jobmanager.model.job.TwoLevelResource)

Example 2 with TwoLevelResource

use of com.netflix.titus.api.jobmanager.model.job.TwoLevelResource in project titus-control-plane by Netflix.

the class GrpcJobManagementModelConverters method toCoreTwoLevelResources.

/**
 * We do not expose the {@link TwoLevelResource} data outside Titus, so we try to reconstruct this information
 * from the GRPC model.
 */
private static List<TwoLevelResource> toCoreTwoLevelResources(Job<?> job, com.netflix.titus.grpc.protogen.Task grpcTask) {
    Map<String, String> context = grpcTask.getTaskContextMap();
    String eniIndex = context.get(TASK_ATTRIBUTES_NETWORK_INTERFACE_INDEX);
    if (eniIndex == null) {
        return Collections.emptyList();
    }
    TwoLevelResource resource = TwoLevelResource.newBuilder().withIndex(Integer.parseInt(eniIndex)).withName("ENIs").withValue(StringExt.concatenate(job.getJobDescriptor().getContainer().getSecurityProfile().getSecurityGroups(), ":")).build();
    return Collections.singletonList(resource);
}
Also used : ByteString(com.google.protobuf.ByteString) TwoLevelResource(com.netflix.titus.api.jobmanager.model.job.TwoLevelResource)

Aggregations

TwoLevelResource (com.netflix.titus.api.jobmanager.model.job.TwoLevelResource)2 ByteString (com.google.protobuf.ByteString)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1