org.apache.nifi.groups.RemoteProcessGroup Java Examples

The following examples show how to use org.apache.nifi.groups.RemoteProcessGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureProxyUser() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyUser("proxy-user");

    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());

}
 
Example #2
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteProcessGroupEntity updateRemoteProcessGroup(final Revision revision, final RemoteProcessGroupDTO remoteProcessGroupDTO) {
    final RemoteProcessGroup remoteProcessGroupNode = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
    final RevisionUpdate<RemoteProcessGroupDTO> snapshot = updateComponent(
            revision,
            remoteProcessGroupNode,
            () -> remoteProcessGroupDAO.updateRemoteProcessGroup(remoteProcessGroupDTO),
            remoteProcessGroup -> dtoFactory.createRemoteProcessGroupDto(remoteProcessGroup));

    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(remoteProcessGroupNode);
    final RevisionDTO updateRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
    final RemoteProcessGroupStatusDTO status = dtoFactory.createRemoteProcessGroupStatusDto(controllerFacade.getRemoteProcessGroupStatus(remoteProcessGroupNode.getIdentifier()));
    final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(remoteProcessGroupNode.getIdentifier()));
    final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
    return entityFactory.createRemoteProcessGroupEntity(snapshot.getComponent(), updateRevision, permissions, status, bulletinEntities);
}
 
Example #3
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureCommunicationsTimeout() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getCommunicationsTimeout()).thenReturn("30 sec");

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setCommunicationsTimeout("31 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(), "Communications Timeout",
            existingRPG.getCommunicationsTimeout(), inputRPGDTO.getCommunicationsTimeout());

}
 
Example #4
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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());

}
 
Example #5
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureProxyPortClear() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getProxyPort()).thenReturn(3128);

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyPort(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 Port",
            existingRPG.getProxyPort(), inputRPGDTO.getProxyPort());

}
 
Example #6
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public RemoteGroupPort updateRemoteProcessGroupInputPort(String remoteProcessGroupId, RemoteProcessGroupPortDTO remoteProcessGroupPortDto) {
    final RemoteProcessGroup remoteProcessGroup = locateRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort port = remoteProcessGroup.getInputPort(remoteProcessGroupPortDto.getId());

    if (port == null) {
        throw new ResourceNotFoundException(
                String.format("Unable to find remote process group input port with id '%s'.", remoteProcessGroupPortDto.getId()));
    }

    // verify the update
    verifyUpdatePort(port, remoteProcessGroupPortDto);

    // perform the update
    updatePort(port, remoteProcessGroupPortDto, remoteProcessGroup);

    remoteProcessGroup.getProcessGroup().onComponentModified();
    return port;
}
 
Example #7
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #8
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureProxyHostClear() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getProxyHost()).thenReturn("proxy.example.com");

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyHost("");

    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 Host",
            existingRPG.getProxyHost(), inputRPGDTO.getProxyHost());

}
 
Example #9
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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());

}
 
Example #10
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureProxyPortClear() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getProxyPort()).thenReturn(3128);

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyPort(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 Port",
            existingRPG.getProxyPort(), inputRPGDTO.getProxyPort());

}
 
Example #11
Source File: SnippetAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the type of component the specified connectable is.
 */
private Component determineConnectableType(ConnectableDTO connectable) {
    Component component = Component.Controller;

    final String connectableType = connectable.getType();
    if (ConnectableType.PROCESSOR.name().equals(connectableType)) {
        component = Component.Processor;
    } else if (ConnectableType.INPUT_PORT.name().equals(connectableType)) {
        component = Component.InputPort;
    } else if (ConnectableType.OUTPUT_PORT.name().equals(connectableType)) {
        component = Component.OutputPort;
    } else if (ConnectableType.FUNNEL.name().equals(connectableType)) {
        component = Component.Funnel;
    } else {
        component = Component.RemoteProcessGroup;
    }

    return component;
}
 
Example #12
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the status history for the specified remote process group.
 *
 * @param remoteProcessGroupId remote process group id
 * @return status history
 */
