@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()); }
@GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) public Response getSiteToSiteDetails(@Context HttpServletRequest req) { authorizeSiteToSite(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } final ControllerDTO controller = serviceFacade.getSiteToSiteDetails(); final ControllerEntity entity = new ControllerEntity(); entity.setController(controller); if (isEmpty(req.getHeader(HttpHeaders.PROTOCOL_VERSION))) { logger.debug("Converting result to provide backward compatibility..."); controller.setRemoteSiteHttpListeningPort(null); } return clusterContext(noCache(Response.ok(entity))).build(); }
SiteToSiteResource extends ApplicationResource { @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) public Response getSiteToSiteDetails(@Context HttpServletRequest req) { authorizeSiteToSite(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } final ControllerDTO controller = serviceFacade.getSiteToSiteDetails(); final ControllerEntity entity = new ControllerEntity(); entity.setController(controller); if (isEmpty(req.getHeader(HttpHeaders.PROTOCOL_VERSION))) { logger.debug("Converting result to provide backward compatibility..."); controller.setRemoteSiteHttpListeningPort(null); } return clusterContext(noCache(Response.ok(entity))).build(); } }
SiteToSiteResource extends ApplicationResource { @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) public Response getSiteToSiteDetails(@Context HttpServletRequest req) { authorizeSiteToSite(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } final ControllerDTO controller = serviceFacade.getSiteToSiteDetails(); final ControllerEntity entity = new ControllerEntity(); entity.setController(controller); if (isEmpty(req.getHeader(HttpHeaders.PROTOCOL_VERSION))) { logger.debug("Converting result to provide backward compatibility..."); controller.setRemoteSiteHttpListeningPort(null); } return clusterContext(noCache(Response.ok(entity))).build(); } SiteToSiteResource(final NiFiProperties nifiProperties); }
SiteToSiteResource extends ApplicationResource { @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) public Response getSiteToSiteDetails(@Context HttpServletRequest req) { authorizeSiteToSite(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } final ControllerDTO controller = serviceFacade.getSiteToSiteDetails(); final ControllerEntity entity = new ControllerEntity(); entity.setController(controller); if (isEmpty(req.getHeader(HttpHeaders.PROTOCOL_VERSION))) { logger.debug("Converting result to provide backward compatibility..."); controller.setRemoteSiteHttpListeningPort(null); } return clusterContext(noCache(Response.ok(entity))).build(); } SiteToSiteResource(final NiFiProperties nifiProperties); @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) Response getSiteToSiteDetails(@Context HttpServletRequest req); @GET @Path("/peers") @Consumes(MediaType.WILDCARD) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation( value = "Returns the available Peers and its status of this NiFi", response = PeersEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) Response getPeers(@Context HttpServletRequest req); void setServiceFacade(final NiFiServiceFacade serviceFacade); void setAuthorizer(Authorizer authorizer); @Override void setClusterCoordinator(final ClusterCoordinator clusterCoordinator); }
SiteToSiteResource extends ApplicationResource { @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) public Response getSiteToSiteDetails(@Context HttpServletRequest req) { authorizeSiteToSite(); if (isReplicateRequest()) { return replicate(HttpMethod.GET); } final ControllerDTO controller = serviceFacade.getSiteToSiteDetails(); final ControllerEntity entity = new ControllerEntity(); entity.setController(controller); if (isEmpty(req.getHeader(HttpHeaders.PROTOCOL_VERSION))) { logger.debug("Converting result to provide backward compatibility..."); controller.setRemoteSiteHttpListeningPort(null); } return clusterContext(noCache(Response.ok(entity))).build(); } SiteToSiteResource(final NiFiProperties nifiProperties); @GET @Consumes(MediaType.WILDCARD) @Produces(MediaType.APPLICATION_JSON) @ApiOperation( value = "Returns the details about this NiFi necessary to communicate via site to site", response = ControllerEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) Response getSiteToSiteDetails(@Context HttpServletRequest req); @GET @Path("/peers") @Consumes(MediaType.WILDCARD) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @ApiOperation( value = "Returns the available Peers and its status of this NiFi", response = PeersEntity.class, authorizations = { @Authorization(value = "Read - /site-to-site", type = "") } ) @ApiResponses( value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") } ) Response getPeers(@Context HttpServletRequest req); void setServiceFacade(final NiFiServiceFacade serviceFacade); void setAuthorizer(Authorizer authorizer); @Override void setClusterCoordinator(final ClusterCoordinator clusterCoordinator);  }