use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class JobManagementSpringResourceTest method testFindJob.
@Test
public void testFindJob() throws Exception {
when(jobServiceGatewayMock.findJob(JOB_ID_1, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(JOB_1));
Job entity = SpringMockMvcUtil.doGet(mockMvc, String.format("/api/v3/jobs/%s", JOB_ID_1), Job.class);
assertThat(entity).isEqualTo(JOB_1);
verify(jobServiceGatewayMock, times(1)).findJob(JOB_ID_1, JUNIT_REST_CALL_METADATA);
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class JobManagerCursors method jobIndexOf.
/**
* Find an index of the element pointed to by the cursor, or if not found, the element immediately preceding it.
* <p>
* If the element pointed to by the cursor would be the first element in the list (index=0) this returns -1.
*
* @deprecated Use core model entities.
*/
@Deprecated
public static Optional<Integer> jobIndexOf(List<Job> jobs, String cursor) {
return decode(cursor).map(cursorValues -> {
String jobId = cursorValues.getLeft();
long timestamp = cursorValues.getRight();
Job referenceJob = Job.newBuilder().setId(jobId).setStatus(JobStatus.newBuilder().setState(JobStatus.JobState.Accepted).setTimestamp(timestamp)).build();
int idx = Collections.binarySearch(jobs, referenceJob, jobCursorOrderComparator());
if (idx >= 0) {
return idx;
}
return Math.max(-1, -idx - 2);
});
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class TaskEventsGenerator method buildEventStream.
private void buildEventStream() {
taskEvents = titusClient.getJobAndTaskUpdates().publishOn(scheduler).flatMap(jobOrTaskUpdate -> jobOrTaskUpdate.hasTask() ? Flux.just(jobOrTaskUpdate.getTask()) : Flux.empty()).map(task -> {
final Mono<Job> jobById = titusClient.getJobById(task.getJobId());
return Pair.of(task, jobById);
}).flatMap(taskMonoPair -> {
final Task task = taskMonoPair.getLeft();
return taskMonoPair.getRight().flatMap(job -> {
try {
final com.netflix.titus.api.jobmanager.model.job.Job coreJob = GrpcJobManagementModelConverters.toCoreJob(job);
final com.netflix.titus.api.jobmanager.model.job.Task coreTask = GrpcJobManagementModelConverters.toCoreTask(coreJob, task);
return Mono.just(TaskDocument.fromV3Task(coreTask, coreJob, ElasticSearchUtils.DATE_FORMAT, buildTaskContext(task)));
} catch (Exception e) {
// If the mapping fails, we do not want to break the pipeline, and possible cause an infinite number
// of retries, each failing on the same bad job/task record. Instead, we log the error.
titusRuntime.getCodeInvariants().unexpectedError(String.format("Cannot map Titus job/task to ES TaskDocument: job=%s, task=%s", job, task), e);
logger.warn("Cannot map Titus job/task to ES TaskDocument", e);
return Mono.empty();
}
}).flux();
}).doOnError(error -> logger.error("TitusClient event stream error", error)).retryWhen(TaskPublisherRetryUtil.buildRetryHandler(TaskPublisherRetryUtil.INITIAL_RETRY_DELAY_MS, TaskPublisherRetryUtil.MAX_RETRY_DELAY_MS, -1)).publish();
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class TitusClientImpl method getJobAndTaskUpdates.
@Override
public Flux<JobOrTaskUpdate> getJobAndTaskUpdates() {
return Flux.create(sink -> attachCallerId(jobManagementService, CLIENT_ID).observeJobs(ObserveJobsQuery.newBuilder().build(), new StreamObserver<JobChangeNotification>() {
@Override
public void onNext(JobChangeNotification jobChangeNotification) {
switch(jobChangeNotification.getNotificationCase()) {
case JOBUPDATE:
final Job job = jobChangeNotification.getJobUpdate().getJob();
jobs.put(job.getId(), CompletableFuture.completedFuture(job));
logger.debug("<{}> JobUpdate {}", Thread.currentThread().getName(), jobChangeNotification.getJobUpdate().getJob().getId());
sink.next(JobOrTaskUpdate.jobUpdate(job));
numJobUpdates.incrementAndGet();
break;
case TASKUPDATE:
logger.debug("<{}> TaskUpdate {}", Thread.currentThread().getName(), jobChangeNotification.getTaskUpdate().getTask().getId());
final Task task = jobChangeNotification.getTaskUpdate().getTask();
sink.next(JobOrTaskUpdate.taskUpdate(task));
numTaskUpdates.incrementAndGet();
break;
case SNAPSHOTEND:
logger.info("<{}> SnapshotEnd {}", Thread.currentThread().getName(), jobChangeNotification);
numSnapshotUpdates.incrementAndGet();
break;
default:
logger.error("<{}> Unknown Notification ? {}", Thread.currentThread().getName(), jobChangeNotification.getNotificationCase());
}
}
@Override
public void onError(Throwable t) {
logger.error("Exception in ObserveJobs :: ", t);
apiErrors.incrementAndGet();
sink.error(t);
}
@Override
public void onCompleted() {
logger.info("STREAM completed ?");
sink.complete();
}
}));
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class DefaultAppAutoScalingCallbackService method setScalableTargetResourceInfo.
@Override
public Observable<ScalableTargetResourceInfo> setScalableTargetResourceInfo(String jobId, ScalableTargetResourceInfo scalableTargetResourceInfo, CallMetadata callMetadata) {
logger.info("(BEFORE setting job instances) for jobId {} :: {}", jobId, scalableTargetResourceInfo);
JobCapacityWithOptionalAttributes jobCapacityWithOptionalAttributes = JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(scalableTargetResourceInfo.getDesiredCapacity()).build()).build();
JobCapacityUpdateWithOptionalAttributes jobCapacityRequest = JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(jobCapacityWithOptionalAttributes).build();
return jobServiceGateway.updateJobCapacityWithOptionalAttributes(jobCapacityRequest, callMetadata).andThen(getScalableTargetResourceInfo(jobId, callMetadata).map(scalableTargetResourceInfoReturned -> {
scalableTargetResourceInfoReturned.setScalingStatus(ScalingStatus.Pending.name());
logger.info("(set job instances) Returning value Instances for jobId {} :: {}", jobId, scalableTargetResourceInfo);
return scalableTargetResourceInfoReturned;
}));
}
Aggregations