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