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()));
}
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)));
}
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("-------");
}
}
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);
}
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);
}
Aggregations