org.apache.nifi.controller.service.ControllerServiceNode Java Examples
The following examples show how to use
org.apache.nifi.controller.service.ControllerServiceNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardFlowSynchronizer.java From localization_nifi with Apache License 2.0 | 6 votes |
private void updateReportingTaskControllerServices(final Set<ReportingTaskNode> reportingTasks, final Map<String, ControllerServiceNode> controllerServiceMapping) { for (ReportingTaskNode reportingTask : reportingTasks) { if (reportingTask.getProperties() != null) { final Set<Map.Entry<PropertyDescriptor, String>> propertyDescriptors = reportingTask.getProperties().entrySet().stream() .filter(e -> e.getKey().getControllerServiceDefinition() != null) .filter(e -> controllerServiceMapping.containsKey(e.getValue())) .collect(Collectors.toSet()); final Map<String,String> controllerServiceProps = new HashMap<>(); for (Map.Entry<PropertyDescriptor, String> propEntry : propertyDescriptors) { final PropertyDescriptor propertyDescriptor = propEntry.getKey(); final ControllerServiceNode clone = controllerServiceMapping.get(propEntry.getValue()); controllerServiceProps.put(propertyDescriptor.getName(), clone.getIdentifier()); } reportingTask.setProperties(controllerServiceProps); } } }
Example #2
Source File: StandardControllerServiceDAO.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public Set<ConfiguredComponent> updateControllerServiceReferencingComponents( final String controllerServiceId, final ScheduledState scheduledState, final ControllerServiceState controllerServiceState) { // get the controller service final ControllerServiceNode controllerService = locateControllerService(controllerServiceId); // this request is either acting upon referencing services or schedulable components if (controllerServiceState != null) { if (ControllerServiceState.ENABLED.equals(controllerServiceState)) { return serviceProvider.enableReferencingServices(controllerService); } else { return serviceProvider.disableReferencingServices(controllerService); } } else if (scheduledState != null) { if (ScheduledState.RUNNING.equals(scheduledState)) { return serviceProvider.scheduleReferencingComponents(controllerService); } else { return serviceProvider.unscheduleReferencingComponents(controllerService); } } return Collections.emptySet(); }
Example #3
Source File: StandardControllerServiceDAO.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void verifyUpdateReferencingComponents(final String controllerServiceId, final ScheduledState scheduledState, final ControllerServiceState controllerServiceState) { final ControllerServiceNode controllerService = locateControllerService(controllerServiceId); if (controllerServiceState != null) { if (ControllerServiceState.ENABLED.equals(controllerServiceState)) { serviceProvider.verifyCanEnableReferencingServices(controllerService); } else { serviceProvider.verifyCanDisableReferencingServices(controllerService); } } else if (scheduledState != null) { if (ScheduledState.RUNNING.equals(scheduledState)) { serviceProvider.verifyCanScheduleReferencingComponents(controllerService); } else { serviceProvider.verifyCanStopReferencingComponents(controllerService); } } }
Example #4
Source File: StandardControllerServiceDAO.java From localization_nifi with Apache License 2.0 | 6 votes |
private void configureControllerService(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) { final String name = controllerServiceDTO.getName(); final String annotationData = controllerServiceDTO.getAnnotationData(); final String comments = controllerServiceDTO.getComments(); final Map<String, String> properties = controllerServiceDTO.getProperties(); if (isNotNull(name)) { controllerService.setName(name); } if (isNotNull(annotationData)) { controllerService.setAnnotationData(annotationData); } if (isNotNull(comments)) { controllerService.setComments(comments); } if (isNotNull(properties)) { controllerService.setProperties(properties); } }
Example #5
Source File: StandardSnippetDAO.java From localization_nifi with Apache License 2.0 | 6 votes |
private void lookupSensitiveControllerServiceProperties(final Set<ControllerServiceDTO> controllerServices) { // go through each service for (final ControllerServiceDTO serviceDTO : controllerServices) { // ensure that some property configuration have been specified final Map<String, String> serviceProperties = serviceDTO.getProperties(); if (serviceProperties != null) { // find the corresponding controller service final ControllerServiceNode serviceNode = flowController.getControllerServiceNode(serviceDTO.getId()); if (serviceNode == null) { throw new IllegalArgumentException(String.format("Unable to create snippet because Controller Service '%s' could not be found", serviceDTO.getId())); } // look for sensitive properties get the actual value for (Entry<PropertyDescriptor, String> entry : serviceNode.getProperties().entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); if (descriptor.isSensitive()) { serviceProperties.put(descriptor.getName(), entry.getValue()); } } } } }
Example #6
Source File: StandardNiFiServiceFacade.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public ControllerServiceEntity updateControllerService(final Revision revision, final ControllerServiceDTO controllerServiceDTO) { // get the component, ensure we have access to it, and perform the update request final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceDTO.getId()); final RevisionUpdate<ControllerServiceDTO> snapshot = updateComponent(revision, controllerService, () -> controllerServiceDAO.updateControllerService(controllerServiceDTO), cs -> { final ControllerServiceDTO dto = dtoFactory.createControllerServiceDto(cs); final ControllerServiceReference ref = controllerService.getReferences(); final ControllerServiceReferencingComponentsEntity referencingComponentsEntity = createControllerServiceReferencingComponentsEntity(ref, Sets.newHashSet(controllerService.getIdentifier())); dto.setReferencingComponents(referencingComponentsEntity.getControllerServiceReferencingComponents()); return dto; }); final PermissionsDTO permissions = dtoFactory.createPermissionsDto(controllerService); final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(controllerServiceDTO.getId())); final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList()); return entityFactory.createControllerServiceEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities); }
Example #7
Source File: SnippetUtils.java From localization_nifi with Apache License 2.0 | 6 votes |
private Set<ControllerServiceDTO> getControllerServices(final Map<PropertyDescriptor, String> componentProperties) { final Set<ControllerServiceDTO> serviceDtos = new HashSet<>(); for (final Map.Entry<PropertyDescriptor, String> entry : componentProperties.entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); if (descriptor.getControllerServiceDefinition() != null) { final String controllerServiceId = entry.getValue(); if (controllerServiceId != null) { final ControllerServiceNode serviceNode = flowController.getControllerServiceNode(controllerServiceId); if (serviceNode != null) { serviceDtos.add(dtoFactory.createControllerServiceDto(serviceNode)); final Set<ControllerServiceDTO> recursiveRefs = getControllerServices(serviceNode.getProperties()); serviceDtos.addAll(recursiveRefs); } } } } return serviceDtos; }
Example #8
Source File: ControllerServiceAuditor.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * Audits the creation of controller service via createControllerService(). * * This method only needs to be run 'after returning'. However, in Java 7 the order in which these methods are returned from Class.getDeclaredMethods (even though there is no order guaranteed) * seems to differ from Java 6. SpringAOP depends on this ordering to determine advice precedence. By normalizing all advice into Around advice we can alleviate this issue. * * @param proceedingJoinPoint join point * @return node * @throws java.lang.Throwable ex */ @Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(org.apache.nifi.controller.service.ControllerServiceNode createControllerService(org.apache.nifi.web.api.dto.ControllerServiceDTO))") public ControllerServiceNode createControllerServiceAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { // update the controller service state ControllerServiceNode controllerService = (ControllerServiceNode) proceedingJoinPoint.proceed(); // if no exceptions were thrown, add the controller service action... final Action action = generateAuditRecord(controllerService, Operation.Add); // save the actions if (action != null) { saveAction(action, logger); } return controllerService; }
Example #9
Source File: StandardFlowSerializer.java From nifi with Apache License 2.0 | 6 votes |
public void addControllerService(final Element element, final ControllerServiceNode serviceNode) { final Element serviceElement = element.getOwnerDocument().createElement("controllerService"); addTextElement(serviceElement, "id", serviceNode.getIdentifier()); addTextElement(serviceElement, "versionedComponentId", serviceNode.getVersionedComponentId()); addTextElement(serviceElement, "name", serviceNode.getName()); addTextElement(serviceElement, "comment", serviceNode.getComments()); addTextElement(serviceElement, "class", serviceNode.getCanonicalClassName()); addBundle(serviceElement, serviceNode.getBundleCoordinate()); final ControllerServiceState state = serviceNode.getState(); final boolean enabled = (state == ControllerServiceState.ENABLED || state == ControllerServiceState.ENABLING); addTextElement(serviceElement, "enabled", String.valueOf(enabled)); addConfiguration(serviceElement, serviceNode.getRawPropertyValues(), serviceNode.getAnnotationData(), encryptor); element.appendChild(serviceElement); }
Example #10
Source File: ControllerServiceAuditor.java From nifi with Apache License 2.0 | 6 votes |
/** * Audits the removal of a controller service via deleteControllerService(). * * @param proceedingJoinPoint join point * @param controllerServiceId id * @param controllerServiceDAO dao * @throws Throwable ex */ @Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(void deleteControllerService(java.lang.String)) && " + "args(controllerServiceId) && " + "target(controllerServiceDAO)") public void removeControllerServiceAdvice(ProceedingJoinPoint proceedingJoinPoint, String controllerServiceId, ControllerServiceDAO controllerServiceDAO) throws Throwable { // get the controller service before removing it ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId); // remove the controller service proceedingJoinPoint.proceed(); // if no exceptions were thrown, add removal actions... // audit the controller service removal final Action action = generateAuditRecord(controllerService, Operation.Remove); // save the actions if (action != null) { saveAction(action, logger); } }
Example #11
Source File: FlowDifferenceFilters.java From nifi with Apache License 2.0 | 6 votes |
public static boolean isNewPropertyWithDefaultValue(final FlowDifference fd, final FlowManager flowManager) { if (fd.getDifferenceType() != DifferenceType.PROPERTY_ADDED) { return false; } final VersionedComponent componentB = fd.getComponentB(); if (componentB instanceof InstantiatedVersionedProcessor) { final InstantiatedVersionedProcessor instantiatedProcessor = (InstantiatedVersionedProcessor) componentB; final ProcessorNode processorNode = flowManager.getProcessorNode(instantiatedProcessor.getInstanceId()); return isNewPropertyWithDefaultValue(fd, processorNode); } else if (componentB instanceof InstantiatedVersionedControllerService) { final InstantiatedVersionedControllerService instantiatedControllerService = (InstantiatedVersionedControllerService) componentB; final ControllerServiceNode controllerService = flowManager.getControllerServiceNode(instantiatedControllerService.getInstanceId()); return isNewPropertyWithDefaultValue(fd, controllerService); } return false; }
Example #12
Source File: StandardSchedulingContext.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void leaseControllerService(final String identifier) { final ControllerServiceNode serviceNode = serviceProvider.getControllerServiceNode(identifier); if (serviceNode == null) { throw new IllegalArgumentException("Cannot lease Controller Service because no Controller Service exists with identifier " + identifier); } if (serviceNode.getState() != ControllerServiceState.ENABLED) { throw new IllegalStateException("Cannot lease Controller Service because Controller Service " + serviceNode.getProxiedControllerService().getIdentifier() + " is not currently enabled"); } if (!serviceNode.isValid()) { throw new IllegalStateException("Cannot lease Controller Service because Controller Service " + serviceNode.getProxiedControllerService().getIdentifier() + " is not currently valid"); } serviceNode.addReference(processorNode); }
Example #13
Source File: StandardControllerServiceDAO.java From nifi with Apache License 2.0 | 5 votes |
private ControllerServiceNode locateControllerService(final String controllerServiceId) { // get the controller service final ControllerServiceNode controllerService = serviceProvider.getControllerServiceNode(controllerServiceId); // ensure the controller service exists if (controllerService == null) { throw new ResourceNotFoundException(String.format("Unable to locate controller service with id '%s'.", controllerServiceId)); } return controllerService; }
Example #14
Source File: TestStandardProcessScheduler.java From nifi with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testDisableControllerServiceWithProcessorTryingToStartUsingIt() throws InterruptedException, ExecutionException { final String uuid = UUID.randomUUID().toString(); final Processor proc = new ServiceReferencingProcessor(); proc.initialize(new StandardProcessorInitializationContext(uuid, null, null, null, KerberosConfig.NOT_CONFIGURED)); final ReloadComponent reloadComponent = Mockito.mock(ReloadComponent.class); final ControllerServiceNode service = flowManager.createControllerService(NoStartServiceImpl.class.getName(), "service", systemBundle.getBundleDetails().getCoordinate(), null, true, true); rootGroup.addControllerService(service); final LoggableComponent<Processor> loggableComponent = new LoggableComponent<>(proc, systemBundle.getBundleDetails().getCoordinate(), null); final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, variableRegistry); final ProcessorNode procNode = new StandardProcessorNode(loggableComponent, uuid, validationContextFactory, scheduler, serviceProvider, new StandardComponentVariableRegistry(VariableRegistry.EMPTY_REGISTRY), reloadComponent, extensionManager, new SynchronousValidationTrigger()); rootGroup.addProcessor(procNode); Map<String, String> procProps = new HashMap<>(); procProps.put(ServiceReferencingProcessor.SERVICE_DESC.getName(), service.getIdentifier()); procNode.setProperties(procProps); service.performValidation(); scheduler.enableControllerService(service); procNode.performValidation(); scheduler.startProcessor(procNode, true); Thread.sleep(25L); scheduler.stopProcessor(procNode); assertTrue(service.isActive()); assertSame(service.getState(), ControllerServiceState.ENABLING); scheduler.disableControllerService(service).get(); assertFalse(service.isActive()); assertSame(service.getState(), ControllerServiceState.DISABLED); }
Example #15
Source File: TestFlowController.java From nifi with Apache License 2.0 | 5 votes |
private void purgeFlow() { final ProcessGroup processGroup = controller.getFlowManager().getRootGroup(); for (final ProcessorNode procNode : processGroup.getProcessors()) { processGroup.removeProcessor(procNode); } for (final ControllerServiceNode serviceNode : controller.getFlowManager().getAllControllerServices()) { controller.getControllerServiceProvider().removeControllerService(serviceNode); } }
Example #16
Source File: FlowController.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public void removeReportingTask(final ReportingTaskNode reportingTaskNode) { final ReportingTaskNode existing = reportingTasks.get(reportingTaskNode.getIdentifier()); if (existing == null || existing != reportingTaskNode) { throw new IllegalStateException("Reporting Task " + reportingTaskNode + " does not exist in this Flow"); } reportingTaskNode.verifyCanDelete(); try (final NarCloseable x = NarCloseable.withComponentNarLoader(reportingTaskNode.getReportingTask().getClass(), reportingTaskNode.getReportingTask().getIdentifier())) { ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, reportingTaskNode.getReportingTask(), reportingTaskNode.getConfigurationContext()); } for (final Map.Entry<PropertyDescriptor, String> entry : reportingTaskNode.getProperties().entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); if (descriptor.getControllerServiceDefinition() != null) { final String value = entry.getValue() == null ? descriptor.getDefaultValue() : entry.getValue(); if (value != null) { final ControllerServiceNode serviceNode = controllerServiceProvider.getControllerServiceNode(value); if (serviceNode != null) { serviceNode.removeReference(reportingTaskNode); } } } } reportingTasks.remove(reportingTaskNode.getIdentifier()); ExtensionManager.removeInstanceClassLoaderIfExists(reportingTaskNode.getIdentifier()); }
Example #17
Source File: StandardControllerServiceDAO.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) { // ensure the type is specified if (controllerServiceDTO.getType() == null) { throw new IllegalArgumentException("The controller service type must be specified."); } try { // create the controller service final ControllerServiceNode controllerService = serviceProvider.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), true); // ensure we can perform the update verifyUpdate(controllerService, controllerServiceDTO); // perform the update configureControllerService(controllerService, controllerServiceDTO); final String groupId = controllerServiceDTO.getParentGroupId(); if (groupId == null) { flowController.addRootControllerService(controllerService); } else { final ProcessGroup group; if (groupId.equals(ROOT_GROUP_ID_ALIAS)) { group = flowController.getGroup(flowController.getRootGroupId()); } else { group = flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(groupId); } if (group == null) { throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId)); } group.addControllerService(controllerService); } return controllerService; } catch (final ControllerServiceInstantiationException csie) { throw new NiFiCoreException(csie.getMessage(), csie); } }
Example #18
Source File: StandardFlowSerializer.java From localization_nifi with Apache License 2.0 | 5 votes |
public void addControllerService(final Element element, final ControllerServiceNode serviceNode) { final Element serviceElement = element.getOwnerDocument().createElement("controllerService"); addTextElement(serviceElement, "id", serviceNode.getIdentifier()); addTextElement(serviceElement, "name", serviceNode.getName()); addTextElement(serviceElement, "comment", serviceNode.getComments()); addTextElement(serviceElement, "class", serviceNode.getCanonicalClassName()); final ControllerServiceState state = serviceNode.getState(); final boolean enabled = (state == ControllerServiceState.ENABLED || state == ControllerServiceState.ENABLING); addTextElement(serviceElement, "enabled", String.valueOf(enabled)); addConfiguration(serviceElement, serviceNode.getProperties(), serviceNode.getAnnotationData(), encryptor); element.appendChild(serviceElement); }
Example #19
Source File: TestFlowController.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testInstantiateSnippetWithControllerService() throws ProcessorInstantiationException { final String id = UUID.randomUUID().toString(); final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate(); final ControllerServiceNode controllerServiceNode = controller.getFlowManager().createControllerService(ServiceA.class.getName(), id, coordinate, null, true, true); // create the controller service dto final ControllerServiceDTO csDto = new ControllerServiceDTO(); csDto.setId(UUID.randomUUID().toString()); // use a different id csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier()); csDto.setName(controllerServiceNode.getName()); csDto.setType(controllerServiceNode.getCanonicalClassName()); csDto.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); csDto.setState(controllerServiceNode.getState().name()); csDto.setAnnotationData(controllerServiceNode.getAnnotationData()); csDto.setComments(controllerServiceNode.getComments()); csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class)); csDto.setRestricted(controllerServiceNode.isRestricted()); csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing()); csDto.setDescriptors(new LinkedHashMap<>()); csDto.setProperties(new LinkedHashMap<>()); // create the snippet with the controller service final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO(); flowSnippetDTO.setControllerServices(Collections.singleton(csDto)); // instantiate the snippet assertEquals(0, controller.getFlowManager().getRootGroup().getControllerServices(false).size()); controller.getFlowManager().instantiateSnippet(controller.getFlowManager().getRootGroup(), flowSnippetDTO); assertEquals(1, controller.getFlowManager().getRootGroup().getControllerServices(false).size()); }
Example #20
Source File: StandardControllerServiceDAO.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) { // get the controller service final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId()); // ensure we can perform the update verifyUpdate(controllerService, controllerServiceDTO); // perform the update configureControllerService(controllerService, controllerServiceDTO); // enable or disable as appropriate if (isNotNull(controllerServiceDTO.getState())) { final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState()); // only attempt an action if it is changing if (!purposedControllerServiceState.equals(controllerService.getState())) { if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) { serviceProvider.enableControllerService(controllerService); } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) { serviceProvider.disableControllerService(controllerService); } } } return controllerService; }
Example #21
Source File: StandardNiFiServiceFacade.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public Set<ControllerServiceEntity> getControllerServices(final String groupId) { final Set<ControllerServiceNode> serviceNodes = controllerServiceDAO.getControllerServices(groupId); final Set<String> serviceIds = serviceNodes.stream().map(service -> service.getIdentifier()).collect(Collectors.toSet()); return serviceNodes.stream() .map(serviceNode -> createControllerServiceEntity(serviceNode, serviceIds)) .collect(Collectors.toSet()); }
Example #22
Source File: TestFlowController.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testDeleteProcessGroup() { ProcessGroup pg = controller.getFlowManager().createProcessGroup("my-process-group"); pg.setName("my-process-group"); ControllerServiceNode cs = controller.getFlowManager().createControllerService("org.apache.nifi.NonExistingControllerService", "my-controller-service", systemBundle.getBundleDetails().getCoordinate(), null, false, true); pg.addControllerService(cs); controller.getFlowManager().getRootGroup().addProcessGroup(pg); controller.getFlowManager().getRootGroup().removeProcessGroup(pg); pg.getControllerServices(true); assertTrue(pg.getControllerServices(true).isEmpty()); }
Example #23
Source File: TestFlowController.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testReloadControllerServiceWithAdditionalResources() throws MalformedURLException { final URL resource1 = new File("src/test/resources/TestClasspathResources/resource1.txt").toURI().toURL(); final URL resource2 = new File("src/test/resources/TestClasspathResources/resource2.txt").toURI().toURL(); final URL resource3 = new File("src/test/resources/TestClasspathResources/resource3.txt").toURI().toURL(); final Set<URL> additionalUrls = new LinkedHashSet<>(Arrays.asList(resource1, resource2, resource3)); final String id = "ServiceA" + System.currentTimeMillis(); final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate(); final ControllerServiceNode controllerServiceNode = controller.getFlowManager().createControllerService(ServiceA.class.getName(), id, coordinate, null, true, true); // the instance class loader shouldn't have any of the resources yet URLClassLoader instanceClassLoader = extensionManager.getInstanceClassLoader(id); assertNotNull(instanceClassLoader); assertFalse(containsResource(instanceClassLoader.getURLs(), resource1)); assertFalse(containsResource(instanceClassLoader.getURLs(), resource2)); assertFalse(containsResource(instanceClassLoader.getURLs(), resource3)); assertTrue(instanceClassLoader instanceof InstanceClassLoader); assertTrue(((InstanceClassLoader) instanceClassLoader).getAdditionalResourceUrls().isEmpty()); controller.getReloadComponent().reload(controllerServiceNode, ServiceB.class.getName(), coordinate, additionalUrls); // the instance class loader shouldn't have any of the resources yet instanceClassLoader = extensionManager.getInstanceClassLoader(id); assertNotNull(instanceClassLoader); assertTrue(containsResource(instanceClassLoader.getURLs(), resource1)); assertTrue(containsResource(instanceClassLoader.getURLs(), resource2)); assertTrue(containsResource(instanceClassLoader.getURLs(), resource3)); assertTrue(instanceClassLoader instanceof InstanceClassLoader); assertEquals(3, ((InstanceClassLoader) instanceClassLoader).getAdditionalResourceUrls().size()); }
Example #24
Source File: AbstractComponentNode.java From nifi with Apache License 2.0 | 5 votes |
protected final Collection<ValidationResult> validateReferencedControllerServices(final ValidationContext validationContext) { final Set<PropertyDescriptor> propertyDescriptors = validationContext.getProperties().keySet(); if (propertyDescriptors == null) { return Collections.emptyList(); } final Collection<ValidationResult> validationResults = new ArrayList<>(); for (final PropertyDescriptor descriptor : propertyDescriptors) { if (descriptor.getControllerServiceDefinition() == null) { // skip properties that aren't for a controller service continue; } final String controllerServiceId = validationContext.getProperty(descriptor).getValue(); if (controllerServiceId == null) { continue; } final ControllerServiceNode controllerServiceNode = getControllerServiceProvider().getControllerServiceNode(controllerServiceId); if (controllerServiceNode == null) { final ValidationResult result = createInvalidResult(controllerServiceId, descriptor.getDisplayName(), "Invalid Controller Service: " + controllerServiceId + " is not a valid Controller Service Identifier"); validationResults.add(result); continue; } final ValidationResult apiResult = validateControllerServiceApi(descriptor, controllerServiceNode); if (apiResult != null) { validationResults.add(apiResult); continue; } if (!controllerServiceNode.isActive()) { validationResults.add(new DisabledServiceValidationResult(descriptor.getDisplayName(), controllerServiceId)); } } return validationResults; }
Example #25
Source File: ControllerServiceAuditor.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Generates an audit record for the creation of a controller service. * * @param controllerService service * @param operation operation * @param actionDetails details * @return action */ private Action generateAuditRecord(ControllerServiceNode controllerService, Operation operation, ActionDetails actionDetails) { FlowChangeAction action = null; // get the current user NiFiUser user = NiFiUserUtils.getNiFiUser(); // ensure the user was found if (user != null) { // create the controller service details FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails(); serviceDetails.setType(controllerService.getComponentType()); // create the controller service action for adding this controller service action = new FlowChangeAction(); action.setUserIdentity(user.getIdentity()); action.setOperation(operation); action.setTimestamp(new Date()); action.setSourceId(controllerService.getIdentifier()); action.setSourceName(controllerService.getName()); action.setSourceType(Component.ControllerService); action.setComponentDetails(serviceDetails); if (actionDetails != null) { action.setActionDetails(actionDetails); } } return action; }
Example #26
Source File: ControllerServiceAuditor.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Extracts the values for the configured properties from the specified ControllerService. * * @param controllerService service * @param controllerServiceDTO dto * @return properties */ private Map<String, String> extractConfiguredPropertyValues(ControllerServiceNode controllerService, ControllerServiceDTO controllerServiceDTO) { 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.getProperties() != null) { // for each property specified, extract its configured value Map<String, String> properties = controllerServiceDTO.getProperties(); Map<PropertyDescriptor, String> configuredProperties = controllerService.getProperties(); for (String propertyName : properties.keySet()) { // build a descriptor for getting the configured value PropertyDescriptor propertyDescriptor = new PropertyDescriptor.Builder().name(propertyName).build(); String configuredPropertyValue = configuredProperties.get(propertyDescriptor); // if the configured value couldn't be found, use the default value from the actual descriptor if (configuredPropertyValue == null) { propertyDescriptor = locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor); configuredPropertyValue = propertyDescriptor.getDefaultValue(); } values.put(propertyName, configuredPropertyValue); } } if (controllerServiceDTO.getComments() != null) { values.put(COMMENTS, controllerService.getComments()); } return values; }
Example #27
Source File: ComponentStateAuditor.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Audits clearing of state from a Controller Service. * * @param proceedingJoinPoint join point * @param controllerService the controller service * @throws java.lang.Throwable ex */ @Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.service.ControllerServiceNode)) && " + "args(controllerService)") public StateMap clearControllerServiceStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ControllerServiceNode controllerService) throws Throwable { // update the controller service state final StateMap stateMap = (StateMap) proceedingJoinPoint.proceed(); // if no exception were thrown, add the clear action... // get the current user NiFiUser user = NiFiUserUtils.getNiFiUser(); // ensure the user was found if (user != null) { Collection<Action> actions = new ArrayList<>(); // create the controller service details FlowChangeExtensionDetails controllerServiceDetails = new FlowChangeExtensionDetails(); controllerServiceDetails.setType(controllerService.getComponentType()); // create the clear action FlowChangeAction configAction = new FlowChangeAction(); configAction.setUserIdentity(user.getIdentity()); configAction.setOperation(Operation.ClearState); configAction.setTimestamp(new Date()); configAction.setSourceId(controllerService.getIdentifier()); configAction.setSourceName(controllerService.getName()); configAction.setSourceType(Component.ControllerService); configAction.setComponentDetails(controllerServiceDetails); actions.add(configAction); // record the action saveActions(actions, logger); } return stateMap; }
Example #28
Source File: StandardAuthorizableLookup.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public Authorizable getControllerServiceReferencingComponent(String controllerServiceId, String id) { final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId); final ControllerServiceReference referencingComponents = controllerService.getReferences(); final ConfiguredComponent reference = findControllerServiceReferencingComponent(referencingComponents, id); if (reference == null) { throw new ResourceNotFoundException("Unable to find referencing component with id " + id); } return reference; }
Example #29
Source File: StandardControllerServiceDAO.java From nifi with Apache License 2.0 | 5 votes |
private List<String> validateProposedConfiguration(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) { final List<String> validationErrors = new ArrayList<>(); final Map<String, String> properties = controllerServiceDTO.getProperties(); if (isNotNull(properties)) { try { controllerService.verifyCanUpdateProperties(properties); } catch (final IllegalArgumentException | IllegalStateException iae) { validationErrors.add(iae.getMessage()); } } return validationErrors; }
Example #30
Source File: FlowController.java From localization_nifi with Apache License 2.0 | 5 votes |
public void removeRootControllerService(final ControllerServiceNode service) { final ControllerServiceNode existing = rootControllerServices.get(requireNonNull(service).getIdentifier()); if (existing == null) { throw new IllegalStateException(service + " is not a member of this Process Group"); } service.verifyCanDelete(); try (final NarCloseable x = NarCloseable.withComponentNarLoader(service.getControllerServiceImplementation().getClass(), service.getIdentifier())) { final ConfigurationContext configurationContext = new StandardConfigurationContext(service, controllerServiceProvider, null, variableRegistry); ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext); } for (final Map.Entry<PropertyDescriptor, String> entry : service.getProperties().entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); if (descriptor.getControllerServiceDefinition() != null) { final String value = entry.getValue() == null ? descriptor.getDefaultValue() : entry.getValue(); if (value != null) { final ControllerServiceNode referencedNode = getRootControllerService(value); if (referencedNode != null) { referencedNode.removeReference(service); } } } } rootControllerServices.remove(service.getIdentifier()); getStateManagerProvider().onComponentRemoved(service.getIdentifier()); ExtensionManager.removeInstanceClassLoaderIfExists(service.getIdentifier()); LOG.info("{} removed from Flow Controller", service, this); }