code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
private void sleep(final long milliseconds) { try { Thread.sleep(milliseconds); } catch (final InterruptedException e) { logger.error("Sleep interrupted", e); } }
When database is completed down, DB connection fails to be fetched immediately. So we need to sleep 15 seconds for retry.
sleep
java
azkaban/azkaban
azkaban-db/src/main/java/azkaban/db/MySQLDataSource.java
https://github.com/azkaban/azkaban/blob/master/azkaban-db/src/main/java/azkaban/db/MySQLDataSource.java
Apache-2.0
@Override public String getDBType() { return "mysql"; }
When database is completed down, DB connection fails to be fetched immediately. So we need to sleep 15 seconds for retry.
getDBType
java
azkaban/azkaban
azkaban-db/src/main/java/azkaban/db/MySQLDataSource.java
https://github.com/azkaban/azkaban/blob/master/azkaban-db/src/main/java/azkaban/db/MySQLDataSource.java
Apache-2.0
@Override public boolean allowsOnDuplicateKey() { return true; }
When database is completed down, DB connection fails to be fetched immediately. So we need to sleep 15 seconds for retry.
allowsOnDuplicateKey
java
azkaban/azkaban
azkaban-db/src/main/java/azkaban/db/MySQLDataSource.java
https://github.com/azkaban/azkaban/blob/master/azkaban-db/src/main/java/azkaban/db/MySQLDataSource.java
Apache-2.0
public static void writeJSON(final HttpServletResponse resp, final Object obj) throws IOException { resp.setContentType(JSON_MIME_TYPE); final ObjectMapper mapper = new ObjectMapper(); final OutputStream stream = resp.getOutputStream(); mapper.writeValue(stream, obj); }
Write an Object to HttpResponse in Json format. @param resp @param obj @throws IOException
writeJSON
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/common/ServletUtils.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/common/ServletUtils.java
Apache-2.0
public static Path getCurrentDir() { // AZ_HOME must provide a correct path, if not then azHome is set to current working dir. final String azHome = Optional.ofNullable(System.getenv(Constants.AZ_HOME)).orElse(""); return Paths.get(azHome).toAbsolutePath(); }
FlowPreparer implementation for containerized execution. It creates the PROJECT_DIR and downloads and unzips the project zip in it thus READYing it for execution.
getCurrentDir
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerizedFlowPreparer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerizedFlowPreparer.java
Apache-2.0
@Override public void setup(final ExecutableFlow flow) throws ExecutorManagerException { final ProjectDirectoryMetadata projectDirMetadata = new ProjectDirectoryMetadata( flow.getProjectId(), flow.getVersion(), flow.getProjectName()); final long flowPrepStartTime = System.currentTimeMillis(); final int execId = flow.getExecutionId(); // Setup project/execution directory final File projectDir = setupExecutionDir(getCurrentDir(), flow); LOGGER.info("Starting the flow preparation for containerized execution"); try { downloadAndUnzipProject(projectDirMetadata, execId, projectDir); final long flowPrepCompletionTime = System.currentTimeMillis(); LOGGER.info("Flow preparation completed in {} sec(s). [execid: {}, path: {}]", (flowPrepCompletionTime - flowPrepStartTime) / 1000, flow.getExecutionId(), projectDir.getPath()); } catch (final IOException e) { LOGGER.error("Error in downloading project files for flow execution {}", execId, e); throw new ExecutorManagerException(e); } }
Prepare the directory for flow execution. @param flow Executable Flow instance.
setup
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerizedFlowPreparer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerizedFlowPreparer.java
Apache-2.0
@Override protected File setupExecutionDir(final Path dir, final ExecutableFlow flow) throws ExecutorManagerException { // Create project dir final Path projectDirPath = Paths.get(dir.toString(), PROJECT_DIR); // A directory of name projectDirPath cannot pre-exist. if (Files.exists(projectDirPath)) { final String msg = "A project directory of name " + projectDirPath + " already exists"; LOGGER.error(msg); throw new ExecutorManagerException(msg); } LOGGER.info("Creating execution dir"); try { Files.createDirectory(projectDirPath); } catch (final IOException e) { LOGGER.error("Error creating directory :" + projectDirPath, e); throw new ExecutorManagerException(e); } flow.setExecutionPath(projectDirPath.toString()); return projectDirPath.toFile(); }
Prepare the directory for flow execution. @param flow Executable Flow instance.
setupExecutionDir
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerizedFlowPreparer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerizedFlowPreparer.java
Apache-2.0
@VisibleForTesting void handleModifyExecutionRequest(final Map<String, Object> respMap, final int execId, final String user, final HttpServletRequest req) throws ServletException { if (user == null) { respMap.put(ConnectorParams.RESPONSE_ERROR, "user has not been set"); return; } if (!hasParam(req, ConnectorParams.MODIFY_EXECUTION_ACTION_TYPE)) { respMap.put(ConnectorParams.RESPONSE_ERROR, "Modification type not set."); return; } final String modificationType = getParam(req, ConnectorParams.MODIFY_EXECUTION_ACTION_TYPE); try { if (ConnectorParams.MODIFY_RETRY_FAILURES.equals(modificationType)) { this.flowContainer.retryFailures(execId, user); } } catch (final ExecutorManagerException e) { logger.error(e.getMessage(), e); respMap.put(ConnectorParams.RESPONSE_ERROR, e.getMessage()); } }
This method checks if the modifyExecution request also has param modifyType with value retryFailures, then it attempts to retry the failed jobs in the running execution. @param respMap @param execId @param user @param req @throws ServletException
handleModifyExecutionRequest
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
Apache-2.0
@VisibleForTesting void handlePing(HashMap<String, Object> respMap) { respMap.put(ConnectorParams.STATUS_PARAM, ConnectorParams.RESPONSE_ALIVE); }
This method checks if the modifyExecution request also has param modifyType with value retryFailures, then it attempts to retry the failed jobs in the running execution. @param respMap @param execId @param user @param req @throws ServletException
handlePing
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
Apache-2.0
private void handleAjaxCancel(final Map<String, Object> respMap, final int execid, final String user) { if (user == null) { respMap.put(ConnectorParams.RESPONSE_ERROR, "user has not been set"); return; } try { this.flowContainer.cancelFlow(execid, user); respMap.put(ConnectorParams.STATUS_PARAM, ConnectorParams.RESPONSE_SUCCESS); } catch (final ExecutorManagerException e) { logger.error(e.getMessage(), e); respMap.put(ConnectorParams.RESPONSE_ERROR, e.getMessage()); } }
This method checks if the modifyExecution request also has param modifyType with value retryFailures, then it attempts to retry the failed jobs in the running execution. @param respMap @param execId @param user @param req @throws ServletException
handleAjaxCancel
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
Apache-2.0
private void handleFetchLogEvent(final int execId, final HttpServletRequest req, final HttpServletResponse resp, final Map<String, Object> respMap) throws ServletException { final String type = getParam(req, "type"); final int startByte = getIntParam(req, "offset"); final int length = getIntParam(req, "length"); resp.setContentType(Constants.CONTENT_TYPE_TEXT_PLAIN); resp.setCharacterEncoding(Constants.CHARACTER_ENCODING_UTF_8); if (type.equals("flow")) { final FileIOUtils.LogData result; try { result = this.flowContainer.readFlowLogs(execId, startByte, length); respMap.putAll(result.toObject()); } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put(ConnectorParams.RESPONSE_ERROR, e.getMessage()); } } else { final int attempt = getIntParam(req, "attempt", 0); final String jobId = getParam(req, "jobId"); try { final FileIOUtils.LogData result = this.flowContainer.readJobLogs(execId, jobId, attempt, startByte, length); respMap.putAll(result.toObject()); } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put("error", e.getMessage()); } } }
This method checks if the modifyExecution request also has param modifyType with value retryFailures, then it attempts to retry the failed jobs in the running execution. @param respMap @param execId @param user @param req @throws ServletException
handleFetchLogEvent
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
Apache-2.0
private void handleFetchMetaDataEvent(final int execId, final HttpServletRequest req, final HttpServletResponse resp, final Map<String, Object> respMap) throws ServletException { final int startByte = getIntParam(req, "offset"); final int length = getIntParam(req, "length"); resp.setContentType("text/plain"); resp.setCharacterEncoding("utf-8"); final int attempt = getIntParam(req, "attempt", 0); final String jobId = getParam(req, "jobId"); try { final FileIOUtils.JobMetaData result = this.flowContainer.readJobMetaData(execId, jobId, attempt, startByte, length); respMap.putAll(result.toObject()); } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put("error", e.getMessage()); } }
This method checks if the modifyExecution request also has param modifyType with value retryFailures, then it attempts to retry the failed jobs in the running execution. @param respMap @param execId @param user @param req @throws ServletException
handleFetchMetaDataEvent
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/ContainerServlet.java
Apache-2.0
private static Props setAzkabanProps(final Path jobtypePluginPath) { final Map<String, String> propsMap = new HashMap<>(); propsMap.put(AzkabanExecutorServer.JOBTYPE_PLUGIN_DIR, jobtypePluginPath.toString()); // Setup the azkaban.properties here. final String[] args = {CONF_ARG, CONF_DIR}; final Props props = AzkabanServer.loadProps(args); return new Props(props, propsMap); }
Set Azkaban Props @param jobtypePluginPath Path where all the jobtype plugins are mounted. @return Populated Azkaban properties.
setAzkabanProps
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@VisibleForTesting static void setInjector(final Props azkabanProps) { // Inject AzkabanCommonModule final Injector injector = Guice.createInjector( new AzkabanCommonModule(azkabanProps), new ClusterModule(), new ExecJettyServerModule() ); SERVICE_PROVIDER.setInjector(injector); }
Set Azkaban Props @param jobtypePluginPath Path where all the jobtype plugins are mounted. @return Populated Azkaban properties.
setInjector
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@VisibleForTesting void setResourceUtilization() { final FlowRunnerProxy flowRunnerProxy = this.flowRunner.getProxy(); final String cpuRequest = System .getenv(Constants.ContainerizedDispatchManagerProperties.ENV_CPU_REQUEST); final String memoryRequest = System .getenv(Constants.ContainerizedDispatchManagerProperties.ENV_MEMORY_REQUEST); // cpuRequest and memoryRequest are converted to Quantity object to get the parsed value from // the human readable string. Example: // 1KiB will be converted to 1024 bytes // 500m will be converted to 0.500 if (null != cpuRequest) { final Quantity cpuRequestQuantity = new Quantity(cpuRequest); flowRunnerProxy.setCpuUtilization(cpuRequestQuantity.getNumber().doubleValue()); } if (null != memoryRequest) { final Quantity memoryRequestQuantity = new Quantity(memoryRequest); try { flowRunnerProxy.setMemoryUtilization(memoryRequestQuantity.getNumber().longValueExact()); } catch (ArithmeticException e) { logger.info("Unable to set Memory Utilization", e); } } }
This method reads the CPU and MEMORY REQUEST ENV variables. If they are present then they will be used to set the Resource Utilization in FlowRunner object via FlowRunnerProxy.
setResourceUtilization
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private void createFlowRunner(final ExecutableFlow flow) throws ExecutorManagerException { // Prepare the flow with project dependencies. this.flowPreparer.setup(flow); // Setup flow watcher FlowWatcher watcher = null; final ExecutionOptions options = flow.getExecutionOptions(); if (options.getPipelineExecutionId() != null) { final int pipelinedExecId = options.getPipelineExecutionId(); watcher = new RemoteFlowWatcher(pipelinedExecId, this.executorLoader); } int numJobThreads = this.numJobThreadPerFlow; if (options.getFlowParameters().containsKey(FLOW_NUM_JOB_THREADS)) { try { if (!ProjectWhitelist.isXmlFileLoaded()) { ProjectWhitelist.load(azkabanProps); } final int numJobs = Integer.valueOf(options.getFlowParameters().get( FLOW_NUM_JOB_THREADS)); logger.info("Num of job threads read from flow parameter is " + numJobs); if (numJobs > 0 && (numJobs <= numJobThreads || ProjectWhitelist .isProjectWhitelisted(flow.getProjectId(), WhitelistType.NumJobPerFlow))) { numJobThreads = numJobs; } } catch (final Exception e) { throw new ExecutorManagerException( "Failed to set the number of job threads " + options.getFlowParameters().get(FLOW_NUM_JOB_THREADS) + " for flow " + flow.getExecutionId(), e); } } // TODO : figure out the metrics // Create the FlowRunner final MetricsManager metricsManager = new MetricsManager(new MetricRegistry()); final CommonMetrics commonMetrics = new CommonMetrics(metricsManager); final ExecMetrics execMetrics = new ExecMetrics(metricsManager); this.flowRunner = new FlowRunner(flow, this.executorLoader, this.executionLogsLoader, this.projectLoader, this.jobTypeManager, this.azkabanProps, this.eventReporter, this.alerterHolder, commonMetrics, execMetrics); this.flowRunner.setFlowWatcher(watcher) .setJobLogSettings(this.jobLogChunkSize, this.jobLogNumFiles) .setValidateProxyUser(this.validateProxyUser) .setNumJobThreads(numJobThreads) .addListener(this); }
Create Flow Runner and setup the flow execution directory with project dependencies. @param flow Executable flow object. @return FlowRunner object. @throws ExecutorManagerException
createFlowRunner
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private void setupKeyStore() throws ExecutorManagerException { // Fetch keyStore props and use it to get the KeyStore, put it in JobTypeManager final Props commonPluginLoadProps = this.jobTypeManager.getCommonPluginLoadProps(); if (commonPluginLoadProps != null) { // Load HadoopSecurityManager HadoopSecurityManager hadoopSecurityManager = null; try { final String hadoopSecurityClassName = commonPluginLoadProps.getString(HadoopJobUtils.HADOOP_SECURITY_MANAGER_CLASS_PARAM); final Class<?> hadoopSecurityManagerClass = HadoopProxy.class.getClassLoader().loadClass(hadoopSecurityClassName); logger.info("Loading hadoop security manager " + hadoopSecurityManagerClass.getName()); hadoopSecurityManager = (HadoopSecurityManager) Utils.callConstructor(hadoopSecurityManagerClass, commonPluginLoadProps); } catch (final Exception e) { logger.error("Could not instantiate Hadoop Security Manager ", e); throw new RuntimeException("Failed to get hadoop security manager!" + e.getCause(), e); } if (commonPluginLoadProps.getBoolean("use.polp.keystores", false)){ final Map<String, KeyStore> keyStoreMap = hadoopSecurityManager.getKeyStoreMap(commonPluginLoadProps); if (keyStoreMap == null) { logger.error("Failed to Prefetch KeyStore Map of Proxy Users"); throw new ExecutorManagerException("Failed to Prefetch KeyStore Map of Proxy Users"); } } else { final KeyStore keyStore = hadoopSecurityManager.getKeyStore(commonPluginLoadProps); if (keyStore == null) { logger.error("Failed to Prefetch KeyStore"); throw new ExecutorManagerException("Failed to Prefetch KeyStore"); } } logger.info("In-memory Keystore is setup, delete the cert file"); // Delete the cert file from disk as the KeyStore is already cached above. final Path certFilePath = Paths.get(this.azkabanProps.get( Constants.ConfigurationKeys.CSR_KEYSTORE_LOCATION)); deleteSymlinkedFile(certFilePath); } }
Setup in-memory keystore to be reused for all the job executions in the flow. @throws ExecutorManagerException
setupKeyStore
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@VisibleForTesting void start() { AzkabanServer.setupTimeZone(this.azkabanProps, logger); this.containerContext.setAttribute(Constants.AZKABAN_CONTAINER_CONTEXT_KEY, this); JmxJobMBeanManager.getInstance().initialize(this.azkabanProps); ServerUtils.configureJobCallback(FlowContainer.logger, this.azkabanProps); configureMBeanServer(); // Start the Jetty Server launchCtrlMsgListener(this); }
Starts the Jetty Server and sets up callback mechanisms
start
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@Override public void pauseFlow(int execId, String user) throws ExecutorManagerException { throw new NotImplementedException("Operation not yet implemented."); }
Starts the Jetty Server and sets up callback mechanisms
pauseFlow
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@Override public void resumeFlow(int execId, String user) throws ExecutorManagerException { throw new NotImplementedException("Operation not yet implemented."); }
Starts the Jetty Server and sets up callback mechanisms
resumeFlow
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@Override public void cancelFlow(final int execId, final String user) throws ExecutorManagerException { logger.info("Cancel Flow called"); if (this.flowRunner == null) { logger.warn(String.format("Attempt to cancel flow execId: %d before flow got a chance to start.", execId)); throw new ExecutorManagerException("Flow has not launched yet."); } if (Status.isStatusFinished(this.flowRunner.getExecutableFlow().getStatus())) { logger.warn("Found a finished execution in the list of running flows: " + execId); throw new ExecutorManagerException("Execution is already finished."); } this.flowRunner.kill(user); }
Starts the Jetty Server and sets up callback mechanisms
cancelFlow
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@Override public void cancelJobBySLA(final int execId, final String jobId) throws ExecutorManagerException { if (this.flowRunner == null) { throw new ExecutorManagerException("Execution " + execId + " is not running."); } this.flowRunner.getExecutableFlow().setModifiedBy("SLA"); for (final JobRunner jobRunner : this.flowRunner.getActiveJobRunners()) { if (!jobRunner.getJobId().equals(jobId)) { continue; } logger.info("Killing job " + jobId + " in execution " + execId + " by SLA"); jobRunner.killBySLA(); break; } }
Starts the Jetty Server and sets up callback mechanisms
cancelJobBySLA
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@Override public void retryFailures(final int execId, final String user) throws ExecutorManagerException { if (this.flowRunner == null) { logger.warn(String.format("Attempt to retry failures for execId: %d before flow got a " + "chance to start.", execId)); throw new ExecutorManagerException("Execution " + execId + " is not running."); } this.flowRunner.retryFailures(user); }
Starts the Jetty Server and sets up callback mechanisms
retryFailures
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
public LogData readFlowLogs(final int execId, final int startByte, final int length) throws ExecutorManagerException { logger.info("readFlowLogs called"); if (this.flowRunner == null) { logger.warn(String.format("Attempt to read flow logs before flow execId: %d got a chance to start", execId)); throw new ExecutorManagerException("The flow has not launched yet!"); } final File dir = this.flowRunner.getExecutionDir(); if (dir == null || !dir.exists()) { logger.warn(String.format("Error reading file. Execution directory does not exist for flow execId: %d", execId)); throw new ExecutorManagerException("Error reading file. Execution directory does not exist"); } try { if (this.logFile.exists()) { return FileIOUtils.readUtf8File(this.logFile, startByte, length); } else { logger.warn(String.format("Flow log file does not exist for flow execId: %d", execId)); throw new ExecutorManagerException("Flow log file does not exist."); } } catch (final IOException e) { logger.error(String.format("IOException while trying to read flow log file for flow execId: %d", execId)); throw new ExecutorManagerException(e); } }
Return accumulated flow logs with the specified length from the flow container starting from the given byte offset. @param execId @param startByte @param length @return @throws ExecutorManagerException
readFlowLogs
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
public LogData readJobLogs(final int execId, final String jobId, final int attempt, final int startByte, final int length) throws ExecutorManagerException { logger.info("readJobLogs called"); if (this.flowRunner == null) { logger.warn(String.format("Attempt to read job logs before flow got a chance to start. " + "Flow execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException("The flow has not launched yet!"); } final File dir = this.flowRunner.getExecutionDir(); if (dir == null || !dir.exists()) { logger.warn(String.format("Error reading jobLogs. Execution dir does not exist. execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException( "Error reading file. Execution directory does not exist."); } try { final File logFile = this.flowRunner.getJobLogFile(jobId, attempt); if (logFile != null && logFile.exists()) { return FileIOUtils.readUtf8File(logFile, startByte, length); } else { logger.warn(String.format("Job log file does not exist. Flow execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException("Job log file does not exist."); } } catch (final IOException e) { logger.error(String.format("IOException while trying to read Job logs. execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException(e); } }
Return accumulated job logs for a specific job starting with the provided byte offset. @param execId @param jobId @param attempt @param startByte @param length @return @throws ExecutorManagerException
readJobLogs
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
public JobMetaData readJobMetaData(final int execId, final String jobId, final int attempt, final int startByte, final int length) throws ExecutorManagerException { logger.info("readJobMetaData called"); if (this.flowRunner == null) { logger.warn(String.format("Metadata cannot be read as flow has not started. execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException("The flow has not launched yet."); } final File dir = this.flowRunner.getExecutionDir(); if (dir == null || !dir.exists()) { logger.warn(String.format("Execution directory does not exist. execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException( "Error reading file. Execution directory does not exist."); } try { final File metaDataFile = this.flowRunner.getJobMetaDataFile(jobId, attempt); if (metaDataFile != null && metaDataFile.exists()) { return FileIOUtils.readUtf8MetaDataFile(metaDataFile, startByte, length); } else { logger.warn(String.format("Job metadata file does not exist. execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException("Job metadata file does not exist."); } } catch (final IOException e) { logger.error(String.format("IOException while trying to read metadata file. execId: %d, jobId: %s", execId, jobId)); throw new ExecutorManagerException(e); } }
@param execId @param jobId @param attempt @param startByte @param length @return @throws ExecutorManagerException
readJobMetaData
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@VisibleForTesting static void launchCtrlMsgListener(final FlowContainer flowContainer) { try { flowContainer.jettyServer.start(); } catch (final Exception e) { logger.error(e.getMessage()); } final Connector[] connectors = flowContainer.jettyServer.getConnectors(); checkState(connectors.length >= 1, "Server must have at least 1 connector"); // The first connector is created upon initializing the server. That's the one that has the port. flowContainer.port = connectors[0].getLocalPort(); logger.info(String.format("Listening on port %d for control messages.", flowContainer.port)); }
@param execId @param jobId @param attempt @param startByte @param length @return @throws ExecutorManagerException
launchCtrlMsgListener
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private static int getExecutionId() throws ExecutorManagerException { final String execIdStr = System.getenv( Constants.ContainerizedDispatchManagerProperties.ENV_FLOW_EXECUTION_ID); if (execIdStr == null) { final String msg = "Execution ID is not set!"; logger.error(msg); throw new ExecutorManagerException(msg); } // Process Execution ID. int execId = -1; try { execId = Integer.parseInt(execIdStr); logger.info(String.format("Execution ID : %d", execId)); } catch (final NumberFormatException ne) { logger.error(String.format("Execution ID set in environment is invalid %s", execIdStr)); throw new ExecutorManagerException(ne); } if (execId < 1) { final String msg = "Invalid Execution ID : " + execId; logger.error(msg); throw new ExecutorManagerException(msg); } return execId; }
@param execId @param jobId @param attempt @param startByte @param length @return @throws ExecutorManagerException
getExecutionId
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private void logVersionSet(final ExecutableFlow flow) { final VersionSet versionSet = flow.getVersionSet(); if (versionSet == null) { // Should not happen. logger.error("VersionSet is not set for the flow"); } else { logger.info("VersionSet: " + ServerUtils.getVersionSetJsonString(versionSet)); } }
Log the versionSet for this flow execution @param flow Executable flow.
logVersionSet
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private void logVPAEnabled(final ExecutableFlow flow) { if (flow.isVPAEnabled()) { logger.info(String.format("This flow execution pod %s is autoscaled by Azkaban. If this " + "execution ends with Out-Of-Memory Killed, please reach out to Azkaban team for " + "help.", flow.getExecutionId())); } }
Log if this flow execution pod is autoscaled by VPA @param flow Executable flow.
logVPAEnabled
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
public static void deleteSymlinkedFile(final Path symlinkedFilePath) throws ExecutorManagerException { if (Files.isSymbolicLink(symlinkedFilePath)) { Path filePath = null; try { filePath = Files.readSymbolicLink(symlinkedFilePath); } catch (final IOException e) { logger.error(String.format("Error reading symlink %s", symlinkedFilePath), e); throw new ExecutorManagerException(e); } // Delete the symlink and then delete the symlinked file deleteSymlinkedFile(filePath); } // Delete the file, it could be a symlink try { Files.delete(symlinkedFilePath); } catch (final IOException e) { logger.error(String.format("Error deleting : %s", symlinkedFilePath), e); throw new ExecutorManagerException(e); } }
Deletes all the symlinks and targeted files recursively. @param symlinkedFilePath Path to file, could be a symlink @throws ExecutorManagerException
deleteSymlinkedFile
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private void createLogger() { final Logger rootLogger = Logger.getRootLogger(); for (Object o: Collections.list(rootLogger.getAllAppenders())) { if (o instanceof FileAppender) { final FileAppender appender = (FileAppender) o; logFile = new File(appender.getFile()); break; } } try { if (this.logFile == null) { logFile = new File(DEFAULT_LOG_FILE_NAME); this.fileAppender = new FileAppender(DEFAULT_LAYOUT, logFile.getAbsolutePath(), true); rootLogger.addAppender(this.fileAppender); logger.info("Attached new File appender for flow"); } if (this.azkabanProps.getBoolean(Constants.ConfigurationKeys.AZKABAN_LOGGING_KAFKA_ENABLED, false)) { // Keep the names consistent as what we did in uploadLogFile() this.kafkaLog4jAppender = KafkaLog4jUtils.getAzkabanFlowKafkaLog4jAppender(this.azkabanProps, DEFAULT_LAYOUT, String.valueOf(this.execId), ""); if (this.kafkaLog4jAppender != null) { rootLogger.addAppender(this.kafkaLog4jAppender); rootLogger.setAdditivity(false); logger.info("Attached new Kafka appender for flow"); } } } catch (final Exception e) { logger.error("Could not open log file: " + logFile.getAbsolutePath(), e); } }
setup logger and execution dir for the flowId
createLogger
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private static void removeAppender(final Appender appender) { final Logger rootLogger = Logger.getRootLogger(); if (appender != null) { try { rootLogger.removeAppender(appender); appender.close(); } catch (Exception e) { logger.error("Failed to remove appender " + appender.getName(), e); } } }
setup logger and execution dir for the flowId
removeAppender
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
private void closeLogger() { // If fileAppender is created internally, we should remove it. Otherwise, its lifecycle will be // managed by log4j framework. removeAppender(this.fileAppender); removeAppender(this.kafkaLog4jAppender); try { this.executionLogsLoader.uploadLogFile(this.execId, "", 0, this.logFile); } catch (final ExecutorManagerException e) { logger.error("Failed to close logger", e); } }
setup logger and execution dir for the flowId
closeLogger
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
@VisibleForTesting void shutdown() { logger.info("Shutting down the container"); if (this.flowRunner != null) { while (!this.flowFuture.isDone()) { // This should not happen immediately as submitFlowRunner is a blocking call. try { Thread.sleep(100); } catch (final InterruptedException e) { logger.error(String.format("The sleep while waiting for execution : %d to finish was " + "interrupted", this.execId)); } } } else { logger.warn("Flowrunner is null, the flow execution never started!"); } boolean result = false; try { this.executorService.shutdown(); // Wait upto 10 seconds for clean shutdown, otherwise, System.exit() will wipe out // everything logger.info("Awaiting Shutdown of executing flow"); result = this.executorService.awaitTermination( SHUTDOWN_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS); } catch (final InterruptedException e) { logger.error(e.getMessage()); } if (!result) { logger.warn("ExecutorService did not shut down cleanly yet. Ignoring it."); } try { this.jettyServer.stop(); this.jettyServer.destroy(); } catch (final Exception e) { // Eat up the exception logger.error("Error shutting down JettyServer while winding down the FlowContainer", e); } logger.info("Sayonara!"); closeLogger(); System.exit(0); }
Shutdown the Container. This shuts down the ExecutorService which runs the flow execution as well as JettyServer.
shutdown
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/container/FlowContainer.java
Apache-2.0
void addNode(final Node node) { assert (node.getDag() == this); this.nodes.add(node); }
Adds a node to the current dag. <p>It's important NOT to expose this method as public. The design relies on this to ensure correctness. The DAG's structure shouldn't change after it is created. <p>The DagBuilder will check that node names are unique within a dag. No check is necessary here since the method package private and where it is called is carefully controlled within a relatively small package. </p> @param node a node to add
addNode
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
void start() { assert (this.status == Status.READY); changeStatus(Status.RUNNING); for (final Node node : this.nodes) { node.runIfAllowed(); } // It's possible that all nodes are disabled. In this rare case the dag should be // marked success. Otherwise it will be stuck in the the running state. updateDagStatus(); }
Adds a node to the current dag. <p>It's important NOT to expose this method as public. The design relies on this to ensure correctness. The DAG's structure shouldn't change after it is created. <p>The DagBuilder will check that node names are unique within a dag. No check is necessary here since the method package private and where it is called is carefully controlled within a relatively small package. </p> @param node a node to add
start
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
void kill() { if (this.status.isTerminal() || this.status == Status.KILLING) { // It is possible that a kill is issued after a dag has finished or multiple kill requests // are received. Without this check, this method will make duplicate calls to the // DagProcessor. return; } changeStatus(Status.KILLING); for (final Node node : this.nodes) { node.kill(); } updateDagStatus(); }
Adds a node to the current dag. <p>It's important NOT to expose this method as public. The design relies on this to ensure correctness. The DAG's structure shouldn't change after it is created. <p>The DagBuilder will check that node names are unique within a dag. No check is necessary here since the method package private and where it is called is carefully controlled within a relatively small package. </p> @param node a node to add
kill
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
void updateDagStatus() { // A dag may have nodes that are disabled. It's safer to scan all the nodes. // Assume the overhead is minimal. If it is not the case, we can optimize later. boolean failed = false; for (final Node node : this.nodes) { final Status nodeStatus = node.getStatus(); if (!nodeStatus.isTerminal()) { return; } if (nodeStatus == Status.FAILURE) { failed = true; } } // Update the dag status only after all nodes have reached terminal states. updateDagStatusInternal(failed); }
Update the final dag status when all nodes are done. <p>If any node has not reached its terminal state, this method will simply return.
updateDagStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
private void updateDagStatusInternal(final boolean failed) { if (this.status == Status.KILLING) { /* It's possible that some nodes have failed when the dag is killed. Since killing a dag signals an intent from an operator, it is more important to make the dag status reflect the result of that explict intent. e.g. if the killing is a result of handing a job failure, users more likely want to know that someone has taken an action rather than that a job has failed. Operators can still see the individual job status. */ changeStatus(Status.KILLED); } else if (failed) { changeStatus(Status.FAILURE); } else { changeStatus(Status.SUCCESS); } }
Update the final dag status. @param failed true if any of the jobs has failed
updateDagStatusInternal
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
private void changeStatus(final Status status) { this.status = status; this.dagProcessor.changeStatus(this, status); }
Update the final dag status. @param failed true if any of the jobs has failed
changeStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
@Override public String toString() { return String.format("dag (%s), status (%s)", this.name, this.status); }
Update the final dag status. @param failed true if any of the jobs has failed
toString
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
String getName() { return this.name; }
Update the final dag status. @param failed true if any of the jobs has failed
getName
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
Status getStatus() { return this.status; }
Update the final dag status. @param failed true if any of the jobs has failed
getStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
@VisibleForTesting void setStatus(final Status status) { this.status = status; }
Update the final dag status. @param failed true if any of the jobs has failed
setStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
@VisibleForTesting public List<Node> getNodes() { return this.nodes; }
Update the final dag status. @param failed true if any of the jobs has failed
getNodes
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Dag.java
Apache-2.0
public Node createNode(final String name, final NodeProcessor nodeProcessor) { checkIsBuilt(); if (this.nameToNodeMap.get(name) != null) { throw new DagException(String.format("Node names in %s need to be unique. The name " + "(%s) already exists.", this, name)); } final Node node = new Node(name, nodeProcessor, this.dag); this.nameToNodeMap.put(name, node); return node; }
Creates a new node and adds it to the DagBuilder. @param name name of the node @param nodeProcessor node processor associated with this node @return a new node @throws DagException if the name is not unique in the DAG.
createNode
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
private void checkIsBuilt() { if (this.isBuilt) { final String msg = String .format("The DAG (%s) is built already. Can't create new nodes.", this); throw new DagException(msg); } }
Throws an exception if the {@link DagBuilder#build()} method has been called.
checkIsBuilt
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
public void addParentNode(final String childNodeName, final String parentNodeName) { checkIsBuilt(); final Node child = this.nameToNodeMap.get(childNodeName); if (child == null) { throw new DagException(String.format("Unknown child node (%s). Did you create the node?", childNodeName)); } final Node parent = this.nameToNodeMap.get(parentNodeName); if (parent == null) { throw new DagException( String.format("Unknown parent node (%s). Did you create the node?", parentNodeName)); } child.addParent(parent); }
Add a parent node to a child node. All the names should have been registered with this builder with the {@link DagBuilder#createNode(String, NodeProcessor)} call. @param childNodeName name of the child node @param parentNodeName name of the parent node
addParentNode
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
public Dag build() { checkIsBuilt(); checkCircularDependencies(); this.isBuilt = true; return this.dag; }
Builds the dag. <p>Once this method is called, subsequent calls via NodeBuilder to modify the nodes's relationships in the dag will have no effect on the returned Dag object. </p> @return the Dag reflecting the current state of the DagBuilder
build
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
private void checkCircularDependencies() { class CircularDependencyChecker { // The nodes that need to be visited private final Set<Node> toVisit = new HashSet<>(DagBuilder.this.nameToNodeMap.values()); // The nodes that have finished traversing all their parent nodes private final Set<Node> finished = new HashSet<>(); // The nodes that are waiting for their parent nodes to finish visit. private final Set<Node> ongoing = new HashSet<>(); // One sample of nodes that form a circular dependency private final List<Node> sampleCircularNodes = new ArrayList<>(); /** * Checks if the builder contains nodes that form a circular dependency ring. * * @throws DagException if true */ private void check() { while (!this.toVisit.isEmpty()) { final Node node = removeOneNodeFromToVisitSet(); if (checkNode(node)) { final String msg = String.format("Circular dependency detected. Sample: %s", this.sampleCircularNodes); throw new DagException(msg); } } } /** * Removes one node from the toVisit set and returns that node. * * @return a node */ private Node removeOneNodeFromToVisitSet() { final Iterator<Node> iterator = this.toVisit.iterator(); final Node node = iterator.next(); iterator.remove(); return node; } /** * Checks if the node is part of a group of nodes that form a circular dependency ring. * * <p>If true, the node will be added to the sampleCircularNodes list</p> * * @param node node to check * @return true if it is */ private boolean checkNode(final Node node) { if (this.finished.contains(node)) { return false; } if (this.ongoing.contains(node)) { this.sampleCircularNodes.add(node); return true; } this.toVisit.remove(node); this.ongoing.add(node); for (final Node parent : node.getParents()) { if (checkNode(parent)) { this.sampleCircularNodes.add(node); return true; } } this.ongoing.remove(node); this.finished.add(node); return false; } } final CircularDependencyChecker checker = new CircularDependencyChecker(); checker.check(); }
Checks if the builder contains nodes that form a circular dependency ring. <p>The depth first algorithm is described in this article <a href="https://en.wikipedia.org/wiki/Topological_sorting">https://en.wikipedia.org/wiki/Topological_sorting</a> </p> @throws DagException if true
checkCircularDependencies
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
private void check() { while (!this.toVisit.isEmpty()) { final Node node = removeOneNodeFromToVisitSet(); if (checkNode(node)) { final String msg = String.format("Circular dependency detected. Sample: %s", this.sampleCircularNodes); throw new DagException(msg); } } }
Checks if the builder contains nodes that form a circular dependency ring. @throws DagException if true
check
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
private Node removeOneNodeFromToVisitSet() { final Iterator<Node> iterator = this.toVisit.iterator(); final Node node = iterator.next(); iterator.remove(); return node; }
Removes one node from the toVisit set and returns that node. @return a node
removeOneNodeFromToVisitSet
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
private boolean checkNode(final Node node) { if (this.finished.contains(node)) { return false; } if (this.ongoing.contains(node)) { this.sampleCircularNodes.add(node); return true; } this.toVisit.remove(node); this.ongoing.add(node); for (final Node parent : node.getParents()) { if (checkNode(parent)) { this.sampleCircularNodes.add(node); return true; } } this.ongoing.remove(node); this.finished.add(node); return false; }
Checks if the node is part of a group of nodes that form a circular dependency ring. <p>If true, the node will be added to the sampleCircularNodes list</p> @param node node to check @return true if it is
checkNode
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
@Override public String toString() { return String.format("DagBuilder (%s)", this.dag.getName()); }
Checks if the node is part of a group of nodes that form a circular dependency ring. <p>If true, the node will be added to the sampleCircularNodes list</p> @param node node to check @return true if it is
toString
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagBuilder.java
Apache-2.0
public void shutdownAndAwaitTermination() throws InterruptedException { logger.info("DagService is shutting down."); this.executorServiceUtils.gracefulShutdown(this.executorService, SHUTDOWN_WAIT_TIMEOUT); }
Shuts down the service and waits for the tasks to finish.
shutdownAndAwaitTermination
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagService.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagService.java
Apache-2.0
@VisibleForTesting ExecutorService getExecutorService() { return this.executorService; }
Shuts down the service and waits for the tasks to finish.
getExecutorService
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/DagService.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/DagService.java
Apache-2.0
Dag getDag() { return this.dag; }
Node in a DAG: Directed acyclic graph.
getDag
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
void addParent(final Node node) { this.parents.add(node); node.addChild(this); }
Adds the node as the current node's parent i.e. the current node depends on the given node. <p>It's important NOT to expose this method as public. The design relies on this to ensure correctness. The DAG's structure shouldn't change after it is created.
addParent
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
boolean hasParent() { return !this.parents.isEmpty(); }
Adds the node as the current node's parent i.e. the current node depends on the given node. <p>It's important NOT to expose this method as public. The design relies on this to ensure correctness. The DAG's structure shouldn't change after it is created.
hasParent
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
private boolean isReady() { if (this.status != Status.READY) { // e.g. if the node is disabled, it is not ready to run. return false; } for (final Node parent : this.parents) { if (!parent.status.isSuccessEffectively()) { return false; } } return true; }
Checks if the node is ready to run. @return true if the node is ready to run
isReady
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
void markSuccess() { // It's possible that the dag is killed before this method is called. assertRunningOrKilling(); changeStatus(Status.SUCCESS); for (final Node child : this.children) { child.runIfAllowed(); } this.dag.updateDagStatus(); }
Transitions the node to the success state.
markSuccess
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
void runIfAllowed() { if (isReady()) { changeStatus(Status.RUNNING); } }
Checks if all the dependencies are met and run if they are.
runIfAllowed
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
void markFailed() { // It's possible that the dag is killed before this method is called. assertRunningOrKilling(); changeStatus(Status.FAILURE); for (final Node child : this.children) { child.cancel(); } //todo: HappyRay support failure options "Finish Current Running" and "Cancel All" this.dag.updateDagStatus(); }
Transitions the node to the failure state.
markFailed
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
private void cancel() { // The node shouldn't have started. assert (this.status.isPreRunState()); if (this.status != Status.DISABLED) { changeStatus(Status.CANCELED); } for (final Node node : this.children) { node.cancel(); } }
Transitions the node to the failure state.
cancel
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
private void assertRunningOrKilling() { assert (this.status == Status.RUNNING || this.status == Status.KILLING); }
Asserts that the state is running or killing.
assertRunningOrKilling
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
private void changeStatus(final Status status) { this.status = status; this.nodeProcessor.changeStatus(this, this.status); }
Asserts that the state is running or killing.
changeStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
void kill() { assert (this.dag.getStatus() == Status.KILLING); if (this.status == Status.READY || this.status == Status.BLOCKED) { // If the node is disabled, keep the status as disabled. changeStatus(Status.CANCELED); } else if (this.status == Status.RUNNING) { changeStatus(Status.KILLING); } // If the node has finished, leave the status intact. }
Kills a node. <p>A node is not designed to be killed individually. This method expects {@link Dag#kill()} method to kill all nodes. Thus this method itself doesn't need to propagate the kill signal to the node's children nodes.
kill
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
void markKilled() { assert (this.status == Status.KILLING); changeStatus(Status.KILLED); this.dag.updateDagStatus(); }
Transition the node from the killing state to the killed state.
markKilled
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
@Override public String toString() { return String.format("Node (%s) status (%s) in %s", this.name, this.status, this.dag); }
Transition the node from the killing state to the killed state.
toString
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
Status getStatus() { return this.status; }
Transition the node from the killing state to the killed state.
getStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
@VisibleForTesting void setStatus(final Status status) { this.status = status; }
Transition the node from the killing state to the killed state.
setStatus
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
String getName() { return this.name; }
Transition the node from the killing state to the killed state.
getName
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
@VisibleForTesting List<Node> getChildren() { return this.children; }
Transition the node from the killing state to the killed state.
getChildren
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
@VisibleForTesting List<Node> getParents() { return this.parents; }
Transition the node from the killing state to the killed state.
getParents
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/dag/Node.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/dag/Node.java
Apache-2.0
static long calculateDirSizeAndSave(final File dir) throws IOException { final Path path = Paths.get(dir.getPath(), AbstractFlowPreparer.PROJECT_DIR_SIZE_FILE_NAME); if (!Files.exists(path)) { final long sizeInByte = FileUtils.sizeOfDirectory(dir); FileIOUtils.dumpNumberToFile(path, sizeInByte); return sizeInByte; } else { return FileIOUtils.readNumberFromFile(path); } }
Calculate the directory size and save it to a file. @param dir the directory whose size needs to be saved. @return the size of the dir.
calculateDirSizeAndSave
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AbstractFlowPreparer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AbstractFlowPreparer.java
Apache-2.0
@VisibleForTesting public void downloadAndUnzipProject(final ProjectDirectoryMetadata proj, final int execId, final File dest) throws IOException { final long start = System.currentTimeMillis(); final ProjectFileHandler projectFileHandler = requireNonNull(this.projectStorageManager .getProjectFile(proj.getProjectId(), proj.getVersion())); LOGGER.info("Downloading zip file for project {} when preparing execution [execid {}] " + "completed in {} second(s)", proj, execId, (System.currentTimeMillis() - start) / 1000); try { checkState("zip".equalsIgnoreCase(projectFileHandler.getFileType())); final File zipFile = requireNonNull(projectFileHandler.getLocalFile()); final ZipFile zip = new ZipFile(zipFile); Utils.unzip(zip, dest); // Download all startup dependencies. If this is a fat archive, it will be an empty set (so we won't download // anything). Note that we are getting our list of startup dependencies from the DB, NOT from the // startup-dependencies.json file contained in the archive. Both should be IDENTICAL, however we chose to get the // list from the DB because this will be consistent with how containerized executions determine the startup // dependency list. downloadAllDependencies(proj, execId, dest, projectFileHandler.getStartupDependencies()); proj.setDirSizeInByte(calculateDirSizeAndSave(dest)); } finally { projectFileHandler.deleteLocalFile(); } }
Calculate the directory size and save it to a file. @param dir the directory whose size needs to be saved. @return the size of the dir.
downloadAndUnzipProject
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AbstractFlowPreparer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AbstractFlowPreparer.java
Apache-2.0
private void downloadAllDependencies(final ProjectDirectoryMetadata proj, final int execId, final File folder, final Set<Dependency> dependencies) { // Download all of the dependencies from storage LOGGER.info("Downloading {} JAR dependencies... Project: {}, ExecId: {}", dependencies.size(), proj, execId); final Set<DependencyFile> depFiles = dependencies .stream() .map(d -> getDependencyFile(folder, d)) .collect(Collectors.toSet()); try { final long start = System.currentTimeMillis(); this.dependencyTransferManager.downloadAllDependencies(depFiles, proj.getProjectName()); LOGGER.info("Downloading {} JAR dependencies for project {} when preparing " + "execution [execid {}] completed in {} second(s)", dependencies.size(), proj, execId, (System.currentTimeMillis() - start) / 1000); } catch (final DependencyTransferException e) { LOGGER.error("Unable to download one or more dependencies when preparing execId {} for " + "project {}.", execId, proj); throw e; } }
Download necessary JAR dependencies from storage @param proj project to download @param execId execution id number @param folder root of unzipped project @param dependencies the set of dependencies to download
downloadAllDependencies
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AbstractFlowPreparer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AbstractFlowPreparer.java
Apache-2.0
@Override protected void configure() { install(new ExecJettyServerModule()); install(new ClusterModule()); }
This Guice module is currently a one place container for all bindings in the current module. This is intended to help during the migration process to Guice. Once this class starts growing we can move towards more modular structuring of Guice components.
configure
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecServerModule.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecServerModule.java
Apache-2.0
public static AzkabanExecutorServer getApp() { return app; }
Returns the currently executing executor server, if one exists.
getApp
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
private void configureMetricReports() throws MetricException { final Props props = getAzkabanProps(); if (props != null && props.getBoolean("executor.metric.reports", false)) { logger.info("Starting to configure Metric Reports"); final MetricReportManager metricManager = MetricReportManager.getInstance(); final IMetricEmitter metricEmitter = new InMemoryMetricEmitter(props); metricManager.addMetricEmitter(metricEmitter); logger.info("Adding number of failed flow metric"); metricManager.addMetric(new NumFailedFlowMetric(metricManager, props .getInt(METRIC_INTERVAL + NumFailedFlowMetric.NUM_FAILED_FLOW_METRIC_NAME, props.getInt(METRIC_INTERVAL + "default")))); logger.info("Adding number of failed jobs metric"); metricManager.addMetric(new NumFailedJobMetric(metricManager, props .getInt(METRIC_INTERVAL + NumFailedJobMetric.NUM_FAILED_JOB_METRIC_NAME, props.getInt(METRIC_INTERVAL + "default")))); logger.info("Adding number of running Jobs metric"); metricManager.addMetric(new NumRunningJobMetric(metricManager, props .getInt(METRIC_INTERVAL + NumRunningJobMetric.NUM_RUNNING_JOB_METRIC_NAME, props.getInt(METRIC_INTERVAL + "default")))); logger.info("Adding number of running flows metric"); metricManager.addMetric(new NumRunningFlowMetric(this.runnerManager, metricManager, props.getInt(METRIC_INTERVAL + NumRunningFlowMetric.NUM_RUNNING_FLOW_METRIC_NAME, props.getInt(METRIC_INTERVAL + "default")))); logger.info("Adding number of queued flows metric"); metricManager.addMetric(new NumQueuedFlowMetric(this.runnerManager, metricManager, props.getInt(METRIC_INTERVAL + NumQueuedFlowMetric.NUM_QUEUED_FLOW_METRIC_NAME, props.getInt(METRIC_INTERVAL + "default")))); logger.info("Completed configuring Metric Reports"); } }
Configure Metric Reporting as per azkaban.properties settings
configureMetricReports
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
private void loadCustomJMXAttributeProcessor(final Props props) { final String jmxAttributeEmitter = props.get(CUSTOM_JMX_ATTRIBUTE_PROCESSOR_PROPERTY); if (jmxAttributeEmitter != null) { try { logger.info("jmxAttributeEmitter: " + jmxAttributeEmitter); final Constructor<Props>[] constructors = (Constructor<Props>[]) Class.forName(jmxAttributeEmitter).getConstructors(); constructors[0].newInstance(props.toProperties()); } catch (final Exception e) { logger.error("Encountered error while loading and instantiating " + jmxAttributeEmitter, e); throw new IllegalStateException( "Encountered error while loading and instantiating " + jmxAttributeEmitter, e); } } else { logger.info("No value for property: " + CUSTOM_JMX_ATTRIBUTE_PROCESSOR_PROPERTY + " was found"); } }
Load a custom class, which is provided by a configuration CUSTOM_JMX_ATTRIBUTE_PROCESSOR_PROPERTY. <p> This method will try to instantiate an instance of this custom class and with given properties as the argument in the constructor. <p> Basically the custom class must have a constructor that takes an argument with type Properties.
loadCustomJMXAttributeProcessor
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
public ExecutorLoader getExecutorLoader() { return this.executionLoader; }
Load a custom class, which is provided by a configuration CUSTOM_JMX_ATTRIBUTE_PROCESSOR_PROPERTY. <p> This method will try to instantiate an instance of this custom class and with given properties as the argument in the constructor. <p> Basically the custom class must have a constructor that takes an argument with type Properties.
getExecutorLoader
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
public int getPort() { final Connector[] connectors = this.server.getConnectors(); checkState(connectors.length >= 1, "Server must have at least 1 connector"); // The first connector is created upon initializing the server. That's the one that has the port. return connectors[0].getLocalPort(); }
Get the current server port @return the port at which the executor server is running
getPort
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
public String getExecutorHostPort() { return getHost() + ":" + getPort(); }
Returns host:port combination for currently running executor
getExecutorHostPort
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
private void sleep(final Duration duration) { try { Thread.sleep(duration.toMillis()); } catch (final InterruptedException e) { logger.error(e); } }
Returns host:port combination for currently running executor
sleep
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
public void shutdown() { logger.warn("Shutting down AzkabanExecutorServer..."); new Thread(() -> { // Hack: Sleep for a little time to allow API calls to complete sleep(Duration.ofSeconds(2)); shutdownInternal(); }, "shutdown").start(); }
Shutdown the server. - performs a safe shutdown. Waits for completion of current tasks - spawns a shutdown thread and returns immediately.
shutdown
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
private void shutdownInternal() { getFlowRampManager().shutdown(); getFlowRunnerManager().shutdown(); // Sleep for an hour to wait for web server updater thread // {@link azkaban.executor.RunningExecutionsUpdaterThread#updateExecutions} to finalize updating sleep(Duration.ofHours(1)); // trigger shutdown hook System.exit(0); }
(internal API) Note: This should be run in a separate thread. <p> Shutdown the server. (blocking call) - waits for jobs to finish - doesn't accept any new jobs
shutdownInternal
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/AzkabanExecutorServer.java
Apache-2.0
ProjectCacheHitRatio getProjectCacheHitRatio() { return this.projectCacheHitRatio; }
This class ExecMetrics is in charge of collecting metrics from executors.
getProjectCacheHitRatio
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
Apache-2.0
public void addFlowRunnerManagerMetrics(final FlowRunnerManager flowRunnerManager) { this.metricsManager .addGauge(NUM_RUNNING_FLOWS_NAME, flowRunnerManager::getNumRunningFlows); this.metricsManager .addGauge(NUM_QUEUED_FLOWS_NAME, flowRunnerManager::getNumQueuedFlows); }
This class ExecMetrics is in charge of collecting metrics from executors.
addFlowRunnerManagerMetrics
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
Apache-2.0
public Timer.Context getFlowSetupTimerContext() { return this.flowSetupTimer.time(); }
@return the {@link Timer.Context} for the timer.
getFlowSetupTimerContext
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
Apache-2.0
public Timer.Context getFlowStartupDelayTimerContext() { return this.flowStartupDelayTimer.time(); }
@return the {@link Timer.Context} for the flow-startup-delay timer.
getFlowStartupDelayTimerContext
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecMetrics.java
Apache-2.0
@Deprecated @Override public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { handleRequest(req, resp); }
@deprecated GET available for seamless upgrade. azkaban-web now uses POST.
doGet
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { handleRequest(req, resp); }
@deprecated GET available for seamless upgrade. azkaban-web now uses POST.
doPost
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
public void handleRequest(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { final HashMap<String, Object> respMap = new HashMap<>(); try { if (!hasParam(req, ConnectorParams.ACTION_PARAM)) { logger.error("Parameter action not set"); respMap.put("error", "Parameter action not set"); } else { final String action = getParam(req, ConnectorParams.ACTION_PARAM); if (action.equals(ConnectorParams.UPDATE_ACTION)) { handleAjaxUpdateRequest(req, respMap); } else if (action.equals(ConnectorParams.PING_ACTION)) { respMap.put(ConnectorParams.STATUS_PARAM, ConnectorParams.RESPONSE_ALIVE); } else if (action.equals(ConnectorParams.RELOAD_JOBTYPE_PLUGINS_ACTION)) { logger.info("Reloading Jobtype plugins"); handleReloadJobTypePlugins(respMap); } else if (action.equals(ConnectorParams.ACTIVATE)) { logger.warn("Setting ACTIVE flag to true"); setActive(true, respMap); } else if (action.equals(ConnectorParams.GET_STATUS)) { logger.debug("Get Executor Status: "); getStatus(respMap); } else if (action.equals(ConnectorParams.DEACTIVATE)) { logger.warn("Setting ACTIVE flag to false"); setActive(false, respMap); } else if (action.equals(ConnectorParams.SHUTDOWN)) { shutdown(respMap); } else if (action.equals(ConnectorParams.MODIFY_PROPERTY_ACTION)) { String propName = getParam(req, ConnectorParams.PROPERTY_NAME_PARAM); String propValue = getParam(req, ConnectorParams.PROPERTY_VALUE_PARAM); handleModifyProperty(propName, propValue, respMap); } else { final int execid = Integer.parseInt(getParam(req, ConnectorParams.EXECID_PARAM)); final String user = getParam(req, ConnectorParams.USER_PARAM, null); logger.info("User " + user + " has called action " + action + " on " + execid); if (action.equals(ConnectorParams.METADATA_ACTION)) { handleFetchMetaDataEvent(execid, req, resp, respMap); } else if (action.equals(ConnectorParams.LOG_ACTION)) { handleFetchLogEvent(execid, req, resp, respMap); } else if (action.equals(ConnectorParams.ATTACHMENTS_ACTION)) { handleFetchAttachmentsEvent(execid, req, resp, respMap); } else if (action.equals(ConnectorParams.EXECUTE_ACTION)) { handleAjaxExecute(req, respMap, execid); } else if (action.equals(ConnectorParams.STATUS_ACTION)) { handleAjaxFlowStatus(respMap, execid); } else if (action.equals(ConnectorParams.CANCEL_ACTION)) { logger.info("Cancel called."); handleAjaxCancel(respMap, execid, user); } else if (action.equals(ConnectorParams.PAUSE_ACTION)) { logger.info("Paused called."); handleAjaxPause(respMap, execid, user); } else if (action.equals(ConnectorParams.RESUME_ACTION)) { logger.info("Resume called."); handleAjaxResume(respMap, execid, user); } else if (action.equals(ConnectorParams.MODIFY_EXECUTION_ACTION)) { logger.info("Modify Execution Action"); handleModifyExecutionRequest(respMap, execid, user, req); } else { logger.error("action: '" + action + "' not supported."); respMap.put("error", "action: '" + action + "' not supported."); } } } } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put(ConnectorParams.RESPONSE_ERROR, e.getMessage()); } writeJSON(resp, respMap); resp.flushBuffer(); }
@deprecated GET available for seamless upgrade. azkaban-web now uses POST.
handleRequest
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
private void handleModifyProperty(@Nullable final String propName, @Nullable final String propValue, final HashMap<String, Object> respMap) throws ServletException { if (propName == null || propValue == null) { String errMsg = String.format("Both %s and %s need to be provided for action %s. " + "(%s, %s) = (%s, %s)", ConnectorParams.PROPERTY_NAME_PARAM, ConnectorParams.PROPERTY_VALUE_PARAM, ConnectorParams.MODIFY_PROPERTY_ACTION, ConnectorParams.PROPERTY_NAME_PARAM, ConnectorParams.PROPERTY_VALUE_PARAM, propName, propValue); logger.error(errMsg); respMap.put(ConnectorParams.RESPONSE_ERROR, errMsg); return; } if (propName.equals(ConnectorParams.POLLING_INTERVAL_MILLIS_PROPERTY_NAME)) { modifyPollingInterval(propValue, respMap); } else { String errMsg = String.format("Modification of %s property is not supported.", propName); logger.error(errMsg); respMap.put(ConnectorParams.RESPONSE_ERROR, errMsg); } }
@deprecated GET available for seamless upgrade. azkaban-web now uses POST.
handleModifyProperty
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
private void modifyPollingInterval(@Nonnull final String newPollingIntervalMillis, final HashMap<String, Object> respMap) { int pollingIntervalMillis = 0; boolean isValidValue = false; try { pollingIntervalMillis = Integer.parseUnsignedInt(newPollingIntervalMillis); isValidValue = (pollingIntervalMillis > 0); } catch (NumberFormatException ex) { // isValidValue will continue to be false, which we will used for error handling. // No need to do anything additional in the catch block. } if (!isValidValue) { String errMsg = String.format("%s doesn't look like a positive integer." + " (%s, %s) = (%s, %s)", newPollingIntervalMillis, ConnectorParams.PROPERTY_NAME_PARAM, ConnectorParams.PROPERTY_VALUE_PARAM, ConnectorParams.POLLING_INTERVAL_MILLIS_PROPERTY_NAME, newPollingIntervalMillis); logger.error(errMsg); respMap.put(ConnectorParams.RESPONSE_ERROR, errMsg); return; } if (flowRunnerManager.changePollingInterval(pollingIntervalMillis)) { respMap.put(ConnectorParams.STATUS_ACTION, String.format("Changed polling interval to %s ms", newPollingIntervalMillis)); } else { respMap.put(ConnectorParams.RESPONSE_ERROR, "Failed to change polling interval. Please check" + " the logs for error messages from underlying functions. Please retry if existing " + "schedule got canceled and new one didn't start."); } }
Modifies the time interval at which the executor is polling the queue for unassigned jobs, and assigning a job(s) to itself. @param newPollingIntervalMillis The desired polling interval. It needs to be a positive integer (milliseconds) in String format. @param respMap The response map.
modifyPollingInterval
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
private void handleModifyExecutionRequest(final Map<String, Object> respMap, final int execId, final String user, final HttpServletRequest req) throws ServletException { if (!hasParam(req, ConnectorParams.MODIFY_EXECUTION_ACTION_TYPE)) { respMap.put(ConnectorParams.RESPONSE_ERROR, "Modification type not set."); } final String modificationType = getParam(req, ConnectorParams.MODIFY_EXECUTION_ACTION_TYPE); try { if (ConnectorParams.MODIFY_RETRY_FAILURES.equals(modificationType)) { this.flowRunnerManager.retryFailures(execId, user); } } catch (final ExecutorManagerException e) { logger.error(e.getMessage(), e); respMap.put("error", e.getMessage()); } }
Modifies the time interval at which the executor is polling the queue for unassigned jobs, and assigning a job(s) to itself. @param newPollingIntervalMillis The desired polling interval. It needs to be a positive integer (milliseconds) in String format. @param respMap The response map.
handleModifyExecutionRequest
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
private void handleFetchLogEvent(final int execId, final HttpServletRequest req, final HttpServletResponse resp, final Map<String, Object> respMap) throws ServletException { final String type = getParam(req, "type"); final int startByte = getIntParam(req, "offset"); final int length = getIntParam(req, "length"); resp.setContentType("text/plain"); resp.setCharacterEncoding("utf-8"); if (type.equals("flow")) { final LogData result; try { result = this.flowRunnerManager.readFlowLogs(execId, startByte, length); respMap.putAll(result.toObject()); } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put(ConnectorParams.RESPONSE_ERROR, e.getMessage()); } } else { final int attempt = getIntParam(req, "attempt", 0); final String jobId = getParam(req, "jobId"); try { final LogData result = this.flowRunnerManager.readJobLogs(execId, jobId, attempt, startByte, length); respMap.putAll(result.toObject()); } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put("error", e.getMessage()); } } }
Modifies the time interval at which the executor is polling the queue for unassigned jobs, and assigning a job(s) to itself. @param newPollingIntervalMillis The desired polling interval. It needs to be a positive integer (milliseconds) in String format. @param respMap The response map.
handleFetchLogEvent
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0
private void handleFetchAttachmentsEvent(final int execId, final HttpServletRequest req, final HttpServletResponse resp, final Map<String, Object> respMap) throws ServletException { final String jobId = getParam(req, "jobId"); final int attempt = getIntParam(req, "attempt", 0); try { final List<Object> result = this.flowRunnerManager.readJobAttachments(execId, jobId, attempt); respMap.put("attachments", result); } catch (final Exception e) { logger.error(e.getMessage(), e); respMap.put("error", e.getMessage()); } }
Modifies the time interval at which the executor is polling the queue for unassigned jobs, and assigning a job(s) to itself. @param newPollingIntervalMillis The desired polling interval. It needs to be a positive integer (milliseconds) in String format. @param respMap The response map.
handleFetchAttachmentsEvent
java
azkaban/azkaban
azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
https://github.com/azkaban/azkaban/blob/master/azkaban-exec-server/src/main/java/azkaban/execapp/ExecutorServlet.java
Apache-2.0