Search in sources :

Example 16 with WorkflowConfig

use of org.apache.helix.task.WorkflowConfig in project incubator-gobblin by apache.

the class GobblinHelixTaskDriver method deleteWorkflow.

/**
 * Delete the workflow
 *
 * @param workflow  The workflow name
 * @param timeout   The timeout for deleting the workflow/queue in seconds
 */
public void deleteWorkflow(String workflow, long timeout) throws InterruptedException {
    WorkflowConfig workflowConfig = _taskDriver.getWorkflowConfig(workflow);
    // set the target state if not already set
    if (workflowConfig != null && workflowConfig.getTargetState() != TargetState.DELETE) {
        _taskDriver.delete(workflow);
    }
    long endTime = System.currentTimeMillis() + (timeout * 1000);
    // check for completion of deletion request
    while (System.currentTimeMillis() <= endTime) {
        WorkflowContext workflowContext = _taskDriver.getWorkflowContext(workflow);
        if (workflowContext != null) {
            Thread.sleep(1000);
        } else {
            // Successfully deleted
            return;
        }
    }
    // Failed to complete deletion within timeout
    throw new HelixException(String.format("Fail to delete the workflow/queue %s within %d seconds.", workflow, timeout));
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) HelixException(org.apache.helix.HelixException) WorkflowContext(org.apache.helix.task.WorkflowContext)

Example 17 with WorkflowConfig

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

the class TaskTestUtil method pollForWorkflowParallelState.

// 1. Different jobs in a same work flow is in RUNNING at the same time
// 2. When disallow overlap assignment, no two jobs in the same work flow is in RUNNING at the same instance
// Use this method with caution because it assumes workflow doesn't finish too quickly and number of parallel running
// tasks can be counted.
public static boolean pollForWorkflowParallelState(TaskDriver driver, String workflowName) throws InterruptedException {
    WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflowName);
    Assert.assertNotNull(workflowConfig);
    WorkflowContext workflowContext = null;
    while (workflowContext == null) {
        workflowContext = driver.getWorkflowContext(workflowName);
        Thread.sleep(100);
    }
    int maxRunningCount = 0;
    boolean finished = false;
    while (!finished) {
        finished = true;
        int runningCount = 0;
        workflowContext = driver.getWorkflowContext(workflowName);
        for (String jobName : workflowConfig.getJobDag().getAllNodes()) {
            TaskState jobState = workflowContext.getJobState(jobName);
            if (jobState == TaskState.IN_PROGRESS) {
                ++runningCount;
                finished = false;
            }
        }
        if (runningCount > maxRunningCount) {
            maxRunningCount = runningCount;
        }
        List<JobContext> jobContextList = new ArrayList<JobContext>();
        for (String jobName : workflowConfig.getJobDag().getAllNodes()) {
            JobContext jobContext = driver.getJobContext(jobName);
            if (jobContext != null) {
                jobContextList.add(driver.getJobContext(jobName));
            }
        }
        if (!workflowConfig.isAllowOverlapJobAssignment()) {
            Set<String> instances = new HashSet<String>();
            for (JobContext jobContext : jobContextList) {
                for (int partition : jobContext.getPartitionSet()) {
                    String instance = jobContext.getAssignedParticipant(partition);
                    TaskPartitionState taskPartitionState = jobContext.getPartitionState(partition);
                    if (instance == null) {
                        continue;
                    }
                    if (taskPartitionState != TaskPartitionState.INIT && taskPartitionState != TaskPartitionState.RUNNING) {
                        continue;
                    }
                    if (instances.contains(instance)) {
                        return false;
                    }
                    TaskPartitionState state = jobContext.getPartitionState(partition);
                    if (state != TaskPartitionState.COMPLETED) {
                        instances.add(instance);
                    }
                }
            }
        }
        Thread.sleep(100);
    }
    return maxRunningCount > 1 && (workflowConfig.isJobQueue() ? maxRunningCount <= workflowConfig.getParallelJobs() : true);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) WorkflowContext(org.apache.helix.task.WorkflowContext) ArrayList(java.util.ArrayList) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) TaskState(org.apache.helix.task.TaskState) HashSet(java.util.HashSet)

