Search in sources :

Example 1 with NiFiServiceFacade

use of org.apache.nifi.web.NiFiServiceFacade in project nifi by apache.

the class TestSiteToSiteResource method testPeersVersionWasNotSpecified.

@Test
public void testPeersVersionWasNotSpecified() throws Exception {
    final HttpServletRequest req = mock(HttpServletRequest.class);
    final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
    final SiteToSiteResource resource = getSiteToSiteResource(serviceFacade);
    final Response response = resource.getPeers(req);
    TransactionResultEntity resultEntity = (TransactionResultEntity) response.getEntity();
    assertEquals(400, response.getStatus());
    assertEquals(ResponseCode.ABORT.getCode(), resultEntity.getResponseCode());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) TransactionResultEntity(org.apache.nifi.web.api.entity.TransactionResultEntity) Test(org.junit.Test)

Example 2 with NiFiServiceFacade

use of org.apache.nifi.web.NiFiServiceFacade in project nifi by apache.

the class TestSiteToSiteResource method testGetController.

@Test
public void testGetController() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
    final ControllerEntity controllerEntity = new ControllerEntity();
    final ControllerDTO controller = new ControllerDTO();
    controllerEntity.setController(controller);
    controller.setRemoteSiteHttpListeningPort(8080);
    controller.setRemoteSiteListeningPort(9990);
    doReturn(controller).when(serviceFacade).getSiteToSiteDetails();
    final SiteToSiteResource resource = getSiteToSiteResource(serviceFacade);
    final Response response = resource.getSiteToSiteDetails(req);
    ControllerEntity resultEntity = (ControllerEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertEquals("remoteSiteHttpListeningPort should be retained", new Integer(8080), resultEntity.getController().getRemoteSiteHttpListeningPort());
    assertEquals("Other fields should be retained.", new Integer(9990), controllerEntity.getController().getRemoteSiteListeningPort());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) ControllerEntity(org.apache.nifi.web.api.entity.ControllerEntity) ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO) Test(org.junit.Test)

Example 3 with NiFiServiceFacade

use of org.apache.nifi.web.NiFiServiceFacade in project nifi by apache.

the class TestDataTransferResource method getDataTransferResource.

private DataTransferResource getDataTransferResource() {
    final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
    final HttpFlowFileServerProtocol serverProtocol = mock(HttpFlowFileServerProtocol.class);
    final DataTransferResource resource = new DataTransferResource(NiFiProperties.createBasicNiFiProperties(null, null)) {

        @Override
        protected void authorizeDataTransfer(AuthorizableLookup lookup, ResourceType resourceType, String identifier) {
        }

        @Override
        HttpFlowFileServerProtocol getHttpFlowFileServerProtocol(VersionNegotiator versionNegotiator) {
            return serverProtocol;
        }
    };
    resource.setProperties(NiFiProperties.createBasicNiFiProperties(null, null));
    resource.setServiceFacade(serviceFacade);
    return resource;
}
Also used : AuthorizableLookup(org.apache.nifi.authorization.AuthorizableLookup) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) VersionNegotiator(org.apache.nifi.remote.VersionNegotiator) HttpFlowFileServerProtocol(org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol) ResourceType(org.apache.nifi.authorization.resource.ResourceType)

Example 4 with NiFiServiceFacade

use of org.apache.nifi.web.NiFiServiceFacade in project nifi by apache.

the class TestSiteToSiteResource method testGetControllerForOlderVersion.

@Test
public void testGetControllerForOlderVersion() throws Exception {
    final HttpServletRequest req = mock(HttpServletRequest.class);
    final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
    final ControllerEntity controllerEntity = new ControllerEntity();
    final ControllerDTO controller = new ControllerDTO();
    controllerEntity.setController(controller);
    controller.setRemoteSiteHttpListeningPort(8080);
    controller.setRemoteSiteListeningPort(9990);
    doReturn(controller).when(serviceFacade).getSiteToSiteDetails();
    final SiteToSiteResource resource = getSiteToSiteResource(serviceFacade);
    final Response response = resource.getSiteToSiteDetails(req);
    ControllerEntity resultEntity = (ControllerEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertNull("remoteSiteHttpListeningPort should be null since older version doesn't recognize this field" + " and throws JSON mapping exception.", resultEntity.getController().getRemoteSiteHttpListeningPort());
    assertEquals("Other fields should be retained.", new Integer(9990), controllerEntity.getController().getRemoteSiteListeningPort());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) ControllerEntity(org.apache.nifi.web.api.entity.ControllerEntity) ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO) Test(org.junit.Test)

