/** * Create a new builder that is initialized with properties of the given * definition. Useful for "mutating" a definition by building a slightly different * copy. * * @param definition the StreamAppDefinition to create a new Builder instance with * stream name, registeredAppName, label, and properties populated * @return a StreamAppDefinition builder */ public static Builder from(StreamAppDefinition definition) { Builder builder = new Builder(); builder.setStreamName(definition.getStreamName()).setRegisteredAppName(definition.getRegisteredAppName()) .setApplicationType(definition.getApplicationType()) .setLabel(definition.getName()).addProperties(definition.getProperties()); return builder; }
/** * Return a new instance of {@link StreamAppDefinition}. * * @param streamName the name of the stream * @return new instance of {@code StreamAppDefinition} */ public StreamAppDefinition build(String streamName) { if (this.label == null) { this.setLabel(this.registeredAppName); } return new StreamAppDefinition(this.registeredAppName, this.label, this.applicationType, streamName, this.properties); } }
/** * Determines a deployment key for a stream application. * * @param streamAppDefinition the stream application definition * @return the deployment key */ public static String forStreamAppDefinition(StreamAppDefinition streamAppDefinition) { Assert.notNull(streamAppDefinition, "streamAppDefinition must not be null"); return String.format("%s.%s", streamAppDefinition.getStreamName(), streamAppDefinition.getName()); }
private String getRegisteredName(StreamDefinition streamDefinition, String adrAppName) { for (StreamAppDefinition appDefinition: streamDefinition.getAppDefinitions()) { if (appDefinition.getName().equals(adrAppName)) { return appDefinition.getRegisteredAppName(); } } return adrAppName; }
@Override public String toString() { return "StreamAppDefinition [streamName=" + streamName + ", name=" + this.appDefinition.getName() + ", type=" + getApplicationType()+", registeredAppName=" + getRegisteredAppName() + ", properties=" + this.appDefinition.getProperties() + "]"; }
/** * Return the {@link ApplicationType} for a {@link AppDefinition} in the context of a * defined stream. * * @param appDefinition the app for which to determine the type * @return {@link ApplicationType} for the given app * @throws CannotDetermineApplicationTypeException Thrown if the * {@link ApplicationType} cannot be determined */ public static ApplicationType determineApplicationType(StreamAppDefinition appDefinition) { // Parser has already taken care of source/sink destinations, etc boolean hasOutput = appDefinition.getProperties().containsKey(BindingPropertyKeys.OUTPUT_DESTINATION); boolean hasInput = appDefinition.getProperties().containsKey(BindingPropertyKeys.INPUT_DESTINATION); if (hasInput && hasOutput) { return ApplicationType.processor; } else if (hasInput) { return ApplicationType.sink; } else if (hasOutput) { return ApplicationType.source; } else { throw new CannotDetermineApplicationTypeException( appDefinition.getName() + " had neither input nor " + "output set"); } } }
CompletionProposal.Factory proposals = CompletionProposal.expanding(":" + streamName + "."); for (StreamAppDefinition streamAppDefinition : streamDefinition.getAppDefinitions()) { ApplicationType applicationType = streamAppDefinition.getApplicationType(); if (streamAppDefinition.getName().startsWith(appName) && !applicationType.equals(ApplicationType.sink)) { collector.add(proposals.withSuffix(streamAppDefinition.getName()));
while (iterator.hasNext()) { StreamAppDefinition currentApp = iterator.next(); ApplicationType type = currentApp.getApplicationType(); AppRegistration appRegistration = this.appRegistry.find(currentApp.getRegisteredAppName(), type); Assert.notNull(appRegistration, String.format("no application '%s' of type '%s' exists in the registry", currentApp.getName(), type)); .extractAndQualifyDeployerProperties(updateProperties, currentApp.getName()); AppDefinition appDefinition = new AppDefinition(currentApp.getName(), expandedAppUpdateTimeProperties);
private String extractAppVersionProperty(StreamAppDefinition appDefinition, Map<String, String> updateProperties) { String versionPrefix = String.format("version.%s", appDefinition.getName()); for (Map.Entry<String, String> entry : updateProperties.entrySet()) { if (entry.getKey().startsWith(versionPrefix)) { return entry.getValue(); } } return null; }
/** * Return the type(s) a given stream app definition <em>could</em> have, in the * context of code completion. */ static ApplicationType[] determinePotentialTypes(StreamAppDefinition appDefinition, boolean multipleAppsInStreamDefinition) { Set<String> properties = appDefinition.getProperties().keySet(); if (properties.contains(BindingPropertyKeys.INPUT_DESTINATION)) { // Can't be source. For the purpose of completion, being the last app // (hence having BindingPropertyKeys.OUTPUT_DESTINATION not set) does NOT // guarantee we're dealing // with a sink (could be an unfinished "source | processor | processor" // stream) if (properties.contains(BindingPropertyKeys.OUTPUT_DESTINATION)) { return new ApplicationType[] { ApplicationType.processor }; } else { return new ApplicationType[] { ApplicationType.processor, ApplicationType.sink }; } } else { // Multiple apps and no binding properties indicates unbound app sequence (a,b,c) if (multipleAppsInStreamDefinition) { return new ApplicationType[] { ApplicationType.app }; } else { return new ApplicationType[] { ApplicationType.source, ApplicationType.app }; } } }
/** * Return {@code true} if the upstream app (the app that appears before the provided app) * contains partition related properties. * * @param stream stream for the app * @param currentApp app for which to determine if the upstream app has partition * properties * @param streamDeploymentProperties deployment properties for the stream * @return true if the upstream app has partition properties */ /* default */ boolean upstreamAppHasPartitionInfo(StreamDefinition stream, StreamAppDefinition currentApp, Map<String, String> streamDeploymentProperties) { Iterator<StreamAppDefinition> iterator = stream.getDeploymentOrderIterator(); while (iterator.hasNext()) { StreamAppDefinition app = iterator.next(); if (app.equals(currentApp) && iterator.hasNext()) { StreamAppDefinition prevApp = iterator.next(); Map<String, String> appDeploymentProperties = extractAppProperties(prevApp, streamDeploymentProperties); return appDeploymentProperties.containsKey(BindingPropertyKeys.OUTPUT_PARTITION_KEY_EXPRESSION) || appDeploymentProperties .containsKey(BindingPropertyKeys.OUTPUT_PARTITION_KEY_EXTRACTOR_CLASS); } } return false; }
/** * Return a new app definition where definition-time and deploy-time properties have been * merged and short form parameters have been expanded to their long form (amongst the * whitelisted supported properties of the app) if applicable. */ /* default */ AppDefinition mergeAndExpandAppProperties(StreamAppDefinition original, Resource metadataResource, Map<String, String> appDeployTimeProperties) { Map<String, String> merged = new HashMap<>(original.getProperties()); merged.putAll(appDeployTimeProperties); merged = this.whitelistProperties.qualifyProperties(merged, metadataResource); merged.putIfAbsent(StreamPropertyKeys.METRICS_PROPERTIES, "spring.application.name,spring.application.index," + "spring.cloud.application.*,spring.cloud.dataflow.*"); merged.putIfAbsent(StreamPropertyKeys.METRICS_TRIGGER_INCLUDES, "integration**"); return new AppDefinition(original.getName(), merged); }
@Override public ValidationStatus validateStream(String name) { StreamDefinition definition = streamDefinitionRepository.findById(name) .orElseThrow(() -> new NoSuchStreamDefinitionException(name)); ValidationStatus validationStatus = new ValidationStatus( definition.getName(), definition.getDslText()); for (StreamAppDefinition streamAppDefinition : definition.getAppDefinitions()) { ApplicationType appType = streamAppDefinition.getApplicationType(); boolean status = this.validate(streamAppDefinition.getName(), appType); validationStatus.getAppsStatuses().put( String.format("%s:%s", appType.name(), streamAppDefinition.getName()), (status) ? NodeStatus.valid.name() : NodeStatus.invalid.name()); } return validationStatus; } }
while (iterator.hasNext()) { StreamAppDefinition currentApp = iterator.next(); ApplicationType type = currentApp.getApplicationType(); AppRegistration appRegistration = this.appRegistry.find(currentApp.getRegisteredAppName(), type); Assert.notNull(appRegistration, String.format("no application '%s' of type '%s' exists in the registry", currentApp.getName(), type)); .extractAndQualifyDeployerProperties(updateProperties, currentApp.getName()); AppDefinition appDefinition = new AppDefinition(currentApp.getName(), expandedAppUpdateTimeProperties);
private String extractAppVersionProperty(StreamAppDefinition appDefinition, Map<String, String> updateProperties) { String versionPrefix = String.format("version.%s", appDefinition.getName()); for (Map.Entry<String, String> entry : updateProperties.entrySet()) { if (entry.getKey().startsWith(versionPrefix)) { return entry.getValue(); } } return null; }
StreamDeployment streamDeployment = this.streamService.info(streamDefinition.getName()); for (StreamAppDefinition streamAppDefinition : streamDefinition.getAppDefinitions()) { final String streamAppName = streamAppDefinition.getRegisteredAppName(); final ApplicationType streamAppType = streamAppDefinition.getApplicationType(); if (appType != streamAppType) { continue;
private String getRegisteredName(StreamDefinition streamDefinition, String adrAppName) { for (StreamAppDefinition appDefinition : streamDefinition.getAppDefinitions()) { if (appDefinition.getName().equals(adrAppName)) { return appDefinition.getRegisteredAppName(); } } return adrAppName; }
/** * Redacts sensitive property values in a stream. * * @param streamDefinition the stream definition to sanitize * @return Stream definition text that has sensitive data redacted. */ public String sanitizeStream(StreamDefinition streamDefinition) { List<StreamAppDefinition> sanitizedAppDefinitions = streamDefinition.getAppDefinitions().stream() .map(app -> StreamAppDefinition.Builder .from(app) .setProperties(this.sanitizeProperties(app.getProperties())) .build(streamDefinition.getName()) ).collect(Collectors.toList()); return this.streamDslConverter.toDsl(sanitizedAppDefinitions); }
/** * Return {@code true} if the upstream app (the app that appears before the provided app) * contains partition related properties. * * @param stream stream for the app * @param currentApp app for which to determine if the upstream app has partition * properties * @param streamDeploymentProperties deployment properties for the stream * @return true if the upstream app has partition properties */ /* default */ boolean upstreamAppHasPartitionInfo(StreamDefinition stream, StreamAppDefinition currentApp, Map<String, String> streamDeploymentProperties) { Iterator<StreamAppDefinition> iterator = stream.getDeploymentOrderIterator(); while (iterator.hasNext()) { StreamAppDefinition app = iterator.next(); if (app.equals(currentApp) && iterator.hasNext()) { StreamAppDefinition prevApp = iterator.next(); Map<String, String> appDeploymentProperties = extractAppProperties(prevApp, streamDeploymentProperties); return appDeploymentProperties.containsKey(BindingPropertyKeys.OUTPUT_PARTITION_KEY_EXPRESSION) || appDeploymentProperties .containsKey(BindingPropertyKeys.OUTPUT_PARTITION_KEY_EXTRACTOR_CLASS); } } return false; }
Map<String, String> props = appDefinition.getProperties(); String inputDestination = props.get(BindingPropertyKeys.INPUT_DESTINATION); String outputDestination = props.get(BindingPropertyKeys.OUTPUT_DESTINATION); if (inputGroup != null && !inputGroup.equals(appDefinition.getStreamName())) { dslBuilder.append(" --group=").append(inputGroup); dslBuilder.append(appDefinition.getName()); if (!appDefinition.getName().equals(appDefinition.getRegisteredAppName())) { dslBuilder.append(": ").append(appDefinition.getRegisteredAppName()); if (appDefinition.getApplicationType() != ApplicationType.app) { dslBuilder.append(" | "); } else {