Search in sources :

Example 11 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.

the class RemoteProcessGroupEntityMergerTest method testMergeRemoteProcessGroups.

@Test
public void testMergeRemoteProcessGroups() throws Exception {
    final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1", 8080, "host-1", 19998, null, null, null, false);
    final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2", 8081, "host-2", 19999, null, null, null, false);
    final PermissionsDTO permissed = new PermissionsDTO();
    permissed.setCanRead(true);
    permissed.setCanWrite(true);
    final RemoteProcessGroupStatusDTO status = new RemoteProcessGroupStatusDTO();
    status.setAggregateSnapshot(new RemoteProcessGroupStatusSnapshotDTO());
    final RemoteProcessGroupPortDTO in1_1 = new RemoteProcessGroupPortDTO();
    in1_1.setName("in1");
    final RemoteProcessGroupPortDTO in1_2 = new RemoteProcessGroupPortDTO();
    in1_2.setName("in2");
    final Set<RemoteProcessGroupPortDTO> inputs1 = new HashSet<>();
    inputs1.add(in1_1);
    inputs1.add(in1_2);
    final RemoteProcessGroupPortDTO out1_1 = new RemoteProcessGroupPortDTO();
    out1_1.setName("out1");
    final Set<RemoteProcessGroupPortDTO> outputs1 = new HashSet<>();
    outputs1.add(out1_1);
    final RemoteProcessGroupContentsDTO contents1 = new RemoteProcessGroupContentsDTO();
    contents1.setInputPorts(inputs1);
    contents1.setOutputPorts(outputs1);
    final RemoteProcessGroupDTO rpg1 = new RemoteProcessGroupDTO();
    rpg1.setContents(contents1);
    final RemoteProcessGroupEntity entity1 = new RemoteProcessGroupEntity();
    entity1.setPermissions(permissed);
    entity1.setStatus(status);
    entity1.setComponent(rpg1);
    final RemoteProcessGroupPortDTO in2_1 = new RemoteProcessGroupPortDTO();
    in2_1.setName("in1");
    final Set<RemoteProcessGroupPortDTO> inputs2 = new HashSet<>();
    inputs2.add(in2_1);
    final RemoteProcessGroupPortDTO out2_1 = new RemoteProcessGroupPortDTO();
    out2_1.setName("out1");
    final RemoteProcessGroupPortDTO out2_2 = new RemoteProcessGroupPortDTO();
    out2_2.setName("out2");
    final Set<RemoteProcessGroupPortDTO> outputs2 = new HashSet<>();
    outputs2.add(out2_1);
    outputs2.add(out2_2);
    final RemoteProcessGroupContentsDTO contents2 = new RemoteProcessGroupContentsDTO();
    contents2.setInputPorts(inputs2);
    contents2.setOutputPorts(outputs2);
    final RemoteProcessGroupDTO rpg2 = new RemoteProcessGroupDTO();
    rpg2.setContents(contents2);
    final RemoteProcessGroupEntity entity2 = new RemoteProcessGroupEntity();
    entity2.setPermissions(permissed);
    entity2.setStatus(status);
    entity2.setComponent(rpg2);
    final Map<NodeIdentifier, RemoteProcessGroupEntity> nodeMap = new HashMap<>();
    nodeMap.put(node1, entity1);
    nodeMap.put(node2, entity2);
    final RemoteProcessGroupEntityMerger merger = new RemoteProcessGroupEntityMerger();
    merger.merge(entity1, nodeMap);
    // should only include ports in common to all rpg's
    assertEquals(1, entity1.getComponent().getContents().getInputPorts().size());
    assertEquals("in1", entity1.getComponent().getContents().getInputPorts().iterator().next().getName());
    assertEquals(1, entity1.getComponent().getContents().getOutputPorts().size());
    assertEquals("out1", entity1.getComponent().getContents().getOutputPorts().iterator().next().getName());
}
Also used : HashMap(java.util.HashMap) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) RemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.

the class RemoteProcessGroupResource method updateRemoteProcessGroupInputPort.

