@Test public void testPutClusterConfig() throws Exception { JsonObject originalConfig = new JsonObject(); originalConfig.addProperty("key1", "val1"); Cluster cluster = Cluster.builder() .setID("123") .setAccount(USER1_ACCOUNT) .setName("get-config-test") .setProvider(Entities.ProviderExample.JOYENT) .setClusterTemplate(Entities.ClusterTemplateExample.HDFS) .setConfig(originalConfig) .build(); cluster.setStatus(Cluster.Status.ACTIVE); clusterStoreService.getView(cluster.getAccount()).writeCluster(cluster); HttpResponse response = doGetExternalAPI("/clusters/123/config", USER1_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); Reader reader = new InputStreamReader(response.getEntity().getContent(), Charsets.UTF_8); JsonObject actual = gson.fromJson(reader, JsonObject.class); Assert.assertEquals(originalConfig, actual); JsonObject newConfig = new JsonObject(); newConfig.addProperty("key2", "val2"); ClusterConfigureRequest configRequest = new ClusterConfigureRequest(null, newConfig, false); assertResponseStatus(doPutExternalAPI("/clusters/123/config", gson.toJson(configRequest), USER1_HEADERS), HttpResponseStatus.OK); response = doGetExternalAPI("/clusters/123/config", USER1_HEADERS); assertResponseStatus(response, HttpResponseStatus.OK); reader = new InputStreamReader(response.getEntity().getContent(), Charsets.UTF_8); actual = gson.fromJson(reader, JsonObject.class); Assert.assertEquals(newConfig, actual); }
@Test public void testInvalidClusterConfigRequests() throws Exception { Cluster cluster = Cluster.builder() .setID("123") .setAccount(USER1_ACCOUNT) .setName("get-config-test") .setClusterTemplate(Entities.ClusterTemplateExample.HDFS) .build(); clusterStoreService.getView(cluster.getAccount()).writeCluster(cluster); String requestStr = gson.toJson(new ClusterConfigureRequest(null, new JsonObject(), false)); assertResponseStatus(doPutExternalAPI("/clusters/" + cluster.getId() + "/config", "{}", USER1_HEADERS), HttpResponseStatus.BAD_REQUEST); assertResponseStatus(doPutExternalAPI("/clusters/" + cluster.getId() + "9/config", requestStr, USER1_HEADERS), HttpResponseStatus.NOT_FOUND); assertResponseStatus(doPutExternalAPI("/clusters/" + cluster.getId() + "/config", requestStr, USER2_HEADERS), HttpResponseStatus.NOT_FOUND); cluster.setStatus(Cluster.Status.INCOMPLETE); clusterStoreService.getView(cluster.getAccount()).writeCluster(cluster); assertResponseStatus(doPutExternalAPI("/clusters/" + cluster.getId() + "/config", requestStr, USER1_HEADERS), HttpResponseStatus.CONFLICT); }
@Test public void testPutClusterConfigCanRunOnInconsistentClusters() throws Exception { Cluster cluster = Cluster.builder() .setID("123") .setAccount(USER1_ACCOUNT) .setName("get-config-test") .setProvider(Entities.ProviderExample.JOYENT) .setClusterTemplate(Entities.ClusterTemplateExample.HDFS) .build(); cluster.setStatus(Cluster.Status.INCONSISTENT); clusterStoreService.getView(cluster.getAccount()).writeCluster(cluster); String requestStr = gson.toJson(new ClusterConfigureRequest(null, new JsonObject(), false)); assertResponseStatus(doPutExternalAPI("/clusters/" + cluster.getId() + "/config", requestStr, USER1_HEADERS), HttpResponseStatus.OK); }