UpgradeCatalog240 extends AbstractUpgradeCatalog { protected String addParam(String source, List<String> params) { JsonObject sourceJson = new JsonParser().parse(source).getAsJsonObject(); JsonArray parametersJson = sourceJson.getAsJsonArray("parameters"); boolean parameterExists = parametersJson != null && !parametersJson.isJsonNull(); if (parameterExists) { Iterator<JsonElement> jsonElementIterator = parametersJson.iterator(); while (jsonElementIterator.hasNext()) { JsonElement element = jsonElementIterator.next(); JsonElement name = element.getAsJsonObject().get("name"); if (name != null && !name.isJsonNull() && params.contains(name.getAsString())) { params.remove(name.getAsString()); } } if (params.size() == 0) { return sourceJson.toString(); } } List<JsonObject> paramsToAdd = new ArrayList<>(); if (params.contains("connection.timeout")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("connection.timeout")); param.add("display_name", new JsonPrimitive("Connection Timeout")); param.add("value", new JsonPrimitive(5.0)); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The maximum time before this alert is considered to be CRITICAL")); param.add("units", new JsonPrimitive("seconds")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("checkpoint.time.warning.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("checkpoint.time.warning.threshold")); param.add("display_name", new JsonPrimitive("Checkpoint Warning")); param.add("value", new JsonPrimitive(2.0)); param.add("type", new JsonPrimitive("PERCENT")); param.add("description", new JsonPrimitive("The percentage of the last checkpoint time greater than the interval in order to trigger a warning alert.")); param.add("units", new JsonPrimitive("%")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("checkpoint.time.critical.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("checkpoint.time.critical.threshold")); param.add("display_name", new JsonPrimitive("Checkpoint Critical")); param.add("value", new JsonPrimitive(4.0)); param.add("type", new JsonPrimitive("PERCENT")); param.add("description", new JsonPrimitive("The percentage of the last checkpoint time greater than the interval in order to trigger a critical alert.")); param.add("units", new JsonPrimitive("%")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("checkpoint.txns.multiplier.warning.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("checkpoint.txns.multiplier.warning.threshold")); param.add("display_name", new JsonPrimitive("Uncommitted transactions Warning")); param.add("value", new JsonPrimitive(2.0)); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The multiplier to use against dfs.namenode.checkpoint.period compared to the difference between last transaction id and most recent transaction id beyond which to trigger a warning alert.")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("checkpoint.txns.multiplier.critical.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("checkpoint.txns.multiplier.critical.threshold")); param.add("display_name", new JsonPrimitive("Uncommitted transactions Critical")); param.add("value", new JsonPrimitive(4.0)); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The multiplier to use against dfs.namenode.checkpoint.period compared to the difference between last transaction id and most recent transaction id beyond which to trigger a critical alert.")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("default.smoke.user")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("default.smoke.user")); param.add("display_name", new JsonPrimitive("Default Smoke User")); param.add("value", new JsonPrimitive("ambari-qa")); param.add("type", new JsonPrimitive("STRING")); param.add("description", new JsonPrimitive("The user that will run the Hive commands if not specified in cluster-env/smokeuser")); paramsToAdd.add(param); } if (params.contains("default.smoke.principal")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("default.smoke.principal")); param.add("display_name", new JsonPrimitive("Default Smoke Principal")); param.add("value", new JsonPrimitive("ambari-qa@EXAMPLE.COM")); param.add("type", new JsonPrimitive("STRING")); param.add("description", new JsonPrimitive("The principal to use when retrieving the kerberos ticket if not specified in cluster-env/smokeuser_principal_name")); paramsToAdd.add(param); } if (params.contains("default.smoke.keytab")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("default.smoke.keytab")); param.add("display_name", new JsonPrimitive("Default Smoke Keytab")); param.add("value", new JsonPrimitive("/etc/security/keytabs/smokeuser.headless.keytab")); param.add("type", new JsonPrimitive("STRING")); param.add("description", new JsonPrimitive("The keytab to use when retrieving the kerberos ticket if not specified in cluster-env/smokeuser_keytab")); paramsToAdd.add(param); } if (params.contains("run.directory")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("run.directory")); param.add("display_name", new JsonPrimitive("Run Directory")); param.add("value", new JsonPrimitive("/var/run/flume")); param.add("type", new JsonPrimitive("STRING")); param.add("description", new JsonPrimitive("The directory where flume agent processes will place their PID files.")); paramsToAdd.add(param); } if (params.contains("minimum.free.space")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("minimum.free.space")); param.add("display_name", new JsonPrimitive("Minimum Free Space")); param.add("value", new JsonPrimitive("5000000000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The overall amount of free disk space left before an alert is triggered.")); param.add("units", new JsonPrimitive("bytes")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("percent.used.space.warning.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("percent.used.space.warning.threshold")); param.add("display_name", new JsonPrimitive("Warning")); param.add("value", new JsonPrimitive("50")); param.add("type", new JsonPrimitive("PERCENT")); param.add("description", new JsonPrimitive("The percent of disk space consumed before a warning is triggered.")); param.add("units", new JsonPrimitive("%")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("percent.free.space.critical.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("percent.free.space.critical.threshold")); param.add("display_name", new JsonPrimitive("Critical")); param.add("value", new JsonPrimitive("80")); param.add("type", new JsonPrimitive("PERCENT")); param.add("description", new JsonPrimitive("The percent of disk space consumed before a critical alert is triggered.")); param.add("units", new JsonPrimitive("%")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("request.by.status.warning.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("request.by.status.warning.threshold")); param.add("display_name", new JsonPrimitive("Warning Request Time")); param.add("value", new JsonPrimitive("3000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The time to find requests in progress before a warning alert is triggered.")); param.add("units", new JsonPrimitive("ms")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("request.by.status.critical.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("request.by.status.critical.threshold")); param.add("display_name", new JsonPrimitive("Critical Request Time")); param.add("value", new JsonPrimitive("5000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The time to find requests in progress before a critical alert is triggered.")); param.add("units", new JsonPrimitive("ms")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("task.status.aggregation.warning.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("task.status.aggregation.warning.threshold")); param.add("display_name", new JsonPrimitive("Warning Process Time")); param.add("value", new JsonPrimitive("3000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The time to calculate a request's status from its tasks before a warning alert is triggered.")); param.add("units", new JsonPrimitive("ms")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("task.status.aggregation.critical.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("task.status.aggregation.critical.threshold")); param.add("display_name", new JsonPrimitive("Critical Process Time")); param.add("value", new JsonPrimitive("5000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The time to calculate a request's status from its tasks before a critical alert is triggered.")); param.add("units", new JsonPrimitive("ms")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("rest.api.cluster.warning.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("rest.api.cluster.warning.threshold")); param.add("display_name", new JsonPrimitive("Warning Response Time")); param.add("value", new JsonPrimitive("5000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The time to get a cluster via the REST API before a warning alert is triggered.")); param.add("units", new JsonPrimitive("ms")); param.add("threshold", new JsonPrimitive("WARNING")); paramsToAdd.add(param); } if (params.contains("rest.api.cluster.critical.threshold")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("rest.api.cluster.critical.threshold")); param.add("display_name", new JsonPrimitive("Critical Response Time")); param.add("value", new JsonPrimitive("7000")); param.add("type", new JsonPrimitive("NUMERIC")); param.add("description", new JsonPrimitive("The time to get a cluster via the REST API before a critical alert is triggered.")); param.add("units", new JsonPrimitive("ms")); param.add("threshold", new JsonPrimitive("CRITICAL")); paramsToAdd.add(param); } if (params.contains("socket.command")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("socket.command")); param.add("display_name", new JsonPrimitive("Socket Command")); param.add("value", new JsonPrimitive("ruok")); param.add("type", new JsonPrimitive("STRING")); param.add("description", new JsonPrimitive("A socket command which queries ZooKeeper to respond with its state. The expected response is imok.")); paramsToAdd.add(param); } if (params.contains("socket.command.response")) { JsonObject param = new JsonObject(); param.add("name", new JsonPrimitive("socket.command.response")); param.add("display_name", new JsonPrimitive("Expected Response")); param.add("value", new JsonPrimitive("imok")); param.add("type", new JsonPrimitive("STRING")); param.add("description", new JsonPrimitive("The expected response to the socket command.")); paramsToAdd.add(param); } if (!parameterExists) { parametersJson = new JsonArray(); for (JsonObject param : paramsToAdd) { parametersJson.add(param); } sourceJson.add("parameters", parametersJson); } else { for (JsonObject param : paramsToAdd) { parametersJson.add(param); } sourceJson.remove("parameters"); sourceJson.add("parameters", parametersJson); } return sourceJson.toString(); } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String DESIRED_VERSION_COLUMN_NAME; static final String BLUEPRINT_SETTING_TABLE; static final String BLUEPRINT_NAME_COL; static final String SETTING_NAME_COL; static final String SETTING_DATA_COL; static final String ID; static final String BLUEPRINT_TABLE; static final String VIEWINSTANCE_TABLE; static final String SHORT_URL_COLUMN; static final String CLUSTER_HANDLE_COLUMN; static final String REQUESTSCHEDULE_TABLE; static final String AUTHENTICATED_USER_ID_COLUMN; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String ONE_DIR_PER_PARITION_PROPERTY; static final String VIEWURL_TABLE; static final String URL_ID_COLUMN; static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_TYPE_COLUMN; static final String REMOTE_AMBARI_CLUSTER_TABLE; static final String REMOTE_AMBARI_CLUSTER_SERVICE_TABLE; static final String CLUSTER_ID; static final String SERVICE_NAME; static final String CLUSTER_NAME; }
@Test public void test_addParam_ParamsNotAvailable() { UpgradeCatalog240 upgradeCatalog240 = new UpgradeCatalog240(injector); String inputSource = "{ \"path\" : \"test_path\", \"type\" : \"SCRIPT\"}"; List<String> params = Arrays.asList("connection.timeout", "checkpoint.time.warning.threshold", "checkpoint.time.critical.threshold"); String expectedSource = "{\"path\":\"test_path\",\"type\":\"SCRIPT\",\"parameters\":[{\"name\":\"connection.timeout\",\"display_name\":\"Connection Timeout\",\"value\":5.0,\"type\":\"NUMERIC\",\"description\":\"The maximum time before this alert is considered to be CRITICAL\",\"units\":\"seconds\",\"threshold\":\"CRITICAL\"},{\"name\":\"checkpoint.time.warning.threshold\",\"display_name\":\"Checkpoint Warning\",\"value\":2.0,\"type\":\"PERCENT\",\"description\":\"The percentage of the last checkpoint time greater than the interval in order to trigger a warning alert.\",\"units\":\"%\",\"threshold\":\"WARNING\"},{\"name\":\"checkpoint.time.critical.threshold\",\"display_name\":\"Checkpoint Critical\",\"value\":4.0,\"type\":\"PERCENT\",\"description\":\"The percentage of the last checkpoint time greater than the interval in order to trigger a critical alert.\",\"units\":\"%\",\"threshold\":\"CRITICAL\"}]}"; String result = upgradeCatalog240.addParam(inputSource, params); Assert.assertEquals(result, expectedSource); }
@Test public void test_addParam_ParamsAvailableWithOneOFNeededItem() { UpgradeCatalog240 upgradeCatalog240 = new UpgradeCatalog240(injector); String inputSource = "{\"path\":\"test_path\",\"type\":\"SCRIPT\",\"parameters\":[{\"name\":\"connection.timeout\",\"display_name\":\"Connection Timeout\",\"value\":5.0,\"type\":\"NUMERIC\",\"description\":\"The maximum time before this alert is considered to be CRITICAL\",\"units\":\"seconds\",\"threshold\":\"CRITICAL\"}]}"; List<String> params = new ArrayList<>(Arrays.asList("connection.timeout", "checkpoint.time.warning.threshold", "checkpoint.time.critical.threshold")); String expectedSource = "{\"path\":\"test_path\",\"type\":\"SCRIPT\",\"parameters\":[{\"name\":\"connection.timeout\",\"display_name\":\"Connection Timeout\",\"value\":5.0,\"type\":\"NUMERIC\",\"description\":\"The maximum time before this alert is considered to be CRITICAL\",\"units\":\"seconds\",\"threshold\":\"CRITICAL\"},{\"name\":\"checkpoint.time.warning.threshold\",\"display_name\":\"Checkpoint Warning\",\"value\":2.0,\"type\":\"PERCENT\",\"description\":\"The percentage of the last checkpoint time greater than the interval in order to trigger a warning alert.\",\"units\":\"%\",\"threshold\":\"WARNING\"},{\"name\":\"checkpoint.time.critical.threshold\",\"display_name\":\"Checkpoint Critical\",\"value\":4.0,\"type\":\"PERCENT\",\"description\":\"The percentage of the last checkpoint time greater than the interval in order to trigger a critical alert.\",\"units\":\"%\",\"threshold\":\"CRITICAL\"}]}"; String result = upgradeCatalog240.addParam(inputSource, params); Assert.assertEquals(result, expectedSource); }