Search in sources :

Example 1 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardNiFiServiceFacade method updateRemoteProcessGroupOutputPort.

@Override
public RemoteProcessGroupPortEntity updateRemoteProcessGroupOutputPort(final Revision revision, final String remoteProcessGroupId, final RemoteProcessGroupPortDTO remoteProcessGroupPortDTO) {
    final RemoteProcessGroup remoteProcessGroupNode = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupPortDTO.getGroupId());
    final RevisionUpdate<RemoteProcessGroupPortDTO> snapshot = updateComponent(revision, remoteProcessGroupNode, () -> remoteProcessGroupDAO.updateRemoteProcessGroupOutputPort(remoteProcessGroupId, remoteProcessGroupPortDTO), remoteGroupPort -> dtoFactory.createRemoteProcessGroupPortDto(remoteGroupPort));
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroupNode);
    final RevisionDTO updatedRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
    return entityFactory.createRemoteProcessGroupPortEntity(snapshot.getComponent(), updatedRevision, permissions);
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 2 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardNiFiServiceFacade method deleteProcessGroup.

@Override
public ProcessGroupEntity deleteProcessGroup(final Revision revision, final String groupId) {
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroup);
    // grab the resources in the snippet so we can delete the policies afterwards
    final Set<Resource> groupResources = new HashSet<>();
    processGroup.findAllProcessors().forEach(processor -> groupResources.add(processor.getResource()));
    processGroup.findAllInputPorts().forEach(inputPort -> groupResources.add(inputPort.getResource()));
    processGroup.findAllOutputPorts().forEach(outputPort -> groupResources.add(outputPort.getResource()));
    processGroup.findAllFunnels().forEach(funnel -> groupResources.add(funnel.getResource()));
    processGroup.findAllLabels().forEach(label -> groupResources.add(label.getResource()));
    processGroup.findAllProcessGroups().forEach(childGroup -> groupResources.add(childGroup.getResource()));
    processGroup.findAllRemoteProcessGroups().forEach(remoteProcessGroup -> groupResources.add(remoteProcessGroup.getResource()));
    processGroup.findAllTemplates().forEach(template -> groupResources.add(template.getResource()));
    processGroup.findAllControllerServices().forEach(controllerService -> groupResources.add(controllerService.getResource()));
    final ProcessGroupDTO snapshot = deleteComponent(revision, processGroup.getResource(), () -> processGroupDAO.deleteProcessGroup(groupId), true, dtoFactory.createProcessGroupDto(processGroup));
    // delete all applicable component policies
    groupResources.forEach(groupResource -> cleanUpPolicies(groupResource));
    return entityFactory.createProcessGroupEntity(snapshot, null, permissions, null, null);
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) EnforcePolicyPermissionsThroughBaseResource(org.apache.nifi.authorization.resource.EnforcePolicyPermissionsThroughBaseResource) Resource(org.apache.nifi.authorization.Resource) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardNiFiServiceFacade method deleteSnippet.

@Override
public SnippetEntity deleteSnippet(final Set<Revision> revisions, final String snippetId) {
    final Snippet snippet = snippetDAO.getSnippet(snippetId);
    // grab the resources in the snippet so we can delete the policies afterwards
    final Set<Resource> snippetResources = new HashSet<>();
    snippet.getProcessors().keySet().forEach(id -> snippetResources.add(processorDAO.getProcessor(id).getResource()));
    snippet.getInputPorts().keySet().forEach(id -> snippetResources.add(inputPortDAO.getPort(id).getResource()));
    snippet.getOutputPorts().keySet().forEach(id -> snippetResources.add(outputPortDAO.getPort(id).getResource()));
    snippet.getFunnels().keySet().forEach(id -> snippetResources.add(funnelDAO.getFunnel(id).getResource()));
    snippet.getLabels().keySet().forEach(id -> snippetResources.add(labelDAO.getLabel(id).getResource()));
    snippet.getRemoteProcessGroups().keySet().forEach(id -> snippetResources.add(remoteProcessGroupDAO.getRemoteProcessGroup(id).getResource()));
    snippet.getProcessGroups().keySet().forEach(id -> {
        final ProcessGroup processGroup = processGroupDAO.getProcessGroup(id);
        // add the process group
        snippetResources.add(processGroup.getResource());
        // add each encapsulated component
        processGroup.findAllProcessors().forEach(processor -> snippetResources.add(processor.getResource()));
        processGroup.findAllInputPorts().forEach(inputPort -> snippetResources.add(inputPort.getResource()));
        processGroup.findAllOutputPorts().forEach(outputPort -> snippetResources.add(outputPort.getResource()));
        processGroup.findAllFunnels().forEach(funnel -> snippetResources.add(funnel.getResource()));
        processGroup.findAllLabels().forEach(label -> snippetResources.add(label.getResource()));
        processGroup.findAllProcessGroups().forEach(childGroup -> snippetResources.add(childGroup.getResource()));
        processGroup.findAllRemoteProcessGroups().forEach(remoteProcessGroup -> snippetResources.add(remoteProcessGroup.getResource()));
        processGroup.findAllTemplates().forEach(template -> snippetResources.add(template.getResource()));
        processGroup.findAllControllerServices().forEach(controllerService -> snippetResources.add(controllerService.getResource()));
    });
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final RevisionClaim claim = new StandardRevisionClaim(revisions);
    final SnippetDTO dto = revisionManager.deleteRevision(claim, user, new DeleteRevisionTask<SnippetDTO>() {

        @Override
        public SnippetDTO performTask() {
            // delete the components in the snippet
            snippetDAO.deleteSnippetComponents(snippetId);
            // drop the snippet
            snippetDAO.dropSnippet(snippetId);
            // save
            controllerFacade.save();
            // create the dto for the snippet that was just removed
            return dtoFactory.createSnippetDto(snippet);
        }
    });
    // clean up component policies
    snippetResources.forEach(resource -> cleanUpPolicies(resource));
    return entityFactory.createSnippetEntity(dto);
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) SnippetDTO(org.apache.nifi.web.api.dto.SnippetDTO) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) EnforcePolicyPermissionsThroughBaseResource(org.apache.nifi.authorization.resource.EnforcePolicyPermissionsThroughBaseResource) Resource(org.apache.nifi.authorization.Resource) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) Snippet(org.apache.nifi.controller.Snippet) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim) RevisionClaim(org.apache.nifi.web.revision.RevisionClaim) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardNiFiServiceFacade method deleteRemoteProcessGroup.

