Search in sources :

Example 6 with WorkflowConfig

use of org.apache.helix.task.WorkflowConfig in project helix by apache.

the class TestTaskRebalancerStopResume method stopAndDeleteQueue.

@Test
public void stopAndDeleteQueue() throws Exception {
    final String queueName = TestHelper.getTestMethodName();
    // Create a queue
    System.out.println("START " + queueName + " at " + new Date(System.currentTimeMillis()));
    WorkflowConfig wfCfg = new WorkflowConfig.Builder(queueName).setExpiry(2, TimeUnit.MINUTES).build();
    JobQueue qCfg = new JobQueue.Builder(queueName).fromMap(wfCfg.getResourceConfigMap()).build();
    _driver.createQueue(qCfg);
    // Enqueue 2 jobs
    Set<String> master = Sets.newHashSet("MASTER");
    JobConfig.Builder job1 = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB).setTargetPartitionStates(master);
    String job1Name = "masterJob";
    LOG.info("Enqueuing job1: " + job1Name);
    _driver.enqueueJob(queueName, job1Name, job1);
    Set<String> slave = Sets.newHashSet("SLAVE");
    JobConfig.Builder job2 = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB).setTargetPartitionStates(slave);
    String job2Name = "slaveJob";
    LOG.info("Enqueuing job2: " + job2Name);
    _driver.enqueueJob(queueName, job2Name, job2);
    String namespacedJob1 = String.format("%s_%s", queueName, job1Name);
    _driver.pollForJobState(queueName, namespacedJob1, TaskState.COMPLETED);
    String namespacedJob2 = String.format("%s_%s", queueName, job2Name);
    _driver.pollForJobState(queueName, namespacedJob2, TaskState.COMPLETED);
    // Stop queue
    _driver.stop(queueName);
    boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    // Delete queue
    _driver.delete(queueName);
    // Wait until all status are cleaned up
    result = TestHelper.verify(new TestHelper.Verifier() {

        @Override
        public boolean verify() throws Exception {
            HelixDataAccessor accessor = _manager.getHelixDataAccessor();
            PropertyKey.Builder keyBuilder = accessor.keyBuilder();
            // check paths for resource-config, ideal-state, external-view, property-store
            List<String> paths = Lists.newArrayList(keyBuilder.resourceConfigs().getPath(), keyBuilder.idealStates().getPath(), keyBuilder.externalViews().getPath(), PropertyPathBuilder.propertyStore(CLUSTER_NAME) + TaskConstants.REBALANCER_CONTEXT_ROOT);
            for (String path : paths) {
                List<String> childNames = accessor.getBaseDataAccessor().getChildNames(path, 0);
                for (String childName : childNames) {
                    if (childName.startsWith(queueName)) {
                        return false;
                    }
                }
            }
            return true;
        }
    }, 30 * 1000);
    Assert.assertTrue(result);
    System.out.println("END " + queueName + " at " + new Date(System.currentTimeMillis()));
}
Also used : JobQueue(org.apache.helix.task.JobQueue) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Date(java.util.Date) JobConfig(org.apache.helix.task.JobConfig) WorkflowConfig(org.apache.helix.task.WorkflowConfig) HelixDataAccessor(org.apache.helix.HelixDataAccessor) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Example 7 with WorkflowConfig

use of org.apache.helix.task.WorkflowConfig in project helix by apache.

the class TestUpdateWorkflow method testUpdateStoppedQueue.

@Test
public void testUpdateStoppedQueue() throws InterruptedException {
    String queueName = TestHelper.getTestMethodName();
    // Create a queue
    LOG.info("Starting job-queue: " + queueName);
    JobQueue queue = createDefaultRecurrentJobQueue(queueName, 2);
    _driver.start(queue);
    WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
    // ensure current schedule is started
    String scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
    _driver.pollForWorkflowState(scheduledQueue, TaskState.IN_PROGRESS);
    _driver.stop(queueName);
    WorkflowConfig workflowConfig = _driver.getWorkflowConfig(queueName);
    Assert.assertEquals(workflowConfig.getTargetState(), TargetState.STOP);
    WorkflowConfig.Builder configBuilder = new WorkflowConfig.Builder(workflowConfig);
    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.SECOND, startTime.get(Calendar.SECOND) + 1);
    ScheduleConfig scheduleConfig = ScheduleConfig.recurringFromDate(startTime.getTime(), TimeUnit.MINUTES, 2);
    configBuilder.setScheduleConfig(scheduleConfig);
    _driver.updateWorkflow(queueName, configBuilder.build());
    workflowConfig = _driver.getWorkflowConfig(queueName);
    Assert.assertEquals(workflowConfig.getTargetState(), TargetState.STOP);
    _driver.resume(queueName);
    // ensure current schedule is completed
    _driver.pollForWorkflowState(scheduledQueue, TaskState.COMPLETED);
    Thread.sleep(1000);
    wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
    scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
    WorkflowConfig wCfg = _driver.getWorkflowConfig(scheduledQueue);
    Calendar configStartTime = Calendar.getInstance();
    configStartTime.setTime(wCfg.getStartTime());
    Assert.assertTrue((startTime.get(Calendar.HOUR_OF_DAY) == configStartTime.get(Calendar.HOUR_OF_DAY) && startTime.get(Calendar.MINUTE) == configStartTime.get(Calendar.MINUTE) && startTime.get(Calendar.SECOND) == configStartTime.get(Calendar.SECOND)));
}
Also used : ScheduleConfig(org.apache.helix.task.ScheduleConfig) WorkflowConfig(org.apache.helix.task.WorkflowConfig) JobQueue(org.apache.helix.task.JobQueue) WorkflowContext(org.apache.helix.task.WorkflowContext) Calendar(java.util.Calendar) Test(org.testng.annotations.Test)

