Search in sources :

Example 6 with Image

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

the class TaskDocument method fromV3Task.

public static TaskDocument fromV3Task(Task task, Job job, SimpleDateFormat dateFormat, Map<String, String> context) {
    TaskDocument taskDocument = new TaskDocument();
    JobDescriptor jobDescriptor = job.getJobDescriptor();
    Container container = jobDescriptor.getContainer();
    Image image = container.getImage();
    ContainerResources containerResources = container.getContainerResources();
    JobGroupInfo jobGroupInfo = jobDescriptor.getJobGroupInfo();
    taskDocument.name = jobDescriptor.getApplicationName();
    taskDocument.applicationName = image.getName();
    taskDocument.appName = jobDescriptor.getApplicationName();
    taskDocument.user = jobDescriptor.getOwner().getTeamEmail();
    taskDocument.labels = sanitizeMap(container.getAttributes());
    taskDocument.version = image.getTag();
    taskDocument.digest = image.getDigest();
    taskDocument.entryPoint = StringExt.concatenate(container.getEntryPoint(), " ");
    taskDocument.cpu = containerResources.getCpu();
    taskDocument.memory = containerResources.getMemoryMB();
    taskDocument.networkMbps = containerResources.getNetworkMbps();
    taskDocument.disk = containerResources.getDiskMB();
    taskDocument.gpu = containerResources.getGpu();
    taskDocument.shm = containerResources.getShmMB();
    taskDocument.allocateIpAddress = containerResources.isAllocateIP();
    taskDocument.env = sanitizeMap(container.getEnv());
    taskDocument.iamProfile = container.getSecurityProfile().getIamRole();
    taskDocument.securityGroups = container.getSecurityProfile().getSecurityGroups();
    taskDocument.softConstraints = new ArrayList<>(container.getSoftConstraints().keySet());
    taskDocument.hardConstraints = new ArrayList<>(container.getHardConstraints().keySet());
    taskDocument.capacityGroup = jobDescriptor.getCapacityGroup();
    taskDocument.jobGroupStack = jobGroupInfo.getStack();
    taskDocument.jobGroupDetail = jobGroupInfo.getDetail();
    taskDocument.jobGroupSequence = jobGroupInfo.getSequence();
    JobDescriptor.JobDescriptorExt jobDescriptorExt = jobDescriptor.getExtensions();
    if (jobDescriptorExt instanceof BatchJobExt) {
        BatchJobExt batchJobExt = (BatchJobExt) jobDescriptorExt;
        taskDocument.runtimeLimitSecs = batchJobExt.getRuntimeLimitMs();
        taskDocument.type = TitusJobType.batch;
        taskDocument.inService = false;
        taskDocument.instances = batchJobExt.getSize();
        taskDocument.instancesMin = batchJobExt.getSize();
        taskDocument.instancesMax = batchJobExt.getSize();
        taskDocument.instancesDesired = batchJobExt.getSize();
        taskDocument.retries = batchJobExt.getRetryPolicy().getRetries();
        taskDocument.restartOnSuccess = false;
    } else if (jobDescriptorExt instanceof ServiceJobExt) {
        ServiceJobExt serviceJobExt = (ServiceJobExt) jobDescriptorExt;
        taskDocument.runtimeLimitSecs = 0L;
        taskDocument.type = TitusJobType.service;
        taskDocument.inService = serviceJobExt.isEnabled();
        Capacity capacity = serviceJobExt.getCapacity();
        taskDocument.instances = capacity.getDesired();
        taskDocument.instancesMin = capacity.getMin();
        taskDocument.instancesMax = capacity.getMax();
        taskDocument.instancesDesired = capacity.getDesired();
        taskDocument.retries = serviceJobExt.getRetryPolicy().getRetries();
        taskDocument.restartOnSuccess = false;
    }
    Map<String, String> taskContext = task.getTaskContext();
    taskDocument.id = task.getId();
    taskDocument.instanceId = task.getId();
    taskDocument.jobId = task.getJobId();
    taskDocument.state = toV2TaskState(task.getStatus()).name();
    taskDocument.jobLabels = sanitizeMap(job.getJobDescriptor().getAttributes());
    taskDocument.host = taskContext.get(TASK_ATTRIBUTES_AGENT_HOST);
    taskDocument.tier = taskContext.getOrDefault(TASK_ATTRIBUTES_TIER, "Unknown");
    taskDocument.computedFields = new ComputedFields();
    final String region = taskContext.get(TASK_ATTRIBUTES_AGENT_REGION);
    if (region != null) {
        taskDocument.region = region;
    }
    final String zone = taskContext.get(TASK_ATTRIBUTES_AGENT_ZONE);
    if (zone != null) {
        taskDocument.zone = zone;
    }
    final String asg = taskContext.get(TASK_ATTRIBUTES_AGENT_ASG);
    if (asg != null) {
        taskDocument.asg = asg;
    }
    final String instanceType = taskContext.get(TASK_ATTRIBUTES_AGENT_ITYPE);
    if (instanceType != null) {
        taskDocument.instanceType = instanceType;
    }
    final String instanceId = taskContext.get(TASK_ATTRIBUTES_AGENT_INSTANCE_ID);
    if (instanceId != null) {
        taskDocument.hostInstanceId = instanceId;
    }
    final String ipAddressAllocationId = taskContext.get(TASK_ATTRIBUTES_IP_ALLOCATION_ID);
    if (ipAddressAllocationId != null) {
        taskDocument.ipAddressAllocationId = ipAddressAllocationId;
    }
    extractNetworkConfigurationData(taskContext, taskDocument);
    long acceptedAt = findTaskStatus(task, TaskState.Accepted).map(ExecutableStatus::getTimestamp).orElse(0L);
    long launchedAt = findTaskStatus(task, TaskState.Launched).map(ExecutableStatus::getTimestamp).orElse(0L);
    long startingAt = findTaskStatus(task, TaskState.StartInitiated).map(ExecutableStatus::getTimestamp).orElse(0L);
    long startedAt = findTaskStatus(task, TaskState.Started).map(ExecutableStatus::getTimestamp).orElse(0L);
    long completedAt = findTaskStatus(task, TaskState.Finished).map(ExecutableStatus::getTimestamp).orElse(0L);
    if (acceptedAt > 0) {
        taskDocument.submittedAt = doSafeDateFormat(dateFormat, new Date(acceptedAt));
    }
    if (launchedAt > 0) {
        taskDocument.launchedAt = doSafeDateFormat(dateFormat, new Date(launchedAt));
        taskDocument.computedFields.msFromSubmittedToLaunched = launchedAt - acceptedAt;
    }
    if (startingAt > 0) {
        taskDocument.startingAt = doSafeDateFormat(dateFormat, new Date(startingAt));
        taskDocument.computedFields.msFromLaunchedToStarting = startingAt - launchedAt;
        taskDocument.computedFields.msToStarting = startingAt - acceptedAt;
    }
    if (startedAt > 0) {
        taskDocument.startedAt = doSafeDateFormat(dateFormat, new Date(startedAt));
        taskDocument.computedFields.msFromStartingToStarted = startedAt - startingAt;
        taskDocument.computedFields.msToStarted = startedAt - acceptedAt;
    }
    if (completedAt > 0) {
        taskDocument.finishedAt = doSafeDateFormat(dateFormat, new Date(completedAt));
        taskDocument.computedFields.msFromStartedToFinished = completedAt - startedAt;
        taskDocument.computedFields.msToFinished = completedAt - acceptedAt;
    }
    taskDocument.message = task.getStatus().getReasonMessage();
    taskDocument.titusContext = context;
    return taskDocument;
}
Also used : JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Image(com.netflix.titus.api.jobmanager.model.job.Image) Date(java.util.Date) Container(com.netflix.titus.api.jobmanager.model.job.Container) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) ContainerResources(com.netflix.titus.api.jobmanager.model.job.ContainerResources)

