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