use of com.linkedin.drelephant.schedulers.Scheduler in project dr-elephant by linkedin.
the class InfoExtractor method getSchedulerInstance.
/**
* Find the scheduler which scheduled the job.
*
* @param appId The application id
* @param properties The application properties
* @return the corresponding Scheduler which scheduled the job.
*/
public static Scheduler getSchedulerInstance(String appId, Properties properties) {
if (properties != null) {
for (SchedulerConfigurationData data : _configuredSchedulers) {
try {
Class<?> schedulerClass = Class.forName(data.getClassName());
Object instance = schedulerClass.getConstructor(String.class, Properties.class, SchedulerConfigurationData.class).newInstance(appId, properties, data);
if (!(instance instanceof Scheduler)) {
throw new IllegalArgumentException("Class " + schedulerClass.getName() + " is not an implementation of " + Scheduler.class.getName());
}
Scheduler scheduler = (Scheduler) instance;
if (!scheduler.isEmpty()) {
return scheduler;
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not find class " + data.getClassName(), e);
} catch (InstantiationException e) {
throw new RuntimeException("Could not instantiate class " + data.getClassName(), e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not access constructor for class" + data.getClassName(), e);
} catch (RuntimeException e) {
throw new RuntimeException(data.getClassName() + " is not a valid Scheduler class.", e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Could not invoke class " + data.getClassName(), e);
} catch (NoSuchMethodException e) {
throw new RuntimeException("Could not find constructor for class " + data.getClassName(), e);
}
}
}
return null;
}
use of com.linkedin.drelephant.schedulers.Scheduler in project dr-elephant by linkedin.
the class InfoExtractorTest method testGetSchedulerInstanceAirflow.
@Test
public void testGetSchedulerInstanceAirflow() {
Properties properties = new Properties();
properties.put(AirflowScheduler.AIRFLOW_DAG_ID, "airflow_dag_id");
properties.put(AirflowScheduler.AIRFLOW_DAG_RUN_EXECUTION_DATE, "airflow_dag_run_execution_date");
properties.put(AirflowScheduler.AIRFLOW_TASK_ID, "airflow_task_id");
properties.put(AirflowScheduler.AIRFLOW_TASK_INSTANCE_EXECUTION_DATE, "airflow_task_instance_execution_date");
Scheduler scheduler = InfoExtractor.getSchedulerInstance("id", properties);
assertEquals(true, scheduler instanceof AirflowScheduler);
assertEquals("airflow_dag_id", scheduler.getFlowDefId());
assertEquals("airflow_dag_id/airflow_dag_run_execution_date", scheduler.getFlowExecId());
assertEquals("airflow_dag_id/airflow_task_id", scheduler.getJobDefId());
assertEquals("airflow_dag_id/airflow_dag_run_execution_date/airflow_task_id/airflow_task_instance_execution_date", scheduler.getJobExecId());
assertEquals("airflow_task_id", scheduler.getJobName());
assertEquals("airflow", scheduler.getSchedulerName());
}
use of com.linkedin.drelephant.schedulers.Scheduler in project dr-elephant by linkedin.
the class InfoExtractorTest method testGetSchedulerInstanceAzkaban.
@Test
public void testGetSchedulerInstanceAzkaban() {
Properties properties = new Properties();
properties.put(AzkabanScheduler.AZKABAN_WORKFLOW_URL, "azkaban_workflow_url");
properties.put(AzkabanScheduler.AZKABAN_JOB_URL, "azkaba_job_url");
properties.put(AzkabanScheduler.AZKABAN_EXECUTION_URL, "azkaban_execution_url");
properties.put(AzkabanScheduler.AZKABAN_ATTEMPT_URL, "azkaba_attempt_url");
properties.put(AzkabanScheduler.AZKABAN_JOB_NAME, "azkaba_job_name");
Scheduler scheduler = InfoExtractor.getSchedulerInstance("id", properties);
assertEquals(true, scheduler instanceof AzkabanScheduler);
assertEquals("azkaban_workflow_url", scheduler.getFlowDefId());
assertEquals("azkaba_job_url", scheduler.getJobDefId());
assertEquals("azkaban_execution_url", scheduler.getFlowExecId());
assertEquals("azkaba_attempt_url", scheduler.getJobExecId());
assertEquals("azkaba_job_name", scheduler.getJobName());
assertEquals("azkaban", scheduler.getSchedulerName());
}
use of com.linkedin.drelephant.schedulers.Scheduler in project dr-elephant by linkedin.
the class InfoExtractorTest method testGetSchedulerInstanceOozie.
@Test
public void testGetSchedulerInstanceOozie() throws Exception {
final String jobInfo = "0004167-160629080632562-oozie-oozi-W";
final String jobParentInfo = "0004166-160629080632562-oozie-oozi-W";
Properties properties = new Properties();
properties.put("oozie.action.id", jobInfo + "@some-action");
properties.put("oozie.job.id", jobInfo);
new Expectations() {
{
workflowJob.getId();
result = jobInfo;
workflowJob.getParentId();
result = jobParentInfo;
oozieClient.getJobInfo(jobInfo);
result = workflowJob;
parentWorkflowJob.getId();
result = jobParentInfo;
parentWorkflowJob.getParentId();
result = null;
oozieClient.getJobInfo(jobParentInfo);
result = parentWorkflowJob;
}
};
Scheduler scheduler = InfoExtractor.getSchedulerInstance("id", properties);
assertEquals(true, scheduler instanceof OozieScheduler);
assertEquals("oozie", scheduler.getSchedulerName());
assertEquals(jobParentInfo, scheduler.getFlowDefId());
assertEquals(jobParentInfo, scheduler.getFlowExecId());
assertEquals(jobInfo, scheduler.getJobDefId());
assertEquals(jobInfo, scheduler.getJobExecId());
assertEquals(jobInfo, scheduler.getJobName());
}
use of com.linkedin.drelephant.schedulers.Scheduler in project dr-elephant by linkedin.
the class InfoExtractorTest method testGetSchedulerInstanceNull.
@Test
public void testGetSchedulerInstanceNull() {
Properties properties = new Properties();
Scheduler scheduler = InfoExtractor.getSchedulerInstance("id", properties);
assertEquals(null, scheduler);
}
Aggregations