ClusterResource { @GET @Path("/{cluster_name}") public Response getCluster( @PathParam("cluster_name") String clusterName, @QueryParam("limit") Optional<Integer> limit) { LOG.debug("get cluster called with cluster_name: {}", clusterName); try { Cluster cluster = context.storage.getCluster(clusterName); String jmxUsername = ""; boolean jmxPasswordIsSet = false; Optional<JmxCredentials> jmxCredentials = context.jmxConnectionFactory .getJmxCredentialsForCluster(Optional.ofNullable(cluster)); if (jmxCredentials.isPresent()) { jmxUsername = StringUtils.trimToEmpty(jmxCredentials.get().getUsername()); jmxPasswordIsSet = !StringUtils.isEmpty(jmxCredentials.get().getPassword()); } ClusterStatus clusterStatus = new ClusterStatus( cluster, jmxUsername, jmxPasswordIsSet, context.storage.getClusterRunStatuses(cluster.getName(), limit.orElse(Integer.MAX_VALUE)), context.storage.getClusterScheduleStatuses(cluster.getName()), getNodesStatus(cluster)); return Response.ok().entity(clusterStatus).build(); } catch (IllegalArgumentException ignore) { } return Response.status(404).entity("cluster with name \"" + clusterName + "\" not found").build(); } ClusterResource(AppContext context, Cryptograph cryptograph, ExecutorService executor); @GET Response getClusterList(@QueryParam("seedHost") Optional<String> seedHost); @GET @Path("/{cluster_name}") Response getCluster(
      @PathParam("cluster_name") String clusterName,
      @QueryParam("limit") Optional<Integer> limit); @GET @Path("/{cluster_name}/tables") Response getClusterTables(@PathParam("cluster_name") String clusterName); @POST Response addOrUpdateCluster(
      @Context UriInfo uriInfo,
      @QueryParam("seedHost") Optional<String> seedHost,
      @QueryParam("jmxPort") Optional<Integer> jmxPort); @POST @Path("/auth") Response addOrUpdateCluster(
      @Context UriInfo uriInfo,
      @FormParam("seedHost") Optional<String> seedHost,
      @FormParam("jmxPort") Optional<Integer> jmxPort,
      @FormParam("jmxUsername") Optional<String> jmxUsername,
      @FormParam("jmxPassword") Optional<String> jmxPassword); @PUT @Path("/{cluster_name}") Response addOrUpdateCluster(
      @Context UriInfo uriInfo,
      @PathParam("cluster_name") String clusterName,
      @QueryParam("seedHost") Optional<String> seedHost,
      @QueryParam("jmxPort") Optional<Integer> jmxPort); @PUT @Path("/auth/{cluster_name}") Response addOrUpdateCluster(
      @Context UriInfo uriInfo,
      @PathParam("cluster_name") String clusterName,
      @FormParam("seedHost") Optional<String> seedHost,
      @FormParam("jmxPort") Optional<Integer> jmxPort,
      @FormParam("jmxUsername") Optional<String> jmxUsername,
      @FormParam("jmxPassword") Optional<String> jmxPassword); Optional<Cluster> findClusterWithSeedHost(String seedHost,
                                                   Optional<Integer> jmxPort,
                                                   Optional<JmxCredentials> jmxCredentials); @DELETE @Path("/{cluster_name}") Response deleteCluster(
      @PathParam("cluster_name") String clusterName,
      @QueryParam("force") Optional<Boolean> force);  }
@Test public void testGetNonExistingCluster() throws ReaperException { final MockObjects mocks = initMocks(); when(mocks.jmxProxy.getLiveNodes()).thenReturn(Arrays.asList(SEED_HOST)); ClusterResource clusterResource = new ClusterResource(mocks.context, mocks.cryptograph, EXECUTOR); Response response = clusterResource.getCluster(I_DONT_EXIST, Optional.<Integer>empty()); Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404); }
@Test public void testGetExistingCluster() throws ReaperException { final MockObjects mocks = initMocks(); when(mocks.jmxProxy.getLiveNodes()).thenReturn(Arrays.asList(SEED_HOST)); Cluster cluster = Cluster.builder() .withName(I_DO_EXIST) .withPartitioner(PARTITIONER) .withSeedHosts(ImmutableSet.of(SEED_HOST)) .withState(Cluster.State.ACTIVE) .build(); mocks.context.storage.addCluster(cluster); ClusterResource clusterResource = new ClusterResource(mocks.context, mocks.cryptograph, EXECUTOR); Response response = clusterResource.getCluster(I_DO_EXIST, Optional.<Integer>empty()); Assertions.assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200); }