@Override public Set<String> getPrimaryServerHosts() { final HashSet<String> ports = new HashSet<>(); try { for (final Executor executor : this.executorLoader.fetchActiveExecutors()) { ports.add(executor.getHost() + ":" + executor.getPort()); } } catch (final ExecutorManagerException e) { logger.error("Failed to get primary server hosts.", e); } return ports; }
@Override public Set<String> getPrimaryServerHosts() { // Only one for now. More probably later. final HashSet<String> ports = new HashSet<>(); for (final Executor executor : this.activeExecutors.getAll()) { ports.add(executor.getHost() + ":" + executor.getPort()); } return ports; }
@Override public Map<String, Object> callExecutorStats(final int executorId, final String action, final Pair<String, String>... params) throws IOException, ExecutorManagerException { final Executor executor = fetchExecutor(executorId); final List<Pair<String, String>> paramList = new ArrayList<>(); if (params != null) { paramList.addAll(Arrays.asList(params)); } paramList.add(new Pair<>(ConnectorParams.ACTION_PARAM, action)); return this.apiGateway.callForJsonObjectMap(executor.getHost(), executor.getPort(), "/stats", paramList); }
@Override public Set<String> getAllActiveExecutorServerHosts() { // Includes non primary server/hosts final HashSet<String> ports = new HashSet<>(); for (final Executor executor : this.activeExecutors.getAll()) { ports.add(executor.getHost() + ":" + executor.getPort()); } // include executor which were initially active and still has flows running for (final Pair<ExecutionReference, ExecutableFlow> running : this.runningExecutions.get() .values()) { final ExecutionReference ref = running.getFirst(); if (ref.getExecutor().isPresent()) { final Executor executor = ref.getExecutor().get(); ports.add(executor.getHost() + ":" + executor.getPort()); } } return ports; }
Map<String, Object> callWithReference(final ExecutionReference ref, final String action, final Pair<String, String>... params) throws ExecutorManagerException { final Executor executor = ref.getExecutor().get(); return callWithExecutionId(executor.getHost(), executor.getPort(), action, ref.getExecId(), null, params); }
Map<String, Object> callWithExecutable(final ExecutableFlow exflow, final Executor executor, final String action) throws ExecutorManagerException { return callWithExecutionId(executor.getHost(), executor.getPort(), action, exflow.getExecutionId(), null, (Pair<String, String>[]) null); }
/** * Manage servlet call for stats servlet in Azkaban execution server {@inheritDoc} * * @see azkaban.executor.ExecutorManagerAdapter#callExecutorStats(int, java.lang.String, * azkaban.utils.Pair[]) */ @Override public Map<String, Object> callExecutorStats(final int executorId, final String action, final Pair<String, String>... params) throws IOException, ExecutorManagerException { final Executor executor = fetchExecutor(executorId); final List<Pair<String, String>> paramList = new ArrayList<>(); // if params = null if (params != null) { paramList.addAll(Arrays.asList(params)); } paramList .add(new Pair<>(ConnectorParams.ACTION_PARAM, action)); return this.apiGateway.callForJsonObjectMap(executor.getHost(), executor.getPort(), "/stats", paramList); }
Map<String, Object> callWithReferenceByUser(final ExecutionReference ref, final String action, final String user, final Pair<String, String>... params) throws ExecutorManagerException { final Executor executor = ref.getExecutor().get(); return callWithExecutionId(executor.getHost(), executor.getPort(), action, ref.getExecId(), user, params); }
@Override public Executor fetchExecutor(final String host, final int port) throws ExecutorManagerException { for (final Executor executor : this.executors) { if (executor.getHost().equals(host) && executor.getPort() == port) { return executor; } } return null; }
@Override public Set<String> getAllActiveExecutorServerHosts() { final Set<String> ports = getPrimaryServerHosts(); // include executor which were initially active and still has flows running try { for (final Pair<ExecutionReference, ExecutableFlow> running : this.executorLoader .fetchActiveFlows().values()) { final ExecutionReference ref = running.getFirst(); if (ref.getExecutor().isPresent()) { final Executor executor = ref.getExecutor().get(); ports.add(executor.getHost() + ":" + executor.getPort()); } } } catch (final ExecutorManagerException e) { logger.error("Failed to get all active executor server hosts.", e); } return ports; }
.callWithExecutionId(executor.getHost(), executor.getPort(), ConnectorParams.PING_ACTION, null, null); if (results == null || results.containsKey(ConnectorParams.RESPONSE_ERROR) || !results
@Test public void testFetchAllActiveExecutorServerHosts() throws Exception { final Set<String> activeExecutorServerHosts = this.controller.getAllActiveExecutorServerHosts(); assertThat(activeExecutorServerHosts.size()).isEqualTo(3); this.allExecutors.forEach(executor -> assertThat( activeExecutorServerHosts.contains(executor.getHost() + ":" + executor.getPort())) .isTrue()); }
public Map<String, Object> updateExecutions(final Executor executor, final List<ExecutableFlow> executions) throws ExecutorManagerException { final List<Long> updateTimesList = new ArrayList<>(); final List<Integer> executionIdsList = new ArrayList<>(); // We pack the parameters of the same host together before query for (final ExecutableFlow flow : executions) { executionIdsList.add(flow.getExecutionId()); updateTimesList.add(flow.getUpdateTime()); } final Pair<String, String> updateTimes = new Pair<>( ConnectorParams.UPDATE_TIME_LIST_PARAM, JSONUtils.toJSON(updateTimesList)); final Pair<String, String> executionIds = new Pair<>( ConnectorParams.EXEC_ID_LIST_PARAM, JSONUtils.toJSON(executionIdsList)); return callWithExecutionId(executor.getHost(), executor.getPort(), ConnectorParams.UPDATE_ACTION, null, null, executionIds, updateTimes); }
@Test public void testSingleExecutorFetchHostPort() throws Exception { final List<Executor> executors = addTestExecutors(); for (final Executor executor : executors) { final Executor fetchedExecutor = this.executorDao.fetchExecutor(executor.getHost(), executor.getPort()); assertThat(executor).isEqualTo(fetchedExecutor); } }
private void handleException(final Entry<Optional<Executor>, List<ExecutableFlow>> entry, final Executor executor, final ExecutorManagerException e, final ArrayList<ExecutableFlow> finalizeFlows) { logger.error("Failed to get update from executor " + executor.getHost(), e); boolean sendUnresponsiveEmail = false; final boolean executorRemoved = isExecutorRemoved(executor.getId());
/** * Test running flow is not finalized and alert email is not sent when executor is alive. */ @Test public void checkExecutorHealthAlive() throws Exception { this.activeFlows.put(EXECUTION_ID_11, new Pair<>( new ExecutionReference(EXECUTION_ID_11, this.executor1), this.flow1)); when(this.apiGateway.callWithExecutionId(this.executor1.getHost(), this.executor1.getPort(), ConnectorParams.PING_ACTION, null, null)).thenReturn(ImmutableMap.of(ConnectorParams .STATUS_PARAM, ConnectorParams.RESPONSE_ALIVE)); this.executorHealthChecker.checkExecutorHealth(); assertThat(this.flow1.getStatus()).isEqualTo(Status.RUNNING); verifyZeroInteractions(this.alerterHolder); }
verify(this.apiGateway).callWithExecutionId(this.executor1.getHost(), this.executor1.getPort(), ConnectorParams.PING_ACTION, null, null); verifyZeroInteractions(this.alerterHolder); when(this.apiGateway.callWithExecutionId(this.executor1.getHost(), this.executor1.getPort(), ConnectorParams.PING_ACTION, null, null)).thenReturn(ImmutableMap.of(ConnectorParams .STATUS_PARAM, ConnectorParams.RESPONSE_ALIVE)); when(this.apiGateway.callWithExecutionId(this.executor1.getHost(), this.executor1.getPort(), ConnectorParams.PING_ACTION, null, null)).thenReturn(null); this.executorHealthChecker.checkExecutorHealth();
public void updateExecutor(final Executor executor) throws ExecutorManagerException { final String UPDATE = "UPDATE executors SET host=?, port=?, active=? where id=?"; try { final int rows = this.dbOperator.update(UPDATE, executor.getHost(), executor.getPort(), executor.isActive(), executor.getId()); if (rows == 0) { throw new ExecutorManagerException("No executor with id :" + executor.getId()); } } catch (final SQLException e) { throw new ExecutorManagerException("Error inactivating executor " + executor.getId(), e); } }
@Test public void testFetchAllActiveExecutorServerHosts() throws Exception { testSetUpForRunningFlows(); final Set<String> activeExecutorServerHosts = this.manager.getAllActiveExecutorServerHosts(); final Executor executor1 = this.manager.fetchExecutor(this.flow1.getExecutionId()); final Executor executor2 = this.manager.fetchExecutor(this.flow2.getExecutionId()); Assert.assertTrue( activeExecutorServerHosts.contains(executor1.getHost() + ":" + executor1.getPort())); Assert.assertTrue( activeExecutorServerHosts.contains(executor2.getHost() + ":" + executor2.getPort())); }
private List<ExecutableFlow> createExecutions() throws Exception { final Executor executor = this.executorDao.addExecutor("test", 1); final ExecutableFlow flow1 = createExecutionAndAssign(Status.PREPARING, executor); // flow2 is not assigned final ExecutableFlow flow2 = createExecution(Status.PREPARING); final ExecutableFlow flow3 = createExecutionAndAssign(Status.RUNNING, executor); flow3.setStartTime(System.currentTimeMillis() + 1); this.executionFlowDao.updateExecutableFlow(flow3); final ExecutableFlow flow4 = createExecutionAndAssign(Status.SUCCEEDED, executor); flow4.setStartTime(System.currentTimeMillis() - 2); flow4.setEndTime(System.currentTimeMillis() - 1); this.executionFlowDao.updateExecutableFlow(flow4); final Executor executor2 = this.executorDao.addExecutor("test2", 2); // flow5 is assigned to an executor that is then removed final ExecutableFlow flow5 = createExecutionAndAssign(Status.RUNNING, executor2); flow5.setStartTime(System.currentTimeMillis() + 1); this.executionFlowDao.updateExecutableFlow(flow5); this.executorDao.removeExecutor(executor2.getHost(), executor2.getPort()); return ImmutableList.of(flow1, flow2, flow3, flow4, flow5); }