use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class StandardNiFiServiceFacade method getControllerServiceReferencingComponents.
@Override
public ControllerServiceReferencingComponentsEntity getControllerServiceReferencingComponents(final String controllerServiceId) {
final ControllerServiceNode service = controllerServiceDAO.getControllerService(controllerServiceId);
final ControllerServiceReference ref = service.getReferences();
return createControllerServiceReferencingComponentsEntity(ref, Sets.newHashSet(controllerServiceId));
}
use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class StandardNiFiServiceFacade method deleteControllerService.
@Override
public ControllerServiceEntity deleteControllerService(final Revision revision, final String controllerServiceId) {
final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId);
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(controllerService);
final ControllerServiceDTO snapshot = deleteComponent(revision, controllerService.getResource(), () -> controllerServiceDAO.deleteControllerService(controllerServiceId), true, dtoFactory.createControllerServiceDto(controllerService));
return entityFactory.createControllerServiceEntity(snapshot, null, permissions, null);
}
use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class TestFlowController method testSynchronizeFlowWithReportingTaskAndProcessorReferencingControllerService.
@Test
public void testSynchronizeFlowWithReportingTaskAndProcessorReferencingControllerService() throws IOException {
final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
// create a mock proposed data flow with the same auth fingerprint as the current authorizer
final String authFingerprint = authorizer.getFingerprint();
final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
when(proposedDataFlow.getAuthorizerFingerprint()).thenReturn(authFingerprint.getBytes(StandardCharsets.UTF_8));
final File flowFile = new File("src/test/resources/conf/reporting-task-with-cs-flow-0.7.0.xml");
final String flow = IOUtils.toString(new FileInputStream(flowFile));
when(proposedDataFlow.getFlow()).thenReturn(flow.getBytes(StandardCharsets.UTF_8));
controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
// should be two controller services
final Set<ControllerServiceNode> controllerServiceNodes = controller.getAllControllerServices();
assertNotNull(controllerServiceNodes);
assertEquals(2, controllerServiceNodes.size());
// find the controller service that was moved to the root group
final ControllerServiceNode rootGroupCs = controllerServiceNodes.stream().filter(c -> c.getProcessGroup() != null).findFirst().get();
assertNotNull(rootGroupCs);
// find the controller service that was not moved to the root group
final ControllerServiceNode controllerCs = controllerServiceNodes.stream().filter(c -> c.getProcessGroup() == null).findFirst().get();
assertNotNull(controllerCs);
// should be same class (not Ghost), different ids, and same properties
assertEquals(rootGroupCs.getCanonicalClassName(), controllerCs.getCanonicalClassName());
assertFalse(rootGroupCs.getCanonicalClassName().contains("Ghost"));
assertNotEquals(rootGroupCs.getIdentifier(), controllerCs.getIdentifier());
assertEquals(rootGroupCs.getProperties(), controllerCs.getProperties());
// should be one processor
final Set<ProcessorNode> processorNodes = controller.getGroup(controller.getRootGroupId()).getProcessors();
assertNotNull(processorNodes);
assertEquals(1, processorNodes.size());
// verify the processor is still pointing at the controller service that got moved to the root group
final ProcessorNode processorNode = processorNodes.stream().findFirst().get();
final PropertyDescriptor procControllerServiceProp = processorNode.getProperties().entrySet().stream().filter(e -> e.getValue().equals(rootGroupCs.getIdentifier())).map(e -> e.getKey()).findFirst().get();
assertNotNull(procControllerServiceProp);
// should be one reporting task
final Set<ReportingTaskNode> reportingTaskNodes = controller.getAllReportingTasks();
assertNotNull(reportingTaskNodes);
assertEquals(1, reportingTaskNodes.size());
// verify that the reporting task is pointing at the controller service at the controller level
final ReportingTaskNode reportingTaskNode = reportingTaskNodes.stream().findFirst().get();
final PropertyDescriptor reportingTaskControllerServiceProp = reportingTaskNode.getProperties().entrySet().stream().filter(e -> e.getValue().equals(controllerCs.getIdentifier())).map(e -> e.getKey()).findFirst().get();
assertNotNull(reportingTaskControllerServiceProp);
}
use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class TestFlowController method testInstantiateSnippetWithControllerService.
@Test
public void testInstantiateSnippetWithControllerService() throws ProcessorInstantiationException {
final String id = UUID.randomUUID().toString();
final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
// create the controller service dto
final ControllerServiceDTO csDto = new ControllerServiceDTO();
// use a different id
csDto.setId(UUID.randomUUID().toString());
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.getRootGroup().getControllerServices(false).size());
controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
assertEquals(1, controller.getRootGroup().getControllerServices(false).size());
}
use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.
the class TestFlowController method testReloadControllerServiceWithAdditionalResources.
@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.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
final String originalName = controllerServiceNode.getName();
// the instance class loader shouldn't have any of the resources yet
InstanceClassLoader instanceClassLoader = ExtensionManager.getInstanceClassLoader(id);
assertNotNull(instanceClassLoader);
assertFalse(containsResource(instanceClassLoader.getURLs(), resource1));
assertFalse(containsResource(instanceClassLoader.getURLs(), resource2));
assertFalse(containsResource(instanceClassLoader.getURLs(), resource3));
assertTrue(instanceClassLoader.getAdditionalResourceUrls().isEmpty());
controller.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));
assertEquals(3, instanceClassLoader.getAdditionalResourceUrls().size());
}
Aggregations