Search in sources :

Example 1 with JobManagementServiceBlockingStub

use of com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceBlockingStub in project titus-control-plane by Netflix.

the class ObserveJobsCommand method executeWithFiltering.

private void executeWithFiltering(CommandContext context, Set<String> jobFields, Set<String> taskFields, boolean printEvents, boolean snapshotOnly) {
    JobManagementServiceBlockingStub stub = context.getJobManagementGrpcBlockingStub();
    Stopwatch stopwatch = Stopwatch.createStarted();
    ObserveJobsQuery query = ObserveJobsQuery.newBuilder().addAllJobFields(jobFields).addAllTaskFields(taskFields).build();
    Iterator<JobChangeNotification> eventIt = stub.observeJobs(query);
    while (eventIt.hasNext()) {
        JobChangeNotification next = eventIt.next();
        if (next.getNotificationCase() == JobChangeNotification.NotificationCase.SNAPSHOTEND) {
            logger.info("Emitted: snapshot marker in {}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
            if (snapshotOnly) {
                return;
            }
        } else if (next.getNotificationCase() == JobChangeNotification.NotificationCase.JOBUPDATE) {
            com.netflix.titus.grpc.protogen.Job job = next.getJobUpdate().getJob();
            if (printEvents) {
                logger.info("Emitted job update: jobId={}({}), jobState={}, version={}", job.getId(), next.getJobUpdate().getArchived() ? "archived" : job.getStatus().getState(), job.getStatus(), job.getVersion());
            }
        } else if (next.getNotificationCase() == JobChangeNotification.NotificationCase.TASKUPDATE) {
            com.netflix.titus.grpc.protogen.Task task = next.getTaskUpdate().getTask();
            if (printEvents) {
                logger.info("Emitted task update: jobId={}({}), taskId={}, taskState={}, version={}", task.getJobId(), next.getTaskUpdate().getArchived() ? "archived" : task.getStatus().getState(), task.getId(), task.getStatus(), task.getVersion());
            }
        } else {
            logger.info("Unrecognized event type: {}", next);
        }
    }
}
Also used : JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobManagementServiceBlockingStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceBlockingStub) Stopwatch(com.google.common.base.Stopwatch) Job(com.netflix.titus.api.jobmanager.model.job.Job) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)1 JobManagementServiceBlockingStub (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceBlockingStub)1 ObserveJobsQuery (com.netflix.titus.grpc.protogen.ObserveJobsQuery)1