@Override protected void doResume() throws Exception { LOG.info("Resuming flow: " + flowSpec.getName()); lock.lock(); try { Futures.successfulAsList( Iterables.transform(flowlets.values(), new Function<ProgramController, ListenableFuture<ProgramController>>() { @Override public ListenableFuture<ProgramController> apply(ProgramController input) { return input.resume(); } })).get(); } finally { lock.unlock(); } LOG.info("Flow resumed: " + flowSpec.getName()); }
@Override protected void doSuspend() throws Exception { LOG.info("Suspending flow: " + flowSpec.getName()); lock.lock(); try { Futures.successfulAsList( Iterables.transform(flowlets.values(), new Function<ProgramController, ListenableFuture<ProgramController>>() { @Override public ListenableFuture<ProgramController> apply(ProgramController input) { return input.suspend(); } })).get(); } finally { lock.unlock(); } LOG.info("Flow suspended: " + flowSpec.getName()); }
@Override protected void doStop() throws Exception { LOG.info("Stopping flow: " + flowSpec.getName()); lock.lock(); try { Futures.successfulAsList( Iterables.transform(flowlets.values(), new Function<ProgramController, ListenableFuture<ProgramController>>() { @Override public ListenableFuture<ProgramController> apply(ProgramController input) { return input.stop(); } })).get(); } finally { lock.unlock(); } LOG.info("Flow stopped: " + flowSpec.getName()); }
@Override public JsonElement serialize(FlowSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("flowlets", serializeMap(src.getFlowlets(), context, FlowletDefinition.class)); jsonObj.add("connections", serializeList(src.getConnections(), context, FlowletConnection.class)); return jsonObj; }
public DefaultFlowSpecification(String className, FlowSpecification other) { this(className, other.getName(), other.getDescription(), other.getFlowlets(), other.getConnections()); }
@Override public void startFlow(File jarPath, String className, Map<String, String> userArgs) { try { Program program = deployClient.createProgram(jarPath, className, jarUnpackDir); String flowName = program.getSpecification().getName(); if (listAllFlows().contains(flowName)) { throw new Exception("Flow with the same name is running! Stop or Delete the Flow before starting again"); } Location jarInHDFS = location.append(flowName); //Delete any existing JAR with the same flowName. jarInHDFS.delete(); jarInHDFS.createNew(); //Copy the JAR to HDFS. ByteStreams.copy(Locations.newInputSupplier(program.getJarLocation()), Locations.newOutputSupplier(jarInHDFS)); //Start the Flow. deployClient.startFlow(program, userArgs); } catch (Exception e) { LOG.error(e.getMessage(), e); } }
Table<Node, String, Set<QueueSpecification>> table = HashBasedTable.create(); String flow = input.getName(); Map<String, FlowletDefinition> flowlets = input.getFlowlets();
@Override protected ProgramController launch(Program program, ProgramOptions options, File hConfFile, File cConfFile, ApplicationLauncher launcher) { // Extract and verify parameters FlowSpecification flowSpec = program.getSpecification(); ProgramType processorType = program.getType(); Preconditions.checkNotNull(processorType, "Missing processor type."); Preconditions.checkArgument(processorType == ProgramType.FLOW, "Only FLOW process type is supported."); try { Preconditions.checkNotNull(flowSpec, "Missing FlowSpecification for %s", program.getName()); for (FlowletDefinition flowletDefinition : flowSpec.getFlowlets().values()) { int maxInstances = flowletDefinition.getFlowletSpec().getMaxInstances(); Preconditions.checkArgument(flowletDefinition.getInstances() <= maxInstances, "Flowlet %s can have a maximum of %s instances", flowletDefinition.getFlowletSpec().getName(), maxInstances); } LOG.info("Configuring flowlets queues"); Multimap<String, QueueName> flowletQueues = FlowUtils.configureQueue(program, flowSpec, queueAdmin); // Launch flowlet program runners LOG.info("Launching distributed flow: " + program.getName() + ":" + flowSpec.getName()); TwillController controller = launcher.launch(new FlowTwillApplication(program, flowSpec, hConfFile, cConfFile, eventHandler)); DistributedFlowletInstanceUpdater instanceUpdater = new DistributedFlowletInstanceUpdater(program, controller, queueAdmin, flowletQueues); return new FlowTwillProgramController(program.getName(), controller, instanceUpdater).startListen(); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public TwillSpecification configure() { TwillSpecification.Builder.MoreRunnable moreRunnable = TwillSpecification.Builder.with() .setName(String.format("%s.%s", ProgramType.FLOW.name().toLowerCase(), spec.getName())) .withRunnable();