Search in sources :

Example 1 with TaskFactory

use of org.apache.myriad.scheduler.TaskFactory in project incubator-myriad by apache.

the class MyriadTestModule method configure.

@SuppressWarnings("unchecked")
@Override
protected void configure() {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        cfg = mapper.readValue(Thread.currentThread().getContextClassLoader().getResource("myriad-config-test-default.yml"), MyriadConfiguration.class);
    } catch (IOException e1) {
        LOGGER.error("IOException", e1);
        return;
    }
    if (cfg == null) {
        return;
    }
    bind(MyriadConfiguration.class).toInstance(cfg);
    MapBinder<String, TaskFactory> mapBinder = MapBinder.newMapBinder(binder(), String.class, TaskFactory.class);
    mapBinder.addBinding(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX).to(NMTaskFactory.class).in(Scopes.SINGLETON);
    Map<String, ServiceConfiguration> auxServicesConfigs = cfg.getServiceConfigurations();
    for (Map.Entry<String, ServiceConfiguration> entry : auxServicesConfigs.entrySet()) {
        String taskFactoryClass = entry.getValue().getTaskFactoryImplName().orNull();
        if (taskFactoryClass != null) {
            try {
                Class<? extends TaskFactory> implClass = (Class<? extends TaskFactory>) Class.forName(taskFactoryClass);
                mapBinder.addBinding(entry.getKey()).to(implClass).in(Scopes.SINGLETON);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            mapBinder.addBinding(entry.getKey()).to(ServiceTaskFactory.class).in(Scopes.SINGLETON);
        }
    }
}
Also used : IOException(java.io.IOException) ServiceTaskFactory(org.apache.myriad.scheduler.ServiceTaskFactory) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) ServiceConfiguration(org.apache.myriad.configuration.ServiceConfiguration) TaskFactory(org.apache.myriad.scheduler.TaskFactory) ServiceTaskFactory(org.apache.myriad.scheduler.ServiceTaskFactory) NMTaskFactory(org.apache.myriad.scheduler.NMTaskFactory) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NMTaskFactory(org.apache.myriad.scheduler.NMTaskFactory)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 IOException (java.io.IOException)1 Map (java.util.Map)1 MyriadConfiguration (org.apache.myriad.configuration.MyriadConfiguration)1 ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)1 NMTaskFactory (org.apache.myriad.scheduler.NMTaskFactory)1 ServiceTaskFactory (org.apache.myriad.scheduler.ServiceTaskFactory)1 TaskFactory (org.apache.myriad.scheduler.TaskFactory)1