Search in sources :

Example 51 with ControllerServiceNode

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));
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference)

Example 52 with ControllerServiceNode

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);
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO)

Example 53 with ControllerServiceNode

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);
}
Also used : MockPolicyBasedAuthorizer(org.apache.nifi.authorization.MockPolicyBasedAuthorizer) Bundle(org.apache.nifi.bundle.Bundle) Arrays(java.util.Arrays) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) ProcessGroup(org.apache.nifi.groups.ProcessGroup) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) URL(java.net.URL) AbstractPolicyBasedAuthorizer(org.apache.nifi.authorization.AbstractPolicyBasedAuthorizer) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) ServiceB(org.apache.nifi.controller.service.mock.ServiceB) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) After(org.junit.After) Map(java.util.Map) MockProvenanceRepository(org.apache.nifi.provenance.MockProvenanceRepository) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Set(java.util.Set) UUID(java.util.UUID) StandardCharsets(java.nio.charset.StandardCharsets) User(org.apache.nifi.authorization.User) VariableRegistry(org.apache.nifi.registry.VariableRegistry) IOUtils(org.apache.commons.io.IOUtils) Stateful(org.apache.nifi.annotation.behavior.Stateful) Assert.assertFalse(org.junit.Assert.assertFalse) DummyProcessor(org.apache.nifi.controller.service.mock.DummyProcessor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ExtensionManager(org.apache.nifi.nar.ExtensionManager) DummyReportingTask(org.apache.nifi.controller.service.mock.DummyReportingTask) AuditService(org.apache.nifi.admin.service.AuditService) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) Mockito.mock(org.mockito.Mockito.mock) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) HashMap(java.util.HashMap) Group(org.apache.nifi.authorization.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) Relationship(org.apache.nifi.processor.Relationship) SystemBundle(org.apache.nifi.nar.SystemBundle) LogLevel(org.apache.nifi.logging.LogLevel) LinkedHashSet(java.util.LinkedHashSet) Before(org.junit.Before) InstanceClassLoader(org.apache.nifi.nar.InstanceClassLoader) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) MalformedURLException(java.net.MalformedURLException) RequestAction(org.apache.nifi.authorization.RequestAction) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) LogRepository(org.apache.nifi.logging.LogRepository) Test(org.junit.Test) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) Mockito.when(org.mockito.Mockito.when) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) NiFiProperties(org.apache.nifi.util.NiFiProperties) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) Assert(org.junit.Assert) Collections(java.util.Collections) LogRepositoryFactory(org.apache.nifi.logging.LogRepositoryFactory) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) FileInputStream(java.io.FileInputStream) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) File(java.io.File) Test(org.junit.Test)

Example 54 with ControllerServiceNode

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());
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

Example 55 with ControllerServiceNode

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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) InstanceClassLoader(org.apache.nifi.nar.InstanceClassLoader) File(java.io.File) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)88 HashSet (java.util.HashSet)29 ProcessGroup (org.apache.nifi.groups.ProcessGroup)26 HashMap (java.util.HashMap)25 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)25 ArrayList (java.util.ArrayList)24 Map (java.util.Map)24 LinkedHashSet (java.util.LinkedHashSet)22 Test (org.junit.Test)19 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)18 ProcessorNode (org.apache.nifi.controller.ProcessorNode)18 ConfiguredComponent (org.apache.nifi.controller.ConfiguredComponent)17 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)17 Set (java.util.Set)16 Connection (org.apache.nifi.connectable.Connection)16 List (java.util.List)15 Port (org.apache.nifi.connectable.Port)15 Label (org.apache.nifi.controller.label.Label)15 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)15 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)15