Java Code Examples for org.apache.nifi.registry.flow.VersionedProcessGroup#setControllerServices()

The following examples show how to use org.apache.nifi.registry.flow.VersionedProcessGroup#setControllerServices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void populateVersionedContentsRecursively(final VersionedProcessGroup group, final NiFiUser user) throws NiFiRegistryException, IOException {
    if (group == null) {
        return;
    }

    final VersionedFlowCoordinates coordinates = group.getVersionedFlowCoordinates();
    if (coordinates != null) {
        final String registryUrl = coordinates.getRegistryUrl();
        final String bucketId = coordinates.getBucketId();
        final String flowId = coordinates.getFlowId();
        final int version = coordinates.getVersion();

        final RegistryUtil subFlowUtil = new RegistryUtil(registryUrl, sslContext);
        final VersionedFlowSnapshot snapshot = subFlowUtil.getFlowByID(bucketId, flowId, version);
        final VersionedProcessGroup contents = snapshot.getFlowContents();

        group.setComments(contents.getComments());
        group.setConnections(contents.getConnections());
        group.setControllerServices(contents.getControllerServices());
        group.setFunnels(contents.getFunnels());
        group.setInputPorts(contents.getInputPorts());
        group.setLabels(contents.getLabels());
        group.setOutputPorts(contents.getOutputPorts());
        group.setProcessGroups(contents.getProcessGroups());
        group.setProcessors(contents.getProcessors());
        group.setRemoteProcessGroups(contents.getRemoteProcessGroups());
        group.setVariables(contents.getVariables());
        coordinates.setLatest(snapshot.isLatest());
    }

    for (final VersionedProcessGroup child : group.getProcessGroups()) {
        populateVersionedContentsRecursively(child, user);
    }
}
 
Example 2
Source File: ImportFlowIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
private VersionedFlowSnapshot createFlowSnapshot(final List<ControllerServiceNode> controllerServices, final List<ProcessorNode> processors, final Set<Parameter> parameters) {
    final VersionedFlowSnapshotMetadata snapshotMetadata = new VersionedFlowSnapshotMetadata();
    snapshotMetadata.setAuthor("unit-test");
    snapshotMetadata.setBucketIdentifier("unit-test-bucket");
    snapshotMetadata.setFlowIdentifier("unit-test-flow");
    snapshotMetadata.setTimestamp(System.currentTimeMillis());
    snapshotMetadata.setVersion(1);

    final Bucket bucket = new Bucket();
    bucket.setCreatedTimestamp(System.currentTimeMillis());
    bucket.setIdentifier("unit-test-bucket");
    bucket.setName("Unit Test Bucket");

    final VersionedFlow flow = new VersionedFlow();
    flow.setBucketIdentifier("unit-test-bucket");
    flow.setBucketName("Unit Test Bucket");
    flow.setCreatedTimestamp(System.currentTimeMillis());
    flow.setIdentifier("unit-test-flow");
    flow.setName("Unit Test Flow");

    final BundleCoordinate coordinate = getSystemBundle().getBundleDetails().getCoordinate();
    final Bundle bundle = new Bundle();
    bundle.setArtifact(coordinate.getId());
    bundle.setGroup(coordinate.getGroup());
    bundle.setVersion(coordinate.getVersion());

    final NiFiRegistryFlowMapper flowMapper = new NiFiRegistryFlowMapper(getExtensionManager());

    final Set<VersionedProcessor> versionedProcessors = new HashSet<>();
    for (final ProcessorNode processor : processors) {
        final VersionedProcessor versionedProcessor = flowMapper.mapProcessor(processor, getFlowController().getControllerServiceProvider(), Collections.emptySet(), new HashMap<>());
        versionedProcessors.add(versionedProcessor);
        processor.setVersionedComponentId(versionedProcessor.getIdentifier());
    }

    final Set<VersionedControllerService> services = new HashSet<>();
    for (final ControllerServiceNode serviceNode : controllerServices) {
        final VersionedControllerService service = flowMapper.mapControllerService(serviceNode, getFlowController().getControllerServiceProvider(), Collections.emptySet(), new HashMap<>());
        services.add(service);
        serviceNode.setVersionedComponentId(service.getIdentifier());
    }

    final VersionedProcessGroup flowContents = new VersionedProcessGroup();
    flowContents.setIdentifier("unit-test-flow-contents");
    flowContents.setName("Unit Test");
    flowContents.setProcessors(versionedProcessors);
    flowContents.setControllerServices(services);

    final VersionedFlowSnapshot versionedFlowSnapshot = new VersionedFlowSnapshot();
    versionedFlowSnapshot.setSnapshotMetadata(snapshotMetadata);
    versionedFlowSnapshot.setBucket(bucket);
    versionedFlowSnapshot.setFlow(flow);
    versionedFlowSnapshot.setFlowContents(flowContents);

    if (parameters != null) {
        final Set<VersionedParameter> versionedParameters = new HashSet<>();
        for (final Parameter parameter : parameters) {
            final VersionedParameter versionedParameter = new VersionedParameter();
            versionedParameter.setName(parameter.getDescriptor().getName());
            versionedParameter.setValue(parameter.getValue());
            versionedParameter.setSensitive(parameter.getDescriptor().isSensitive());

            versionedParameters.add(versionedParameter);
        }

        final VersionedParameterContext versionedParameterContext = new VersionedParameterContext();
        versionedParameterContext.setName("Unit Test Context");
        versionedParameterContext.setParameters(versionedParameters);
        versionedFlowSnapshot.setParameterContexts(Collections.singletonMap(versionedParameterContext.getName(), versionedParameterContext));

        flowContents.setParameterContextName("Unit Test Context");
    }

    return versionedFlowSnapshot;
}