Search in sources :

Example 1 with TopologyAlreadyExistsOnCluster

use of com.hortonworks.streamline.common.exception.service.exception.request.TopologyAlreadyExistsOnCluster 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);
        }
    }
}
Also used : Path(java.nio.file.Path) HiveSink(com.hortonworks.streamline.streams.layout.component.impl.HiveSink) Arrays(java.util.Arrays) StormTopologyUtil(com.hortonworks.streamline.streams.storm.common.StormTopologyUtil) LoggerFactory(org.slf4j.LoggerFactory) StormJaasCreator(com.hortonworks.streamline.streams.storm.common.StormJaasCreator) StringUtils(org.apache.commons.lang3.StringUtils) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Matcher(java.util.regex.Matcher) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) Path(java.nio.file.Path) Config(com.hortonworks.streamline.common.Config) StormTopologyValidator(com.hortonworks.streamline.streams.layout.storm.StormTopologyValidator) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) HdfsSink(com.hortonworks.streamline.streams.layout.component.impl.HdfsSink) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StormTopologyFluxGenerator(com.hortonworks.streamline.streams.layout.storm.StormTopologyFluxGenerator) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) IOUtils(org.apache.commons.io.IOUtils) StatusImpl(com.hortonworks.streamline.streams.actions.StatusImpl) List(java.util.List) HBaseSink(com.hortonworks.streamline.streams.layout.component.impl.HBaseSink) StormTopologyLayoutConstants(com.hortonworks.streamline.streams.layout.storm.StormTopologyLayoutConstants) HdfsSource(com.hortonworks.streamline.streams.layout.component.impl.HdfsSource) LogLevelLoggerResponse(com.hortonworks.streamline.streams.storm.common.logger.LogLevelLoggerResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) ClientConfig(org.glassfish.jersey.client.ClientConfig) TopologyLayoutConstants(com.hortonworks.streamline.streams.layout.TopologyLayoutConstants) Client(javax.ws.rs.client.Client) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyAlreadyExistsOnCluster(com.hortonworks.streamline.common.exception.service.exception.request.TopologyAlreadyExistsOnCluster) Yaml(org.yaml.snakeyaml.Yaml) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) DumperOptions(org.yaml.snakeyaml.DumperOptions) LinkedHashMap(java.util.LinkedHashMap) ClientBuilder(javax.ws.rs.client.ClientBuilder) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) OutputStreamWriter(java.io.OutputStreamWriter) TopologyActionContext(com.hortonworks.streamline.streams.actions.TopologyActionContext) Logger(org.slf4j.Logger) StormRestAPIClient(com.hortonworks.streamline.streams.storm.common.StormRestAPIClient) LogLevelResponse(com.hortonworks.streamline.streams.storm.common.logger.LogLevelResponse) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Constants(com.hortonworks.streamline.streams.cluster.Constants) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) Subject(javax.security.auth.Subject) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Collections(java.util.Collections) InputStream(java.io.InputStream) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) IOException(java.io.IOException) TopologyAlreadyExistsOnCluster(com.hortonworks.streamline.common.exception.service.exception.request.TopologyAlreadyExistsOnCluster)

Aggregations

Joiner (com.google.common.base.Joiner)1 Lists (com.google.common.collect.Lists)1 Config (com.hortonworks.streamline.common.Config)1 TopologyAlreadyExistsOnCluster (com.hortonworks.streamline.common.exception.service.exception.request.TopologyAlreadyExistsOnCluster)1 StatusImpl (com.hortonworks.streamline.streams.actions.StatusImpl)1 TopologyActionContext (com.hortonworks.streamline.streams.actions.TopologyActionContext)1 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)1 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)1 Constants (com.hortonworks.streamline.streams.cluster.Constants)1 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)1 TopologyNotAliveException (com.hortonworks.streamline.streams.exception.TopologyNotAliveException)1 TopologyLayoutConstants (com.hortonworks.streamline.streams.layout.TopologyLayoutConstants)1 InputComponent (com.hortonworks.streamline.streams.layout.component.InputComponent)1 OutputComponent (com.hortonworks.streamline.streams.layout.component.OutputComponent)1 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)1 TopologyLayout (com.hortonworks.streamline.streams.layout.component.TopologyLayout)1 HBaseSink (com.hortonworks.streamline.streams.layout.component.impl.HBaseSink)1 HdfsSink (com.hortonworks.streamline.streams.layout.component.impl.HdfsSink)1 HdfsSource (com.hortonworks.streamline.streams.layout.component.impl.HdfsSource)1 HiveSink (com.hortonworks.streamline.streams.layout.component.impl.HiveSink)1