Search in sources :

Example 1 with SchedulerConfigurationData

use of com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData in project dr-elephant by linkedin.

the class InfoExtractor method getWorkflowClientInstance.

/**
 * Returns the workflow client instance based on the scheduler name and the workflow url
 * @param scheduler The name of the scheduler
 * @param url The url of the workflow
 * @return The Workflow cient based on the workflow url
 */
public static WorkflowClient getWorkflowClientInstance(String scheduler, String url) {
    for (SchedulerConfigurationData data : _configuredSchedulers) {
        if (data.getSchedulerName().equals(scheduler)) {
            try {
                String workflowClass = data.getParamMap().get("exception_class");
                Class<?> schedulerClass = Class.forName(workflowClass);
                Object instance = schedulerClass.getConstructor(String.class).newInstance(url);
                if (!(instance instanceof WorkflowClient)) {
                    throw new IllegalArgumentException("Class " + schedulerClass.getName() + " is not an implementation of " + WorkflowClient.class.getName());
                }
                WorkflowClient workflowClient = (WorkflowClient) instance;
                return workflowClient;
            } 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 : WorkflowClient(com.linkedin.drelephant.clients.WorkflowClient) InvocationTargetException(java.lang.reflect.InvocationTargetException) SchedulerConfigurationData(com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData)

Example 2 with SchedulerConfigurationData

use of com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData 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 3 with SchedulerConfigurationData

use of com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData in project dr-elephant by linkedin.

the class OozieSchedulerTest method testOozieLoadInfoWithOozieClientException.

@Test
public void testOozieLoadInfoWithOozieClientException() throws Exception {
    thrown.expect(RuntimeException.class);
    thrown.expectMessage("Failed fetching Oozie workflow " + jobInfo + " info");
    doThrow(new OozieClientException("500 Internal server error", "BOOM")).when(oozieClient).getJobInfo(anyString());
    SchedulerConfigurationData schedulerConfig = makeConfig("oozie", getDefaultSchedulerParams());
    new OozieScheduler("id", getOozieProperties(), schedulerConfig, oozieClient);
}
Also used : SchedulerConfigurationData(com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData) Test(org.junit.Test)

Example 4 with SchedulerConfigurationData

use of com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData in project dr-elephant by linkedin.

the class OozieSchedulerTest method testUserGivenTemplateArePreferredUrl.

@Test
public void testUserGivenTemplateArePreferredUrl() throws Exception {
    Map<String, String> params = getDefaultSchedulerParams();
    SchedulerConfigurationData schedulerConfig = makeConfig("oozie", params);
    OozieScheduler scheduler = new OozieScheduler("id", getOozieProperties(), schedulerConfig, manualCommittedJobClient);
    assertEquals("http://oozie/search?workflow=" + jobInfo, scheduler.getJobDefUrl());
    assertEquals("http://oozie/workflows/" + jobInfo, scheduler.getJobExecUrl());
    assertEquals("http://oozie/search?workflow=" + parentJobInfo, scheduler.getFlowDefUrl());
    assertEquals("http://oozie/workflows/" + parentJobInfo, scheduler.getFlowExecUrl());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) SchedulerConfigurationData(com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData) Test(org.junit.Test)

Example 5 with SchedulerConfigurationData

use of com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData in project dr-elephant by linkedin.

the class OozieSchedulerTest method testOozieLoadsNameFromConfData.

@Test
public void testOozieLoadsNameFromConfData() {
    SchedulerConfigurationData schedulerConfig = makeConfig("othername", getDefaultSchedulerParams());
    OozieScheduler scheduler = new OozieScheduler("id", null, schedulerConfig);
    assertEquals("othername", scheduler.getSchedulerName());
}
Also used : SchedulerConfigurationData(com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData) Test(org.junit.Test)

Aggregations

SchedulerConfigurationData (com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData)16 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)6 Scheduler (com.linkedin.drelephant.schedulers.Scheduler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 ApplicationType (com.linkedin.drelephant.analysis.ApplicationType)1 HadoopApplicationData (com.linkedin.drelephant.analysis.HadoopApplicationData)1 WorkflowClient (com.linkedin.drelephant.clients.WorkflowClient)1 SchedulerConfiguration (com.linkedin.drelephant.configurations.scheduler.SchedulerConfiguration)1 AirflowScheduler (com.linkedin.drelephant.schedulers.AirflowScheduler)1 AzkabanScheduler (com.linkedin.drelephant.schedulers.AzkabanScheduler)1 OozieScheduler (com.linkedin.drelephant.schedulers.OozieScheduler)1 File (java.io.File)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 AppResult (models.AppResult)1