Example 5 with NiFiServiceFacade

use of org.apache.nifi.web.NiFiServiceFacade in project nifi by apache.

the class TestSiteToSiteResource method testPeersClustered.

@Test
public void testPeersClustered() throws Exception {
    final HttpServletRequest req = createCommonHttpServletRequest();
    final NiFiServiceFacade serviceFacade = mock(NiFiServiceFacade.class);
    final Map<String, String> clusterSettings = new HashMap<>();
    clusterSettings.put(NiFiProperties.CLUSTER_IS_NODE, "true");
    final SiteToSiteResource resource = getSiteToSiteResource(serviceFacade, clusterSettings);
    final ClusterCoordinator clusterCoordinator = mock(ClusterCoordinator.class);
    final Map<String, NodeWorkload> hostportWorkloads = new HashMap<>();
    final Map<NodeIdentifier, NodeWorkload> workloads = new HashMap<>();
    IntStream.range(1, 4).forEach(i -> {
        final String hostname = "node" + i;
        final int siteToSiteHttpApiPort = 8110 + i;
        final NodeIdentifier nodeId = new NodeIdentifier(hostname, hostname, 8080 + i, hostname, 8090 + i, hostname, 8100 + i, siteToSiteHttpApiPort, false);
        final NodeWorkload workload = new NodeWorkload();
        workload.setReportedTimestamp(System.currentTimeMillis() - i);
        workload.setFlowFileBytes(1024 * i);
        workload.setFlowFileCount(10 * i);
        workload.setActiveThreadCount(i);
        workload.setSystemStartTime(System.currentTimeMillis() - (1000 * i));
        workloads.put(nodeId, workload);
        hostportWorkloads.put(hostname + ":" + siteToSiteHttpApiPort, workload);
    });
    when(clusterCoordinator.getClusterWorkload()).thenReturn(workloads);
    resource.setClusterCoordinator(clusterCoordinator);
    final Response response = resource.getPeers(req);
    PeersEntity resultEntity = (PeersEntity) response.getEntity();
    assertEquals(200, response.getStatus());
    assertEquals(3, resultEntity.getPeers().size());
    resultEntity.getPeers().stream().forEach(peerDTO -> {
        final NodeWorkload workload = hostportWorkloads.get(peerDTO.getHostname() + ":" + peerDTO.getPort());
        assertNotNull(workload);
        assertEquals(workload.getFlowFileCount(), peerDTO.getFlowFileCount());
    });
}
Also used : HashMap(java.util.HashMap) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) NodeWorkload(org.apache.nifi.cluster.coordination.node.NodeWorkload) HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) NiFiServiceFacade(org.apache.nifi.web.NiFiServiceFacade) PeersEntity(org.apache.nifi.web.api.entity.PeersEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Test(org.junit.Test)

Aggregations

NiFiServiceFacade (org.apache.nifi.web.NiFiServiceFacade)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Response (javax.ws.rs.core.Response)7 Test (org.junit.Test)7 PeersEntity (org.apache.nifi.web.api.entity.PeersEntity)4 HashMap (java.util.HashMap)2 ControllerDTO (org.apache.nifi.web.api.dto.ControllerDTO)2 PeerDTO (org.apache.nifi.web.api.dto.remote.PeerDTO)2 ControllerEntity (org.apache.nifi.web.api.entity.ControllerEntity)2 AuthorizableLookup (org.apache.nifi.authorization.AuthorizableLookup)1 ResourceType (org.apache.nifi.authorization.resource.ResourceType)1 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)1 NodeWorkload (org.apache.nifi.cluster.coordination.node.NodeWorkload)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 VersionNegotiator (org.apache.nifi.remote.VersionNegotiator)1 HttpFlowFileServerProtocol (org.apache.nifi.remote.protocol.http.HttpFlowFileServerProtocol)1 TransactionResultEntity (org.apache.nifi.web.api.entity.TransactionResultEntity)1