use of org.apache.nifi.web.api.dto.ControllerDTO in project nifi by apache.
the class StandardNiFiServiceFacade method getSiteToSiteDetails.
@Override
public ControllerDTO getSiteToSiteDetails() {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
if (user == null) {
throw new WebApplicationException(new Throwable("Unable to access details for current user."));
}
// serialize the input ports this NiFi has access to
final Set<PortDTO> inputPortDtos = new LinkedHashSet<>();
final Set<RootGroupPort> inputPorts = controllerFacade.getInputPorts();
for (final RootGroupPort inputPort : inputPorts) {
if (isUserAuthorized(user, inputPort)) {
final PortDTO dto = new PortDTO();
dto.setId(inputPort.getIdentifier());
dto.setName(inputPort.getName());
dto.setComments(inputPort.getComments());
dto.setState(inputPort.getScheduledState().toString());
inputPortDtos.add(dto);
}
}
// serialize the output ports this NiFi has access to
final Set<PortDTO> outputPortDtos = new LinkedHashSet<>();
for (final RootGroupPort outputPort : controllerFacade.getOutputPorts()) {
if (isUserAuthorized(user, outputPort)) {
final PortDTO dto = new PortDTO();
dto.setId(outputPort.getIdentifier());
dto.setName(outputPort.getName());
dto.setComments(outputPort.getComments());
dto.setState(outputPort.getScheduledState().toString());
outputPortDtos.add(dto);
}
}
// get the root group
final ProcessGroup rootGroup = processGroupDAO.getProcessGroup(controllerFacade.getRootGroupId());
final ProcessGroupCounts counts = rootGroup.getCounts();
// create the controller dto
final ControllerDTO controllerDTO = new ControllerDTO();
controllerDTO.setId(controllerFacade.getRootGroupId());
controllerDTO.setInstanceId(controllerFacade.getInstanceId());
controllerDTO.setName(controllerFacade.getName());
controllerDTO.setComments(controllerFacade.getComments());
controllerDTO.setInputPorts(inputPortDtos);
controllerDTO.setOutputPorts(outputPortDtos);
controllerDTO.setInputPortCount(inputPortDtos.size());
controllerDTO.setOutputPortCount(outputPortDtos.size());
controllerDTO.setRunningCount(counts.getRunningCount());
controllerDTO.setStoppedCount(counts.getStoppedCount());
controllerDTO.setInvalidCount(counts.getInvalidCount());
controllerDTO.setDisabledCount(counts.getDisabledCount());
// determine the site to site configuration
controllerDTO.setRemoteSiteListeningPort(controllerFacade.getRemoteSiteListeningPort());
controllerDTO.setRemoteSiteHttpListeningPort(controllerFacade.getRemoteSiteListeningHttpPort());
controllerDTO.setSiteToSiteSecure(controllerFacade.isRemoteSiteCommsSecure());
return controllerDTO;
}
use of org.apache.nifi.web.api.dto.ControllerDTO in project nifi by apache.
the class TestSiteInfoProvider method testConnectException.
@Test
public void testConnectException() throws Exception {
final Set<String> expectedClusterUrl = new LinkedHashSet<>(Arrays.asList(new String[] { "http://node1:8443, http://node2:8443" }));
final SiteInfoProvider siteInfoProvider = spy(new SiteInfoProvider());
siteInfoProvider.setClusterUrls(expectedClusterUrl);
final ControllerDTO controllerDTO = new ControllerDTO();
controllerDTO.setInputPorts(Collections.emptySet());
controllerDTO.setOutputPorts(Collections.emptySet());
controllerDTO.setRemoteSiteListeningPort(8081);
controllerDTO.setRemoteSiteHttpListeningPort(8080);
controllerDTO.setSiteToSiteSecure(false);
// SiteInfoProvider uses SiteToSIteRestApiClient to get ControllerDTO.
doAnswer(invocation -> {
final SiteToSiteRestApiClient apiClient = mock(SiteToSiteRestApiClient.class);
when(apiClient.getController(eq(expectedClusterUrl))).thenThrow(new IOException("Connection refused."));
return apiClient;
}).when(siteInfoProvider).createSiteToSiteRestApiClient(any(), any());
try {
siteInfoProvider.getSiteToSitePort();
fail();
} catch (IOException e) {
}
try {
siteInfoProvider.getActiveClusterUrl();
fail();
} catch (IOException e) {
}
}
use of org.apache.nifi.web.api.dto.ControllerDTO in project nifi by apache.
the class SiteInfoProvider method getSiteToSitePort.
/**
* @return the port that the remote instance is listening on for
* RAW Socket site-to-site communication, or <code>null</code> if the remote instance
* is not configured to allow site-to-site communications.
*
* @throws IOException if unable to communicate with the remote instance
*/
public Integer getSiteToSitePort() throws IOException {
Integer listeningPort;
remoteInfoReadLock.lock();
try {
listeningPort = this.siteToSitePort;
if (listeningPort != null && this.remoteRefreshTime > System.currentTimeMillis() - REMOTE_REFRESH_MILLIS) {
return listeningPort;
}
} finally {
remoteInfoReadLock.unlock();
}
final ControllerDTO controller = refreshRemoteInfo();
listeningPort = controller.getRemoteSiteListeningPort();
return listeningPort;
}
use of org.apache.nifi.web.api.dto.ControllerDTO in project nifi by apache.
the class SiteInfoProvider method isSecure.
/**
* @return {@code true} if the remote instance is configured for secure
* site-to-site communications, {@code false} otherwise
* @throws IOException if unable to check if secure
*/
public boolean isSecure() throws IOException {
remoteInfoReadLock.lock();
try {
final Boolean secure = this.siteToSiteSecure;
if (secure != null && this.remoteRefreshTime > System.currentTimeMillis() - REMOTE_REFRESH_MILLIS) {
return secure;
}
} finally {
remoteInfoReadLock.unlock();
}
final ControllerDTO controller = refreshRemoteInfo();
final Boolean isSecure = controller.isSiteToSiteSecure();
if (isSecure == null) {
throw new IOException("Remote NiFi instance " + clusterUrls + " is not currently configured to accept site-to-site connections");
}
return isSecure;
}
use of org.apache.nifi.web.api.dto.ControllerDTO 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());
}
Aggregations