Example 8 with WorkflowConfig

use of org.apache.helix.task.WorkflowConfig in project helix by apache.

the class TaskAdmin method list.

private static void list(TaskDriver taskDriver, String workflow) {
    WorkflowConfig wCfg = taskDriver.getWorkflowConfig(workflow);
    if (wCfg == null) {
        LOG.error("Workflow " + workflow + " does not exist!");
        return;
    }
    WorkflowContext wCtx = taskDriver.getWorkflowContext(workflow);
    LOG.info("Workflow " + workflow + " consists of the following tasks: " + wCfg.getJobDag().getAllNodes());
    String workflowState = (wCtx != null) ? wCtx.getWorkflowState().name() : TaskState.NOT_STARTED.name();
    LOG.info("Current state of workflow is " + workflowState);
    LOG.info("Job states are: ");
    LOG.info("-------");
    for (String job : wCfg.getJobDag().getAllNodes()) {
        TaskState jobState = (wCtx != null) ? wCtx.getJobState(job) : TaskState.NOT_STARTED;
        LOG.info("Job " + job + " is " + jobState);
        // fetch job information
        JobConfig jCfg = taskDriver.getJobConfig(job);
        JobContext jCtx = taskDriver.getJobContext(job);
        if (jCfg == null || jCtx == null) {
            LOG.info("-------");
            continue;
        }
        // calculate taskPartitions
        List<Integer> partitions = Lists.newArrayList(jCtx.getPartitionSet());
        Collections.sort(partitions);
        // report status
        for (Integer partition : partitions) {
            String taskId = jCtx.getTaskIdForPartition(partition);
            taskId = (taskId != null) ? taskId : jCtx.getTargetForPartition(partition);
            LOG.info("Task: " + taskId);
            TaskConfig taskConfig = jCfg.getTaskConfig(taskId);
            if (taskConfig != null) {
                LOG.info("Configuration: " + taskConfig.getConfigMap());
            }
            TaskPartitionState state = jCtx.getPartitionState(partition);
            state = (state != null) ? state : TaskPartitionState.INIT;
            LOG.info("State: " + state);
            String assignedParticipant = jCtx.getAssignedParticipant(partition);
            if (assignedParticipant != null) {
                LOG.info("Assigned participant: " + assignedParticipant);
            }
            LOG.info("-------");
        }
        LOG.info("-------");
    }
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) WorkflowContext(org.apache.helix.task.WorkflowContext) TaskConfig(org.apache.helix.task.TaskConfig) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) TaskState(org.apache.helix.task.TaskState) JobConfig(org.apache.helix.task.JobConfig)

Example 9 with WorkflowConfig

use of org.apache.helix.task.WorkflowConfig in project helix by apache.

the class TestRecurringJobQueue method testGetNoExistWorkflowConfig.

@Test
public void testGetNoExistWorkflowConfig() {
    String randomName = "randomJob";
    WorkflowConfig workflowConfig = _driver.getWorkflowConfig(randomName);
    Assert.assertNull(workflowConfig);
    JobConfig jobConfig = _driver.getJobConfig(randomName);
    Assert.assertNull(jobConfig);
    WorkflowContext workflowContext = _driver.getWorkflowContext(randomName);
    Assert.assertNull(workflowContext);
    JobContext jobContext = _driver.getJobContext(randomName);
    Assert.assertNull(jobContext);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) WorkflowContext(org.apache.helix.task.WorkflowContext) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 10 with WorkflowConfig

use of org.apache.helix.task.WorkflowConfig in project helix by apache.

the class TestRecurringJobQueue method testCreateStoppedQueue.

@Test
public void testCreateStoppedQueue() throws InterruptedException {
    String queueName = TestHelper.getTestMethodName();
    // Create a queue
    LOG.info("Starting job-queue: " + queueName);
    JobQueue.Builder queueBuild = TaskTestUtil.buildRecurrentJobQueue(queueName, 0, 600000, TargetState.STOP);
    createAndEnqueueJob(queueBuild, 2);
    _driver.createQueue(queueBuild.build());
    WorkflowConfig workflowConfig = _driver.getWorkflowConfig(queueName);
    Assert.assertEquals(workflowConfig.getTargetState(), TargetState.STOP);
    _driver.resume(queueName);
    // TaskTestUtil.pollForWorkflowState(_driver, queueName, );
    WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
    // ensure current schedule is started
    String scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
    _driver.pollForWorkflowState(scheduledQueue, TaskState.COMPLETED);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) JobQueue(org.apache.helix.task.JobQueue) WorkflowContext(org.apache.helix.task.WorkflowContext) Test(org.testng.annotations.Test)

Aggregations

WorkflowConfig (org.apache.helix.task.WorkflowConfig)28 Test (org.testng.annotations.Test)14 JobQueue (org.apache.helix.task.JobQueue)13 WorkflowContext (org.apache.helix.task.WorkflowContext)12 JobConfig (org.apache.helix.task.JobConfig)11 TaskDriver (org.apache.helix.task.TaskDriver)11 JobContext (org.apache.helix.task.JobContext)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 JobDag (org.apache.helix.task.JobDag)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HelixDataAccessor (org.apache.helix.HelixDataAccessor)3 HelixException (org.apache.helix.HelixException)3 PropertyKey (org.apache.helix.PropertyKey)3 ObjectNode (org.codehaus.jackson.node.ObjectNode)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2