Search in sources :

Example 1 with ControllerDTO

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcessGroupCounts(org.apache.nifi.groups.ProcessGroupCounts) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) WebApplicationException(javax.ws.rs.WebApplicationException) RootGroupPort(org.apache.nifi.remote.RootGroupPort) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO)

Example 2 with 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) {
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SiteToSiteRestApiClient(org.apache.nifi.remote.util.SiteToSiteRestApiClient) ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ControllerDTO

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;
}
Also used : ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO)

Example 4 with ControllerDTO

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;
}
Also used : ControllerDTO(org.apache.nifi.web.api.dto.ControllerDTO) IOException(java.io.IOException)

Example 5 with ControllerDTO

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

Aggregations

ControllerDTO (org.apache.nifi.web.api.dto.ControllerDTO)14 SiteToSiteRestApiClient (org.apache.nifi.remote.util.SiteToSiteRestApiClient)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 LinkedHashSet (java.util.LinkedHashSet)4 PortDTO (org.apache.nifi.web.api.dto.PortDTO)4 ControllerEntity (org.apache.nifi.web.api.entity.ControllerEntity)3 URISyntaxException (java.net.URISyntaxException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Response (javax.ws.rs.core.Response)2 NiFiServiceFacade (org.apache.nifi.web.NiFiServiceFacade)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 CertificateException (java.security.cert.CertificateException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1