use of com.netflix.titus.runtime.connector.jobmanager.RemoteJobManagementClient in project titus-control-plane by Netflix.
the class ObserveJobsCommand method execute.
@Override
public void execute(CommandContext context) throws Exception {
long keepAliveMs = context.getCLI().hasOption('k') ? Long.parseLong(context.getCLI().getOptionValue('k')) : -1;
RemoteJobManagementClient service = keepAliveMs > 0 ? context.getJobManagementClientWithKeepAlive(keepAliveMs) : context.getJobManagementClient();
Flux<JobManagerEvent<?>> events;
Set<String> jobFields = StringExt.splitByCommaIntoSet(context.getCLI().getOptionValue('j'));
Set<String> taskFields = StringExt.splitByCommaIntoSet(context.getCLI().getOptionValue('t'));
boolean printLatency = context.getCLI().hasOption('l');
boolean printEvents = !context.getCLI().hasOption('n');
boolean snapshotOnly = context.getCLI().hasOption('s');
JobEventPropagationMetrics metrics = JobEventPropagationMetrics.newExternalClientMetrics("cli", context.getTitusRuntime());
if (context.getCLI().hasOption('i')) {
String jobId = context.getCLI().getOptionValue('i');
events = service.observeJob(jobId);
} else if (jobFields.isEmpty() && taskFields.isEmpty()) {
events = service.observeJobs(Collections.emptyMap());
} else {
// Special case. Fields filtering cannot be used with RemoteJobManagementClient which converts data to
// the core model. We have to use GRPC directly.
executeWithFiltering(context, jobFields, taskFields, printEvents, snapshotOnly);
return;
}
while (true) {
logger.info("Establishing a new connection to the job event stream endpoint...");
executeOnce(events, metrics, printLatency, printEvents, snapshotOnly);
if (snapshotOnly) {
return;
}
}
}
use of com.netflix.titus.runtime.connector.jobmanager.RemoteJobManagementClient in project titus-control-plane by Netflix.
the class RemoveUnschedulableJobsCommand method execute.
@Override
public void execute(CommandContext context) throws Exception {
long stuckInAcceptedThresholdMs = TimeUnitExt.toMillis(context.getCLI().getOptionValue('e')).orElseThrow(() -> new IllegalArgumentException("Wrong expiry threshold"));
int limit = Integer.parseInt(context.getCLI().getOptionValue('l'));
Pair<Map<String, Job>, Map<String, Map<String, Task>>> all = loadActiveJobsAndTasks(context);
Map<String, Job> jobs = all.getLeft();
Map<String, UnschedulableJob> unschedulable = UnschedulableFinder.findUnschedulableJobs(context, all.getLeft(), all.getRight(), stuckInAcceptedThresholdMs);
logger.info("Found {} unschedulable jobs", unschedulable.size());
logger.info("Removing the oldest {}...", limit);
List<Job> orderedJobs = unschedulable.keySet().stream().map(jobs::get).sorted(Comparator.comparingLong(j -> j.getStatus().getTimestamp())).collect(Collectors.toList());
RemoteJobManagementClient jobClient = context.getJobManagementClient();
int len = Math.min(orderedJobs.size(), limit);
for (int i = 0; i < len; i++) {
Job jobToRemove = orderedJobs.get(i);
logger.info("Removing job {}...", jobToRemove);
CallMetadata callMetadata = CallMetadata.newBuilder().withCallReason(unschedulable.get(jobToRemove.getId()).getReason()).withCallers(Collections.singletonList(Caller.newBuilder().withId(Evaluators.getOrDefault(System.getenv("USER"), "titusCLI")).withCallerType(CallerType.User).build())).build();
jobClient.killJob(jobToRemove.getId(), callMetadata).block(Duration.ofSeconds(60));
}
logger.info("Removed {} unschedulable jobs out of {} (left {})", len, unschedulable.size(), unschedulable.size() - len);
}
Aggregations