Search in sources :

Example 6 with AffectedComponentDTO

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

the class AffectedComponentEntityMerger method mergeAffectedComponents.

public void mergeAffectedComponents(final Set<AffectedComponentEntity> affectedComponents, final Map<NodeIdentifier, Set<AffectedComponentEntity>> affectedComponentMap) {
    final Map<String, Integer> activeThreadCounts = new HashMap<>();
    final Map<String, String> states = new HashMap<>();
    final Map<String, PermissionsDTO> canReads = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, Set<AffectedComponentEntity>> nodeEntry : affectedComponentMap.entrySet()) {
        final Set<AffectedComponentEntity> nodeAffectedComponents = nodeEntry.getValue();
        // go through all the nodes referencing components
        if (nodeAffectedComponents != null) {
            for (final AffectedComponentEntity nodeAffectedComponentEntity : nodeAffectedComponents) {
                final AffectedComponentDTO nodeAffectedComponent = nodeAffectedComponentEntity.getComponent();
                if (nodeAffectedComponentEntity.getPermissions().getCanRead()) {
                    // handle active thread counts
                    if (nodeAffectedComponent.getActiveThreadCount() != null && nodeAffectedComponent.getActiveThreadCount() > 0) {
                        final Integer current = activeThreadCounts.get(nodeAffectedComponent.getId());
                        if (current == null) {
                            activeThreadCounts.put(nodeAffectedComponent.getId(), nodeAffectedComponent.getActiveThreadCount());
                        } else {
                            activeThreadCounts.put(nodeAffectedComponent.getId(), nodeAffectedComponent.getActiveThreadCount() + current);
                        }
                    }
                    // handle controller service state
                    final String state = states.get(nodeAffectedComponent.getId());
                    if (state == null) {
                        if (ControllerServiceState.DISABLING.name().equals(nodeAffectedComponent.getState())) {
                            states.put(nodeAffectedComponent.getId(), ControllerServiceState.DISABLING.name());
                        } else if (ControllerServiceState.ENABLING.name().equals(nodeAffectedComponent.getState())) {
                            states.put(nodeAffectedComponent.getId(), ControllerServiceState.ENABLING.name());
                        }
                    }
                }
                // handle read permissions
                final PermissionsDTO mergedPermissions = canReads.get(nodeAffectedComponentEntity.getId());
                final PermissionsDTO permissions = nodeAffectedComponentEntity.getPermissions();
                if (permissions != null) {
                    if (mergedPermissions == null) {
                        canReads.put(nodeAffectedComponentEntity.getId(), permissions);
                    } else {
                        PermissionsDtoMerger.mergePermissions(mergedPermissions, permissions);
                    }
                }
            }
        }
    }
    // go through each affected components
    if (affectedComponents != null) {
        for (final AffectedComponentEntity affectedComponent : affectedComponents) {
            final PermissionsDTO permissions = canReads.get(affectedComponent.getId());
            if (permissions != null && permissions.getCanRead() != null && permissions.getCanRead()) {
                final Integer activeThreadCount = activeThreadCounts.get(affectedComponent.getId());
                if (activeThreadCount != null) {
                    affectedComponent.getComponent().setActiveThreadCount(activeThreadCount);
                }
                final String state = states.get(affectedComponent.getId());
                if (state != null) {
                    affectedComponent.getComponent().setState(state);
                }
            } else {
                affectedComponent.setPermissions(permissions);
                affectedComponent.setComponent(null);
            }
        }
    }
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) Map(java.util.Map) HashMap(java.util.HashMap) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 7 with AffectedComponentDTO

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

the class StandardNiFiServiceFacade method createAffectedComponentEntity.