/**
 * Updates the specified remote process group input port.
 *
 * @param httpServletRequest           request
 * @param id                           The id of the remote process group to update.
 * @param portId                       The id of the input port to update.
 * @param requestRemoteProcessGroupPortEntity The remoteProcessGroupPortEntity
 * @return A remoteProcessGroupPortEntity
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/input-ports/{port-id}")
@ApiOperation(value = "Updates a remote port", notes = NON_GUARANTEED_ENDPOINT, response = RemoteProcessGroupPortEntity.class, authorizations = { @Authorization(value = "Write - /remote-process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateRemoteProcessGroupInputPort(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The remote process group id.", required = true) @PathParam("id") final String id, @ApiParam(value = "The remote process group port id.", required = true) @PathParam("port-id") final String portId, @ApiParam(value = "The remote process group port.", required = true) final RemoteProcessGroupPortEntity requestRemoteProcessGroupPortEntity) {
    if (requestRemoteProcessGroupPortEntity == null || requestRemoteProcessGroupPortEntity.getRemoteProcessGroupPort() == null) {
        throw new IllegalArgumentException("Remote process group port details must be specified.");
    }
    if (requestRemoteProcessGroupPortEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final RemoteProcessGroupPortDTO requestRemoteProcessGroupPort = requestRemoteProcessGroupPortEntity.getRemoteProcessGroupPort();
    if (!portId.equals(requestRemoteProcessGroupPort.getId())) {
        throw new IllegalArgumentException(String.format("The remote process group port id (%s) in the request body does not equal the " + "remote process group port id of the requested resource (%s).", requestRemoteProcessGroupPort.getId(), portId));
    }
    // ensure the group ids are the same
    if (!id.equals(requestRemoteProcessGroupPort.getGroupId())) {
        throw new IllegalArgumentException(String.format("The remote process group id (%s) in the request body does not equal the " + "remote process group id of the requested resource (%s).", requestRemoteProcessGroupPort.getGroupId(), id));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestRemoteProcessGroupPortEntity);
    }
    final Revision requestRevision = getRevision(requestRemoteProcessGroupPortEntity, id);
    return withWriteLock(serviceFacade, requestRemoteProcessGroupPortEntity, requestRevision, lookup -> {
        final Authorizable remoteProcessGroup = lookup.getRemoteProcessGroup(id);
        remoteProcessGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyUpdateRemoteProcessGroupInputPort(id, requestRemoteProcessGroupPort), (revision, remoteProcessGroupPortEntity) -> {
        final RemoteProcessGroupPortDTO remoteProcessGroupPort = remoteProcessGroupPortEntity.getRemoteProcessGroupPort();
        // update the specified remote process group
        final RemoteProcessGroupPortEntity controllerResponse = serviceFacade.updateRemoteProcessGroupInputPort(revision, id, remoteProcessGroupPort);
        // get the updated revision
        final RevisionDTO updatedRevision = controllerResponse.getRevision();
        // build the response entity
        final RemoteProcessGroupPortEntity entity = new RemoteProcessGroupPortEntity();
        entity.setRevision(updatedRevision);
        entity.setRemoteProcessGroupPort(controllerResponse.getRemoteProcessGroupPort());
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) RemoteProcessGroupPortEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupPortEntity) Authorizable(org.apache.nifi.authorization.resource.Authorizable) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.

the class RemoteProcessGroupResource method updateRemoteProcessGroupOutputPort.

/**
 * Updates the specified remote process group output port.
 *
 * @param httpServletRequest           request
 * @param id                           The id of the remote process group to update.
 * @param portId                       The id of the output port to update.
 * @param requestRemoteProcessGroupPortEntity The remoteProcessGroupPortEntity
 * @return A remoteProcessGroupPortEntity
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/output-ports/{port-id}")
@ApiOperation(value = "Updates a remote port", notes = NON_GUARANTEED_ENDPOINT, response = RemoteProcessGroupPortEntity.class, authorizations = { @Authorization(value = "Write - /remote-process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response updateRemoteProcessGroupOutputPort(@Context HttpServletRequest httpServletRequest, @ApiParam(value = "The remote process group id.", required = true) @PathParam("id") String id, @ApiParam(value = "The remote process group port id.", required = true) @PathParam("port-id") String portId, @ApiParam(value = "The remote process group port.", required = true) RemoteProcessGroupPortEntity requestRemoteProcessGroupPortEntity) {
    if (requestRemoteProcessGroupPortEntity == null || requestRemoteProcessGroupPortEntity.getRemoteProcessGroupPort() == null) {
        throw new IllegalArgumentException("Remote process group port details must be specified.");
    }
    if (requestRemoteProcessGroupPortEntity.getRevision() == null) {
        throw new IllegalArgumentException("Revision must be specified.");
    }
    // ensure the ids are the same
    final RemoteProcessGroupPortDTO requestRemoteProcessGroupPort = requestRemoteProcessGroupPortEntity.getRemoteProcessGroupPort();
    if (!portId.equals(requestRemoteProcessGroupPort.getId())) {
        throw new IllegalArgumentException(String.format("The remote process group port id (%s) in the request body does not equal the " + "remote process group port id of the requested resource (%s).", requestRemoteProcessGroupPort.getId(), portId));
    }
    // ensure the group ids are the same
    if (!id.equals(requestRemoteProcessGroupPort.getGroupId())) {
        throw new IllegalArgumentException(String.format("The remote process group id (%s) in the request body does not equal the " + "remote process group id of the requested resource (%s).", requestRemoteProcessGroupPort.getGroupId(), id));
    }
    if (isReplicateRequest()) {
        return replicate(HttpMethod.PUT, requestRemoteProcessGroupPortEntity);
    }
    // handle expects request (usually from the cluster manager)
    final Revision requestRevision = getRevision(requestRemoteProcessGroupPortEntity, id);
    return withWriteLock(serviceFacade, requestRemoteProcessGroupPortEntity, requestRevision, lookup -> {
        final Authorizable remoteProcessGroup = lookup.getRemoteProcessGroup(id);
        remoteProcessGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyUpdateRemoteProcessGroupOutputPort(id, requestRemoteProcessGroupPort), (revision, remoteProcessGroupPortEntity) -> {
        final RemoteProcessGroupPortDTO remoteProcessGroupPort = remoteProcessGroupPortEntity.getRemoteProcessGroupPort();
        // update the specified remote process group
        final RemoteProcessGroupPortEntity controllerResponse = serviceFacade.updateRemoteProcessGroupOutputPort(revision, id, remoteProcessGroupPort);
        // get the updated revision
        final RevisionDTO updatedRevision = controllerResponse.getRevision();
        // build the response entity
        RemoteProcessGroupPortEntity entity = new RemoteProcessGroupPortEntity();
        entity.setRevision(updatedRevision);
        entity.setRemoteProcessGroupPort(controllerResponse.getRemoteProcessGroupPort());
        return generateOkResponse(entity).build();
    });
}
Also used : Revision(org.apache.nifi.web.Revision) RemoteProcessGroupPortEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupPortEntity) Authorizable(org.apache.nifi.authorization.resource.Authorizable) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.

the class SnippetUtils method copyContentsForGroup.

private FlowSnippetDTO copyContentsForGroup(final FlowSnippetDTO snippetContents, final String groupId, final Map<String, ConnectableDTO> parentConnectableMap, Map<String, String> serviceIdMap, final String idGenerationSeed, boolean isCopy) {
    final FlowSnippetDTO snippetContentsCopy = new FlowSnippetDTO();
    try {
        // 
        if (serviceIdMap == null) {
            serviceIdMap = new HashMap<>();
        }
        final Set<ControllerServiceDTO> services = new HashSet<>();
        if (snippetContents.getControllerServices() != null) {
            for (final ControllerServiceDTO serviceDTO : snippetContents.getControllerServices()) {
                final ControllerServiceDTO service = dtoFactory.copy(serviceDTO);
                service.setId(generateId(serviceDTO.getId(), idGenerationSeed, isCopy));
                service.setState(ControllerServiceState.DISABLED.name());
                services.add(service);
                // Map old service ID to new service ID so that we can make sure that we reference the new ones.
                serviceIdMap.put(serviceDTO.getId(), service.getId());
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.ControllerService, serviceDTO.getId(), serviceDTO.getName()), ResourceFactory.getComponentResource(ResourceType.ControllerService, service.getId(), service.getName()), idGenerationSeed);
                }
            }
        }
        // if there is any controller service that maps to another controller service, update the id's
        for (final ControllerServiceDTO serviceDTO : services) {
            final Map<String, String> properties = serviceDTO.getProperties();
            final Map<String, PropertyDescriptorDTO> descriptors = serviceDTO.getDescriptors();
            if (properties != null && descriptors != null) {
                for (final PropertyDescriptorDTO descriptor : descriptors.values()) {
                    if (descriptor.getIdentifiesControllerService() != null) {
                        final String currentServiceId = properties.get(descriptor.getName());
                        if (currentServiceId == null) {
                            continue;
                        }
                        final String newServiceId = serviceIdMap.get(currentServiceId);
                        properties.put(descriptor.getName(), newServiceId);
                    }
                }
            }
        }
        snippetContentsCopy.setControllerServices(services);
        // 
        // Copy the labels
        // 
        final Set<LabelDTO> labels = new HashSet<>();
        if (snippetContents.getLabels() != null) {
            for (final LabelDTO labelDTO : snippetContents.getLabels()) {
                final LabelDTO label = dtoFactory.copy(labelDTO);
                label.setId(generateId(labelDTO.getId(), idGenerationSeed, isCopy));
                label.setParentGroupId(groupId);
                labels.add(label);
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.Label, labelDTO.getId(), labelDTO.getLabel()), ResourceFactory.getComponentResource(ResourceType.Label, label.getId(), label.getLabel()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setLabels(labels);
        // 
        // Copy connectable components
        // 
        // maps a group ID-ID of a Connectable in the template to the new instance
        final Map<String, ConnectableDTO> connectableMap = new HashMap<>();
        // 
        // Copy the funnels
        // 
        final Set<FunnelDTO> funnels = new HashSet<>();
        if (snippetContents.getFunnels() != null) {
            for (final FunnelDTO funnelDTO : snippetContents.getFunnels()) {
                final FunnelDTO cp = dtoFactory.copy(funnelDTO);
                cp.setId(generateId(funnelDTO.getId(), idGenerationSeed, isCopy));
                cp.setParentGroupId(groupId);
                funnels.add(cp);
                connectableMap.put(funnelDTO.getParentGroupId() + "-" + funnelDTO.getId(), dtoFactory.createConnectableDto(cp));
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.Funnel, funnelDTO.getId(), funnelDTO.getId()), ResourceFactory.getComponentResource(ResourceType.Funnel, cp.getId(), cp.getId()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setFunnels(funnels);
        final Set<PortDTO> inputPorts = new HashSet<>();
        if (snippetContents.getInputPorts() != null) {
            for (final PortDTO portDTO : snippetContents.getInputPorts()) {
                final PortDTO cp = dtoFactory.copy(portDTO);
                cp.setId(generateId(portDTO.getId(), idGenerationSeed, isCopy));
                cp.setParentGroupId(groupId);
                cp.setState(ScheduledState.STOPPED.toString());
                inputPorts.add(cp);
                final ConnectableDTO portConnectable = dtoFactory.createConnectableDto(cp, ConnectableType.INPUT_PORT);
                connectableMap.put(portDTO.getParentGroupId() + "-" + portDTO.getId(), portConnectable);
                if (parentConnectableMap != null) {
                    parentConnectableMap.put(portDTO.getParentGroupId() + "-" + portDTO.getId(), portConnectable);
                }
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.InputPort, portDTO.getId(), portDTO.getName()), ResourceFactory.getComponentResource(ResourceType.InputPort, cp.getId(), cp.getName()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setInputPorts(inputPorts);
        final Set<PortDTO> outputPorts = new HashSet<>();
        if (snippetContents.getOutputPorts() != null) {
            for (final PortDTO portDTO : snippetContents.getOutputPorts()) {
                final PortDTO cp = dtoFactory.copy(portDTO);
                cp.setId(generateId(portDTO.getId(), idGenerationSeed, isCopy));
                cp.setParentGroupId(groupId);
                cp.setState(ScheduledState.STOPPED.toString());
                outputPorts.add(cp);
                final ConnectableDTO portConnectable = dtoFactory.createConnectableDto(cp, ConnectableType.OUTPUT_PORT);
                connectableMap.put(portDTO.getParentGroupId() + "-" + portDTO.getId(), portConnectable);
                if (parentConnectableMap != null) {
                    parentConnectableMap.put(portDTO.getParentGroupId() + "-" + portDTO.getId(), portConnectable);
                }
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.OutputPort, portDTO.getId(), portDTO.getName()), ResourceFactory.getComponentResource(ResourceType.OutputPort, cp.getId(), cp.getName()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setOutputPorts(outputPorts);
        // 
        // Copy the processors
        // 
        final Set<ProcessorDTO> processors = new HashSet<>();
        if (snippetContents.getProcessors() != null) {
            for (final ProcessorDTO processorDTO : snippetContents.getProcessors()) {
                final ProcessorDTO cp = dtoFactory.copy(processorDTO);
                cp.setId(generateId(processorDTO.getId(), idGenerationSeed, isCopy));
                cp.setParentGroupId(groupId);
                if (processorDTO.getState() != null && processorDTO.getState().equals(ScheduledState.DISABLED.toString())) {
                    cp.setState(ScheduledState.DISABLED.toString());
                } else {
                    cp.setState(ScheduledState.STOPPED.toString());
                }
                processors.add(cp);
                connectableMap.put(processorDTO.getParentGroupId() + "-" + processorDTO.getId(), dtoFactory.createConnectableDto(cp));
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.Processor, processorDTO.getId(), processorDTO.getName()), ResourceFactory.getComponentResource(ResourceType.Processor, cp.getId(), cp.getName()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setProcessors(processors);
        // if there is any controller service that maps to another controller service, update the id's
        updateControllerServiceIdentifiers(snippetContentsCopy, serviceIdMap);
        // 
        // Copy ProcessGroups
        // 
        // instantiate the process groups, renaming as necessary
        final Set<ProcessGroupDTO> groups = new HashSet<>();
        if (snippetContents.getProcessGroups() != null) {
            for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) {
                final ProcessGroupDTO cp = dtoFactory.copy(groupDTO, false);
                cp.setId(generateId(groupDTO.getId(), idGenerationSeed, isCopy));
                cp.setParentGroupId(groupId);
                // copy the contents of this group - we do not copy via the dto factory since we want to specify new ids
                final FlowSnippetDTO contentsCopy = copyContentsForGroup(groupDTO.getContents(), cp.getId(), connectableMap, serviceIdMap, idGenerationSeed, isCopy);
                cp.setContents(contentsCopy);
                groups.add(cp);
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.ProcessGroup, groupDTO.getId(), groupDTO.getName()), ResourceFactory.getComponentResource(ResourceType.ProcessGroup, cp.getId(), cp.getName()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setProcessGroups(groups);
        final Set<RemoteProcessGroupDTO> remoteGroups = new HashSet<>();
        if (snippetContents.getRemoteProcessGroups() != null) {
            for (final RemoteProcessGroupDTO remoteGroupDTO : snippetContents.getRemoteProcessGroups()) {
                final RemoteProcessGroupDTO cp = dtoFactory.copy(remoteGroupDTO);
                cp.setId(generateId(remoteGroupDTO.getId(), idGenerationSeed, isCopy));
                cp.setParentGroupId(groupId);
                final RemoteProcessGroupContentsDTO contents = cp.getContents();
                if (contents != null && contents.getInputPorts() != null) {
                    for (final RemoteProcessGroupPortDTO remotePort : contents.getInputPorts()) {
                        remotePort.setGroupId(cp.getId());
                        final String originalId = remotePort.getId();
                        if (remotePort.getTargetId() == null) {
                            remotePort.setTargetId(originalId);
                        }
                        remotePort.setId(generateId(remotePort.getId(), idGenerationSeed, isCopy));
                        connectableMap.put(remoteGroupDTO.getId() + "-" + originalId, dtoFactory.createConnectableDto(remotePort, ConnectableType.REMOTE_INPUT_PORT));
                    }
                }
                if (contents != null && contents.getOutputPorts() != null) {
                    for (final RemoteProcessGroupPortDTO remotePort : contents.getOutputPorts()) {
                        remotePort.setGroupId(cp.getId());
                        final String originalId = remotePort.getId();
                        if (remotePort.getTargetId() == null) {
                            remotePort.setTargetId(originalId);
                        }
                        remotePort.setId(generateId(remotePort.getId(), idGenerationSeed, isCopy));
                        connectableMap.put(remoteGroupDTO.getId() + "-" + originalId, dtoFactory.createConnectableDto(remotePort, ConnectableType.REMOTE_OUTPUT_PORT));
                    }
                }
                remoteGroups.add(cp);
                // clone policies as appropriate
                if (isCopy) {
                    cloneComponentSpecificPolicies(ResourceFactory.getComponentResource(ResourceType.RemoteProcessGroup, remoteGroupDTO.getId(), remoteGroupDTO.getName()), ResourceFactory.getComponentResource(ResourceType.RemoteProcessGroup, cp.getId(), cp.getName()), idGenerationSeed);
                }
            }
        }
        snippetContentsCopy.setRemoteProcessGroups(remoteGroups);
        final Set<ConnectionDTO> connections = new HashSet<>();
        if (snippetContents.getConnections() != null) {
            for (final ConnectionDTO connectionDTO : snippetContents.getConnections()) {
                final ConnectionDTO cp = dtoFactory.copy(connectionDTO);
                final ConnectableDTO source = connectableMap.get(cp.getSource().getGroupId() + "-" + cp.getSource().getId());
                final ConnectableDTO destination = connectableMap.get(cp.getDestination().getGroupId() + "-" + cp.getDestination().getId());
                // ensure all referenced components are present
                if (source == null || destination == null) {
                    throw new IllegalArgumentException("The flow snippet contains a Connection that references a component that is not included.");
                }
                cp.setId(generateId(connectionDTO.getId(), idGenerationSeed, isCopy));
                cp.setSource(source);
                cp.setDestination(destination);
                cp.setParentGroupId(groupId);
                connections.add(cp);
            // note - no need to copy policies of a connection as their permissions are inferred through the source and destination
            }
        }
        snippetContentsCopy.setConnections(connections);
        return snippetContentsCopy;
    } catch (Exception e) {
        // attempt to role back any policies of the copies that were created in preparation for the clone
        rollbackClonedPolicies(snippetContentsCopy);
        // rethrow the original exception
        throw e;
    }
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) HashMap(java.util.HashMap) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO)

Example 15 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi by apache.

the class TestRemoteProcessGroupAuditor method defaultRemoteProcessGroupPortDTO.

private RemoteProcessGroupPortDTO defaultRemoteProcessGroupPortDTO() {
    final RemoteProcessGroupPortDTO inputRPGPortDTO = new RemoteProcessGroupPortDTO();
    inputRPGPortDTO.setConcurrentlySchedulableTaskCount(1);
    inputRPGPortDTO.setUseCompression(false);
    return inputRPGPortDTO;
}
Also used : RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)

Aggregations

RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)18 Test (org.junit.Test)7 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)6 HashMap (java.util.HashMap)5 Action (org.apache.nifi.action.Action)5 RemoteProcessGroupContentsDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO)5 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)4 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 HashSet (java.util.HashSet)3 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)3 BatchSettingsDTO (org.apache.nifi.web.api.dto.BatchSettingsDTO)3 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Map (java.util.Map)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2