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());
}
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);
}
}
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;
}
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)));
});
}
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();
}
Aggregations