public StatusHistoryDTO getRemoteProcessGroupStatusHistory(final String remoteProcessGroupId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final RemoteProcessGroup remoteProcessGroup = root.findRemoteProcessGroup(remoteProcessGroupId);

    // ensure the output port was found
    if (remoteProcessGroup == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate remote process group with id '%s'.", remoteProcessGroupId));
    }

    final StatusHistoryDTO statusHistory = flowController.getRemoteProcessGroupStatusHistory(remoteProcessGroupId);

    // if not authorized
    if (!remoteProcessGroup.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser())) {
        statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_NAME, remoteProcessGroupId);
        statusHistory.getComponentDetails().remove(ComponentStatusRepository.COMPONENT_DETAIL_URI);
    }

    return statusHistory;
}
 
Example #13
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureProxyPasswordClear() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getProxyPassword()).thenReturn("proxy-password");

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyPassword(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 Password", SENSITIVE_VALUE_MASK, "");

}
 
Example #14
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private ComponentSearchResultDTO search(final String searchStr, final RemoteProcessGroup group) {
    final List<String> matches = new ArrayList<>();
    addIfAppropriate(searchStr, group.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, group.getName(), "Name", matches);
    addIfAppropriate(searchStr, group.getComments(), "Comments", matches);
    addIfAppropriate(searchStr, group.getTargetUris(), "URLs", matches);

    // consider the transmission status
    if ((StringUtils.containsIgnoreCase("transmitting", searchStr) || StringUtils.containsIgnoreCase("transmission enabled", searchStr)) && group.isTransmitting()) {
        matches.add("Transmission: On");
    } else if ((StringUtils.containsIgnoreCase("not transmitting", searchStr) || StringUtils.containsIgnoreCase("transmission disabled", searchStr)) && !group.isTransmitting()) {
        matches.add("Transmission: Off");
    }

    if (matches.isEmpty()) {
        return null;
    }

    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(group.getIdentifier());
    result.setName(group.getName());
    result.setMatches(matches);
    return result;
}
 
Example #15
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureProxyHost() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyHost("proxy.example.com");

    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 Host",
            existingRPG.getProxyHost(), inputRPGDTO.getProxyHost());

}
 
Example #16
Source File: TestRemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigureCommunicationsTimeout() throws Throwable {

    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getCommunicationsTimeout()).thenReturn("30 sec");

    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setCommunicationsTimeout("31 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(), "Communications Timeout",
            existingRPG.getCommunicationsTimeout(), inputRPGDTO.getCommunicationsTimeout());

}
 
Example #17
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessGroup updateProcessGroupFlow(final String groupId, final VersionedFlowSnapshot proposedSnapshot, final VersionControlInformationDTO versionControlInformation,
                                           final String componentIdSeed, final boolean verifyNotModified, final boolean updateSettings, final boolean updateDescendantVersionedFlows) {

    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    group.updateFlow(proposedSnapshot, componentIdSeed, verifyNotModified, updateSettings, updateDescendantVersionedFlows);
    group.findAllRemoteProcessGroups().forEach(RemoteProcessGroup::initialize);

    // process group being updated may not be versioned
    if (versionControlInformation != null) {
        final StandardVersionControlInformation svci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation)
                .flowSnapshot(proposedSnapshot.getFlowContents())
                .build();
        group.setVersionControlInformation(svci, Collections.emptyMap());
    }

    group.onComponentModified();

    return group;
}
 
Example #18
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status for the specified remote process group.
 *
 * @param remoteProcessGroupId remote process group id
 * @return the status for the specified remote process group
 */
