Search in sources :

Example 1 with WorkflowClient

use of com.linkedin.drelephant.clients.WorkflowClient 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)

Aggregations

WorkflowClient (com.linkedin.drelephant.clients.WorkflowClient)1 SchedulerConfigurationData (com.linkedin.drelephant.configurations.scheduler.SchedulerConfigurationData)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1