Search in sources :

Example 36 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class StandardRemoteProcessGroupDAO method updateRemoteProcessGroupOutputPort.

@Override
public RemoteGroupPort updateRemoteProcessGroupOutputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getOutputPort(remoteProcessGroupPortDto.getId());
    if (port == null) {
        throw new ResourceNotFoundException(String.format("Unable to find remote process group output port with id '%s'.", remoteProcessGroupId));
    }
    // verify the update
    verifyUpdatePort(port, remoteProcessGroupPortDto);
    // perform the update
    updatePort(port, remoteProcessGroupPortDto, remoteProcessGroup);
    remoteProcessGroup.getProcessGroup().onComponentModified();
    return port;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 37 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class StandardRemoteProcessGroupDAO method verifyUpdateOutputPort.

@Override
public void verifyUpdateOutputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getOutputPort(remoteProcessGroupPortDto.getId());
    if (port == null) {
        throw new ResourceNotFoundException(String.format("Unable to find remote process group output port with id '%s'.", remoteProcessGroupPortDto.getId()));
    }
    verifyUpdatePort(port, remoteProcessGroupPortDto);
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 38 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testConfigurePortConcurrency.

@Test
public void testConfigurePortConcurrency() throws Throwable {
    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");
    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setConcurrentlySchedulableTaskCount(2);
    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Concurrent Tasks", "1", "2");
}
Also used : Action(org.apache.nifi.action.Action) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Test(org.junit.Test)

Example 39 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testConfigurePortCompression.

@Test
public void testConfigurePortCompression() throws Throwable {
    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");
    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    inputRPGPortDTO.setUseCompression(true);
    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Compressed", "false", "true");
}
Also used : Action(org.apache.nifi.action.Action) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Test(org.junit.Test)

Example 40 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class TestRemoteProcessGroupAuditor method updateProcessGroupInputPortConfiguration.

@SuppressWarnings("unchecked")
private Collection<Action> updateProcessGroupInputPortConfiguration(RemoteProcessGroupPortDTO inputRPGPortDTO, RemoteGroupPort existingRPGPort) throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
    final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
    final String remoteProcessGroupId = "remote-process-group-id";
    inputRPGPortDTO.setId(remoteProcessGroupId);
    inputRPGPortDTO.setTargetId(remoteProcessGroupId);
    final String targetUrl = "http://localhost:8080/nifi";
    when(existingRPG.getIdentifier()).thenReturn(remoteProcessGroupId);
    when(existingRPG.getTargetUri()).thenReturn(targetUrl);
    final RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
    when(remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId)).thenReturn(existingRPG);
    when(existingRPG.getInputPort(eq(inputRPGPortDTO.getId()))).thenReturn(existingRPGPort);
    // Setup updatedRPGPort mock based on inputRPGPortDTO.
    final RemoteGroupPort updatedRPGPort = mock(RemoteGroupPort.class);
    final String portName = existingRPGPort.getName();
    when(updatedRPGPort.getName()).thenReturn(portName);
    if (inputRPGPortDTO.isTransmitting() != null) {
        when(updatedRPGPort.isRunning()).thenReturn(inputRPGPortDTO.isTransmitting());
    }
    when(updatedRPGPort.getMaxConcurrentTasks()).thenReturn(inputRPGPortDTO.getConcurrentlySchedulableTaskCount());
    when(updatedRPGPort.isUseCompression()).thenReturn(inputRPGPortDTO.getUseCompression());
    final BatchSettingsDTO batchSettings = inputRPGPortDTO.getBatchSettings();
    if (batchSettings != null) {
        when(updatedRPGPort.getBatchCount()).thenReturn(batchSettings.getCount());
        when(updatedRPGPort.getBatchSize()).thenReturn(batchSettings.getSize());
        when(updatedRPGPort.getBatchDuration()).thenReturn(batchSettings.getDuration());
    }
    when(joinPoint.proceed()).thenReturn(updatedRPGPort);
    // 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.auditUpdateProcessGroupInputPortConfiguration(joinPoint, remoteProcessGroupId, inputRPGPortDTO, 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 : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Collection(java.util.Collection) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) AuditService(org.apache.nifi.admin.service.AuditService)

Aggregations

RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)41 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 ProcessGroup (org.apache.nifi.groups.ProcessGroup)11 ArrayList (java.util.ArrayList)9 Connectable (org.apache.nifi.connectable.Connectable)9 Action (org.apache.nifi.action.Action)8 Port (org.apache.nifi.connectable.Port)8 Connection (org.apache.nifi.connectable.Connection)7 RootGroupPort (org.apache.nifi.remote.RootGroupPort)7 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Funnel (org.apache.nifi.connectable.Funnel)6 Authorizable (org.apache.nifi.authorization.resource.Authorizable)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)5 Collection (java.util.Collection)4 Position (org.apache.nifi.connectable.Position)4 Element (org.w3c.dom.Element)4 IOException (java.io.IOException)3