Java Code Examples for org.apache.nifi.web.api.dto.PortDTO#setName()

The following examples show how to use org.apache.nifi.web.api.dto.PortDTO#setName() . 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: PortSchemaFunctionTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    testId = UUID.nameUUIDFromBytes("testId".getBytes(StandardCharsets.UTF_8)).toString();
    testName = "testName";
    testWrapperName = "testWrapperName";
    portDTO = new PortDTO();
    portDTO.setId(testId);
    portDTO.setName(testName);
    portSchemaFunction = new PortSchemaFunction(testWrapperName);
}
 
Example 2
Source File: FlowFromDOMFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static PortDTO getPort(final Element element) {
    final PortDTO portDTO = new PortDTO();
    portDTO.setId(getString(element, "id"));
    portDTO.setVersionedComponentId(getString(element, "versionedComponentId"));
    portDTO.setPosition(getPosition(DomUtils.getChild(element, "position")));
    portDTO.setName(getString(element, "name"));
    portDTO.setComments(getString(element, "comments"));
    portDTO.setAllowRemoteAccess(getBoolean(element, "allowRemoteAccess"));
    final ScheduledState scheduledState = getScheduledState(element);
    portDTO.setState(scheduledState.toString());

    final List<Element> maxTasksElements = getChildrenByTagName(element, "maxConcurrentTasks");
    if (!maxTasksElements.isEmpty()) {
        portDTO.setConcurrentlySchedulableTaskCount(Integer.parseInt(maxTasksElements.get(0).getTextContent()));
    }

    final List<Element> userAccessControls = getChildrenByTagName(element, "userAccessControl");
    if (userAccessControls != null && !userAccessControls.isEmpty()) {
        final Set<String> users = new HashSet<>();
        portDTO.setUserAccessControl(users);
        for (final Element userElement : userAccessControls) {
            users.add(userElement.getTextContent());
        }
    }

    final List<Element> groupAccessControls = getChildrenByTagName(element, "groupAccessControl");
    if (groupAccessControls != null && !groupAccessControls.isEmpty()) {
        final Set<String> groups = new HashSet<>();
        portDTO.setGroupAccessControl(groups);
        for (final Element groupElement : groupAccessControls) {
            groups.add(groupElement.getTextContent());
        }
    }

    return portDTO;
}
 
Example 3
Source File: ITOutputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createOutputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/output-ports";

    final String updatedName = name + count++;

    // create the output port
    PortDTO outputPort = new PortDTO();
    outputPort.setName(updatedName);

    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);

    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(outputPort);

    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);

    // ensure the request is successful
    assertEquals(201, response.getStatus());

    // get the entity body
    entity = response.readEntity(PortEntity.class);

    // verify creation
    outputPort = entity.getComponent();
    assertEquals(updatedName, outputPort.getName());

    // get the output port
    return entity;
}
 
Example 4
Source File: ITOutputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final Response response = updateOutputPort(helper.getNoneUser(), requestEntity);

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example 5
Source File: ITOutputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final Response response = updateOutputPort(helper.getWriteUser(), requestEntity);

    // ensure successful response
    assertEquals(200, response.getStatus());

    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example 6
Source File: ITInputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createInputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/input-ports";

    final String updatedName = name + count++;

    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName(updatedName);

    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);

    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(inputPort);

    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);

    // ensure the request is successful
    assertEquals(201, response.getStatus());

    // get the entity body
    entity = response.readEntity(PortEntity.class);

    // verify creation
    inputPort = entity.getComponent();
    assertEquals(updatedName, inputPort.getName());

    // get the input port
    return entity;
}
 
Example 7
Source File: ITInputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final Response response = updateInputPort(helper.getNoneUser(), requestEntity);

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example 8
Source File: ITInputPortAccessControl.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final Response response = updateInputPort(helper.getWriteUser(), requestEntity);

    // ensure successful response
    assertEquals(200, response.getStatus());

    // get the response
    final PortEntity responseEntity = response.readEntity(PortEntity.class);

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example 9
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private PortDTO createDTO(final Port port) {
    if (port == null) {
        return null;
    }

    final PortDTO dto = new PortDTO();
    dto.setId(port.getIdentifier());
    dto.setPosition(new PositionDTO(port.getPosition().getX(), port.getPosition().getY()));
    dto.setName(port.getName());
    dto.setParentGroupId(port.getProcessGroup().getIdentifier());

    return dto;
}
 
