Search in sources :

Example 36 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class TestRemoteProcessGroupAuditor method updateProcessGroupConfiguration.

@SuppressWarnings("unchecked")
private Collection<Action> updateProcessGroupConfiguration(RemoteProcessGroupDTO inputRPGDTO, RemoteProcessGroup existingRPG) throws Throwable {
    final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
    final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
    final String remoteProcessGroupId = "remote-process-group-id";
    inputRPGDTO.setId(remoteProcessGroupId);
    final String targetUrl = "http://localhost:8080/nifi";
    when(existingRPG.getTargetUri()).thenReturn(targetUrl);
    final RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
    when(remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId)).thenReturn(existingRPG);
    // Setup updatedRPG mock based on inputRPGDTO.
    final RemoteProcessGroup updatedRPG = mock(RemoteProcessGroup.class);
    when(updatedRPG.getIdentifier()).thenReturn(remoteProcessGroupId);
    when(updatedRPG.isTransmitting()).thenReturn(inputRPGDTO.isTransmitting());
    when(updatedRPG.getCommunicationsTimeout()).thenReturn(inputRPGDTO.getCommunicationsTimeout());
    when(updatedRPG.getYieldDuration()).thenReturn(inputRPGDTO.getYieldDuration());
    when(updatedRPG.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.valueOf(inputRPGDTO.getTransportProtocol()));
    when(updatedRPG.getProxyHost()).thenReturn(inputRPGDTO.getProxyHost());
    when(updatedRPG.getProxyPort()).thenReturn(inputRPGDTO.getProxyPort());
    when(updatedRPG.getProxyUser()).thenReturn(inputRPGDTO.getProxyUser());
    when(updatedRPG.getProxyPassword()).thenReturn(inputRPGDTO.getProxyPassword());
    when(joinPoint.proceed()).thenReturn(updatedRPG);
    // Capture added actions so that those can be asserted later.
    final AuditService auditService = mock(AuditService.class);
    final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
    doAnswer(invocation -> {
        Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
        addedActions.set(actions);
        return null;
    }).when(auditService).addActions(any());
    auditor.setAuditService(auditService);
    auditor.auditUpdateProcessGroupConfiguration(joinPoint, inputRPGDTO, remoteProcessGroupDAO);
    final Collection<Action> actions = addedActions.get();
    // Assert common action values.
    if (actions != null) {
        actions.forEach(action -> {
            assertEquals(remoteProcessGroupId, action.getSourceId());
            assertEquals("user-id", action.getUserIdentity());
            assertEquals(targetUrl, ((RemoteProcessGroupDetails) action.getComponentDetails()).getUri());
            assertNotNull(action.getTimestamp());
        });
    }
    return actions;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) Collection(java.util.Collection) AtomicReference(java.util.concurrent.atomic.AtomicReference) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) AuditService(org.apache.nifi.admin.service.AuditService) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 37 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testDisableTransmission.

@Test
public void testDisableTransmission() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.isTransmitting()).thenReturn(true);
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setTransmitting(false);
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Stop, action.getOperation());
    assertNull(action.getActionDetails());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Example 38 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testEnableTransmission.

@Test
public void testEnableTransmission() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.isTransmitting()).thenReturn(false);
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setTransmitting(true);
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Start, action.getOperation());
    assertNull(action.getActionDetails());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Example 39 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testConfigureYieldDuration.

@Test
public void testConfigureYieldDuration() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getYieldDuration()).thenReturn("10 sec");
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setYieldDuration("11 sec");
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "Yield Duration", existingRPG.getYieldDuration(), inputRPGDTO.getYieldDuration());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Example 40 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testConfigureProxyUserClear.

@Test
public void testConfigureProxyUserClear() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getProxyUser()).thenReturn("proxy-user");
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyUser(null);
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "Proxy User", existingRPG.getProxyUser(), inputRPGDTO.getProxyUser());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Aggregations

RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)74 ProcessGroup (org.apache.nifi.groups.ProcessGroup)32 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)31 Action (org.apache.nifi.action.Action)27 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)26 ArrayList (java.util.ArrayList)20 Connection (org.apache.nifi.connectable.Connection)20 Port (org.apache.nifi.connectable.Port)19 Test (org.junit.Test)18 HashSet (java.util.HashSet)16 RootGroupPort (org.apache.nifi.remote.RootGroupPort)16 Funnel (org.apache.nifi.connectable.Funnel)15 Connectable (org.apache.nifi.connectable.Connectable)14 ProcessorNode (org.apache.nifi.controller.ProcessorNode)14 Label (org.apache.nifi.controller.label.Label)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)13 Collection (java.util.Collection)11 HashMap (java.util.HashMap)10 Snippet (org.apache.nifi.controller.Snippet)10 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)10