public static void writeRequirements(OutputStream out, FabricRequirements value) throws IOException { writeRequirements(out,value,false); }
public static FabricRequirements fromJSON(String json) throws IOException { return valueFromJSON(json, FabricRequirements.class); }
actual.sortProfilesRequirements(); boolean valid = RequirementsJson.equal(requirements, actual); if (!valid) { System.out.println("Expected: " + RequirementsJson.toJSON(requirements)); System.out.println("Actual: " + RequirementsJson.toJSON(actual)); System.out.println(); return false; System.out.println("Updated the requirements to: " + RequirementsJson.toJSON(requirements));
public static String toJSON(AutoScaleStatus value) throws IOException { return valueToJSON(value); }
@Override protected Object doExecute() throws Exception { // lets test if the file exists File file = new File(jsonUrl); InputStream is; if (file.exists()) { if (file.isDirectory()) { System.out.println("The file " + jsonUrl + " is a directory!"); return null; } is = new FileInputStream(jsonUrl); } else { is = new URL(jsonUrl).openStream(); } if (is == null) { System.out.println("Could not open the URL " + jsonUrl); return null; } FabricRequirements requirements = RequirementsJson.readRequirements(is); if (requirements != null) { getFabricService().setRequirements(requirements); System.out.println("Imported the fabric requirements from " + jsonUrl); } return null; } }
if (!JSONObject.class.isAssignableFrom(clazz)) { String json = jsonObject.toJSONString(); return RequirementsJson.getMapper().reader(clazz).readValue(json);
@Override public FabricRequirements getRequirements() { assertValid(); try { FabricRequirements answer = null; if (configCache.getCurrentData(REQUIREMENTS_JSON_PATH) != null) { String json = getStringData(configCache, REQUIREMENTS_JSON_PATH); answer = RequirementsJson.fromJSON(json); } if (answer == null) { answer = new FabricRequirements(); } return answer; } catch (Exception e) { throw FabricException.launderThrowable(e); } }
@Override public AutoScaleStatus getAutoScaleStatus() { assertValid(); try { AutoScaleStatus answer = null; String zkPath = ZkPath.AUTO_SCALE_STATUS.getPath(); if (configCache.getCurrentData(zkPath) != null) { String json = getStringData(configCache, zkPath); answer = RequirementsJson.autoScaleStatusFromJSON(json); } if (answer == null) { answer = new AutoScaleStatus(); } return answer; } catch (Exception e) { throw FabricException.launderThrowable(e); } }
public static String toJSON(FabricRequirements value) throws IOException { return valueToJSON(value); }
@Override public void setRequirements(FabricRequirements requirements) throws Exception { String json = RequirementsJson.toJSON(requirements); fabricManager.requirementsJson(json); }
@Override protected Object doExecute() throws Exception { outputFile.getParentFile().mkdirs(); FabricRequirements requirements = getFabricService().getRequirements(); RequirementsJson.writeRequirements(new FileOutputStream(outputFile), requirements); System.out.println("Exported the fabric requirements to " + outputFile.getCanonicalPath()); return null; } }
public static AutoScaleStatus autoScaleStatusFromJSON(String json) throws IOException { return valueFromJSON(json, AutoScaleStatus.class); }
@Override public void setRequirements(FabricRequirements requirements) throws IOException { assertValid(); try { String json = RequirementsJson.toJSON(requirements); setData(curator.get(), REQUIREMENTS_JSON_PATH, json); } catch (Exception e) { throw FabricException.launderThrowable(e); } }
private void autoScale() { FabricService service = fabricService.get(); FabricRequirements requirements = service.getRequirements(); List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements(); if (profileRequirements != null && !profileRequirements.isEmpty()) { AutoScaleStatus status = new AutoScaleStatus(); for (ProfileRequirements profileRequirement : profileRequirements) { ContainerAutoScaler autoScaler = createAutoScaler(requirements, profileRequirement); if (autoScaler != null) { autoScaleProfile(service, autoScaler, requirements, profileRequirement, status); } else { LOGGER.warn("No ContainerAutoScaler available for profile " + profileRequirement.getProfile()); } } if (zkMasterCache != null) { try { String json = RequirementsJson.toJSON(status); String zkPath = ZkPath.AUTO_SCALE_STATUS.getPath(); zkMasterCache.setStringData(zkPath, json, CreateMode.EPHEMERAL); } catch (Exception e) { LOGGER.warn("Failed to write autoscale status " + e, e); } } else { LOGGER.warn("No ZooKeeperMasterCache!"); } } }