@Override public TaskLocation getLocation() { return TaskLocation.create("testHost", 10000, 10000); }
public static TaskLocation create(String host, int port, int tlsPort) { return new TaskLocation(host, port, tlsPort); }
private Request createRequest( String taskId, TaskLocation location, String path, @Nullable String encodedQueryString, HttpMethod method, @Nullable String mediaType, byte[] content ) throws MalformedURLException { final String host = location.getHost(); final String scheme = location.getTlsPort() >= 0 ? "https" : "http"; final int port = location.getTlsPort() >= 0 ? location.getTlsPort() : location.getPort(); // Use URL constructor, not URI, since the path is already encoded. // The below line can throw a MalformedURLException, and this method should return immediately without rety. final URL serviceUrl = new URL( scheme, host, port, encodedQueryString == null ? path : StringUtils.format("%s?%s", path, encodedQueryString) ); final Request request = new Request(method, serviceUrl); // used to validate that we are talking to the correct worker request.addHeader(ChatHandlerResource.TASK_ID_HEADER, StringUtils.urlEncode(taskId)); if (content.length > 0) { request.setContent(Preconditions.checkNotNull(mediaType, "mediaType"), content); } return request; }
@VisibleForTesting public void gracefulShutdownInternal() throws ExecutionException, InterruptedException, TimeoutException { for (TaskGroup taskGroup : activelyReadingTaskGroups.values()) { for (Entry<String, TaskData> entry : taskGroup.tasks.entrySet()) { if (taskInfoProvider.getTaskLocation(entry.getKey()).equals(TaskLocation.unknown())) { killTask(entry.getKey(), "Killing task for graceful shutdown"); } else { entry.getValue().startTime = DateTimes.EPOCH; } } } checkTaskDuration(); }
private RemoteTaskRunnerWorkItem( String taskId, String taskType, SettableFuture<TaskStatus> result, DateTime createdTime, DateTime queueInsertionTime, Worker worker, TaskLocation location, String dataSource ) { super(taskId, result, createdTime, queueInsertionTime); this.result = result; this.taskType = taskType; this.worker = worker; this.location = location == null ? TaskLocation.unknown() : location; this.dataSource = dataSource; }
final TaskLocation taskLocation = TaskLocation.create(childHost, childPort, tlsChildPort); new ProcessBuilder(ImmutableList.copyOf(command)).redirectErrorStream(true).start(), logFile, taskLocation.getHost(), taskLocation.getPort(), taskLocation.getTlsPort() );
FullResponseHolder response = null; Request request = null; TaskLocation location = TaskLocation.unknown(); String path = StringUtils.format("%s/%s/%s", BASE_PATH, StringUtils.urlEncode(taskId), encodedPathSuffix); String host = location.getHost(); String scheme = ""; int port = -1; if (location.equals(TaskLocation.unknown())) { throw new NoTaskLocationException(StringUtils.format("No TaskLocation available for task [%s]", taskId)); host = location.getHost(); scheme = location.getTlsPort() >= 0 ? "https" : "http"; port = location.getTlsPort() >= 0 ? location.getTlsPort() : location.getPort();
Assert.assertEquals(task.getId(), announcements.get(0).getTaskStatus().getId()); Assert.assertEquals(TaskState.SUCCESS, announcements.get(0).getTaskStatus().getStatusCode()); Assert.assertEquals(DUMMY_NODE.getHost(), announcements.get(0).getTaskLocation().getHost()); Assert.assertEquals(DUMMY_NODE.getPlaintextPort(), announcements.get(0).getTaskLocation().getPort());
Assert.assertEquals(task3.getId(), update1.getTaskAnnouncement().getTaskStatus().getId()); Assert.assertTrue(update1.getTaskAnnouncement().getTaskStatus().isRunnable()); Assert.assertNull(update1.getTaskAnnouncement().getTaskLocation().getHost()); Assert.assertNull(update2.getTaskAnnouncement().getTaskLocation().getHost()); Assert.assertNotNull(update3.getTaskAnnouncement().getTaskLocation().getHost()); Assert.assertNotNull(update4.getTaskAnnouncement().getTaskLocation().getHost());
private RemoteTaskRunnerWorkItem( String taskId, String taskType, SettableFuture<TaskStatus> result, Worker worker, TaskLocation location, String dataSource ) { super(taskId, result); this.result = result; this.taskType = taskType; this.worker = worker; this.location = location == null ? TaskLocation.unknown() : location; this.dataSource = dataSource; }
final TaskLocation taskLocation = TaskLocation.create(childHost, childPort, tlsChildPort); new ProcessBuilder(ImmutableList.copyOf(command)).redirectErrorStream(true).start(), logFile, taskLocation.getHost(), taskLocation.getPort(), taskLocation.getTlsPort() );
private static WorkerHolder createWorkerHolder( ObjectMapper smileMapper, HttpClient httpClient, HttpRemoteTaskRunnerConfig config, ScheduledExecutorService workersSyncExec, WorkerHolder.Listener listener, Worker worker, // simulates task announcements received from worker on first sync call for the tasks that are already // running/completed on the worker. List<TaskAnnouncement> preExistingTaskAnnouncements, // defines behavior for what to do when a particular task is assigned Map<Task, List<TaskAnnouncement>> toBeAssignedTasks, // incremented on each runnable completion in workersSyncExec, useful for deterministically watching that some // work completed AtomicInteger ticks, // Updated each time a shutdown(taskId) call is received, useful for asserting that expected shutdowns indeed // happened. Set<String> actualShutdowns ) { return new WorkerHolder(smileMapper, httpClient, config, workersSyncExec, listener, worker) { private final String workerHost = worker.getHost().substring(0, worker.getHost().indexOf(':')); private final int workerPort = Integer.parseInt(worker.getHost().substring(worker.getHost().indexOf(':') + 1)); @Override
@Override public TaskLocation getLocation() { return TaskLocation.unknown(); }
@Inject public SingleTaskBackgroundRunner( TaskToolboxFactory toolboxFactory, TaskConfig taskConfig, ServiceEmitter emitter, @Self DruidNode node, ServerConfig serverConfig ) { this.toolboxFactory = Preconditions.checkNotNull(toolboxFactory, "toolboxFactory"); this.taskConfig = taskConfig; this.emitter = Preconditions.checkNotNull(emitter, "emitter"); this.location = TaskLocation.create(node.getHost(), node.getPlaintextPort(), node.getTlsPort()); this.serverConfig = serverConfig; }
public static class TaskNotRunnableException extends RuntimeException { public TaskNotRunnableException(String message) { super(message); } }
public static TaskLocation create(String host, int port, int tlsPort) { return new TaskLocation(host, port, tlsPort); }
public TaskDetails(Task task) { this.task = task; this.startTime = System.currentTimeMillis(); this.status = TaskStatus.running(task.getId()); this.location = TaskLocation.unknown(); } }