Skip to content

Commit

Permalink
NIFI-13846 [MiNiFi] Create default parameter context to enable runnin…
Browse files Browse the repository at this point in the history
…g empty flows received via C2

Signed-off-by: Ferenc Erdei <erdei.ferenc90@gmail.com>
This closes #9350.
  • Loading branch information
briansolo1985 authored and ferencerdei committed Oct 14, 2024
1 parent c3122b2 commit 66d378c
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.apache.nifi.flow.ScheduledState.ENABLED;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -51,6 +52,7 @@
import org.apache.nifi.flow.VersionedComponent;
import org.apache.nifi.flow.VersionedConfigurableExtension;
import org.apache.nifi.flow.VersionedControllerService;
import org.apache.nifi.flow.VersionedParameterContext;
import org.apache.nifi.flow.VersionedProcessGroup;
import org.apache.nifi.flow.VersionedProcessor;
import org.apache.nifi.flow.VersionedRemoteProcessGroup;
Expand All @@ -72,6 +74,7 @@ public class StandardFlowEnrichService implements FlowEnrichService {

private static final Logger LOG = LoggerFactory.getLogger(StandardFlowEnrichService.class);

private static final String DEFAULT_PARAMETER_CONTEXT = "default-parameter-context";
private static final String NIFI_BUNDLE_GROUP = "org.apache.nifi";
private static final String STANDARD_RESTRICTED_SSL_CONTEXT_SERVICE = "org.apache.nifi.ssl.StandardRestrictedSSLContextService";
private static final String RESTRICTED_SSL_CONTEXT_SERVICE_API = "org.apache.nifi.ssl.RestrictedSSLContextService";
Expand Down Expand Up @@ -136,6 +139,8 @@ public VersionedDataflow enrichFlow(VersionedDataflow versionedDataflow) {

createProvenanceReportingTask(parentSslControllerService).ifPresent(versionedDataflow.getReportingTasks()::add);

createDefaultParameterContext(versionedDataflow);

if (IS_LEGACY_COMPONENT.test(rootGroup)) {
LOG.info("Legacy flow detected. Initializing missing but mandatory properties on components");
initializeComponentsMissingProperties(rootGroup);
Expand All @@ -146,6 +151,25 @@ public VersionedDataflow enrichFlow(VersionedDataflow versionedDataflow) {
return versionedDataflow;
}

private void createDefaultParameterContext(VersionedDataflow versionedDataflow) {
VersionedParameterContext versionedParameterContext = new VersionedParameterContext();
versionedParameterContext.setIdentifier(DEFAULT_PARAMETER_CONTEXT);
versionedParameterContext.setInstanceIdentifier(DEFAULT_PARAMETER_CONTEXT);
versionedParameterContext.setName(DEFAULT_PARAMETER_CONTEXT);
versionedParameterContext.setDescription(DEFAULT_PARAMETER_CONTEXT);
versionedParameterContext.setParameters(new HashSet<>());

ofNullable(versionedDataflow.getParameterContexts())
.ifPresentOrElse(
versionedParameterContexts -> versionedParameterContexts.add(versionedParameterContext),
() -> {
List<VersionedParameterContext> parameterContexts = new ArrayList<>();
parameterContexts.add(versionedParameterContext);
versionedDataflow.setParameterContexts(parameterContexts);
}
);
}

private void enableControllerServices(VersionedProcessGroup processGroup) {
ofNullable(processGroup.getControllerServices()).orElseGet(Set::of)
.forEach(controllerService -> controllerService.setScheduledState(ENABLED));
Expand Down

0 comments on commit 66d378c

Please sign in to comment.