use of org.apache.helix.task.TaskCallbackContext in project incubator-gobblin by apache.
the class GobblinHelixTaskTest method testPrepareTask.
@Test
public void testPrepareTask() throws IOException {
// Serialize the JobState that will be read later in GobblinHelixTask
Path jobStateFilePath = new Path(appWorkDir, TestHelper.TEST_JOB_ID + "." + AbstractJobLauncher.JOB_STATE_FILE_NAME);
JobState jobState = new JobState();
jobState.setJobName(TestHelper.TEST_JOB_NAME);
jobState.setJobId(TestHelper.TEST_JOB_ID);
SerializationUtils.serializeState(this.localFs, jobStateFilePath, jobState);
// Prepare the WorkUnit
WorkUnit workUnit = WorkUnit.createEmpty();
prepareWorkUnit(workUnit);
// Prepare the source Json file
File sourceJsonFile = new File(this.appWorkDir.toString(), TestHelper.TEST_JOB_NAME + ".json");
TestHelper.createSourceJsonFile(sourceJsonFile);
workUnit.setProp(SimpleJsonSource.SOURCE_FILE_KEY, sourceJsonFile.getAbsolutePath());
// Serialize the WorkUnit into a file
// expected path is appWorkDir/_workunits/job_id/job_id.wu
Path workUnitDirPath = new Path(this.appWorkDir, GobblinClusterConfigurationKeys.INPUT_WORK_UNIT_DIR_NAME);
FsStateStore<WorkUnit> wuStateStore = new FsStateStore<>(this.localFs, workUnitDirPath.toString(), WorkUnit.class);
Path workUnitFilePath = new Path(new Path(workUnitDirPath, TestHelper.TEST_JOB_ID), TestHelper.TEST_JOB_NAME + ".wu");
wuStateStore.put(TestHelper.TEST_JOB_ID, TestHelper.TEST_JOB_NAME + ".wu", workUnit);
Assert.assertTrue(this.localFs.exists(workUnitFilePath));
// Prepare the GobblinHelixTask
Map<String, String> taskConfigMap = Maps.newHashMap();
taskConfigMap.put(GobblinClusterConfigurationKeys.WORK_UNIT_FILE_PATH, workUnitFilePath.toString());
taskConfigMap.put(ConfigurationKeys.JOB_NAME_KEY, TestHelper.TEST_JOB_NAME);
taskConfigMap.put(ConfigurationKeys.JOB_ID_KEY, TestHelper.TEST_JOB_ID);
taskConfigMap.put(ConfigurationKeys.TASK_KEY_KEY, Long.toString(Id.parse(TestHelper.TEST_JOB_ID).getSequence()));
TaskConfig taskConfig = new TaskConfig("", taskConfigMap, true);
TaskCallbackContext taskCallbackContext = Mockito.mock(TaskCallbackContext.class);
Mockito.when(taskCallbackContext.getTaskConfig()).thenReturn(taskConfig);
Mockito.when(taskCallbackContext.getManager()).thenReturn(this.helixManager);
GobblinHelixTaskFactory gobblinHelixTaskFactory = new GobblinHelixTaskFactory(Optional.<ContainerMetrics>absent(), this.taskExecutor, this.taskStateTracker, this.localFs, this.appWorkDir, ConfigFactory.empty(), this.helixManager);
this.gobblinHelixTask = (GobblinHelixTask) gobblinHelixTaskFactory.createNewTask(taskCallbackContext);
}
use of org.apache.helix.task.TaskCallbackContext in project helix by apache.
the class TestJobQueuesResource method test.
@Test
public void test() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final int n = 5;
final int p = 20;
final int r = 3;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
_gSetupTool.addCluster(clusterName, true);
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
_gSetupTool.addInstanceToCluster(clusterName, instanceName);
}
// Set up target db
_gSetupTool.addResourceToCluster(clusterName, WorkflowGenerator.DEFAULT_TGT_DB, p, "MasterSlave");
_gSetupTool.rebalanceStorageCluster(clusterName, WorkflowGenerator.DEFAULT_TGT_DB, r);
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put("DummyTask", new TaskFactory() {
@Override
public Task createNewTask(TaskCallbackContext context) {
return new MockTask(context);
}
});
// Start dummy participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
// Register a Task state model factory.
StateMachineEngine stateMachine = participants[i].getStateMachineEngine();
stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(participants[i], taskFactoryReg));
participants[i].syncStart();
}
// start controller
String controllerName = "controller";
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, controllerName);
controller.syncStart();
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// Start a queue
String queueName = "myQueue1";
LOG.info("Starting job-queue: " + queueName);
String jobQueueYamlConfig = "name: " + queueName;
String resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/jobQueues";
ZNRecord postRet = AdminTestHelper.post(_gClient, resourceUrl, jobQueueYamlConfig);
LOG.info("Started job-queue: " + queueName + ", ret: " + postRet);
LOG.info("Getting all job-queues");
ZNRecord getRet = AdminTestHelper.get(_gClient, resourceUrl);
LOG.info("Got job-queues: " + getRet);
// Enqueue job
resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/jobQueues/" + queueName;
WorkflowBean wfBean = new WorkflowBean();
wfBean.name = queueName;
JobBean jBean1 = new JobBean();
jBean1.name = "myJob1";
jBean1.command = "DummyTask";
jBean1.targetResource = WorkflowGenerator.DEFAULT_TGT_DB;
jBean1.targetPartitionStates = Lists.newArrayList("MASTER");
JobBean jBean2 = new JobBean();
jBean2.name = "myJob2";
jBean2.command = "DummyTask";
jBean2.targetResource = WorkflowGenerator.DEFAULT_TGT_DB;
jBean2.targetPartitionStates = Lists.newArrayList("SLAVE");
wfBean.jobs = Lists.newArrayList(jBean1, jBean2);
String jobYamlConfig = new Yaml().dump(wfBean);
LOG.info("Enqueuing jobs: " + jobQueueYamlConfig);
Map<String, String> paraMap = new HashMap<String, String>();
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, TaskDriver.DriverCommand.start.toString());
String postBody = String.format("%s=%s&%s=%s", JsonParameters.JSON_PARAMETERS, ClusterRepresentationUtil.ObjectToJson(paraMap), ResourceUtil.YamlParamKey.NEW_JOB.toString(), jobYamlConfig);
postRet = AdminTestHelper.post(_gClient, resourceUrl, postBody);
LOG.info("Enqueued job, ret: " + postRet);
// Get job
resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/jobQueues/" + queueName + "/" + jBean1.name;
getRet = AdminTestHelper.get(_gClient, resourceUrl);
LOG.info("Got job: " + getRet);
// Stop job queue
resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/jobQueues/" + queueName;
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, TaskDriver.DriverCommand.stop.toString());
postBody = String.format("%s=%s", JsonParameters.JSON_PARAMETERS, ClusterRepresentationUtil.ObjectToJson(paraMap));
postRet = AdminTestHelper.post(_gClient, resourceUrl, postBody);
LOG.info("Stopped job-queue, ret: " + postRet);
// Delete a job
resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/jobQueues/" + queueName + "/" + jBean2.name;
AdminTestHelper.delete(_gClient, resourceUrl);
LOG.info("Delete a job: ");
// Resume job queue
resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/jobQueues/" + queueName;
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, TaskDriver.DriverCommand.resume.toString());
postBody = String.format("%s=%s", JsonParameters.JSON_PARAMETERS, ClusterRepresentationUtil.ObjectToJson(paraMap));
postRet = AdminTestHelper.post(_gClient, resourceUrl, postBody);
LOG.info("Resumed job-queue, ret: " + postRet);
// Flush job queue
paraMap.put(JsonParameters.MANAGEMENT_COMMAND, "flush");
postBody = JsonParameters.JSON_PARAMETERS + "=" + ClusterRepresentationUtil.ObjectToJson(paraMap);
postRet = AdminTestHelper.post(_gClient, resourceUrl, postBody);
LOG.info("Flushed job-queue, ret: " + postRet);
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
if (participants[i] != null && participants[i].isConnected()) {
participants[i].syncStop();
}
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.task.TaskCallbackContext in project helix by apache.
the class TestGenericTaskAssignmentCalculator method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_participants = new MockParticipantManager[_numNodes];
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
// Setup cluster and instances
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < _numNodes; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// start dummy participants
for (int i = 0; i < _numNodes; i++) {
final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
// Set task callbacks
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put("TaskOne", new TaskFactory() {
@Override
public Task createNewTask(TaskCallbackContext context) {
return new TaskOne(context, instanceName);
}
});
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
// Register a Task state model factory.
StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[i], taskFactoryReg));
_participants[i].syncStart();
}
// Start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// Start an admin connection
_manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
_manager.connect();
_driver = new TaskDriver(_manager);
Map<String, String> taskConfigMap = Maps.newHashMap();
_taskConfig = new TaskConfig("TaskOne", taskConfigMap);
_jobCommandMap = Maps.newHashMap();
}
use of org.apache.helix.task.TaskCallbackContext in project helix by apache.
the class TestIndependentTaskRebalancer method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
_participants = new MockParticipantManager[_numNodes];
String namespace = "/" + CLUSTER_NAME;
if (_gZkClient.exists(namespace)) {
_gZkClient.deleteRecursively(namespace);
}
// Setup cluster and instances
ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < _numNodes; i++) {
String storageNodeName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// start dummy participants
for (int i = 0; i < _numNodes; i++) {
final String instanceName = PARTICIPANT_PREFIX + "_" + (_startPort + i);
// Set task callbacks
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put("TaskOne", new TaskFactory() {
@Override
public Task createNewTask(TaskCallbackContext context) {
return new TaskOne(context, instanceName);
}
});
taskFactoryReg.put("TaskTwo", new TaskFactory() {
@Override
public Task createNewTask(TaskCallbackContext context) {
return new TaskTwo(context, instanceName);
}
});
taskFactoryReg.put("SingleFailTask", new TaskFactory() {
@Override
public Task createNewTask(TaskCallbackContext context) {
return new SingleFailTask();
}
});
_participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
// Register a Task state model factory.
StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[i], taskFactoryReg));
_participants[i].syncStart();
}
// Start controller
String controllerName = CONTROLLER_PREFIX + "_0";
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
_controller.syncStart();
// Start an admin connection
_manager = HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
_manager.connect();
_driver = new TaskDriver(_manager);
}
use of org.apache.helix.task.TaskCallbackContext in project helix by apache.
the class TestJobFailureTaskNotStarted method startParticipantsWithStuckTaskStateModelFactory.
protected void startParticipantsWithStuckTaskStateModelFactory() {
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put(MockTask.TASK_COMMAND, new TaskFactory() {
@Override
public Task createNewTask(TaskCallbackContext context) {
return new MockTask(context);
}
});
List<String> instances = _setupTool.getClusterManagementTool().getInstancesInCluster(CLUSTER_NAME);
_participants[0] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(0));
StateMachineEngine stateMachine = _participants[0].getStateMachineEngine();
stateMachine.registerStateModelFactory("Task", new MockTaskStateModelFactory(_participants[0], taskFactoryReg));
_participants[0].syncStart();
_blockedParticipant = _participants[0];
_participants[1] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instances.get(1));
stateMachine = _participants[1].getStateMachineEngine();
stateMachine.registerStateModelFactory("Task", new TaskStateModelFactory(_participants[1], taskFactoryReg));
_participants[1].syncStart();
_normalParticipant = _participants[1];
}
Aggregations