private static Pair<ExecutionReference, ExecutableFlow> getPairWithExecutorInfo(final ResultSet rs, final ExecutableFlow exFlow) throws SQLException { final int executorId = rs.getInt("executorId"); final String host = rs.getString("host"); final int port = rs.getInt("port"); final Executor executor; if (host == null) { logger.warn("Executor id " + executorId + " (on execution " + exFlow.getExecutionId() + ") wasn't found"); executor = null; } else { final boolean executorStatus = rs.getBoolean("executorStatus"); executor = new Executor(executorId, host, port, executorStatus); } final ExecutionReference ref = new ExecutionReference(exFlow.getExecutionId(), executor); return new Pair<>(ref, exFlow); }
/** * Wraps BoundedQueue Take method to have a corresponding update in queuedFlowMap lookup table */ public Pair<ExecutionReference, ExecutableFlow> fetchHead() throws InterruptedException { final Pair<ExecutionReference, ExecutableFlow> pair = this.queuedFlowList.take(); if (pair != null && pair.getFirst() != null) { this.queuedFlowMap.remove(pair.getFirst().getExecId()); } return pair; }
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); }
void addActiveExecutableReference(final ExecutionReference reference) throws ExecutorManagerException { final String INSERT = "INSERT INTO active_executing_flows " + "(exec_id, update_time) values (?,?)"; try { this.dbOperator.update(INSERT, reference.getExecId(), reference.getUpdateTime()); } catch (final SQLException e) { throw new ExecutorManagerException( "Error updating active flow reference " + reference.getExecId(), e); } }
private Map<Optional<Executor>, List<ExecutableFlow>> getFlowToExecutorMap() { final HashMap<Optional<Executor>, List<ExecutableFlow>> exFlowMap = new HashMap<>(); for (final Pair<ExecutionReference, ExecutableFlow> runningFlow : this.runningExecutions.get() .values()) { final ExecutionReference ref = runningFlow.getFirst(); final ExecutableFlow flow = runningFlow.getSecond(); final Optional<Executor> executor = ref.getExecutor(); // We can set the next check time to prevent the checking of certain // flows. if (ref.getNextCheckTime() >= DateTime.now().getMillis()) { continue; } List<ExecutableFlow> flows = exFlowMap.get(executor); if (flows == null) { flows = new ArrayList<>(); exFlowMap.put(executor, flows); } flows.add(flow); } return exFlowMap; }
} else { final ExecutionReference ref = pair.getFirst(); ref.setNextCheckTime(DateTime.now().getMillis() + this.errorThreshold); ref.setNumErrors(ref.getNumErrors() + 1); if (ref.getNumErrors() == this.numErrorsBeforeUnresponsiveEmail || ref.getNumErrors() % this.numErrorsBetweenUnresponsiveEmail == 0) {
private Map<String, Object> callExecutorServer(ExecutionReference ref, String action, Pair<String,String> ... params) throws ExecutorManagerException { try { return callExecutorServer(ref.getHost(), ref.getPort(), action, ref.getExecId(), null, params); } catch (IOException e) { throw new ExecutorManagerException(e); } }
ref.setNextCheckTime(0); ref.setNumErrors(0); final Status oldStatus = flow.getStatus(); flow.applyUpdateObject(updateData);
@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; }
@Override public void addActiveExecutableReference(ExecutionReference reference) throws ExecutorManagerException { final String INSERT = "INSERT INTO active_executing_flows " + "(exec_id, host, port, update_time) values (?,?,?,?)"; QueryRunner runner = createQueryRunner(); try { runner.update( INSERT, reference.getExecId(), reference.getHost(), reference.getPort(), reference.getUpdateTime()); } catch (SQLException e) { throw new ExecutorManagerException( "Error updating active flow reference " + reference.getExecId(), e); } }
throw new ExecutorManagerException(ex); reference.setExecutor(choosenExecutor); exflow.getExecutionId(), reference.getNumErrors()));
logFailedDispatchAttempt(reference, exflow, selectedExecutor, e); ExecutorManager.this.commonMetrics.markDispatchFail(); reference.setNumErrors(reference.getNumErrors() + 1); } while (reference.getNumErrors() < this.maxDispatchingErrors); + " (tried " + reference.getNumErrors() + " executors)"; ExecutorManager.logger.error(message); ExecutorManager.this.executionFinalizer.finalizeFlow(exflow, message, lastError);
ExecutionReference reference = new ExecutionReference(exflow.getExecutionId(), executorHost, executorPort); executorLoader.addActiveExecutableReference(reference); try { executorLoader.removeActiveExecutableReference(reference.getExecId()); throw e;
private void logFailedDispatchAttempt(final ExecutionReference reference, final ExecutableFlow exflow, final Executor selectedExecutor, final ExecutorManagerException e) { ExecutorManager.logger.warn(String.format( "Executor %s responded with exception for exec: %d", selectedExecutor, exflow.getExecutionId()), e); ExecutorManager.logger.info(String.format( "Failed dispatch attempt for exec %d with error count %d", exflow.getExecutionId(), reference.getNumErrors())); }
private Map<ConnectionInfo, List<ExecutableFlow>> getFlowToExecutorMap() { HashMap<ConnectionInfo, List<ExecutableFlow>> exFlowMap = new HashMap<ConnectionInfo, List<ExecutableFlow>>(); ConnectionInfo lastPort = new ConnectionInfo(executorHost, executorPort); for (Pair<ExecutionReference, ExecutableFlow> runningFlow: runningFlows.values()) { ExecutionReference ref = runningFlow.getFirst(); ExecutableFlow flow = runningFlow.getSecond(); // We can set the next check time to prevent the checking of certain flows. if (ref.getNextCheckTime() >= System.currentTimeMillis()) { continue; } // Just a silly way to reduce object creation construction of objects since it's most likely that the values will be the same. if (!lastPort.isEqual(ref.getHost(), ref.getPort())) { lastPort = new ConnectionInfo(ref.getHost(), ref.getPort()); } List<ExecutableFlow> flows = exFlowMap.get(lastPort); if (flows == null) { flows = new ArrayList<ExecutableFlow>(); exFlowMap.put(lastPort, flows); } flows.add(flow); } return exFlowMap; }
ExecutionReference ref = new ExecutionReference(id, host, port); ref.setUpdateTime(updateTime);
@Override public void assignExecutor(final int executorId, final int execId) throws ExecutorManagerException { final ExecutionReference ref = this.refs.get(execId); ref.setExecutor(fetchExecutor(executorId)); this.executionExecutorMapping.put(execId, executorId); }
ref.setNextCheckTime(System.currentTimeMillis() + this.errorThreshold); ref.setNumErrors(ref.getNumErrors() + 1); if (ref.getNumErrors() == this.numErrorsBeforeUnresponsiveEmail || ref.getNumErrors() % this.numErrorsBetweenUnresponsiveEmail == 0) {
private Map<String, Object> callExecutorServer(ExecutionReference ref, String action) throws ExecutorManagerException { try { return callExecutorServer(ref.getHost(), ref.getPort(), action, ref.getExecId(), null, (Pair<String,String>[])null); } catch (IOException e) { throw new ExecutorManagerException(e); } }
ref.setNextCheckTime(0); ref.setNumErrors(0); Status oldStatus = flow.getStatus(); flow.applyUpdateObject(updateData);