Example 18 with WorkflowConfig

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

the class TestTaskRebalancerStopResume method verifyJobNotInQueue.

private void verifyJobNotInQueue(String queueName, String namedSpacedJobName) {
    WorkflowConfig workflowCfg = _driver.getWorkflowConfig(queueName);
    JobDag dag = workflowCfg.getJobDag();
    Assert.assertFalse(dag.getAllNodes().contains(namedSpacedJobName));
    Assert.assertFalse(dag.getChildrenToParents().containsKey(namedSpacedJobName));
    Assert.assertFalse(dag.getParentsToChildren().containsKey(namedSpacedJobName));
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) JobDag(org.apache.helix.task.JobDag)

Example 19 with WorkflowConfig

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

the class TestUpdateWorkflow method testUpdateRunningQueue.

@Test
public void testUpdateRunningQueue() 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);
    WorkflowConfig workflowConfig = _driver.getWorkflowConfig(queueName);
    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);
    // ensure current schedule is started
    String scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
    _driver.pollForWorkflowState(scheduledQueue, TaskState.IN_PROGRESS);
    _driver.updateWorkflow(queueName, configBuilder.build());
    // 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 20 with WorkflowConfig

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

the class TestRecurringJobQueue method testDeletingRecurrentQueueWithHistory.

@Test
public void testDeletingRecurrentQueueWithHistory() throws Exception {
    final String queueName = TestHelper.getTestMethodName();
    // Create a queue
    LOG.info("Starting job-queue: " + queueName);
    JobQueue.Builder queueBuild = TaskTestUtil.buildRecurrentJobQueue(queueName, 0, 60, TargetState.STOP);
    createAndEnqueueJob(queueBuild, 2);
    _driver.createQueue(queueBuild.build());
    WorkflowConfig workflowConfig = _driver.getWorkflowConfig(queueName);
    Assert.assertEquals(workflowConfig.getTargetState(), TargetState.STOP);
    _driver.resume(queueName);
    WorkflowContext wCtx;
    // wait until at least 2 workflows are scheduled based on template queue
    do {
        Thread.sleep(60000);
        wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
    } while (wCtx.getScheduledWorkflows().size() < 2);
    // Stop recurring workflow
    _driver.stop(queueName);
    _driver.pollForWorkflowState(queueName, TaskState.STOPPED);
    // Record all scheduled workflows
    wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
    List<String> scheduledWorkflows = new ArrayList<String>(wCtx.getScheduledWorkflows());
    final String lastScheduledWorkflow = wCtx.getLastScheduledSingleWorkflow();
    // Delete recurrent workflow
    _driver.delete(queueName);
    // Wait until recurrent workflow and the last scheduled workflow are cleaned up
    boolean result = TestHelper.verify(new TestHelper.Verifier() {

        @Override
        public boolean verify() throws Exception {
            WorkflowContext wCtx = _driver.getWorkflowContext(queueName);
            WorkflowContext lastWfCtx = _driver.getWorkflowContext(lastScheduledWorkflow);
            return (wCtx == null && lastWfCtx == null);
        }
    }, 5 * 1000);
    Assert.assertTrue(result);
    for (String scheduledWorkflow : scheduledWorkflows) {
        WorkflowContext scheduledWorkflowCtx = _driver.getWorkflowContext(scheduledWorkflow);
        WorkflowConfig scheduledWorkflowCfg = _driver.getWorkflowConfig(scheduledWorkflow);
        Assert.assertNull(scheduledWorkflowCtx);
        Assert.assertNull(scheduledWorkflowCfg);
    }
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) TestHelper(org.apache.helix.TestHelper) JobQueue(org.apache.helix.task.JobQueue) WorkflowContext(org.apache.helix.task.WorkflowContext) ArrayList(java.util.ArrayList) 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