Search in sources :

Example 1 with BlockingTask

use of org.apache.airavata.datalake.orchestrator.workflow.engine.task.BlockingTask in project airavata-data-lake by apache.

the class Participant method getTaskFactory.

private Map<String, TaskFactory> getTaskFactory() throws Exception {
    Map<String, TaskFactory> taskMap = new HashMap<>();
    for (String className : blockingTaskClasses) {
        try {
            logger.info("Loading blocking task {}", className);
            Class<?> taskClz = Class.forName(className);
            Object taskObj = taskClz.getConstructor().newInstance();
            BlockingTask blockingTask = (BlockingTask) taskObj;
            TaskFactory taskFactory = context -> {
                blockingTask.setCallbackContext(context);
                return blockingTask;
            };
            BlockingTaskDef btDef = blockingTask.getClass().getAnnotation(BlockingTaskDef.class);
            taskMap.put(btDef.name(), taskFactory);
        } catch (ClassNotFoundException e) {
            logger.error("Couldn't find a class with name {}", className);
            throw e;
        }
    }
    for (String className : nonBlockingTaskClasses) {
        try {
            logger.info("Loading non blocking task {}", className);
            Class<?> taskClz = Class.forName(className);
            Object taskObj = taskClz.getConstructor().newInstance();
            NonBlockingTask nonBlockingTask = (NonBlockingTask) taskObj;
            TaskFactory taskFactory = context -> {
                nonBlockingTask.setCallbackContext(context);
                return nonBlockingTask;
            };
            NonBlockingTaskDef nbtDef = nonBlockingTask.getClass().getAnnotation(NonBlockingTaskDef.class);
            taskMap.put(nbtDef.name(), taskFactory);
        } catch (ClassNotFoundException e) {
            logger.error("Couldn't find a class with name {}", className);
            throw e;
        }
    }
    return taskMap;
}
Also used : StateMachineEngine(org.apache.helix.participant.StateMachineEngine) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) BlockingTask(org.apache.airavata.datalake.orchestrator.workflow.engine.task.BlockingTask) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) NonBlockingTask(org.apache.airavata.datalake.orchestrator.workflow.engine.task.NonBlockingTask) Yaml(org.yaml.snakeyaml.Yaml) SpringApplication(org.springframework.boot.SpringApplication) DataSourceAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration) OnlineOfflineStateModelFactory(org.apache.helix.examples.OnlineOfflineStateModelFactory) CommandLineRunner(org.springframework.boot.CommandLineRunner) ZKHelixManager(org.apache.helix.manager.zk.ZKHelixManager) BuiltInStateModelDefinitions(org.apache.helix.model.BuiltInStateModelDefinitions) Logger(org.slf4j.Logger) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) BlockingTaskDef(org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.BlockingTaskDef) NonBlockingTaskDef(org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.NonBlockingTaskDef) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) HibernateJpaAutoConfiguration(org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration) InstanceConfig(org.apache.helix.model.InstanceConfig) ComponentScan(org.springframework.context.annotation.ComponentScan) java.io(java.io) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ZkClient(org.apache.helix.manager.zk.ZkClient) InstanceType(org.apache.helix.InstanceType) WebApplicationType(org.springframework.boot.WebApplicationType) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) TaskStateModelFactory(org.apache.helix.task.TaskStateModelFactory) TaskFactory(org.apache.helix.task.TaskFactory) BlockingTask(org.apache.airavata.datalake.orchestrator.workflow.engine.task.BlockingTask) NonBlockingTask(org.apache.airavata.datalake.orchestrator.workflow.engine.task.NonBlockingTask) NonBlockingTaskDef(org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.NonBlockingTaskDef) TaskFactory(org.apache.helix.task.TaskFactory) BlockingTaskDef(org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.BlockingTaskDef) NonBlockingTaskDef(org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.NonBlockingTaskDef) NonBlockingTask(org.apache.airavata.datalake.orchestrator.workflow.engine.task.NonBlockingTask)

Aggregations

java.io (java.io)1 java.util (java.util)1 BlockingTask (org.apache.airavata.datalake.orchestrator.workflow.engine.task.BlockingTask)1 NonBlockingTask (org.apache.airavata.datalake.orchestrator.workflow.engine.task.NonBlockingTask)1 BlockingTaskDef (org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.BlockingTaskDef)1 NonBlockingTaskDef (org.apache.airavata.datalake.orchestrator.workflow.engine.task.annotation.NonBlockingTaskDef)1 InstanceType (org.apache.helix.InstanceType)1 OnlineOfflineStateModelFactory (org.apache.helix.examples.OnlineOfflineStateModelFactory)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ZKHelixManager (org.apache.helix.manager.zk.ZKHelixManager)1 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)1 ZkClient (org.apache.helix.manager.zk.ZkClient)1 BuiltInStateModelDefinitions (org.apache.helix.model.BuiltInStateModelDefinitions)1 InstanceConfig (org.apache.helix.model.InstanceConfig)1 StateMachineEngine (org.apache.helix.participant.StateMachineEngine)1 TaskFactory (org.apache.helix.task.TaskFactory)1 TaskStateModelFactory (org.apache.helix.task.TaskStateModelFactory)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 CommandLineRunner (org.springframework.boot.CommandLineRunner)1