final AffectedComponentDTO nodeAffectedComponent = nodeAffectedComponentEntity.getComponent(); if (nodeAffectedComponentEntity.getPermissions().getCanRead()) { 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); 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); affectedComponent.setPermissions(permissions); affectedComponent.setComponent(null);
public AffectedComponentEntity createAffectedComponentEntity(final AffectedComponentDTO dto, final RevisionDTO revision, final PermissionsDTO permissions) { final AffectedComponentEntity entity = new AffectedComponentEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setId(dto.getId()); if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); } } return entity; }
public AffectedComponentEntity createAffectedComponentEntity(final PortEntity portEntity, final String referenceType) { if (portEntity == null) { return null; } final AffectedComponentEntity component = new AffectedComponentEntity(); component.setBulletins(portEntity.getBulletins()); component.setId(portEntity.getId()); component.setPermissions(portEntity.getPermissions()); component.setPosition(portEntity.getPosition()); component.setRevision(portEntity.getRevision()); component.setUri(portEntity.getUri()); final PortDTO portDto = portEntity.getComponent(); final AffectedComponentDTO componentDto = new AffectedComponentDTO(); componentDto.setId(portDto.getId()); componentDto.setName(portDto.getName()); componentDto.setProcessGroupId(portDto.getParentGroupId()); componentDto.setReferenceType(referenceType); componentDto.setState(portDto.getState()); componentDto.setValidationErrors(portDto.getValidationErrors()); component.setComponent(componentDto); return component; }
/** * Updates the affected controller services in the specified updateRequest with the serviceEntities. * * @param serviceEntities service entities * @param affectedServices affected services */ private void updateAffectedControllerServices(final Set<ControllerServiceEntity> serviceEntities, final Map<String, AffectedComponentEntity> affectedServices) { // update the affected components serviceEntities.stream() .filter(entity -> affectedServices.containsKey(entity.getId())) .forEach(entity -> { final AffectedComponentEntity affectedComponentEntity = affectedServices.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()); } } }); }
public static AffectedComponentEntity updateEntity(final AffectedComponentEntity componentEntity, final NiFiServiceFacade serviceFacade, final DtoFactory dtoFactory) { switch (componentEntity.getComponent().getReferenceType()) { case AffectedComponentDTO.COMPONENT_TYPE_PROCESSOR: final ProcessorEntity procEntity = serviceFacade.getProcessor(componentEntity.getId()); return dtoFactory.createAffectedComponentEntity(procEntity); case AffectedComponentDTO.COMPONENT_TYPE_INPUT_PORT: { final PortEntity portEntity = serviceFacade.getInputPort(componentEntity.getId()); return dtoFactory.createAffectedComponentEntity(portEntity, AffectedComponentDTO.COMPONENT_TYPE_INPUT_PORT); final PortEntity portEntity = serviceFacade.getOutputPort(componentEntity.getId()); return dtoFactory.createAffectedComponentEntity(portEntity, AffectedComponentDTO.COMPONENT_TYPE_OUTPUT_PORT); final ControllerServiceEntity serviceEntity = serviceFacade.getControllerService(componentEntity.getId()); return dtoFactory.createAffectedComponentEntity(serviceEntity); case AffectedComponentDTO.COMPONENT_TYPE_REMOTE_INPUT_PORT: { final RemoteProcessGroupEntity remoteGroupEntity = serviceFacade.getRemoteProcessGroup(componentEntity.getComponent().getProcessGroupId()); final RemoteProcessGroupContentsDTO remoteGroupContents = remoteGroupEntity.getComponent().getContents(); final Optional<RemoteProcessGroupPortDTO> portDtoOption = remoteGroupContents.getInputPorts().stream() .filter(port -> port.getId().equals(componentEntity.getId())) .findFirst(); final RemoteProcessGroupEntity remoteGroupEntity = serviceFacade.getRemoteProcessGroup(componentEntity.getComponent().getProcessGroupId()); final RemoteProcessGroupContentsDTO remoteGroupContents = remoteGroupEntity.getComponent().getContents(); final Optional<RemoteProcessGroupPortDTO> portDtoOption = remoteGroupContents.getOutputPorts().stream() .filter(port -> port.getId().equals(componentEntity.getId())) .findFirst();
@Override public Set<AffectedComponentEntity> activateControllerServices(final URI exampleUri, final String groupId, final Set<AffectedComponentEntity> services, final ControllerServiceState desiredState, final Pause pause) throws LifecycleManagementException { final Map<String, Revision> serviceRevisions = services.stream() .collect(Collectors.toMap(AffectedComponentEntity::getId, entity -> revisionManager.getRevision(entity.getId()))); final Map<String, AffectedComponentEntity> affectedServiceMap = services.stream() .collect(Collectors.toMap(AffectedComponentEntity::getId, Function.identity())); if (desiredState == ControllerServiceState.ENABLED) { enableControllerServices(groupId, serviceRevisions, affectedServiceMap, pause); } else { disableControllerServices(groupId, serviceRevisions, affectedServiceMap, pause); } return services.stream() .map(componentEntity -> serviceFacade.getControllerService(componentEntity.getId())) .map(dtoFactory::createAffectedComponentEntity) .collect(Collectors.toSet()); }
final PermissionsDTO permissions = affectedComponent.getPermissions(); if (!permissions.getCanRead() || !permissions.getCanWrite()) { canWrite = false;
.filter(dto -> stoppableReferenceTypes.contains(dto.getComponent().getReferenceType())) .filter(dto -> "Running".equalsIgnoreCase(dto.getComponent().getState())) .collect(Collectors.toSet()); .filter(dto -> AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE.equals(dto.getComponent().getReferenceType())) .filter(dto -> "Enabled".equalsIgnoreCase(dto.getComponent().getState())) .collect(Collectors.toSet()); final AffectedComponentDTO componentDto = componentEntity.getComponent(); final String referenceType = componentDto.getReferenceType(); if (!AffectedComponentDTO.COMPONENT_TYPE_REMOTE_INPUT_PORT.equals(referenceType)
/** * Updates the affected controller services in the specified updateRequest with the serviceEntities. * * @param serviceEntities service entities * @param affectedServices all Controller Services whose state should be equal to the given desired state */ private void updateAffectedControllerServices(final Set<ControllerServiceEntity> serviceEntities, final Map<String, AffectedComponentEntity> affectedServices) { // update the affected components serviceEntities.stream() .filter(entity -> affectedServices.containsKey(entity.getId())) .forEach(entity -> { final AffectedComponentEntity affectedComponentEntity = affectedServices.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()); } } }); }
@Override public Set<AffectedComponentEntity> scheduleComponents(final URI exampleUri, final String groupId, final Set<AffectedComponentEntity> components, final ScheduledState desiredState, final Pause pause) throws LifecycleManagementException { final Map<String, Revision> processorRevisions = components.stream() .collect(Collectors.toMap(AffectedComponentEntity::getId, entity -> revisionManager.getRevision(entity.getId()))); final Map<String, AffectedComponentEntity> affectedComponentMap = components.stream() .collect(Collectors.toMap(AffectedComponentEntity::getId, Function.identity())); if (desiredState == ScheduledState.RUNNING) { startComponents(groupId, processorRevisions, affectedComponentMap, pause); } else { stopComponents(groupId, processorRevisions, affectedComponentMap, pause); } final Set<AffectedComponentEntity> updatedEntities = components.stream() .map(component -> AffectedComponentUtils.updateEntity(component, serviceFacade, dtoFactory)) .collect(Collectors.toSet()); return updatedEntities; }
final PermissionsDTO permissions = affectedComponent.getPermissions(); if (!permissions.getCanRead() || !permissions.getCanWrite()) { canWrite = false;
private AffectedComponentEntity createAffectedComponentEntity(final InstantiatedVersionedComponent instance, final String componentTypeName, final String componentState) { 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); 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; }
public AffectedComponentEntity createAffectedComponentEntity(final ControllerServiceEntity serviceEntity) { if (serviceEntity == null) { return null; } final AffectedComponentEntity component = new AffectedComponentEntity(); component.setBulletins(serviceEntity.getBulletins()); component.setId(serviceEntity.getId()); component.setPermissions(serviceEntity.getPermissions()); component.setPosition(serviceEntity.getPosition()); component.setRevision(serviceEntity.getRevision()); component.setUri(serviceEntity.getUri()); final ControllerServiceDTO serviceDto = serviceEntity.getComponent(); final AffectedComponentDTO componentDto = new AffectedComponentDTO(); componentDto.setId(serviceDto.getId()); componentDto.setName(serviceDto.getName()); componentDto.setProcessGroupId(serviceDto.getParentGroupId()); componentDto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE); componentDto.setState(serviceDto.getState()); componentDto.setValidationErrors(serviceDto.getValidationErrors()); component.setComponent(componentDto); return component; }
/** * 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()); } } }); }
public AffectedComponentEntity createAffectedComponentEntity(final RemoteProcessGroupPortDTO remotePortDto, final String referenceType, final RemoteProcessGroupEntity rpgEntity) { if (remotePortDto == null) { return null; } final AffectedComponentEntity component = new AffectedComponentEntity(); component.setId(remotePortDto.getId()); component.setPermissions(rpgEntity.getPermissions()); component.setRevision(rpgEntity.getRevision()); component.setUri(rpgEntity.getUri()); final AffectedComponentDTO componentDto = new AffectedComponentDTO(); componentDto.setId(remotePortDto.getId()); componentDto.setName(remotePortDto.getName()); componentDto.setProcessGroupId(remotePortDto.getGroupId()); componentDto.setReferenceType(referenceType); componentDto.setState(remotePortDto.isTransmitting() ? "Running" : "Stopped"); component.setComponent(componentDto); return component; }
public AffectedComponentEntity createAffectedComponentEntity(final ProcessorEntity processorEntity) { if (processorEntity == null) { return null; } final AffectedComponentEntity component = new AffectedComponentEntity(); component.setBulletins(processorEntity.getBulletins()); component.setId(processorEntity.getId()); component.setPermissions(processorEntity.getPermissions()); component.setPosition(processorEntity.getPosition()); component.setRevision(processorEntity.getRevision()); component.setUri(processorEntity.getUri()); final ProcessorDTO processorDto = processorEntity.getComponent(); final AffectedComponentDTO componentDto = new AffectedComponentDTO(); componentDto.setId(processorDto.getId()); componentDto.setName(processorDto.getName()); componentDto.setProcessGroupId(processorDto.getParentGroupId()); componentDto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_PROCESSOR); componentDto.setState(processorDto.getState()); componentDto.setValidationErrors(processorDto.getValidationErrors()); component.setComponent(componentDto); return component; }
.forEach(entity -> { final AffectedComponentEntity affectedComponentEntity = affectedComponents.get(entity.getId()); affectedComponentEntity.setRevision(entity.getRevision()); if (Boolean.TRUE.equals(affectedComponentEntity.getPermissions().getCanRead())) { final AffectedComponentDTO affectedComponent = affectedComponentEntity.getComponent(); affectedComponent.setState(entity.getStatus().getAggregateSnapshot().getRunStatus()); affectedComponent.setActiveThreadCount(entity.getStatus().getAggregateSnapshot().getActiveThreadCount());
.map(component -> component.getId()) .collect(Collectors.toSet());
private AffectedComponentEntity createAffectedComponentEntity(final ControllerServiceNode serviceNode) { 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); 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; }