Example 10
Source File: FlowFromDOMFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public static PortDTO getPort(final Element element) {
    final PortDTO portDTO = new PortDTO();
    portDTO.setId(getString(element, "id"));
    portDTO.setPosition(getPosition(DomUtils.getChild(element, "position")));
    portDTO.setName(getString(element, "name"));
    portDTO.setComments(getString(element, "comments"));
    final ScheduledState scheduledState = getScheduledState(element);
    portDTO.setState(scheduledState.toString());

    final List<Element> maxTasksElements = getChildrenByTagName(element, "maxConcurrentTasks");
    if (!maxTasksElements.isEmpty()) {
        portDTO.setConcurrentlySchedulableTaskCount(Integer.parseInt(maxTasksElements.get(0).getTextContent()));
    }

    final List<Element> userAccessControls = getChildrenByTagName(element, "userAccessControl");
    if (userAccessControls != null && !userAccessControls.isEmpty()) {
        final Set<String> users = new HashSet<>();
        portDTO.setUserAccessControl(users);
        for (final Element userElement : userAccessControls) {
            users.add(userElement.getTextContent());
        }
    }

    final List<Element> groupAccessControls = getChildrenByTagName(element, "groupAccessControl");
    if (groupAccessControls != null && !groupAccessControls.isEmpty()) {
        final Set<String> groups = new HashSet<>();
        portDTO.setGroupAccessControl(groups);
        for (final Element groupElement : groupAccessControls) {
            groups.add(groupElement.getTextContent());
        }
    }

    return portDTO;
}
 
Example 11
Source File: ITOutputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private PortEntity createOutputPort(final String name) throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/output-ports";

    final String updatedName = name + count++;

    // create the output port
    PortDTO outputPort = new PortDTO();
    outputPort.setName(updatedName);

    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);

    // create the entity body
    PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    entity.setComponent(outputPort);

    // perform the request
    ClientResponse response = helper.getReadWriteUser().testPost(url, entity);

    // ensure the request is successful
    assertEquals(201, response.getStatus());

    // get the entity body
    entity = response.getEntity(PortEntity.class);

    // verify creation
    outputPort = entity.getComponent();
    assertEquals(updatedName, outputPort.getName());

    // get the output port
    return entity;
}
 
Example 12
Source File: ITOutputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final ClientResponse response = updateOutputPort(helper.getNoneUser(), requestEntity);

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example 13
Source File: ITOutputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an output port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutOutputPort() throws Exception {
    final PortEntity entity = getRandomOutputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final ClientResponse response = updateOutputPort(helper.getWriteUser(), requestEntity);

    // ensure successful response
    assertEquals(200, response.getStatus());

    // get the response
    final PortEntity responseEntity = response.getEntity(PortEntity.class);

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example 14
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public PortEntity createOutputPort(final String name, final String groupId) throws NiFiClientException, IOException {
    final PortDTO component = new PortDTO();
    component.setName(name);
    component.setParentGroupId(groupId);

    final PortEntity outputPortEntity = new PortEntity();
    outputPortEntity.setRevision(createNewRevision());
    outputPortEntity.setComponent(component);

    return nifiClient.getOutputPortClient().createOutputPort(groupId, outputPortEntity);
}
 
Example 15
Source File: ITInputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the NONE user cannot put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.NONE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final ClientResponse response = updateInputPort(helper.getNoneUser(), requestEntity);

    // ensure forbidden response
    assertEquals(403, response.getStatus());
}
 
Example 16
Source File: ITInputPortAccessControl.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Ensures the WRITE user can put an input port.
 *
 * @throws Exception ex
 */
