use of com.hortonworks.streamline.streams.actions.TopologyActionContext in project streamline by hortonworks.
the class StormTopologyActionsImpl method deploy.
@Override
public void deploy(TopologyLayout topology, String mavenArtifacts, TopologyActionContext ctx, String asUser) throws Exception {
ctx.setCurrentAction("Adding artifacts to jar");
Path jarToDeploy = addArtifactsToJar(getArtifactsLocation(topology));
ctx.setCurrentAction("Creating Storm topology YAML file");
String fileName = createYamlFileForDeploy(topology);
ctx.setCurrentAction("Deploying topology via 'storm jar' command");
List<String> commands = new ArrayList<String>();
commands.add(stormCliPath);
commands.add("jar");
commands.add(jarToDeploy.toString());
commands.addAll(getExtraJarsArg(topology));
commands.addAll(getMavenArtifactsRelatedArgs(mavenArtifacts));
commands.addAll(getNimbusConf());
commands.addAll(getSecuredClusterConf(asUser));
commands.add("org.apache.storm.flux.Flux");
commands.add("--remote");
commands.add(fileName);
LOG.info("Deploying Application {}", topology.getName());
LOG.info(String.join(" ", commands));
Process process = executeShellProcess(commands);
ShellProcessResult shellProcessResult = waitProcessFor(process);
int exitValue = shellProcessResult.exitValue;
if (exitValue != 0) {
LOG.error("Topology deploy command failed - exit code: {} / output: {}", exitValue, shellProcessResult.stdout);
String[] lines = shellProcessResult.stdout.split("\\n");
String errors = Arrays.stream(lines).filter(line -> line.startsWith("Exception") || line.startsWith("Caused by")).collect(Collectors.joining(", "));
Pattern pattern = Pattern.compile("Topology with name `(.*)` already exists on cluster");
Matcher matcher = pattern.matcher(errors);
if (matcher.find()) {
throw new TopologyAlreadyExistsOnCluster(matcher.group(1));
} else {
throw new Exception("Topology could not be deployed successfully: storm deploy command failed with " + errors);
}
}
}
Aggregations