Search in sources :

Example 1 with Scheduler

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;
}
Also used : Scheduler(com.linkedin.drelephant.schedulers.Scheduler) Properties(java.util.Properties) InvocationTargetException(java.lang.reflect.InvocationTargetException) SchedulerConfigurationData(com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData)

Example 2 with Scheduler

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());
}
Also used : Scheduler(com.linkedin.drelephant.schedulers.Scheduler) AzkabanScheduler(com.linkedin.drelephant.schedulers.AzkabanScheduler) AirflowScheduler(com.linkedin.drelephant.schedulers.AirflowScheduler) OozieScheduler(com.linkedin.drelephant.schedulers.OozieScheduler) Properties(java.util.Properties) AirflowScheduler(com.linkedin.drelephant.schedulers.AirflowScheduler) Test(org.junit.Test)

Example 3 with Scheduler

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());
}
Also used : AzkabanScheduler(com.linkedin.drelephant.schedulers.AzkabanScheduler) Scheduler(com.linkedin.drelephant.schedulers.Scheduler) AzkabanScheduler(com.linkedin.drelephant.schedulers.AzkabanScheduler) AirflowScheduler(com.linkedin.drelephant.schedulers.AirflowScheduler) OozieScheduler(com.linkedin.drelephant.schedulers.OozieScheduler) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with Scheduler

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());
}
Also used : Expectations(mockit.Expectations) Scheduler(com.linkedin.drelephant.schedulers.Scheduler) AzkabanScheduler(com.linkedin.drelephant.schedulers.AzkabanScheduler) AirflowScheduler(com.linkedin.drelephant.schedulers.AirflowScheduler) OozieScheduler(com.linkedin.drelephant.schedulers.OozieScheduler) OozieScheduler(com.linkedin.drelephant.schedulers.OozieScheduler) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with Scheduler

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);
}
Also used : Scheduler(com.linkedin.drelephant.schedulers.Scheduler) AzkabanScheduler(com.linkedin.drelephant.schedulers.AzkabanScheduler) AirflowScheduler(com.linkedin.drelephant.schedulers.AirflowScheduler) OozieScheduler(com.linkedin.drelephant.schedulers.OozieScheduler) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Scheduler (com.linkedin.drelephant.schedulers.Scheduler)7 Properties (java.util.Properties)7 AirflowScheduler (com.linkedin.drelephant.schedulers.AirflowScheduler)5 AzkabanScheduler (com.linkedin.drelephant.schedulers.AzkabanScheduler)5 OozieScheduler (com.linkedin.drelephant.schedulers.OozieScheduler)5 Test (org.junit.Test)5 SchedulerConfigurationData (com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData)2 ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)1 HadoopApplicationData (com.linkedin.drelephant.analysis.HadoopApplicationData)1 MapReduceApplicationData (com.linkedin.drelephant.mapreduce.data.MapReduceApplicationData)1 SparkApplicationData (com.linkedin.drelephant.spark.data.SparkApplicationData)1 TezApplicationData (com.linkedin.drelephant.tez.data.TezApplicationData)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Expectations (mockit.Expectations)1 AppResult (models.AppResult)1