@Test
public void testWriteUserPutInputPort() throws Exception {
    final PortEntity entity = getRandomInputPort(helper.getWriteUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertTrue(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());

    final String updatedName = "Updated Name" + count++;

    // attempt to update the name
    final PortDTO requestDto = new PortDTO();
    requestDto.setId(entity.getId());
    requestDto.setName(updatedName);

    final long version = entity.getRevision().getVersion();
    final RevisionDTO requestRevision = new RevisionDTO();
    requestRevision.setVersion(version);
    requestRevision.setClientId(AccessControlHelper.WRITE_CLIENT_ID);

    final PortEntity requestEntity = new PortEntity();
    requestEntity.setId(entity.getId());
    requestEntity.setRevision(requestRevision);
    requestEntity.setComponent(requestDto);

    // perform the request
    final ClientResponse response = updateInputPort(helper.getWriteUser(), requestEntity);

    // ensure successful response
    assertEquals(200, response.getStatus());

    // get the response
    final PortEntity responseEntity = response.getEntity(PortEntity.class);

    // verify
    assertEquals(WRITE_CLIENT_ID, responseEntity.getRevision().getClientId());
    assertEquals(version + 1, responseEntity.getRevision().getVersion().longValue());
}
 
Example 17
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 5 votes vote down vote up
public PortEntity createRemoteInputPort(final String parentGroupId, final String portName) throws NiFiClientException, IOException {
    final PortDTO component = new PortDTO();
    component.setName(portName);
    component.setAllowRemoteAccess(true);

    final PortEntity entity = new PortEntity();
    entity.setComponent(component);
    entity.setRevision(createNewRevision());

    return nifiClient.getInputPortClient().createInputPort(parentGroupId, entity);
}
 
Example 18
Source File: TestSiteInfoProvider.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecure() throws Exception {

    final Set<String> expectedClusterUrl = new LinkedHashSet<>(Arrays.asList(new String[]{"https://node1:8443", "https://node2:8443"}));
    final String expectedActiveClusterUrl = "https://node2:8443/nifi-api";
    final SSLContext expectedSslConText = mock(SSLContext.class);
    final HttpProxy expectedHttpProxy = mock(HttpProxy.class);

    final SiteInfoProvider siteInfoProvider = spy(new SiteInfoProvider());
    siteInfoProvider.setClusterUrls(expectedClusterUrl);
    siteInfoProvider.setSslContext(expectedSslConText);
    siteInfoProvider.setProxy(expectedHttpProxy);

    final ControllerDTO controllerDTO = new ControllerDTO();

    final PortDTO inputPort1 = new PortDTO();
    inputPort1.setName("input-one");
    inputPort1.setId("input-0001");

    final PortDTO inputPort2 = new PortDTO();
    inputPort2.setName("input-two");
    inputPort2.setId("input-0002");

    final PortDTO outputPort1 = new PortDTO();
    outputPort1.setName("output-one");
    outputPort1.setId("output-0001");

    final PortDTO outputPort2 = new PortDTO();
    outputPort2.setName("output-two");
    outputPort2.setId("output-0002");

    final Set<PortDTO> inputPorts = new HashSet<>();
    inputPorts.add(inputPort1);
    inputPorts.add(inputPort2);

    final Set<PortDTO> outputPorts = new HashSet<>();
    outputPorts.add(outputPort1);
    outputPorts.add(outputPort2);

    controllerDTO.setInputPorts(inputPorts);
    controllerDTO.setOutputPorts(outputPorts);
    controllerDTO.setRemoteSiteListeningPort(8081);
    controllerDTO.setRemoteSiteHttpListeningPort(8443);
    controllerDTO.setSiteToSiteSecure(true);

    // SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
    doAnswer(invocation -> {
        final SSLContext sslContext = invocation.getArgumentAt(0, SSLContext.class);
        final HttpProxy httpProxy = invocation.getArgumentAt(1, HttpProxy.class);

        assertEquals(expectedSslConText, sslContext);
        assertEquals(expectedHttpProxy, httpProxy);

        final SiteToSiteRestApiClient apiClient = mock(SiteToSiteRestApiClient.class);

        when(apiClient.getController(eq(expectedClusterUrl))).thenReturn(controllerDTO);

        when(apiClient.getBaseUrl()).thenReturn(expectedActiveClusterUrl);

        return apiClient;
    }).when(siteInfoProvider).createSiteToSiteRestApiClient(any(), any());

    // siteInfoProvider should expose correct information of the remote NiFi cluster.
    assertEquals(controllerDTO.getRemoteSiteListeningPort(), siteInfoProvider.getSiteToSitePort());
    assertEquals(controllerDTO.getRemoteSiteHttpListeningPort(), siteInfoProvider.getSiteToSiteHttpPort());
    assertEquals(controllerDTO.isSiteToSiteSecure(), siteInfoProvider.isSecure());
    assertTrue(siteInfoProvider.isWebInterfaceSecure());

    assertEquals(inputPort1.getId(), siteInfoProvider.getInputPortIdentifier(inputPort1.getName()));
    assertEquals(inputPort2.getId(), siteInfoProvider.getInputPortIdentifier(inputPort2.getName()));
    assertEquals(outputPort1.getId(), siteInfoProvider.getOutputPortIdentifier(outputPort1.getName()));
    assertEquals(outputPort2.getId(), siteInfoProvider.getOutputPortIdentifier(outputPort2.getName()));
    assertNull(siteInfoProvider.getInputPortIdentifier("not-exist"));
    assertNull(siteInfoProvider.getOutputPortIdentifier("not-exist"));

    assertEquals(inputPort1.getId(), siteInfoProvider.getPortIdentifier(inputPort1.getName(), TransferDirection.SEND));
    assertEquals(outputPort1.getId(), siteInfoProvider.getPortIdentifier(outputPort1.getName(), TransferDirection.RECEIVE));

    assertEquals(expectedActiveClusterUrl, siteInfoProvider.getActiveClusterUrl().toString());

}
 
Example 19
Source File: TestSiteInfoProvider.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecure() throws Exception {

    final Set<String> expectedClusterUrl = new LinkedHashSet<>(Arrays.asList(new String[]{"https://node1:8443", "https://node2:8443"}));
    final String expectedActiveClusterUrl = "https://node2:8443/nifi-api";
    final SSLContext expectedSslConText = mock(SSLContext.class);
    final HttpProxy expectedHttpProxy = mock(HttpProxy.class);

    final SiteInfoProvider siteInfoProvider = spy(new SiteInfoProvider());
    siteInfoProvider.setClusterUrls(expectedClusterUrl);
    siteInfoProvider.setSslContext(expectedSslConText);
    siteInfoProvider.setProxy(expectedHttpProxy);

    final ControllerDTO controllerDTO = new ControllerDTO();

    final PortDTO inputPort1 = new PortDTO();
    inputPort1.setName("input-one");
    inputPort1.setId("input-0001");

    final PortDTO inputPort2 = new PortDTO();
    inputPort2.setName("input-two");
    inputPort2.setId("input-0002");

    final PortDTO outputPort1 = new PortDTO();
    outputPort1.setName("output-one");
    outputPort1.setId("output-0001");

    final PortDTO outputPort2 = new PortDTO();
    outputPort2.setName("output-two");
    outputPort2.setId("output-0002");

    final Set<PortDTO> inputPorts = new HashSet<>();
    inputPorts.add(inputPort1);
    inputPorts.add(inputPort2);

    final Set<PortDTO> outputPorts = new HashSet<>();
    outputPorts.add(outputPort1);
    outputPorts.add(outputPort2);

    controllerDTO.setInputPorts(inputPorts);
    controllerDTO.setOutputPorts(outputPorts);
    controllerDTO.setRemoteSiteListeningPort(8081);
    controllerDTO.setRemoteSiteHttpListeningPort(8443);
    controllerDTO.setSiteToSiteSecure(true);

    // SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
    doAnswer(invocation -> {
        final SSLContext sslContext = invocation.getArgument(0);
        final HttpProxy httpProxy = invocation.getArgument(1);

        assertEquals(expectedSslConText, sslContext);
        assertEquals(expectedHttpProxy, httpProxy);

        final SiteToSiteRestApiClient apiClient = mock(SiteToSiteRestApiClient.class);

        when(apiClient.getController(eq(expectedClusterUrl))).thenReturn(controllerDTO);

        when(apiClient.getBaseUrl()).thenReturn(expectedActiveClusterUrl);

        return apiClient;
    }).when(siteInfoProvider).createSiteToSiteRestApiClient(any(), any());

    // siteInfoProvider should expose correct information of the remote NiFi cluster.
    assertEquals(controllerDTO.getRemoteSiteListeningPort(), siteInfoProvider.getSiteToSitePort());
    assertEquals(controllerDTO.getRemoteSiteHttpListeningPort(), siteInfoProvider.getSiteToSiteHttpPort());
    assertEquals(controllerDTO.isSiteToSiteSecure(), siteInfoProvider.isSecure());
    assertTrue(siteInfoProvider.isWebInterfaceSecure());

    assertEquals(inputPort1.getId(), siteInfoProvider.getInputPortIdentifier(inputPort1.getName()));
    assertEquals(inputPort2.getId(), siteInfoProvider.getInputPortIdentifier(inputPort2.getName()));
    assertEquals(outputPort1.getId(), siteInfoProvider.getOutputPortIdentifier(outputPort1.getName()));
    assertEquals(outputPort2.getId(), siteInfoProvider.getOutputPortIdentifier(outputPort2.getName()));
    assertNull(siteInfoProvider.getInputPortIdentifier("not-exist"));
    assertNull(siteInfoProvider.getOutputPortIdentifier("not-exist"));

    assertEquals(inputPort1.getId(), siteInfoProvider.getPortIdentifier(inputPort1.getName(), TransferDirection.SEND));
    assertEquals(outputPort1.getId(), siteInfoProvider.getPortIdentifier(outputPort1.getName(), TransferDirection.RECEIVE));

    assertEquals(expectedActiveClusterUrl, siteInfoProvider.getActiveClusterUrl().toString());

}
 
Example 20
Source File: TestHttpClient.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Before
public void before() throws Exception {

    System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "TRACE");
    System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote.protocol.http.HttpClientTransaction", "DEBUG");

    testCaseFinished = new CountDownLatch(1);

    final PeerDTO peer = new PeerDTO();
    peer.setHostname("localhost");
    peer.setPort(httpConnector.getLocalPort());
    peer.setFlowFileCount(10);
    peer.setSecure(false);

    peers = new HashSet<>();
    peers.add(peer);

    final PeerDTO peerSecure = new PeerDTO();
    peerSecure.setHostname("localhost");
    peerSecure.setPort(sslConnector.getLocalPort());
    peerSecure.setFlowFileCount(10);
    peerSecure.setSecure(true);

    peersSecure = new HashSet<>();
    peersSecure.add(peerSecure);

    inputPorts = new HashSet<>();

    final PortDTO runningInputPort = new PortDTO();
    runningInputPort.setName("input-running");
    runningInputPort.setId("input-running-id");
    runningInputPort.setType("INPUT_PORT");
    runningInputPort.setState(ScheduledState.RUNNING.name());
    inputPorts.add(runningInputPort);

    final PortDTO timeoutInputPort = new PortDTO();
    timeoutInputPort.setName("input-timeout");
    timeoutInputPort.setId("input-timeout-id");
    timeoutInputPort.setType("INPUT_PORT");
    timeoutInputPort.setState(ScheduledState.RUNNING.name());
    inputPorts.add(timeoutInputPort);

    final PortDTO timeoutDataExInputPort = new PortDTO();
    timeoutDataExInputPort.setName("input-timeout-data-ex");
    timeoutDataExInputPort.setId("input-timeout-data-ex-id");
    timeoutDataExInputPort.setType("INPUT_PORT");
    timeoutDataExInputPort.setState(ScheduledState.RUNNING.name());
    inputPorts.add(timeoutDataExInputPort);

    final PortDTO accessDeniedInputPort = new PortDTO();
    accessDeniedInputPort.setName("input-access-denied");
    accessDeniedInputPort.setId("input-access-denied-id");
    accessDeniedInputPort.setType("INPUT_PORT");
    accessDeniedInputPort.setState(ScheduledState.RUNNING.name());
    inputPorts.add(accessDeniedInputPort);

    outputPorts = new HashSet<>();

    final PortDTO runningOutputPort = new PortDTO();
    runningOutputPort.setName("output-running");
    runningOutputPort.setId("output-running-id");
    runningOutputPort.setType("OUTPUT_PORT");
    runningOutputPort.setState(ScheduledState.RUNNING.name());
    outputPorts.add(runningOutputPort);

    final PortDTO timeoutOutputPort = new PortDTO();
    timeoutOutputPort.setName("output-timeout");
    timeoutOutputPort.setId("output-timeout-id");
    timeoutOutputPort.setType("OUTPUT_PORT");
    timeoutOutputPort.setState(ScheduledState.RUNNING.name());
    outputPorts.add(timeoutOutputPort);

    final PortDTO timeoutDataExOutputPort = new PortDTO();
    timeoutDataExOutputPort.setName("output-timeout-data-ex");
    timeoutDataExOutputPort.setId("output-timeout-data-ex-id");
    timeoutDataExOutputPort.setType("OUTPUT_PORT");
    timeoutDataExOutputPort.setState(ScheduledState.RUNNING.name());
    outputPorts.add(timeoutDataExOutputPort);


}