public RemoteProcessGroupStatus getRemoteProcessGroupStatus(final String remoteProcessGroupId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final RemoteProcessGroup remoteProcessGroup = root.findRemoteProcessGroup(remoteProcessGroupId);

    // ensure the output port was found
    if (remoteProcessGroup == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate remote process group with id '%s'.", remoteProcessGroupId));
    }

    final String groupId = remoteProcessGroup.getProcessGroup().getIdentifier();
    final ProcessGroupStatus groupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
    if (groupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }

    final RemoteProcessGroupStatus status = groupStatus.getRemoteProcessGroupStatus().stream().filter(rpgStatus -> remoteProcessGroupId.equals(rpgStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate remote process group with id '%s'.", remoteProcessGroupId));
    }

    return status;
}
 
Example #19
Source File: StandardRemoteProcessGroupDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a remote process group reference.
 *
 * @param remoteProcessGroupDTO The remote process group
 * @return The remote process group
 */
@Override
public RemoteProcessGroup createRemoteProcessGroup(String groupId, RemoteProcessGroupDTO remoteProcessGroupDTO) {
    ProcessGroup group = locateProcessGroup(flowController, groupId);

    if (remoteProcessGroupDTO.getParentGroupId() != null && !flowController.areGroupsSame(groupId, remoteProcessGroupDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the Remote Process Group is being added.");
    }

    final String targetUris = remoteProcessGroupDTO.getTargetUris();
    if (targetUris == null || targetUris.length() == 0) {
        throw new IllegalArgumentException("Cannot add a Remote Process Group without specifying the Target URI(s)");
    }

    // create the remote process group
    RemoteProcessGroup remoteProcessGroup = flowController.createRemoteProcessGroup(remoteProcessGroupDTO.getId(), targetUris);

    // set other properties
    updateRemoteProcessGroup(remoteProcessGroup, remoteProcessGroupDTO);

    // get the group to add the remote process group to
    group.addRemoteProcessGroup(remoteProcessGroup);

    return remoteProcessGroup;
}
 
Example #20
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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());

}
 
Example #21
Source File: SnippetAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Determines the type of component the specified connectable is.
 */
private Component determineConnectableType(ConnectableDTO connectable) {
    Component component = Component.Controller;

    final String connectableType = connectable.getType();
    if (ConnectableType.PROCESSOR.name().equals(connectableType)) {
        component = Component.Processor;
    } else if (ConnectableType.INPUT_PORT.name().equals(connectableType)) {
        component = Component.InputPort;
    } else if (ConnectableType.OUTPUT_PORT.name().equals(connectableType)) {
        component = Component.OutputPort;
    } else if (ConnectableType.FUNNEL.name().equals(connectableType)) {
        component = Component.Funnel;
    } else {
        component = Component.RemoteProcessGroup;
    }

    return component;
}
 
Example #22
Source File: RemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Audits the removal of a process group via deleteProcessGroup().
 *
 * @param proceedingJoinPoint join point
 * @param remoteProcessGroupId remote group id
 * @param remoteProcessGroupDAO remote group dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && "
        + "execution(void deleteRemoteProcessGroup(java.lang.String)) && "
        + "args(remoteProcessGroupId) && "
        + "target(remoteProcessGroupDAO)")
public void removeRemoteProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, String remoteProcessGroupId, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
    // get the remote process group before removing it
    RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);

    // remove the remote process group
    proceedingJoinPoint.proceed();

    // if no exceptions were thrown, add removal actions...
    final Action action = generateAuditRecord(remoteProcessGroup, Operation.Remove);

    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
 
Example #23
Source File: TestStandardRemoteGroupPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void setupMock(final SiteToSiteTransportProtocol protocol,
        final TransferDirection direction,
       final SiteToSiteClientConfig siteToSiteClientConfig) throws Exception {
    processGroup = null;
    remoteGroup = mock(RemoteProcessGroup.class);
    scheduler = null;
    siteToSiteClient = mock(SiteToSiteClient.class);
    this.transaction = mock(Transaction.class);

    eventReporter = mock(EventReporter.class);

    final ConnectableType connectableType;
    switch (direction) {
        case SEND:
            connectableType = ConnectableType.REMOTE_INPUT_PORT;
            break;
        case RECEIVE:
            connectableType = ConnectableType.OUTPUT_PORT;
            break;
        default:
            connectableType = null;
            break;
    }

    port = spy(new StandardRemoteGroupPort(ID, ID, NAME,
            remoteGroup, direction, connectableType, null, scheduler, new StandardNiFiProperties()));

    doReturn(true).when(remoteGroup).isTransmitting();
    doReturn(protocol).when(remoteGroup).getTransportProtocol();
    doReturn(REMOTE_CLUSTER_URL).when(remoteGroup).getTargetUri();
    doReturn(siteToSiteClient).when(port).getSiteToSiteClient();
    doReturn(transaction).when(siteToSiteClient).createTransaction(eq(direction));
    doReturn(siteToSiteClientConfig).when(siteToSiteClient).getConfig();
    doReturn(eventReporter).when(remoteGroup).getEventReporter();

}
 
