Search in sources :

Example 1 with BatchSettingsDTO

use of org.apache.nifi.web.api.dto.BatchSettingsDTO in project nifi by apache.

the class StandardRemoteProcessGroupDAO method updatePort.

/**
 * @param port Port instance to be updated.
 * @param remoteProcessGroupPortDto DTO containing updated remote process group port settings.
 * @param remoteProcessGroup If remoteProcessGroupPortDto has updated isTransmitting input,
 *                           this method will start or stop the port in this remoteProcessGroup as necessary.
 */
private void updatePort(RemoteGroupPort port, RemoteProcessGroupPortDTO remoteProcessGroupPortDto, RemoteProcessGroup remoteProcessGroup) {
    if (isNotNull(remoteProcessGroupPortDto.getConcurrentlySchedulableTaskCount())) {
        port.setMaxConcurrentTasks(remoteProcessGroupPortDto.getConcurrentlySchedulableTaskCount());
    }
    if (isNotNull(remoteProcessGroupPortDto.getUseCompression())) {
        port.setUseCompression(remoteProcessGroupPortDto.getUseCompression());
    }
    final BatchSettingsDTO batchSettingsDTO = remoteProcessGroupPortDto.getBatchSettings();
    if (isNotNull(batchSettingsDTO)) {
        port.setBatchCount(batchSettingsDTO.getCount());
        port.setBatchSize(batchSettingsDTO.getSize());
        port.setBatchDuration(batchSettingsDTO.getDuration());
    }
    final Boolean isTransmitting = remoteProcessGroupPortDto.isTransmitting();
    if (isNotNull(isTransmitting)) {
        // start or stop as necessary
        if (!port.isRunning() && isTransmitting) {
            remoteProcessGroup.startTransmitting(port);
        } else if (port.isRunning() && !isTransmitting) {
            remoteProcessGroup.stopTransmitting(port);
        }
    }
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO)

Example 2 with BatchSettingsDTO

use of org.apache.nifi.web.api.dto.BatchSettingsDTO in project nifi by apache.

the class TestStandardRemoteProcessGroupDAO method testVerifyUpdateInputPort.

@Test
public void testVerifyUpdateInputPort() {
    final StandardRemoteProcessGroupDAO dao = new StandardRemoteProcessGroupDAO();
    final String remoteProcessGroupId = "remote-process-group-id";
    final String remoteProcessGroupInputPortId = "remote-process-group-input-port-id";
    final FlowController flowController = mock(FlowController.class);
    final ProcessGroup processGroup = mock(ProcessGroup.class);
    final RemoteProcessGroup remoteProcessGroup = mock(RemoteProcessGroup.class);
    final RemoteGroupPort remoteGroupPort = mock(RemoteGroupPort.class);
    dao.setFlowController(flowController);
    when(flowController.getGroup(any())).thenReturn(processGroup);
    when(processGroup.findRemoteProcessGroup(eq(remoteProcessGroupId))).thenReturn(remoteProcessGroup);
    when(remoteProcessGroup.getInputPort(remoteProcessGroupInputPortId)).thenReturn(remoteGroupPort);
    when(remoteGroupPort.getName()).thenReturn("remote-group-port");
    final RemoteProcessGroupPortDTO dto = new RemoteProcessGroupPortDTO();
    dto.setGroupId(remoteProcessGroupId);
    dto.setId(remoteProcessGroupInputPortId);
    dto.setTargetId(remoteProcessGroupInputPortId);
    final BatchSettingsDTO batchSettings = new BatchSettingsDTO();
    dto.setBatchSettings(batchSettings);
    // Empty input values should pass validation.
    dao.verifyUpdateInputPort(remoteProcessGroupId, dto);
    // Concurrent tasks
    dto.setConcurrentlySchedulableTaskCount(0);
    validate(dao, dto, "Concurrent tasks", "positive integer");
    dto.setConcurrentlySchedulableTaskCount(2);
    validate(dao, dto);
    // Batch count
    batchSettings.setCount(-1);
    validate(dao, dto, "Batch count", "positive integer");
    batchSettings.setCount(0);
    validate(dao, dto);
    batchSettings.setCount(1000);
    validate(dao, dto);
    // Batch size
    batchSettings.setSize("AB");
    validate(dao, dto, "Batch size", "Data Size");
    batchSettings.setSize("10 days");
    validate(dao, dto, "Batch size", "Data Size");
    batchSettings.setSize("300MB");
    validate(dao, dto);
    // Batch duration
    batchSettings.setDuration("AB");
    validate(dao, dto, "Batch duration", "Time Unit");
    batchSettings.setDuration("10 KB");
    validate(dao, dto, "Batch duration", "Time Unit");
    batchSettings.setDuration("10 secs");
    validate(dao, dto);
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowController(org.apache.nifi.controller.FlowController) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Test(org.junit.Test)

Example 3 with BatchSettingsDTO

use of org.apache.nifi.web.api.dto.BatchSettingsDTO in project nifi by apache.

the class TestRemoteProcessGroupAuditor method testConfigurePortBatchSettings.

@Test
public void testConfigurePortBatchSettings() throws Throwable {
    final RemoteGroupPort existingRPGPort = defaultRemoteGroupPort();
    when(existingRPGPort.getName()).thenReturn("input-port-1");
    final RemoteProcessGroupPortDTO inputRPGPortDTO = defaultRemoteProcessGroupPortDTO();
    final BatchSettingsDTO batchSettingsDTO = new BatchSettingsDTO();
    batchSettingsDTO.setCount(1234);
    batchSettingsDTO.setSize("64KB");
    batchSettingsDTO.setDuration("10sec");
    inputRPGPortDTO.setBatchSettings(batchSettingsDTO);
    final Collection<Action> actions = updateProcessGroupInputPortConfiguration(inputRPGPortDTO, existingRPGPort);
    assertEquals(3, actions.size());
    final Iterator<Action> iterator = actions.iterator();
    Action action = iterator.next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Batch Count", "0", "1234");
    action = iterator.next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Batch Size", "", "64KB");
    action = iterator.next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "input-port-1.Batch Duration", "", "10sec");
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) 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 4 with BatchSettingsDTO

