Search in sources :

Example 36 with ServiceJobExt

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

the class ServiceJobSchedulingTest method testJobCapacityUpdateToIdenticalAsCurrentCapacityIsNoOp.

@Test
public void testJobCapacityUpdateToIdenticalAsCurrentCapacityIsNoOp() {
    Capacity fixedCapacity = Capacity.newBuilder().withMin(1).withDesired(1).withMax(1).build();
    JobDescriptor<ServiceJobExt> job = JobFunctions.changeServiceJobCapacity(oneTaskServiceJobDescriptor(), fixedCapacity);
    jobsScenarioBuilder.scheduleJob(job, jobScenario -> jobScenario.template(ScenarioTemplates.acceptJobWithOneTask(0, 0)).changeCapacity(fixedCapacity).advance().advance().expectNoStoreUpdate().expectNoJobStateChangeEvent().expectNoTaskStateChangeEvent());
}
Also used : 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 37 with ServiceJobExt

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

the class JobCustomConfigurationValidatorTest method testCustomServiceJobSizeValidation.

@Test(timeout = TEST_TIMEOUT_MS)
public void testCustomServiceJobSizeValidation() {
    JobDescriptor<ServiceJobExt> jobDescriptor = JobFunctions.changeServiceJobCapacity(oneTaskServiceJobDescriptor().toBuilder().withApplicationName("a1").build(), Capacity.newBuilder().withMax(2).build());
    DefaultSettableConfig config = titusStackResource.getMaster().getConfig();
    config.setProperty(CUSTOM_JOB_CONFIGURATION_ROOT + ".a1.pattern", ".*");
    config.setProperty(CUSTOM_JOB_CONFIGURATION_ROOT + ".a1.maxServiceJobSize", "1");
    try {
        client.createJob(toGrpcJobDescriptor(jobDescriptor));
        Assert.fail("Expected to fail due to validation error");
    } catch (StatusRuntimeException e) {
        assertThat(e.getStatus().getCode()).isEqualTo(Status.Code.INVALID_ARGUMENT);
    }
}
Also used : ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) StatusRuntimeException(io.grpc.StatusRuntimeException) DefaultSettableConfig(com.netflix.archaius.config.DefaultSettableConfig) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 38 with ServiceJobExt

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

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

the class BasicServiceJobActions method updateServiceJobProcesses.

/**
 * Change job service processes configuration.
 */
public static TitusChangeAction updateServiceJobProcesses(ReconciliationEngine<JobManagerReconcilerEvent> engine, ServiceJobProcesses processes, JobStore jobStore, VersionSupplier versionSupplier, CallMetadata callMetadata) {
    return TitusChangeAction.newAction("updateServiceJobProcesses").id(engine.getReferenceView().getId()).trigger(V3JobOperations.Trigger.API).summary("Changing job service processes to: %s", processes).callMetadata(callMetadata).changeWithModelUpdates(self -> {
        Job<ServiceJobExt> serviceJob = engine.getReferenceView().getEntity();
        if (serviceJob.getStatus().getState() != JobState.Accepted) {
            return Observable.error(JobManagerException.jobTerminating(serviceJob));
        }
        Job<ServiceJobExt> updatedJob = VersionSuppliers.nextVersion(JobFunctions.changeServiceJobProcesses(serviceJob, processes), versionSupplier);
        TitusModelAction modelAction = TitusModelAction.newModelUpdate(self).jobUpdate(jobHolder -> jobHolder.setEntity(updatedJob));
        return jobStore.updateJob(updatedJob).andThen(Observable.just(ModelActionHolder.referenceAndStore(modelAction)));
    });
}
Also used : TitusModelAction(com.netflix.titus.master.jobmanager.service.common.action.TitusModelAction) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)

Example 40 with ServiceJobExt

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

the class DefaultPodAffinityFactoryTest method relocationBinPackingNegative.

@Test
public void relocationBinPackingNegative() {
    Job<ServiceJobExt> job = JobGenerator.oneServiceJob();
    ServiceJobTask task = JobGenerator.oneServiceTask();
    V1Affinity affinity = factory.buildV1Affinity(job, task).getLeft();
    assertThat(affinity.getPodAffinity()).isNull();
    assertThat(affinity.getPodAntiAffinity()).isNull();
}
Also used : V1Affinity(io.kubernetes.client.openapi.models.V1Affinity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) Test(org.junit.Test)

Aggregations

ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)42 Test (org.junit.Test)17 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)13 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)13 Job (com.netflix.titus.api.jobmanager.model.job.Job)11 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)8 Task (com.netflix.titus.api.jobmanager.model.job.Task)8 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)8 List (java.util.List)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Stopwatch (com.google.common.base.Stopwatch)6 Empty (com.google.protobuf.Empty)6 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)6 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)6 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)6 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)5 JobScenarioBuilder (com.netflix.titus.master.jobmanager.service.integration.scenario.JobScenarioBuilder)5 JobDescriptorGenerator.oneTaskServiceJobDescriptor (com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor)5 ArrayList (java.util.ArrayList)5 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)4