@Override
public RemoteProcessGroupEntity deleteRemoteProcessGroup(final Revision revision, final String remoteProcessGroupId) {
    final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroup);
    final RemoteProcessGroupDTO snapshot = deleteComponent(revision, remoteProcessGroup.getResource(), () -> remoteProcessGroupDAO.deleteRemoteProcessGroup(remoteProcessGroupId), true, dtoFactory.createRemoteProcessGroupDto(remoteProcessGroup));
    return entityFactory.createRemoteProcessGroupEntity(snapshot, null, permissions, null, null);
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Example 5 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardNiFiServiceFacade method validateSnippetContents.

private void validateSnippetContents(final FlowSnippetDTO flow) {
    // validate any processors
    if (flow.getProcessors() != null) {
        for (final ProcessorDTO processorDTO : flow.getProcessors()) {
            final ProcessorNode processorNode = processorDAO.getProcessor(processorDTO.getId());
            final Collection<ValidationResult> validationErrors = processorNode.getValidationErrors();
            if (validationErrors != null && !validationErrors.isEmpty()) {
                final List<String> errors = new ArrayList<>();
                for (final ValidationResult validationResult : validationErrors) {
                    errors.add(validationResult.toString());
                }
                processorDTO.setValidationErrors(errors);
            }
        }
    }
    if (flow.getInputPorts() != null) {
        for (final PortDTO portDTO : flow.getInputPorts()) {
            final Port port = inputPortDAO.getPort(portDTO.getId());
            final Collection<ValidationResult> validationErrors = port.getValidationErrors();
            if (validationErrors != null && !validationErrors.isEmpty()) {
                final List<String> errors = new ArrayList<>();
                for (final ValidationResult validationResult : validationErrors) {
                    errors.add(validationResult.toString());
                }
                portDTO.setValidationErrors(errors);
            }
        }
    }
    if (flow.getOutputPorts() != null) {
        for (final PortDTO portDTO : flow.getOutputPorts()) {
            final Port port = outputPortDAO.getPort(portDTO.getId());
            final Collection<ValidationResult> validationErrors = port.getValidationErrors();
            if (validationErrors != null && !validationErrors.isEmpty()) {
                final List<String> errors = new ArrayList<>();
                for (final ValidationResult validationResult : validationErrors) {
                    errors.add(validationResult.toString());
                }
                portDTO.setValidationErrors(errors);
            }
        }
    }
    // get any remote process group issues
    if (flow.getRemoteProcessGroups() != null) {
        for (final RemoteProcessGroupDTO remoteProcessGroupDTO : flow.getRemoteProcessGroups()) {
            final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
            if (remoteProcessGroup.getAuthorizationIssue() != null) {
                remoteProcessGroupDTO.setAuthorizationIssues(Arrays.asList(remoteProcessGroup.getAuthorizationIssue()));
            }
        }
    }
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ValidationResult(org.apache.nifi.components.ValidationResult)

Aggregations

RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)74 ProcessGroup (org.apache.nifi.groups.ProcessGroup)32 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)31 Action (org.apache.nifi.action.Action)27 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)26 ArrayList (java.util.ArrayList)20 Connection (org.apache.nifi.connectable.Connection)20 Port (org.apache.nifi.connectable.Port)19 Test (org.junit.Test)18 HashSet (java.util.HashSet)16 RootGroupPort (org.apache.nifi.remote.RootGroupPort)16 Funnel (org.apache.nifi.connectable.Funnel)15 Connectable (org.apache.nifi.connectable.Connectable)14 ProcessorNode (org.apache.nifi.controller.ProcessorNode)14 Label (org.apache.nifi.controller.label.Label)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)13 Collection (java.util.Collection)11 HashMap (java.util.HashMap)10 Snippet (org.apache.nifi.controller.Snippet)10 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)10