public ControllerServiceDTO copy(final ControllerServiceDTO original) { final ControllerServiceDTO copy = new ControllerServiceDTO(); copy.setAnnotationData(original.getAnnotationData()); copy.setControllerServiceApis(original.getControllerServiceApis()); copy.setComments(original.getComments()); copy.setCustomUiUrl(original.getCustomUiUrl()); copy.setDescriptors(copy(original.getDescriptors())); copy.setId(original.getId()); copy.setParentGroupId(original.getParentGroupId()); copy.setName(original.getName()); copy.setProperties(copy(original.getProperties())); copy.setReferencingComponents(copy(original.getReferencingComponents())); copy.setState(original.getState()); copy.setType(original.getType()); copy.setBundle(copy(original.getBundle())); copy.setExtensionMissing(original.getExtensionMissing()); copy.setMultipleVersionsAvailable(original.getMultipleVersionsAvailable()); copy.setPersistsState(original.getPersistsState()); copy.setValidationErrors(copy(original.getValidationErrors())); copy.setValidationStatus(original.getValidationStatus()); copy.setVersionedComponentId(original.getVersionedComponentId()); return copy; }
private ControllerServiceDTO createDTOWithDesiredRunStatus(final String id, final String runStatus) { final ControllerServiceDTO dto = new ControllerServiceDTO(); dto.setId(id); dto.setState(runStatus); return dto; }
private void addControllerServiceFingerprint(final StringBuilder builder, final ControllerServiceDTO dto) { builder.append(dto.getId()); builder.append(dto.getVersionedComponentId()); builder.append(dto.getType()); builder.append(dto.getName()); addBundleFingerprint(builder, dto.getBundle()); builder.append(dto.getComments()); builder.append(dto.getAnnotationData()); builder.append(dto.getState()); // get the temp instance of the ControllerService so that we know the default property values final BundleCoordinate coordinate = getCoordinate(dto.getType(), dto.getBundle()); final ConfigurableComponent configurableComponent = extensionManager.getTempComponent(dto.getType(), coordinate); if (configurableComponent == null) { logger.warn("Unable to get ControllerService of type {}; its default properties will be fingerprinted instead of being ignored.", dto.getType()); } addPropertiesFingerprint(builder, configurableComponent, dto.getProperties()); }
final ControllerServiceDTO dto = new ControllerServiceDTO(); dto.setId(controllerServiceNode.getIdentifier()); dto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier()); dto.setName(controllerServiceNode.getName()); dto.setType(controllerServiceNode.getCanonicalClassName()); dto.setBundle(createBundleDto(bundleCoordinate)); dto.setControllerServiceApis(createControllerServiceApiDto(controllerServiceNode.getControllerServiceImplementation().getClass())); dto.setState(controllerServiceNode.getState().name()); dto.setAnnotationData(controllerServiceNode.getAnnotationData()); dto.setComments(controllerServiceNode.getComments()); dto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class)); dto.setRestricted(controllerServiceNode.isRestricted()); dto.setDeprecated(controllerServiceNode.isDeprecated()); dto.setExtensionMissing(controllerServiceNode.isExtensionMissing()); dto.setMultipleVersionsAvailable(compatibleBundles.size() > 1); dto.setVersionedComponentId(controllerServiceNode.getVersionedComponentId().orElse(null)); dto.setDescriptors(new LinkedHashMap<String, PropertyDescriptorDTO>()); dto.setProperties(new LinkedHashMap<String, String>()); for (final Map.Entry<PropertyDescriptor, String> entry : orderedProperties.entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); dto.getDescriptors().put(descriptor.getName(), createPropertyDescriptorDto(descriptor, groupId)); dto.getProperties().put(descriptor.getName(), propertyValue); dto.setValidationStatus(controllerServiceNode.getValidationStatus(1, TimeUnit.MILLISECONDS).name()); dto.setValidationErrors(errors);
Map<String, String> values = new HashMap<>(); if (controllerServiceDTO.getName() != null) { values.put(NAME, controllerService.getName()); if (controllerServiceDTO.getAnnotationData() != null) { values.put(ANNOTATION_DATA, controllerService.getAnnotationData()); if (controllerServiceDTO.getBundle() != null) { final BundleCoordinate bundle = controllerService.getBundleCoordinate(); values.put(EXTENSION_VERSION, formatExtensionVersion(controllerService.getComponentType(), bundle)); if (controllerServiceDTO.getProperties() != null) { Map<String, String> properties = controllerServiceDTO.getProperties(); Map<PropertyDescriptor, String> configuredProperties = controllerService.getProperties(); for (String propertyName : properties.keySet()) { if (controllerServiceDTO.getComments() != null) { values.put(COMMENTS, controllerService.getComments());
private ComponentDetails getComponentConfiguration(final ControllerServiceDTO controllerService) { return new ComponentDetails.Builder() .id(controllerService.getId()) .name(controllerService.getName()) .type(controllerService.getType()) .state(controllerService.getState()) .annotationData(controllerService.getAnnotationData()) .properties(controllerService.getProperties()) .validateErrors(controllerService.getValidationErrors()).build(); } }
private static void scrubControllerServices(final Set<ControllerServiceDTO> controllerServices) { for (final ControllerServiceDTO serviceDTO : controllerServices) { 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 (Boolean.TRUE.equals(descriptor.isSensitive())) { properties.put(descriptor.getName(), null); } scrubPropertyDescriptor(descriptor); } } serviceDTO.setControllerServiceApis(null); serviceDTO.setExtensionMissing(null); serviceDTO.setMultipleVersionsAvailable(null); serviceDTO.setCustomUiUrl(null); serviceDTO.setValidationErrors(null); serviceDTO.setValidationStatus(null); } }
@Override public ControllerServiceSchema apply(ControllerServiceDTO controllerServiceDTO) { Map<String, Object> map = new HashMap<>(); map.put(NAME_KEY, controllerServiceDTO.getName()); map.put(ID_KEY, controllerServiceDTO.getId()); map.put(TYPE_KEY, controllerServiceDTO.getType()); map.put(PROPERTIES_KEY, new HashMap<>(nullToEmpty(controllerServiceDTO.getProperties()))); String annotationData = controllerServiceDTO.getAnnotationData(); if(annotationData != null && !annotationData.isEmpty()) { map.put(ANNOTATION_DATA_KEY, annotationData); } return new ControllerServiceSchema(map); } }
public static ControllerServiceDTO getControllerService(final Element element, final StringEncryptor encryptor) { final ControllerServiceDTO dto = new ControllerServiceDTO(); dto.setId(getString(element, "id")); dto.setVersionedComponentId(getString(element, "versionedComponentId")); dto.setName(getString(element, "name")); dto.setComments(getString(element, "comment")); dto.setType(getString(element, "class")); dto.setBundle(getBundle(DomUtils.getChild(element, "bundle"))); final boolean enabled = getBoolean(element, "enabled"); dto.setState(enabled ? ControllerServiceState.ENABLED.name() : ControllerServiceState.DISABLED.name()); dto.setProperties(getProperties(element, encryptor)); dto.setAnnotationData(getString(element, "annotationData")); return dto; }
final Set<ControllerServiceReferencingComponentEntity> referencingComponents = clientDto.getReferencingComponents(); final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> nodeReferencingComponentsMap = new HashMap<>(); final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>(); if (ControllerServiceState.DISABLING.name().equals(nodeControllerService.getState())) { state = ControllerServiceState.DISABLING.name(); } else if (ControllerServiceState.ENABLING.name().equals(nodeControllerService.getState())) { state = ControllerServiceState.ENABLING.name(); nodeReferencingComponentsMap.put(nodeId, nodeControllerService.getReferencingComponents()); ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeControllerService.getValidationErrors()); final Map<String, PropertyDescriptorDTO> descriptors = nodeControllerService.getDescriptors(); if (descriptors != null) { descriptors.values().stream().forEach(propertyDescriptor -> { final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName()); PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId); clientDto.setState(state); .collect(Collectors.toSet()); clientDto.setValidationStatus(ErrorMerger.mergeValidationStatus(statuses)); clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
if (requestControllerService.getId() != null) { throw new IllegalArgumentException("Controller service ID cannot be specified."); if (StringUtils.isBlank(requestControllerService.getType())) { throw new IllegalArgumentException("The type of controller service to create must be specified."); if (requestControllerService.getParentGroupId() != null && !groupId.equals(requestControllerService.getParentGroupId())) { throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestControllerService.getParentGroupId(), groupId)); requestControllerService.setParentGroupId(groupId); authorizable = lookup.getConfigurableComponent(requestControllerService.getType(), requestControllerService.getBundle()); if (requestControllerService.getProperties() != null) { AuthorizeControllerServiceReference.authorizeControllerServiceReferences(requestControllerService.getProperties(), authorizable, authorizer, lookup); controllerService.setId(generateUuid()); final Revision revision = getRevision(controllerServiceEntity, controllerService.getId()); final ControllerServiceEntity entity = serviceFacade.createControllerService(revision, groupId, controllerService); controllerServiceResource.populateRemainingControllerServiceEntityContent(entity);
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); serviceIdMap.put(serviceDTO.getId(), service.getId()); ResourceFactory.getComponentResource(ResourceType.ControllerService, serviceDTO.getId(), serviceDTO.getName()), ResourceFactory.getComponentResource(ResourceType.ControllerService, service.getId(), service.getName()), idGenerationSeed); 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()) {
private static ControllerServiceNode createControllerService(final FlowController flowController, final Element controllerServiceElement, final StringEncryptor encryptor) { final ControllerServiceDTO dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor); BundleCoordinate coordinate; try { coordinate = BundleUtils.getCompatibleBundle(flowController.getExtensionManager(), dto.getType(), dto.getBundle()); } catch (final IllegalStateException e) { final BundleDTO bundleDTO = dto.getBundle(); if (bundleDTO == null) { coordinate = BundleCoordinate.UNKNOWN_COORDINATE; } else { coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion()); } } final ControllerServiceNode node = flowController.getFlowManager().createControllerService(dto.getType(), dto.getId(), coordinate, Collections.emptySet(), false, true); node.setName(dto.getName()); node.setComments(dto.getComments()); node.setVersionedComponentId(dto.getVersionedComponentId()); return node; }
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; }
@Override protected void writeSimpleResult(final PrintStream output) throws IOException { final Set<ControllerServiceEntity> serviceEntities = controllerServicesEntity.getControllerServices(); if (serviceEntities == null) { return; } final List<ControllerServiceDTO> serviceDTOS = serviceEntities.stream() .map(s -> s.getComponent()) .collect(Collectors.toList()); Collections.sort(serviceDTOS, Comparator.comparing(ControllerServiceDTO::getName)); final Table table = new Table.Builder() .column("#", 3, 3, false) .column("Name", 5, 40, false) .column("State", 5, 40, false) .build(); for (int i=0; i < serviceDTOS.size(); i++) { final ControllerServiceDTO serviceDTO = serviceDTOS.get(i); table.addRow(String.valueOf(i+1), serviceDTO.getName(), serviceDTO.getState()); } final TableWriter tableWriter = new DynamicTableWriter(); tableWriter.write(table, output); }
/** * 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 ControllerServiceEntity createControllerServiceEntity(final ControllerServiceDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final PermissionsDTO operatePermissions, final List<BulletinEntity> bulletins) { final ControllerServiceEntity entity = new ControllerServiceEntity(); entity.setRevision(revision); if (dto != null) { entity.setPermissions(permissions); entity.setOperatePermissions(operatePermissions); entity.setId(dto.getId()); entity.setParentGroupId(dto.getParentGroupId()); entity.setPosition(dto.getPosition()); final ControllerServiceStatusDTO status = new ControllerServiceStatusDTO(); status.setRunStatus(dto.getState()); status.setValidationStatus(dto.getValidationStatus()); entity.setStatus(status); if (permissions != null && permissions.getCanRead()) { entity.setComponent(dto); entity.setBulletins(bulletins); } } return entity; }
private void printServicesNotEnabled(final FlowClient flowClient, final String pgId) throws NiFiClientException, IOException { final ControllerServicesEntity servicesEntity = flowClient.getControllerServices(pgId); if (servicesEntity == null || servicesEntity.getControllerServices() == null) { return; } println(); println("The following services could not be enabled: "); for (final ControllerServiceEntity serviceEntity : servicesEntity.getControllerServices()) { if (!ControllerServiceStates.STATE_ENABLED.equals(serviceEntity.getComponent().getState())) { println(); println("Service: " + serviceEntity.getId() + " - " + serviceEntity.getComponent().getName()); final ControllerServiceDTO serviceDTO = serviceEntity.getComponent(); if (serviceDTO.getValidationErrors() != null) { println(); println("Validation Errors: "); for (final String validationError : serviceDTO.getValidationErrors()) { println("- " + validationError); } } } } }
if (snippet.getControllerServices() != null) { snippet.getControllerServices().forEach(dto -> { if (dto.getProperties() == null) { dto.setProperties(new LinkedHashMap<>()); final ConfigurableComponent configurableComponent = controllerFacade.getTemporaryComponent(dto.getType(), dto.getBundle()); configurableComponent.getPropertyDescriptors().forEach(descriptor -> { if (dto.getProperties().get(descriptor.getName()) == null) { dto.getProperties().put(descriptor.getName(), descriptor.getDefaultValue()); logger.warn(String.format("Unable to create ControllerService of type %s to populate default values.", dto.getType()));