Example 7 with Image

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

the class V1SpecPodFactoryTest method multipleContainers.

@Test
public void multipleContainers() {
    Job<BatchJobExt> job = JobGenerator.oneBatchJob();
    BatchJobTask task = JobGenerator.oneBatchTask();
    Image testImage = Image.newBuilder().withName("testImage").withDigest("123").build();
    List<BasicContainer> extraContainers = Arrays.asList(new BasicContainer("extraContainer1", testImage, Collections.emptyList(), Collections.emptyList(), new HashMap<>(), Collections.emptyList()), new BasicContainer("extraContainer2", testImage, Collections.emptyList(), Collections.emptyList(), new HashMap<>(), Collections.emptyList()));
    job = job.toBuilder().withJobDescriptor(job.getJobDescriptor().toBuilder().withExtraContainers(extraContainers).build()).build();
    when(podAffinityFactory.buildV1Affinity(job, task)).thenReturn(Pair.of(new V1Affinity(), new HashMap<>()));
    V1Pod pod = podFactory.buildV1Pod(job, task);
    List<V1Container> containers = Objects.requireNonNull(pod.getSpec()).getContainers();
    // 3 containers here, 1 from the main container, 2 from the extras
    assertThat(containers.size()).isEqualTo(1 + extraContainers.size());
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) HashMap(java.util.HashMap) V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) V1Pod(io.kubernetes.client.openapi.models.V1Pod) BasicContainer(com.netflix.titus.api.jobmanager.model.job.BasicContainer) Image(com.netflix.titus.api.jobmanager.model.job.Image) Test(org.junit.Test)

Aggregations

Image (com.netflix.titus.api.jobmanager.model.job.Image)7 Test (org.junit.Test)4 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)2 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)1 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)1 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)1 Container (com.netflix.titus.api.jobmanager.model.job.Container)1 ContainerResources (com.netflix.titus.api.jobmanager.model.job.ContainerResources)1 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)1 JobGroupInfo (com.netflix.titus.api.jobmanager.model.job.JobGroupInfo)1 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1 V1Pod (io.kubernetes.client.openapi.models.V1Pod)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1