private static ExecutablePO parse(AbstractExecutable executable) { ExecutablePO result = new ExecutablePO(); result.setName(executable.getName()); result.setUuid(executable.getId()); result.setType(executable.getClass().getName()); result.setParams(executable.getParams()); if (executable instanceof ChainedExecutable) { List<ExecutablePO> tasks = Lists.newArrayList(); for (AbstractExecutable task : ((ChainedExecutable) executable).getTasks()) { tasks.add(parse(task)); } result.setTasks(tasks); } if (executable instanceof CheckpointExecutable) { List<ExecutablePO> tasksForCheck = Lists.newArrayList(); for (AbstractExecutable taskForCheck : ((CheckpointExecutable) executable).getSubTasksForCheck()) { tasksForCheck.add(parse(taskForCheck)); } result.setTasksForCheck(tasksForCheck); } return result; }
subTaskExecutable.setParentExecutable(result); ((ChainedExecutable) result).addTask(parseTo(subTask));
private static void assertJobEqual(Executable one, Executable another) { assertEquals(one.getClass(), another.getClass()); assertEquals(one.getId(), another.getId()); assertEquals(one.getStatus(), another.getStatus()); assertEquals(one.isRunnable(), another.isRunnable()); assertEquals(one.getOutput(), another.getOutput()); assertTrue((one.getParams() == null && another.getParams() == null) || (one.getParams() != null && another.getParams() != null)); if (one.getParams() != null) { assertEquals(one.getParams().size(), another.getParams().size()); for (String key : one.getParams().keySet()) { assertEquals(one.getParams().get(key), another.getParams().get(key)); } } if (one instanceof ChainedExecutable) { assertTrue(another instanceof ChainedExecutable); List<? extends Executable> onesSubs = ((ChainedExecutable) one).getTasks(); List<? extends Executable> anotherSubs = ((ChainedExecutable) another).getTasks(); assertTrue((onesSubs == null && anotherSubs == null) || (onesSubs != null && anotherSubs != null)); if (onesSubs != null) { assertEquals(onesSubs.size(), anotherSubs.size()); for (int i = 0; i < onesSubs.size(); ++i) { assertJobEqual(onesSubs.get(i), anotherSubs.get(i)); } } } } }
private static AbstractExecutable parseTo(ExecutablePO executablePO) { if (executablePO == null) { return null; } String type = executablePO.getType(); try { Class<? extends AbstractExecutable> clazz = ClassUtil.forName(type, AbstractExecutable.class); Constructor<? extends AbstractExecutable> constructor = clazz.getConstructor(); AbstractExecutable result = constructor.newInstance(); result.setId(executablePO.getUuid()); result.setName(executablePO.getName()); result.setParams(executablePO.getParams()); List<ExecutablePO> tasks = executablePO.getTasks(); if (tasks != null && !tasks.isEmpty()) { Preconditions.checkArgument(result instanceof ChainedExecutable); for (ExecutablePO subTask : tasks) { ((ChainedExecutable) result).addTask(parseTo(subTask)); } } return result; } catch (ReflectiveOperationException e) { throw new IllegalArgumentException("cannot parse this job:" + executablePO.getId(), e); } }
private static void assertJobEqual(Executable one, Executable another) { assertEquals(one.getClass(), another.getClass()); assertEquals(one.getId(), another.getId()); assertEquals(one.getStatus(), another.getStatus()); assertEquals(one.isRunnable(), another.isRunnable()); assertEquals(one.getOutput(), another.getOutput()); assertTrue((one.getParams() == null && another.getParams() == null) || (one.getParams() != null && another.getParams() != null)); if (one.getParams() != null) { assertEquals(one.getParams().size(), another.getParams().size()); for (String key : one.getParams().keySet()) { assertEquals(one.getParams().get(key), another.getParams().get(key)); } } if (one instanceof ChainedExecutable) { assertTrue(another instanceof ChainedExecutable); List<? extends Executable> onesSubs = ((ChainedExecutable) one).getTasks(); List<? extends Executable> anotherSubs = ((ChainedExecutable) another).getTasks(); assertTrue((onesSubs == null && anotherSubs == null) || (onesSubs != null && anotherSubs != null)); if (onesSubs != null) { assertEquals(onesSubs.size(), anotherSubs.size()); for (int i = 0; i < onesSubs.size(); ++i) { assertJobEqual(onesSubs.get(i), anotherSubs.get(i)); } } } } }
subTaskExecutable.setParentExecutable(result); ((ChainedExecutable) result).addTask(parseTo(subTask));
private static ExecutablePO parse(AbstractExecutable executable) { ExecutablePO result = new ExecutablePO(); result.setName(executable.getName()); result.setUuid(executable.getId()); result.setType(executable.getClass().getName()); result.setParams(executable.getParams()); if (executable instanceof ChainedExecutable) { List<ExecutablePO> tasks = Lists.newArrayList(); for (AbstractExecutable task : ((ChainedExecutable) executable).getTasks()) { tasks.add(parse(task)); } result.setTasks(tasks); } return result; }
private static ExecutablePO parse(AbstractExecutable executable) { ExecutablePO result = new ExecutablePO(); result.setName(executable.getName()); result.setUuid(executable.getId()); result.setType(executable.getClass().getName()); result.setParams(executable.getParams()); if (executable instanceof ChainedExecutable) { List<ExecutablePO> tasks = Lists.newArrayList(); for (AbstractExecutable task : ((ChainedExecutable) executable).getTasks()) { tasks.add(parse(task)); } result.setTasks(tasks); } if (executable instanceof CheckpointExecutable) { List<ExecutablePO> tasksForCheck = Lists.newArrayList(); for (AbstractExecutable taskForCheck : ((CheckpointExecutable) executable).getSubTasksForCheck()) { tasksForCheck.add(parse(taskForCheck)); } result.setTasksForCheck(tasksForCheck); } return result; }