Example #24
Source File: RemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Generates an audit record for the specified remote process group.
 *
 * @param remoteProcessGroup group
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(RemoteProcessGroup remoteProcessGroup, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;

    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();

    // ensure the user was found
    if (user != null) {
        // create the remote process group details
        FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);

        // create the remote process group action
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(remoteProcessGroup.getIdentifier());
        action.setSourceName(remoteProcessGroup.getName());
        action.setSourceType(Component.RemoteProcessGroup);
        action.setComponentDetails(remoteProcessGroupDetails);

        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }

    return action;
}
 
Example #25
Source File: RemoteProcessGroupAuditor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Audits the update of remote process group output port configuration.
 *
 * @param proceedingJoinPoint join point
 * @param remoteProcessGroupPortDto dto
 * @param remoteProcessGroupDAO dao
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && "
        + "execution(org.apache.nifi.remote.RemoteGroupPort updateRemoteProcessGroupOutputPort(java.lang.String, org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)) && "
        + "args(remoteProcessGroupId, remoteProcessGroupPortDto) && "
        + "target(remoteProcessGroupDAO)")
public RemoteGroupPort auditUpdateProcessGroupOutputPortConfiguration(
        ProceedingJoinPoint proceedingJoinPoint, String remoteProcessGroupId,
        RemoteProcessGroupPortDTO remoteProcessGroupPortDto, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {

    final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);
    final RemoteGroupPort remoteProcessGroupPort = remoteProcessGroup.getOutputPort(remoteProcessGroupPortDto.getId());

    return auditUpdateProcessGroupPortConfiguration(proceedingJoinPoint, remoteProcessGroupPortDto, remoteProcessGroup, remoteProcessGroupPort);
}
 
Example #26
Source File: StandardRemoteProcessGroupDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies the specified remote group can be updated, if necessary.
 */
@SuppressWarnings("unchecked")
private void verifyUpdate(RemoteProcessGroup remoteProcessGroup, RemoteProcessGroupDTO remoteProcessGroupDto) {
    // see if the remote process group can start/stop transmitting
    if (isNotNull(remoteProcessGroupDto.isTransmitting())) {
        if (!remoteProcessGroup.isTransmitting() && remoteProcessGroupDto.isTransmitting()) {
            remoteProcessGroup.verifyCanStartTransmitting();
        } else if (remoteProcessGroup.isTransmitting() && !remoteProcessGroupDto.isTransmitting()) {
            remoteProcessGroup.verifyCanStopTransmitting();
        }
    }

    // validate the proposed configuration
    final List<String> requestValidation = validateProposedRemoteProcessGroupConfiguration(remoteProcessGroupDto);
    // ensure there was no validation errors
    if (!requestValidation.isEmpty()) {
        throw new ValidationException(requestValidation);
    }

    // if any remote group properties are changing, verify update
    if (isAnyNotNull(remoteProcessGroupDto.getYieldDuration(),
            remoteProcessGroupDto.getLocalNetworkInterface(),
            remoteProcessGroupDto.getCommunicationsTimeout(),
            remoteProcessGroupDto.getProxyHost(),
            remoteProcessGroupDto.getProxyPort(),
            remoteProcessGroupDto.getProxyUser(),
            remoteProcessGroupDto.getProxyPassword())) {
        remoteProcessGroup.verifyCanUpdate();
    }
}
 
Example #27
Source File: TestRemoteProcessGroupAuditor.java    From nifi with Apache License 2.0 5 votes vote down vote up
private RemoteProcessGroup defaultRemoteProcessGroup() {
    final RemoteProcessGroup existingRPG = mock(RemoteProcessGroup.class);
    when(existingRPG.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.RAW);
    when(existingRPG.isTransmitting()).thenReturn(false);
    when(existingRPG.getProxyPort()).thenReturn(null);
    return existingRPG;
}
 
Example #28
Source File: SnippetUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to roll back and in the specified snippet.
 *
 * @param snippet snippet
 */