use of org.apache.nifi.web.api.dto.BatchSettingsDTO in project nifi by apache.

the class FlowController method convertRemotePort.

/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports ports
 * @return group descriptors
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<RemoteProcessGroupPortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final RemoteProcessGroupPortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            descriptor.setId(port.getId());
            descriptor.setVersionedComponentId(port.getVersionedComponentId());
            descriptor.setTargetId(port.getTargetId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(port.isTargetRunning());
            descriptor.setConnected(port.isConnected());
            descriptor.setConcurrentlySchedulableTaskCount(port.getConcurrentlySchedulableTaskCount());
            descriptor.setTransmitting(port.isTransmitting());
            descriptor.setUseCompression(port.getUseCompression());
            final BatchSettingsDTO batchSettings = port.getBatchSettings();
            if (batchSettings != null) {
                descriptor.setBatchCount(batchSettings.getCount());
                descriptor.setBatchSize(batchSettings.getSize());
                descriptor.setBatchDuration(batchSettings.getDuration());
            }
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)

Example 5 with BatchSettingsDTO

use of org.apache.nifi.web.api.dto.BatchSettingsDTO in project nifi by apache.

the class StandardRemoteProcessGroupDAO method validateProposedRemoteProcessGroupPortConfiguration.

/**
 * Validates the proposed configuration for the specified remote port.
 */
private List<String> validateProposedRemoteProcessGroupPortConfiguration(RemoteGroupPort remoteGroupPort, RemoteProcessGroupPortDTO remoteProcessGroupPortDTO) {
    final List<String> validationErrors = new ArrayList<>();
    // ensure the proposed port configuration is valid
    if (isNotNull(remoteProcessGroupPortDTO.getConcurrentlySchedulableTaskCount()) && remoteProcessGroupPortDTO.getConcurrentlySchedulableTaskCount() <= 0) {
        validationErrors.add(String.format("Concurrent tasks for port '%s' must be a positive integer.", remoteGroupPort.getName()));
    }
    final BatchSettingsDTO batchSettingsDTO = remoteProcessGroupPortDTO.getBatchSettings();
    if (batchSettingsDTO != null) {
        final Integer batchCount = batchSettingsDTO.getCount();
        if (isNotNull(batchCount) && batchCount < 0) {
            validationErrors.add(String.format("Batch count for port '%s' must be a positive integer.", remoteGroupPort.getName()));
        }
        final String batchSize = batchSettingsDTO.getSize();
        if (isNotNull(batchSize) && batchSize.length() > 0 && !DataUnit.DATA_SIZE_PATTERN.matcher(batchSize.trim().toUpperCase()).matches()) {
            validationErrors.add(String.format("Batch size for port '%s' must be of format <Data Size> <Data Unit>" + " where <Data Size> is a non-negative integer and <Data Unit> is a supported Data" + " Unit, such as: B, KB, MB, GB, TB", remoteGroupPort.getName()));
        }
        final String batchDuration = batchSettingsDTO.getDuration();
        if (isNotNull(batchDuration) && batchDuration.length() > 0 && !FormatUtils.TIME_DURATION_PATTERN.matcher(batchDuration.trim().toLowerCase()).matches()) {
            validationErrors.add(String.format("Batch duration for port '%s' must be of format <duration> <TimeUnit>" + " where <duration> is a non-negative integer and TimeUnit is a supported Time Unit, such " + "as: nanos, millis, secs, mins, hrs, days", remoteGroupPort.getName()));
        }
    }
    return validationErrors;
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) ArrayList(java.util.ArrayList)

Aggregations

BatchSettingsDTO (org.apache.nifi.web.api.dto.BatchSettingsDTO)6 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)3 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)3 Action (org.apache.nifi.action.Action)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AuditService (org.apache.nifi.admin.service.AuditService)1 FlowController (org.apache.nifi.controller.FlowController)1 ProcessGroup (org.apache.nifi.groups.ProcessGroup)1 RemoteProcessGroupPortDescriptor (org.apache.nifi.groups.RemoteProcessGroupPortDescriptor)1 StandardRemoteProcessGroupPortDescriptor (org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor)1 RemoteProcessGroupDAO (org.apache.nifi.web.dao.RemoteProcessGroupDAO)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1