private AffectedComponentEntity createAffectedComponentEntity(final InstantiatedVersionedComponent instance, final String componentTypeName, final String componentState, final NiFiUser user) {
    final AffectedComponentEntity entity = new AffectedComponentEntity();
    entity.setRevision(dtoFactory.createRevisionDTO(revisionManager.getRevision(instance.getInstanceId())));
    entity.setId(instance.getInstanceId());
    final Authorizable authorizable = getAuthorizable(componentTypeName, instance);
    final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(authorizable, user);
    entity.setPermissions(permissionsDto);
    final AffectedComponentDTO dto = new AffectedComponentDTO();
    dto.setId(instance.getInstanceId());
    dto.setReferenceType(componentTypeName);
    dto.setProcessGroupId(instance.getInstanceGroupId());
    dto.setState(componentState);
    entity.setComponent(dto);
    return entity;
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 8 with AffectedComponentDTO

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

the class StandardNiFiServiceFacade method createAffectedComponentEntity.

private AffectedComponentEntity createAffectedComponentEntity(final ControllerServiceNode serviceNode, final NiFiUser user) {
    final AffectedComponentEntity entity = new AffectedComponentEntity();
    entity.setRevision(dtoFactory.createRevisionDTO(revisionManager.getRevision(serviceNode.getIdentifier())));
    entity.setId(serviceNode.getIdentifier());
    final Authorizable authorizable = authorizableLookup.getControllerService(serviceNode.getIdentifier()).getAuthorizable();
    final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(authorizable, user);
    entity.setPermissions(permissionsDto);
    final AffectedComponentDTO dto = new AffectedComponentDTO();
    dto.setId(serviceNode.getIdentifier());
    dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE);
    dto.setProcessGroupId(serviceNode.getProcessGroupIdentifier());
    dto.setState(serviceNode.getState().name());
    entity.setComponent(dto);
    return entity;
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 9 with AffectedComponentDTO

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

the class StandardNiFiServiceFacade method createAffectedComponentEntity.

private AffectedComponentEntity createAffectedComponentEntity(final Connectable connectable, final NiFiUser user) {
    final AffectedComponentEntity entity = new AffectedComponentEntity();
    entity.setRevision(dtoFactory.createRevisionDTO(revisionManager.getRevision(connectable.getIdentifier())));
    entity.setId(connectable.getIdentifier());
    final Authorizable authorizable = getAuthorizable(connectable);
    final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(authorizable, user);
    entity.setPermissions(permissionsDto);
    final AffectedComponentDTO dto = new AffectedComponentDTO();
    dto.setId(connectable.getIdentifier());
    dto.setReferenceType(connectable.getConnectableType().name());
    dto.setState(connectable.getScheduledState().name());
    final String groupId = connectable instanceof RemoteGroupPort ? ((RemoteGroupPort) connectable).getRemoteProcessGroup().getIdentifier() : connectable.getProcessGroupIdentifier();
    dto.setProcessGroupId(groupId);
    entity.setComponent(dto);
    return entity;
}
Also used : InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 10 with AffectedComponentDTO

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

the class ProcessGroupResource method updateAffectedControllerServices.

/**
 * Updates the affected controller services in the specified updateRequest with the serviceEntities.
 *
 * @param serviceEntities service entities
 * @param updateRequest update request
 */
private void updateAffectedControllerServices(final Set<ControllerServiceEntity> serviceEntities, final VariableRegistryUpdateRequest updateRequest) {
    // update the affected components
    serviceEntities.stream().filter(entity -> updateRequest.getAffectedComponents().containsKey(entity.getId())).forEach(entity -> {
        final AffectedComponentEntity affectedComponentEntity = updateRequest.getAffectedComponents().get(entity.getId());
        affectedComponentEntity.setRevision(entity.getRevision());
        // only consider update this component if the user had permissions to it
        if (Boolean.TRUE.equals(affectedComponentEntity.getPermissions().getCanRead())) {
            final AffectedComponentDTO affectedComponent = affectedComponentEntity.getComponent();
            affectedComponent.setState(entity.getComponent().getState());
            if (Boolean.TRUE.equals(entity.getPermissions().getCanRead())) {
                affectedComponent.setValidationErrors(entity.getComponent().getValidationErrors());
            }
        }
    });
}
Also used : FunnelsEntity(org.apache.nifi.web.api.entity.FunnelsEntity) Produces(javax.ws.rs.Produces) InstantiateTemplateRequestEntity(org.apache.nifi.web.api.entity.InstantiateTemplateRequestEntity) ApiParam(io.swagger.annotations.ApiParam) SiteToSiteRestApiClient(org.apache.nifi.remote.util.SiteToSiteRestApiClient) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) StringUtils(org.apache.commons.lang3.StringUtils) ClientIdParameter(org.apache.nifi.web.api.request.ClientIdParameter) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) AuthorizeAccess(org.apache.nifi.authorization.AuthorizeAccess) VariableRegistryUpdateStep(org.apache.nifi.registry.variable.VariableRegistryUpdateStep) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) MediaType(javax.ws.rs.core.MediaType) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) Map(java.util.Map) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) UriBuilder(javax.ws.rs.core.UriBuilder) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) ConnectionsEntity(org.apache.nifi.web.api.entity.ConnectionsEntity) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) VariableRegistryUpdateRequest(org.apache.nifi.registry.variable.VariableRegistryUpdateRequest) ControllerServicesEntity(org.apache.nifi.web.api.entity.ControllerServicesEntity) Set(java.util.Set) InputPortsEntity(org.apache.nifi.web.api.entity.InputPortsEntity) Executors(java.util.concurrent.Executors) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) ProcessGroupsEntity(org.apache.nifi.web.api.entity.ProcessGroupsEntity) FlowComparisonEntity(org.apache.nifi.web.api.entity.FlowComparisonEntity) ScheduledState(org.apache.nifi.controller.ScheduledState) LabelsEntity(org.apache.nifi.web.api.entity.LabelsEntity) UriInfo(javax.ws.rs.core.UriInfo) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) Entity(org.apache.nifi.web.api.entity.Entity) GET(javax.ws.rs.GET) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) TemplateEntity(org.apache.nifi.web.api.entity.TemplateEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) HttpMethod(javax.ws.rs.HttpMethod) HttpServletRequest(javax.servlet.http.HttpServletRequest) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) Api(io.swagger.annotations.Api) VariableRegistryDTO(org.apache.nifi.web.api.dto.VariableRegistryDTO) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) AuthorizableLookup(org.apache.nifi.authorization.AuthorizableLookup) RequestAction(org.apache.nifi.authorization.RequestAction) FlowEncodingVersion(org.apache.nifi.controller.serialization.FlowEncodingVersion) JAXBElement(javax.xml.bind.JAXBElement) RemoteProcessGroupsEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupsEntity) IOException(java.io.IOException) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Authorizer(org.apache.nifi.authorization.Authorizer) ApiResponse(io.swagger.annotations.ApiResponse) FlowEntity(org.apache.nifi.web.api.entity.FlowEntity) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) OutputPortsEntity(org.apache.nifi.web.api.entity.OutputPortsEntity) ScheduleComponentsEntity(org.apache.nifi.web.api.entity.ScheduleComponentsEntity) XmlUtils(org.apache.nifi.security.xml.XmlUtils) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) Date(java.util.Date) ConnectableType(org.apache.nifi.connectable.ConnectableType) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ApiOperation(io.swagger.annotations.ApiOperation) AuthorizeControllerServiceReference(org.apache.nifi.authorization.AuthorizeControllerServiceReference) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) ActivateControllerServicesEntity(org.apache.nifi.web.api.entity.ActivateControllerServicesEntity) XMLStreamReader(javax.xml.stream.XMLStreamReader) DefaultValue(javax.ws.rs.DefaultValue) URI(java.net.URI) ThreadFactory(java.util.concurrent.ThreadFactory) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) UUID(java.util.UUID) BundleUtils(org.apache.nifi.util.BundleUtils) PortEntity(org.apache.nifi.web.api.entity.PortEntity) LongParameter(org.apache.nifi.web.api.request.LongParameter) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) CopySnippetRequestEntity(org.apache.nifi.web.api.entity.CopySnippetRequestEntity) Authentication(org.springframework.security.core.Authentication) Pause(org.apache.nifi.web.util.Pause) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) PathParam(javax.ws.rs.PathParam) Bucket(org.apache.nifi.registry.bucket.Bucket) Revision(org.apache.nifi.web.Revision) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) ConcurrentMap(java.util.concurrent.ConcurrentMap) FlowRegistryUtils(org.apache.nifi.registry.flow.FlowRegistryUtils) CreateTemplateRequestEntity(org.apache.nifi.web.api.entity.CreateTemplateRequestEntity) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) VariableRegistryUpdateRequestEntity(org.apache.nifi.web.api.entity.VariableRegistryUpdateRequestEntity) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) ExecutorService(java.util.concurrent.ExecutorService) Unmarshaller(javax.xml.bind.Unmarshaller) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ProcessorsEntity(org.apache.nifi.web.api.entity.ProcessorsEntity) VariableRegistryEntity(org.apache.nifi.web.api.entity.VariableRegistryEntity) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) PUT(javax.ws.rs.PUT) Authorization(io.swagger.annotations.Authorization) Collections(java.util.Collections) InputStream(java.io.InputStream) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Aggregations

AffectedComponentDTO (org.apache.nifi.web.api.dto.AffectedComponentDTO)15 AffectedComponentEntity (org.apache.nifi.web.api.entity.AffectedComponentEntity)14 Map (java.util.Map)11 Set (java.util.Set)11 URI (java.net.URI)10 HashMap (java.util.HashMap)10 Collectors (java.util.stream.Collectors)10 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)10 ScheduledState (org.apache.nifi.controller.ScheduledState)10 ControllerServiceState (org.apache.nifi.controller.service.ControllerServiceState)10 NiFiServiceFacade (org.apache.nifi.web.NiFiServiceFacade)10 Revision (org.apache.nifi.web.Revision)10 DtoFactory (org.apache.nifi.web.api.dto.DtoFactory)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Function (java.util.function.Function)9 URISyntaxException (java.net.URISyntaxException)8 HttpMethod (javax.ws.rs.HttpMethod)8 List (java.util.List)7 Api (io.swagger.annotations.Api)6