public static void enableControllerServices(final Map<ControllerServiceNode, Element> nodeMap, final FlowController controller, final StringEncryptor encryptor, final boolean autoResumeState) { // Start services if (autoResumeState) { final Set<ControllerServiceNode> nodesToEnable = new HashSet<>(); for (final ControllerServiceNode node : nodeMap.keySet()) { final Element controllerServiceElement = nodeMap.get(node); final ControllerServiceDTO dto; synchronized (controllerServiceElement.getOwnerDocument()) { dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor); } final ControllerServiceState state = ControllerServiceState.valueOf(dto.getState()); if (state == ControllerServiceState.ENABLED) { nodesToEnable.add(node); logger.debug("Will enable Controller Service {}", node); } else { logger.debug("Will not enable Controller Service {} because its state is set to {}", node, state); } } enableControllerServices(nodesToEnable, controller, autoResumeState); } else { logger.debug("Will not enable the following Controller Services because 'auto-resume state' flag is false: {}", nodeMap.keySet()); } }
.map(entity -> entity.getComponent()) .filter(service -> affectedServices.containsKey(service.getId())) .map(service -> service.getState()) .allMatch(state -> desiredStateName.equals(state));
.map(entity -> entity.getComponent()) .filter(service -> serviceIds.contains(service.getId())) .map(service -> service.getState()) .allMatch(state -> desiredStateName.equals(state));
@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); }
.map(entity -> entity.getComponent()) .filter(service -> serviceIds.contains(service.getId())) .map(service -> service.getState()) .allMatch(state -> state.equals(desiredStateName));
.map(entity -> entity.getComponent()) .filter(service -> serviceIds.contains(service.getId())) .map(service -> service.getState()) .allMatch(state -> state.equals(desiredStateName));
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()); }
/** * 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()); } } }); }
/** * 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()); } } }); }
/** * 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 static ControllerServiceStateCounts getControllerServiceStates(final ControllerServicesEntity servicesEntity) throws NiFiClientException { final ControllerServiceStateCounts states = new ControllerServiceStateCounts(); if (servicesEntity == null || servicesEntity.getControllerServices() == null || servicesEntity.getControllerServices().isEmpty()) { return states; } for (final ControllerServiceEntity serviceEntity : servicesEntity.getControllerServices()) { final String state = serviceEntity.getComponent().getState(); switch(state) { case ControllerServiceStates.STATE_ENABLED: states.incrementEnabled(); break; case ControllerServiceStates.STATE_ENABLING: states.incrementEnabling(); break; case ControllerServiceStates.STATE_DISABLED: states.incrementDisabled(); break; case ControllerServiceStates.STATE_DISABLING: states.incrementDisabling(); break; default: throw new NiFiClientException("Unexpected controller service state: " + state); } } return states; }
private void verifyUpdate(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) { if (isNotNull(controllerServiceDTO.getState())) { try { final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
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 void printServicesStillEnabling(final FlowClient flowClient, final String pgId) throws NiFiClientException, IOException { final ControllerServicesEntity servicesEntity = flowClient.getControllerServices(pgId); if (servicesEntity == null || servicesEntity.getControllerServices() == null) { return; } println(); println("One or more services appear to be stuck enabling: "); for (final ControllerServiceEntity serviceEntity : servicesEntity.getControllerServices()) { if (ControllerServiceStates.STATE_ENABLING.equals(serviceEntity.getComponent().getState())) { println(); println("Service: " + serviceEntity.getId() + " - " + serviceEntity.getComponent().getName()); if (serviceEntity.getBulletins() != null) { println(); println("Reasons: "); for (final BulletinEntity bulletinEntity : serviceEntity.getBulletins()) { println("- " + bulletinEntity.getBulletin().getMessage()); } } } } }
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); } } } } }
private void printServicesStillDisabling(final FlowClient flowClient, final String pgId) throws NiFiClientException, IOException { final ControllerServicesEntity servicesEntity = flowClient.getControllerServices(pgId); if (servicesEntity == null || servicesEntity.getControllerServices() == null) { return; } println(); println("One or more services appear to be stuck disabling: "); for (final ControllerServiceEntity serviceEntity : servicesEntity.getControllerServices()) { if (ControllerServiceStates.STATE_DISABLING.equals(serviceEntity.getComponent().getState())) { println(); println("Service: " + serviceEntity.getId() + " - " + serviceEntity.getComponent().getName()); if (serviceEntity.getBulletins() != null) { println(); println("Reasons: "); for (final BulletinEntity bulletinEntity : serviceEntity.getBulletins()) { println("- " + bulletinEntity.getBulletin().getMessage()); } } } } }
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; }
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; }
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; }