ChefJsonGenerator { public static Map<String, JsonObject> generateClusterChefJsonsForPurge(JsonCluster definition, ClusterRuntime clusterEntity) throws KaramelException { Map<String, JsonObject> chefJsons = new HashMap<>(); JsonObject root = new JsonObject(); for (GroupRuntime groupEntity : clusterEntity.getGroups()) { JsonObject clone = cloneJsonObject(root); JsonGroup jsonGroup = UserClusterDataExtractor.findGroup(definition, groupEntity.getName()); for (JsonCookbook cb : jsonGroup.getCookbooks()) { addCookbookAttributes(cb, clone); } for (JsonCookbook cb : jsonGroup.getCookbooks()) { Map<String, JsonObject> gj = generatePurgeChefJsons(clone, cb, groupEntity); chefJsons.putAll(gj); } } return chefJsons; }  static Map<String, JsonObject> generateClusterChefJsonsForPurge(JsonCluster definition,
      ClusterRuntime clusterEntity); static Map<String, JsonObject> generateClusterChefJsonsForInstallation(JsonCluster definition,
      ClusterRuntime clusterEntity); static Map<String, JsonObject> generatePurgeChefJsons(JsonObject json, JsonCookbook cb,
      GroupRuntime groupEntity); static Map<String, JsonObject> generateRecipesChefJsons(JsonObject json, JsonCookbook cb,
      GroupRuntime groupEntity); static JsonObject addMachineNRecipeToJson(JsonObject json, MachineRuntime me, String recipeName); static void addRunListForRecipe(JsonObject chefJson, String recipeName); static void addMachineIps(JsonObject json, MachineRuntime machineEntity); static void addCookbookAttributes(JsonCookbook jc, JsonObject root); static void aggregateIpAddresses(JsonObject json, JsonCluster definition, ClusterRuntime clusterEntity); static void attrMap2Json(JsonObject root, Map<String, Map<String, String>> attrs); static void attr2Json(JsonObject root,
      Map<String, List<String>> attrs); static JsonObject cloneJsonObject(JsonObject jo);  }
@Test public void testGenerateClusterChefJsonsForPurge() throws KaramelException { Settings.CB_CLASSPATH_MODE = true; String jsonString = " {\"name\":\"MySqlCluster\"," + "\"cookbooks\":[{\"id\":\"https: + "\"attrs\":{\"ndb/DataMemory\":" + "\"111\"}}],\"groups\":[{\"name\":\"datanodes\"," + "\"cookbooks\":[{\"id\":\"https: + "\"attrs\":{}," + "\"recipes\":[{\"name\":\"ndb::ndbd\"}]}],\"size\":2,\"provider\":null},{\"name\":\"mgmnodes\",\"cookbooks\":" + "[{\"id\":\"https: + "\"attrs\":{},\"recipes\":" + "[{\"name\":\"ndb::mgmd\"},{\"name\":\"ndb::mysqld\"},{\"name\":\"ndb::memcached\"}]}],\"size\":" + "1,\"provider\":null}],\"ec2\":{\"type\":\"m3.medium\",\"ami\":null,\"region\":\"eu-west-1\",\"price\":" + "null,\"vpc\":null,\"subnet\":null}}"; String yaml = ClusterDefinitionService.jsonToYaml(jsonString); JsonCluster definition = ClusterDefinitionService.yamlToJsonObject(yaml); List<JsonCookbook> cookbooks = definition.getCookbooks(); JsonCookbook ndb = null; for (JsonCookbook jc : cookbooks) { if (jc.getName().equals("ndb")) { ndb = jc; } } ClusterRuntime clusterRuntime = MockingUtil.dummyRuntime(definition); Map<String, JsonObject> chefJsons = ChefJsonGenerator.generateClusterChefJsonsForPurge(definition, clusterRuntime); Assert.assertEquals(3, chefJsons.size()); Assert.assertNotNull(chefJsons.get("datanodes1ndb::purge")); Assert.assertNotNull(chefJsons.get("datanodes2ndb::purge")); Assert.assertNotNull(chefJsons.get("mgmnodes1ndb::purge")); JsonObject jsonObject = chefJsons.get("mgmnodes1ndb::purge"); String st = jsonObject.toString(); }