public StreamDefinition(String name, DataFlowOperations client, String definition, List<StreamApplication> applications) { this.name = name; this.client = client; this.definition = definition; this.applications = applications; if (StringUtils.isEmpty(definition)) { createStreamDefinition(); } this.client.streamOperations().createStream(this.name, this.definition, false); }
/** * Destroy the stream from the server. This method invokes the remote server */ public void destroy() { client.streamOperations().destroy(this.name); }
/** * Undeploy the current {@link Stream}. This method invokes the remote server * @return A reference the the {@link StreamDefinition} so one can invoke other builder operations such as {@link StreamDefinition#deploy()} */ public StreamDefinition undeploy() { client.streamOperations().undeploy(this.name); return new StreamDefinition(this.name, this.client, this.definition, this.applications); }
/** * Deploy the current stream using the deploymentProperties. This method invokes the * remote server * @param deploymentProperties Map of properties to be used during deployment * @return A deployed {@link Stream} */ public Stream deploy(Map<String, String> deploymentProperties) { Map<String, String> resolvedProperties = resolveDeploymentProperties( deploymentProperties); client.streamOperations().deploy(this.name, resolvedProperties); return new Stream(this.name, this.applications, this.definition, this.client); }
@CliCommand(value = LIST_STREAM, help = "List created streams") public Table listStreams() { final PagedResources<StreamDefinitionResource> streams = streamOperations().list(); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Stream Name"); headers.put("dslText", "Stream Definition"); headers.put("statusDescription", "Status"); BeanListTableModel<StreamDefinitionResource> model = new BeanListTableModel<>(streams, headers); return DataFlowTables.applyStyle(new TableBuilder(model)).build(); }
@CliCommand(value = STREAM_MANIFEST_GET, help = "Get manifest for the stream deployed using Skipper") public String getManifest( @CliOption(key = { "", "name" }, help = "the name of the stream", mandatory = true, optionContext = "existing-stream " + "disable-string-converter") String name, @CliOption(key = { "releaseVersion" }, help = "the Skipper release version to get the manifest for", unspecifiedDefaultValue = "0") int releaseVersion) { return streamOperations().getManifest(name, releaseVersion); }
/** * @return Status of the deployed stream */ public String getStatus() { StreamDefinitionResource resource = client.streamOperations() .getStreamDefinition(this.name); return resource.getStatus(); }
@CliCommand(value = DESTROY_STREAM_ALL, help = "Destroy all existing streams") public String destroyAllStreams( @CliOption(key = "force", help = "bypass confirmation prompt", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean force) { if (force || "y".equalsIgnoreCase(userInput.promptWithOptions("Really destroy all streams?", "n", "y", "n"))) { streamOperations().destroyAll(); return "Destroyed all streams"; } else { return ""; } }
@CliCommand(value = STREAM_HISTORY, help = "Get history for the stream deployed using Skipper") public Table history( @CliOption(key = { "", "name" }, help = "the name of the stream", mandatory = true, optionContext = "existing-stream " + "disable-string-converter") String name) { Collection<Release> releases = streamOperations().history(name); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("version", "Version"); headers.put("info.lastDeployed", "Last updated"); headers.put("info.status.statusCode", "Status"); headers.put("pkg.metadata.name", "Package Name"); headers.put("pkg.metadata.version", "Package Version"); headers.put("info.description", "Description"); TableModel model = new BeanListTableModel<>(releases, headers); TableBuilder tableBuilder = new TableBuilder(model); DataFlowTables.applyStyle(tableBuilder); return tableBuilder.build(); }
@CliCommand(value = INFO_STREAM, help = "Show information about a specific stream") public List<Object> streamInfo(@CliOption(key = { "", "name" }, help = "the name of the stream to show", mandatory = true, optionContext = "existing-stream disable-string-converter") String name) { List<Object> result = new ArrayList<>(); final StreamDeploymentResource stream = streamOperations().info(name); TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>(); modelBuilder.addRow().addValue("Stream Name").addValue("Stream Definition").addValue("Status"); modelBuilder.addRow().addValue(stream.getStreamName()) .addValue(stream.getDslText()) .addValue(stream.getStatus()); TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build())); result.add(builder.build()); if (StringUtils.hasText(stream.getDeploymentProperties())) { //TODO: rename Deployment properties for Skipper as it includes apps' info (app:version) as well result.add(String.format("Stream Deployment properties: %s", ShellUtils.prettyPrintIfJson(stream.getDeploymentProperties()))); } return result; }
/** * Deploy the current stream using the deploymentProperties. This method invokes the * remote server * @param deploymentProperties Map of properties to be used during deployment * @return A deployed {@link Stream} */ public Stream deploy(Map<String, String> deploymentProperties) { Map<String, String> resolvedProperties = resolveDeploymentProperties( deploymentProperties); client.streamOperations().deploy(this.name, resolvedProperties); return new Stream(this.name, this.applications, this.definition, this.client); }
@CliCommand(value = LIST_STREAM, help = "List created streams") public Table listStreams() { final PagedResources<StreamDefinitionResource> streams = streamOperations().list(); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("name", "Stream Name"); headers.put("dslText", "Stream Definition"); headers.put("statusDescription", "Status"); BeanListTableModel<StreamDefinitionResource> model = new BeanListTableModel<>(streams, headers); return DataFlowTables.applyStyle(new TableBuilder(model)).build(); }
@CliCommand(value = STREAM_SKIPPER_MANIFEST_GET, help = "Get manifest for the stream deployed using Skipper") public String getManifest( @CliOption(key = { "", "name" }, help = "the name of the stream", mandatory = true, optionContext = "existing-stream " + "disable-string-converter") String name, @CliOption(key = { "releaseVersion" }, help = "the Skipper release version to get the manifest for", unspecifiedDefaultValue = "0") int releaseVersion) { return streamOperations().getManifest(name, releaseVersion); }
/** * @return Status of the deployed stream */ public String getStatus() { StreamDefinitionResource resource = client.streamOperations() .getStreamDefinition(this.name); return resource.getStatus(); }
@CliCommand(value = DESTROY_STREAM_ALL, help = "Destroy all existing streams") public String destroyAllStreams( @CliOption(key = "force", help = "bypass confirmation prompt", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") boolean force) { if (force || "y".equalsIgnoreCase(userInput.promptWithOptions("Really destroy all streams?", "n", "y", "n"))) { streamOperations().destroyAll(); return "Destroyed all streams"; } else { return ""; } }
@CliCommand(value = STREAM_SKIPPER_HISTORY, help = "Get history for the stream deployed using Skipper") public Table history( @CliOption(key = { "", "name" }, help = "the name of the stream", mandatory = true, optionContext = "existing-stream " + "disable-string-converter") String name) { Collection<Release> releases = streamOperations().history(name); LinkedHashMap<String, Object> headers = new LinkedHashMap<>(); headers.put("version", "Version"); headers.put("info.lastDeployed", "Last updated"); headers.put("info.status.statusCode", "Status"); headers.put("pkg.metadata.name", "Package Name"); headers.put("pkg.metadata.version", "Package Version"); headers.put("info.description", "Description"); TableModel model = new BeanListTableModel<>(releases, headers); TableBuilder tableBuilder = new TableBuilder(model); DataFlowTables.applyStyle(tableBuilder); return tableBuilder.build(); }
@CliCommand(value = INFO_STREAM, help = "Show information about a specific stream") public List<Object> streamInfo(@CliOption(key = { "", "name" }, help = "the name of the stream to show", mandatory = true, optionContext = "existing-stream disable-string-converter") String name) { List<Object> result = new ArrayList<>(); final StreamDeploymentResource stream = streamOperations().info(name); TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>(); modelBuilder.addRow().addValue("Stream Name").addValue("Stream Definition").addValue("Status"); modelBuilder.addRow().addValue(stream.getStreamName()) .addValue(stream.getDslText()) .addValue(stream.getStatus()); TableBuilder builder = DataFlowTables.applyStyle(new TableBuilder(modelBuilder.build())); result.add(builder.build()); if (StringUtils.hasText(stream.getDeploymentProperties())) { //TODO: rename Deployment properties for Skipper as it includes apps' info (app:version) as well result.add(String.format("Stream Deployment properties: %s", ShellUtils.prettyPrintIfJson(stream.getDeploymentProperties()))); } return result; }
/** * Destroy the stream from the server. This method invokes the remote server */ public void destroy() { this.client.streamOperations().destroy(this.name); }
@CliCommand(value = STREAM_DEPLOY, help = "Deploy a previously created stream using Skipper") public String deployStream( @CliOption(key = { "", "name" }, help = "the name of the stream to deploy", mandatory = true, optionContext = "existing-stream disable-string-converter") String name, @CliOption(key = { PROPERTIES_OPTION }, help = "the properties for this deployment") String deploymentProperties, @CliOption(key = { PROPERTIES_FILE_OPTION }, help = "the properties for this deployment (as a File)") File propertiesFile, @CliOption(key = "packageVersion", help = "the package version of the package to deploy. Default is 1.0.0", unspecifiedDefaultValue = "1.0.0") String packageVersion, @CliOption(key = "platformName", help = "the name of the target platform to deploy to") String platformName, @CliOption(key = "repoName", help = "the name of the local repository to upload the package to") String repoName) throws IOException { int which = Assertions.atMostOneOf(PROPERTIES_OPTION, deploymentProperties, PROPERTIES_FILE_OPTION, propertiesFile); Map<String, String> propertiesToUse = DeploymentPropertiesUtils.parseDeploymentProperties(deploymentProperties, propertiesFile, which); propertiesToUse.put(SkipperStream.SKIPPER_PACKAGE_NAME, name); Assert.isTrue(StringUtils.hasText(packageVersion), "Package version must be set."); propertiesToUse.put(SkipperStream.SKIPPER_PACKAGE_VERSION, packageVersion); if (StringUtils.hasText(platformName)) { propertiesToUse.put(SkipperStream.SKIPPER_PLATFORM_NAME, platformName); } if (StringUtils.hasText(repoName)) { propertiesToUse.put(SkipperStream.SKIPPER_REPO_NAME, repoName); } streamOperations().deploy(name, propertiesToUse); return String.format("Deployment request has been sent for stream '%s'", name); }
/** * Undeploy the current {@link Stream}. This method invokes the remote server * @return A reference the the {@link StreamDefinition} so one can invoke other builder operations such as {@link StreamDefinition#deploy()} */ public StreamDefinition undeploy() { client.streamOperations().undeploy(this.name); return new StreamDefinition(this.name, this.client, this.definition, this.applications); }