Search in sources :

Example 56 with BatchJobExt

use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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 57 with BatchJobExt

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

the class CassandraJobStoreTest method testUpdateTask.

@Test
public void testUpdateTask() {
    JobStore store = getJobStore();
    Job<BatchJobExt> job = createBatchJobObject();
    store.init().await();
    store.storeJob(job).await();
    Pair<List<Job<?>>, Integer> jobsAndErrors = store.retrieveJobs().toBlocking().first();
    checkRetrievedJob(job, jobsAndErrors.getLeft().get(0));
    Task task = createTaskObject(job);
    store.storeTask(task).await();
    Task retrievedTask = store.retrieveTask(task.getId()).toBlocking().first();
    checkRetrievedTask(task, retrievedTask);
    BatchJobTask newTask = BatchJobTask.newBuilder((BatchJobTask) task).withStatus(TaskStatus.newBuilder().withState(TaskState.Finished).build()).build();
    store.updateTask(newTask).await();
    Task newRetrievedTask = store.retrieveTask(newTask.getId()).toBlocking().first();
    checkRetrievedTask(newTask, newRetrievedTask);
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 58 with BatchJobExt

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

the class CassandraJobStoreTest method testUpdateJob.

@Test
public void testUpdateJob() {
    JobStore store = getJobStore();
    Job<BatchJobExt> job = createBatchJobObject();
    store.init().await();
    store.storeJob(job).await();
    Pair<List<Job<?>>, Integer> jobsAndErrors = store.retrieveJobs().toBlocking().first();
    checkRetrievedJob(job, jobsAndErrors.getLeft().get(0));
    Job<BatchJobExt> newJob = job.toBuilder().withStatus(JobStatus.newBuilder().withState(JobState.Finished).build()).build();
    store.updateJob(newJob).await();
    Pair<List<Job<?>>, Integer> newJobsAndErrors = store.retrieveJobs().toBlocking().first();
    checkRetrievedJob(newJob, newJobsAndErrors.getLeft().get(0));
}
Also used : BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Example 59 with BatchJobExt

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

the class TestStoreLoadCommand method createJobAndTasksObservable.

private Observable<Void> createJobAndTasksObservable(int tasks, JobStore store) {
    Job<BatchJobExt> job = createJobObject();
    List<Task> taskList = new ArrayList<>();
    for (int i = 0; i < tasks; i++) {
        taskList.add(createTaskObject(job));
    }
    return store.storeJob(job).andThen(Observable.fromCallable(() -> {
        List<Observable<Void>> observables = new ArrayList<>();
        for (Task task : taskList) {
            observables.add(store.storeTask(task).toObservable());
        }
        return observables;
    })).flatMap(Observable::merge);
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ArrayList(java.util.ArrayList) Observable(rx.Observable)

Example 60 with BatchJobExt

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

the class CassandraJobStoreTest method testDeleteTask.

@Test
public void testDeleteTask() {
    JobStore store = getJobStore();
    Job<BatchJobExt> job = createBatchJobObject();
    store.init().await();
    store.storeJob(job).await();
    Pair<List<Job<?>>, Integer> jobsAndErrors = store.retrieveJobs().toBlocking().first();
    checkRetrievedJob(job, jobsAndErrors.getLeft().get(0));
    Task task = createTaskObject(job);
    store.storeTask(task).await();
    Task retrievedTask = store.retrieveTask(task.getId()).toBlocking().first();
    checkRetrievedTask(task, retrievedTask);
    store.deleteTask(task).await();
    Pair<List<Task>, Integer> tasks = store.retrieveTasksForJob(job.getId()).toBlocking().first();
    assertThat(tasks.getLeft()).isEmpty();
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobStore(com.netflix.titus.api.jobmanager.store.JobStore) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationNotParallelizableTest(com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)

Aggregations

BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)73 Test (org.junit.Test)55 Task (com.netflix.titus.api.jobmanager.model.job.Task)30 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)25 List (java.util.List)20 ArrayList (java.util.ArrayList)19 JobStore (com.netflix.titus.api.jobmanager.store.JobStore)17 HashMap (java.util.HashMap)16 V1Affinity (io.kubernetes.client.openapi.models.V1Affinity)14 IntegrationNotParallelizableTest (com.netflix.titus.testkit.junit.category.IntegrationNotParallelizableTest)13 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)11 V1Pod (io.kubernetes.client.openapi.models.V1Pod)11 Job (com.netflix.titus.api.jobmanager.model.job.Job)10 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)10 Container (com.netflix.titus.api.jobmanager.model.job.Container)6 Map (java.util.Map)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 V1Container (io.kubernetes.client.openapi.models.V1Container)5 BasicContainer (com.netflix.titus.api.jobmanager.model.job.BasicContainer)4 Image (com.netflix.titus.api.jobmanager.model.job.Image)4