Search in sources :

Example 26 with JobDescriptor

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

the class ServiceJobSchedulingTest method testJobScaleDown.

@Test
public void testJobScaleDown() {
    Capacity newCapacity = Capacity.newBuilder().withMin(0).withDesired(1).withMax(5).build();
    JobDescriptor<ServiceJobExt> twoTaskJob = changeServiceJobCapacity(oneTaskServiceJobDescriptor(), 2);
    jobsScenarioBuilder.scheduleJob(twoTaskJob, jobScenario -> jobScenario.expectJobEvent().advance().inActiveTasks((taskIdx, resubmit) -> ScenarioTemplates.acceptTask(taskIdx, resubmit)).template(ScenarioTemplates.changeJobCapacity(newCapacity)).advance().firstTaskMatch(task -> task.getStatus().getState() == TaskState.KillInitiated, matchingTask -> {
        assertThat(matchingTask.getStatus().getReasonCode()).isEqualTo(TaskStatus.REASON_SCALED_DOWN);
    }));
}
Also used : RecordingCodeInvariants(com.netflix.titus.common.util.code.RecordingCodeInvariants) ScenarioTemplates(com.netflix.titus.master.jobmanager.service.integration.scenario.ScenarioTemplates) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Job(com.netflix.titus.api.jobmanager.model.job.Job) ServiceJobProcesses(com.netflix.titus.api.jobmanager.model.job.ServiceJobProcesses) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobFunctions.changeServiceJobCapacity(com.netflix.titus.api.jobmanager.model.job.JobFunctions.changeServiceJobCapacity) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) Test(org.junit.Test) JobsScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CONCURRENT_STORE_UPDATE_LIMIT(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder.CONCURRENT_STORE_UPDATE_LIMIT) Assertions.fail(org.assertj.core.api.Assertions.fail) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) After(org.junit.After) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) JobFunctions.changeServiceJobCapacity(com.netflix.titus.api.jobmanager.model.job.JobFunctions.changeServiceJobCapacity) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Test(org.junit.Test)

Example 27 with JobDescriptor

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

the class ServiceJobSchedulingTest method testJobScaleDownWithParallelTerminateAndShrink.

@Test
public void testJobScaleDownWithParallelTerminateAndShrink() {
    JobDescriptor<ServiceJobExt> twoTaskJob = changeServiceJobCapacity(oneTaskServiceJobDescriptor(), 2);
    Capacity newCapacity = Capacity.newBuilder().withMin(0).withDesired(0).withMax(5).build();
    jobsScenarioBuilder.withConcurrentStoreUpdateLimit(1).scheduleJob(twoTaskJob, jobScenario -> jobScenario.expectJobEvent().advance().inActiveTasks((taskIdx, resubmit) -> ScenarioTemplates.acceptTask(taskIdx, resubmit)).inActiveTasks((taskIdx, resubmit) -> ScenarioTemplates.startTask(taskIdx, resubmit, TaskState.Started)).changeCapacity(newCapacity).allTasks(tasks -> tasks.forEach(jobScenario::killTaskAndShrinkNoWait)).advance().advance().advance().assertServiceJob(job -> {
        Capacity capacity = job.getJobDescriptor().getExtensions().getCapacity();
        assertThat(capacity.getMin()).isEqualTo(0);
        assertThat(capacity.getDesired()).isEqualTo(0);
    }));
}
Also used : RecordingCodeInvariants(com.netflix.titus.common.util.code.RecordingCodeInvariants) ScenarioTemplates(com.netflix.titus.master.jobmanager.service.integration.scenario.ScenarioTemplates) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Job(com.netflix.titus.api.jobmanager.model.job.Job) ServiceJobProcesses(com.netflix.titus.api.jobmanager.model.job.ServiceJobProcesses) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobFunctions.changeServiceJobCapacity(com.netflix.titus.api.jobmanager.model.job.JobFunctions.changeServiceJobCapacity) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskStatus(com.netflix.titus.api.jobmanager.model.job.TaskStatus) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) JobScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder) Test(org.junit.Test) JobsScenarioBuilder(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CONCURRENT_STORE_UPDATE_LIMIT(com.netflix.titus.master.jobmanager.service.integration.scenario.JobsScenarioBuilder.CONCURRENT_STORE_UPDATE_LIMIT) Assertions.fail(org.assertj.core.api.Assertions.fail) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) After(org.junit.After) JobManagerException(com.netflix.titus.api.jobmanager.service.JobManagerException) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) JobFunctions.changeServiceJobCapacity(com.netflix.titus.api.jobmanager.model.job.JobFunctions.changeServiceJobCapacity) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Test(org.junit.Test)

Example 28 with JobDescriptor

use of com.netflix.titus.api.jobmanager.model.job.JobDescriptor 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)

Aggregations

JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)28 Test (org.junit.Test)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)15 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)13 Before (org.junit.Before)13 Mono (reactor.core.publisher.Mono)12 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)11 AdmissionSanitizer (com.netflix.titus.common.model.admission.AdmissionSanitizer)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_AVAILABLE)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_CONFIDENCE)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_MODEL_ID)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SEC)9 JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_VERSION)9 JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_SANITIZATION_SKIPPED_RUNTIME_PREDICTION)9 JOB_PARAMETER_SKIP_RUNTIME_PREDICTION (com.netflix.titus.api.jobmanager.JobAttributes.JOB_PARAMETER_SKIP_RUNTIME_PREDICTION)9 JobRuntimePrediction (com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction)9 JobRuntimePredictionClient (com.netflix.titus.runtime.connector.prediction.JobRuntimePredictionClient)9