ClusterResource { @POST public Response addOrUpdateCluster( @Context UriInfo uriInfo, @QueryParam("seedHost") Optional<String> seedHost, @QueryParam("jmxPort") Optional<Integer> jmxPort) { LOG.info("POST addOrUpdateCluster called with seedHost: {}", seedHost.orElse(null)); return addOrUpdateCluster(uriInfo, Optional.empty(), seedHost, jmxPort, Optional.empty(), Optional.empty()); } 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 testFailAddingJmxCredentialsWithoutEncryptionConfigured() throws Exception { final MockObjects mocks = initMocks(); ClusterResource clusterResource = new ClusterResource(mocks.context, new NoopCrypotograph(), EXECUTOR); Response response = clusterResource.addOrUpdateCluster(mocks.uriInfo, Optional.of(SEED_HOST), Optional.of(Cluster.DEFAULT_JMX_PORT), Optional.of(JMX_USERNAME), Optional.of(JMX_PASSWORD)); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); }
@Test public void addingAClusterAutomaticallySetupSchedulingRepairsWhenEnabled() throws Exception { final MockObjects mocks = initMocks(); when(mocks.jmxProxy.getLiveNodes()).thenReturn(Arrays.asList(SEED_HOST)); when(mocks.jmxProxy.getKeyspaces()).thenReturn(Lists.newArrayList("keyspace1")); when(mocks.jmxProxy.getTablesForKeyspace("keyspace1")) .thenReturn(Sets.newHashSet(Table.builder().withName("table1").withCompactionStrategy(STCS).build())); mocks.context.config = TestRepairConfiguration.defaultConfigBuilder() .withAutoScheduling( TestRepairConfiguration.defaultAutoSchedulingConfigBuilder() .thatIsEnabled() .withTimeBeforeFirstSchedule(Duration.ofMinutes(1)) .build()) .build(); ClusterResource clusterResource = new ClusterResource( mocks.context, mocks.cryptograph, Executors.newFixedThreadPool(2)); Response response = clusterResource .addOrUpdateCluster(mocks.uriInfo, Optional.of(SEED_HOST), Optional.of(Cluster.DEFAULT_JMX_PORT), Optional.of(JMX_USERNAME), Optional.of(JMX_PASSWORD)); assertEquals(HttpStatus.CREATED_201, response.getStatus()); assertEquals(1, mocks.context.storage.getAllRepairSchedules().size()); assertEquals(1, mocks.context.storage.getRepairSchedulesForClusterAndKeyspace(CLUSTER_NAME, "keyspace1").size()); }