ConfigurationService { @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/getConfig") public Response getConfigurationValue(@QueryParam("siteName") String siteName,@QueryParam("configName") String configName){ LOG.info("Get configuration value for siteName {}, configName {}", siteName, configName); try{ String configValue = context.getCluster().getConfigurationValue(siteName,configName); JSONObject res = new JSONObject(); JSONArray arr = new JSONArray(); JSONObject conf = new JSONObject(); conf.put("siteName",siteName); conf.put("configName", configName); conf.put("configValue", configValue); arr.add(conf); res.put("configs" ,arr); return Response.ok(res).build(); } catch (WebApplicationException ex) { LOG.error("Exception occurred : ", ex); throw ex; } catch (Exception ex) { LOG.error("Exception occurred : ", ex); throw new ServiceFormattedException(ex.getMessage(), ex); } } ConfigurationService(ViewContext context); @GET @Produces(MediaType.APPLICATION_JSON) Response readLatestConfiguration(); @GET @Path("cluster") @Produces(MediaType.APPLICATION_JSON) Response readClusterInfo(); @GET @Path("all") @Produces(MediaType.APPLICATION_JSON) Response readAllConfigurations(); @GET @Path("byTag/{tag}") @Produces(MediaType.APPLICATION_JSON) Response readConfigurationByTag(@PathParam("tag") String tag); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/privilege") Response getPrivilege(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/nodeLabels") Response getNodeLabels(); @GET @Produces(MediaType.APPLICATION_JSON) @Path("/rmCurrentConfig") Response getRmSchedulerConfig(); @PUT @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.APPLICATION_JSON) Response writeConfiguration(String requestBody); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/saveAndRefresh") Response writeAndRefreshConfiguration(JSONObject request); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/saveAndRestart") Response writeAndRestartConfiguration(JSONObject request); @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/getConfig") Response getConfigurationValue(@QueryParam("siteName") String siteName,@QueryParam("configName") String configName);  }
@Test public void testRightConfigurationValue() { Response response = configurationService.getConfigurationValue("ranger-yarn-plugin-properties", "ranger-yarn-plugin-enabled"); JSONObject jsonObject = (JSONObject) response.getEntity(); JSONArray arr = (JSONArray) jsonObject.get("configs"); Assert.assertEquals(arr.size(), 1); JSONObject obj = (JSONObject) arr.get(0); Assert.assertEquals(obj.get("siteName"), "ranger-yarn-plugin-properties"); Assert.assertEquals(obj.get("configName"), "ranger-yarn-plugin-enabled"); Assert.assertEquals(obj.get("configValue"), "Yes"); }
@Test public void testExceptionOnWrongConfigurationValue() { Response response = configurationService.getConfigurationValue("random-site", "random-key"); JSONObject jsonObject = (JSONObject) response.getEntity(); JSONArray arr = (JSONArray) jsonObject.get("configs"); Assert.assertEquals(arr.size(), 1); JSONObject obj = (JSONObject) arr.get(0); Assert.assertEquals(obj.get("siteName"), "random-site"); Assert.assertEquals(obj.get("configName"), "random-key"); Assert.assertEquals(obj.get("configValue"), null); }