public void rollbackClonedPolicies(final FlowSnippetDTO snippet) {
    if (!accessPolicyDAO.supportsConfigurableAuthorizer()) {
        return;
    }

    snippet.getControllerServices().forEach(controllerServiceDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.ControllerService, controllerServiceDTO.getId(), controllerServiceDTO.getName()));
    });
    snippet.getFunnels().forEach(funnelDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.Funnel, funnelDTO.getId(), funnelDTO.getId()));
    });
    snippet.getInputPorts().forEach(inputPortDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.InputPort, inputPortDTO.getId(), inputPortDTO.getName()));
    });
    snippet.getLabels().forEach(labelDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.Label, labelDTO.getId(), labelDTO.getLabel()));
    });
    snippet.getOutputPorts().forEach(outputPortDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.OutputPort, outputPortDTO.getId(), outputPortDTO.getName()));
    });
    snippet.getProcessors().forEach(processorDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.Processor, processorDTO.getId(), processorDTO.getName()));
    });
    snippet.getRemoteProcessGroups().forEach(remoteProcessGroupDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.RemoteProcessGroup, remoteProcessGroupDTO.getId(), remoteProcessGroupDTO.getName()));
    });
    snippet.getProcessGroups().forEach(processGroupDTO -> {
        rollbackClonedPolicy(ResourceFactory.getComponentResource(ResourceType.ProcessGroup, processGroupDTO.getId(), processGroupDTO.getName()));

        // consider all descendant components
        if (processGroupDTO.getContents() != null) {
            rollbackClonedPolicies(processGroupDTO.getContents());
        }
    });
}
 
Example #29
Source File: FingerprintFactoryTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteProcessGroupFingerprintRaw() throws Exception {

    // Fill out every configuration.
    final RemoteProcessGroup component = mock(RemoteProcessGroup.class);
    when(component.getName()).thenReturn("name");
    when(component.getIdentifier()).thenReturn("id");
    when(component.getPosition()).thenReturn(new Position(10.5, 20.3));
    when(component.getTargetUri()).thenReturn("http://node1:8080/nifi");
    when(component.getTargetUris()).thenReturn("http://node1:8080/nifi, http://node2:8080/nifi");
    when(component.getNetworkInterface()).thenReturn("eth0");
    when(component.getComments()).thenReturn("comment");
    when(component.getCommunicationsTimeout()).thenReturn("10 sec");
    when(component.getYieldDuration()).thenReturn("30 sec");
    when(component.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.RAW);
    when(component.getProxyHost()).thenReturn(null);
    when(component.getProxyPort()).thenReturn(null);
    when(component.getProxyUser()).thenReturn(null);
    when(component.getProxyPassword()).thenReturn(null);
    when(component.getVersionedComponentId()).thenReturn(Optional.empty());

    // Assert fingerprints with expected one.
    final String expected = "id" +
            "NO_VALUE" +
            "http://node1:8080/nifi, http://node2:8080/nifi" +
            "eth0" +
            "10 sec" +
            "30 sec" +
            "RAW" +
            "NO_VALUE" +
            "NO_VALUE" +
            "NO_VALUE" +
            "NO_VALUE";

    final Element rootElement = serializeElement(encryptor, RemoteProcessGroup.class, component, "addRemoteProcessGroup", IDENTITY_LOOKUP);
    final Element componentElement = (Element) rootElement.getElementsByTagName("remoteProcessGroup").item(0);
    assertEquals(expected, fingerprint("addRemoteProcessGroupFingerprint", Element.class, componentElement));

}
 
Example #30
Source File: NiFiRegistryFlowMapperTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
private RemoteProcessGroup prepareRemoteProcessGroup(final String processGroupId) {
    final RemoteProcessGroup remoteProcessGroup = mock(RemoteProcessGroup.class);
    prepareComponentAuthorizable(remoteProcessGroup, processGroupId);
    preparePositionable(remoteProcessGroup);
    when(remoteProcessGroup.getName()).thenReturn("remote" + (counter++));
    when(remoteProcessGroup.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.HTTP);
    final RemoteGroupPort remoteGroupInputPort = prepareRemoteGroupPort(remoteProcessGroup);
    when(remoteProcessGroup.getInputPorts()).thenReturn(Sets.newHashSet(remoteGroupInputPort));
    final RemoteGroupPort remoteGroupOutputPort = prepareRemoteGroupPort(remoteProcessGroup);
    when(remoteProcessGroup.getOutputPorts()).thenReturn(Sets.newHashSet(remoteGroupOutputPort));
    return remoteProcessGroup;
}