use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class ApexCli method getContainerLongId.
private String getContainerLongId(String containerId) {
JSONObject json = getResource(StramWebServices.PATH_PHYSICAL_PLAN_CONTAINERS, currentApp);
int shortId = 0;
if (StringUtils.isNumeric(containerId)) {
shortId = Integer.parseInt(containerId);
}
try {
Object containersObj = json.get("containers");
JSONArray containers;
if (containersObj instanceof JSONArray) {
containers = (JSONArray) containersObj;
} else {
containers = new JSONArray();
containers.put(containersObj);
}
if (containersObj != null) {
for (int o = containers.length(); o-- > 0; ) {
JSONObject container = containers.getJSONObject(o);
String id = container.getString("id");
if (id.equals(containerId) || (shortId != 0 && (id.endsWith("_" + shortId) || id.endsWith("0" + shortId)))) {
return id;
}
}
}
} catch (JSONException ex) {
// ignore
}
return null;
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class AppDataPushAgent method getPushData.
private JSONObject getPushData() {
// assemble the json that contains the app stats and logical operator stats and counters
JSONObject json = new JSONObject();
try {
json.put("type", DATA);
json.put("appId", dnmgr.getLogicalPlan().getValue(DAGContext.APPLICATION_ID));
json.put("appName", dnmgr.getLogicalPlan().getValue(DAGContext.APPLICATION_NAME));
json.put("appUser", appContext.getUser());
List<LogicalOperatorInfo> logicalOperatorInfoList = dnmgr.getLogicalOperatorInfoList();
JSONObject logicalOperators = new JSONObject();
for (LogicalOperatorInfo logicalOperator : logicalOperatorInfoList) {
JSONObject logicalOperatorJson = extractFields(logicalOperator);
JSONArray metricsList = new JSONArray();
Queue<Pair<Long, Map<String, Object>>> windowMetrics = dnmgr.getWindowMetrics(logicalOperator.name);
if (windowMetrics != null) {
while (!windowMetrics.isEmpty()) {
Pair<Long, Map<String, Object>> metrics = windowMetrics.remove();
long windowId = metrics.first;
// metric name, aggregated value
Map<String, Object> aggregates = metrics.second;
long now = System.currentTimeMillis();
if (!operatorsSchemaLastSentTime.containsKey(logicalOperator.name) || (metricsTransport.getSchemaResendInterval() > 0 && operatorsSchemaLastSentTime.get(logicalOperator.name) < now - metricsTransport.getSchemaResendInterval())) {
try {
pushMetricsSchema(dnmgr.getLogicalPlan().getOperatorMeta(logicalOperator.name), aggregates);
operatorsSchemaLastSentTime.put(logicalOperator.name, now);
} catch (IOException ex) {
LOG.error("Cannot push metrics schema", ex);
}
}
JSONObject metricsItem = new JSONObject();
metricsItem.put("_windowId", windowId);
long windowToMillis = dnmgr.windowIdToMillis(windowId);
LOG.debug("metric window {} time {}", windowId, windowToMillis);
metricsItem.put("_time", windowToMillis);
for (Map.Entry<String, Object> entry : aggregates.entrySet()) {
String metricName = entry.getKey();
Object aggregateValue = entry.getValue();
metricsItem.put(metricName, aggregateValue);
}
metricsList.put(metricsItem);
}
}
logicalOperatorJson.put("metrics", metricsList);
logicalOperators.put(logicalOperator.name, logicalOperatorJson);
}
json.put("time", System.currentTimeMillis());
json.put("logicalOperators", logicalOperators);
json.put("stats", extractFields(appContext.getStats()));
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
return json;
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class DTConfiguration method toJSONObject.
public JSONObject toJSONObject(String key) {
JSONObject json = new JSONObject();
ValueEntry valueEntry = map.get(key);
if (valueEntry != null) {
try {
json = new JSONObject();
json.put("value", valueEntry.value);
if (valueEntry.description != null) {
json.put("description", valueEntry.description);
}
if (valueEntry.scope == Scope.LOCAL) {
json.put("scope", valueEntry.scope);
}
} catch (JSONException ex) {
// should not happen here
throw new RuntimeException(ex);
}
return json;
} else {
return null;
}
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class StramUtils method getStackTrace.
public static JSONObject getStackTrace() {
Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
for (Map.Entry<Thread, StackTraceElement[]> elements : stackTraces.entrySet()) {
JSONObject jsonThread = new JSONObject();
Thread thread = elements.getKey();
try {
jsonThread.put("name", thread.getName());
jsonThread.put("state", thread.getState());
jsonThread.put("id", thread.getId());
JSONArray stackTraceElements = new JSONArray();
for (StackTraceElement stackTraceElement : elements.getValue()) {
stackTraceElements.put(stackTraceElement.toString());
}
jsonThread.put("stackTraceElements", stackTraceElements);
jsonArray.put(jsonThread);
} catch (Exception ex) {
LOG.warn("Getting stack trace for the thread " + thread.getName() + " failed.");
continue;
}
}
try {
jsonObject.put("threads", jsonArray);
} catch (JSONException e) {
throw new RuntimeException(e);
}
return jsonObject;
}
use of org.codehaus.jettison.json.JSONException in project apex-core by apache.
the class StramAppLauncher method init.
private void init() throws Exception {
String originalAppId = propertiesBuilder.conf.get(ORIGINAL_APP_ID);
if (originalAppId == null) {
throw new AssertionError("Need original app id if launching without apa or appjar");
}
Path appsBasePath = new Path(StramClientUtils.getDTDFSRootDir(fs, conf), StramClientUtils.SUBDIR_APPS);
Path origAppPath = new Path(appsBasePath, originalAppId);
StringWriter writer = new StringWriter();
try (FSDataInputStream in = fs.open(new Path(origAppPath, "meta.json"))) {
IOUtils.copy(in, writer);
}
JSONObject metaJson = new JSONObject(writer.toString());
String originalLibJars = null;
// don't rely on object deserialization for changing the app id in the future.
try {
JSONObject attributes = metaJson.getJSONObject("attributes");
originalLibJars = attributes.getString(Context.DAGContext.LIBRARY_JARS.getSimpleName());
recoveryAppName = attributes.getString(Context.DAGContext.APPLICATION_NAME.getSimpleName());
} catch (JSONException ex) {
recoveryAppName = "Recovery App From " + originalAppId;
}
LinkedHashSet<URL> clUrls = new LinkedHashSet<>();
String libjars = propertiesBuilder.conf.get(LIBJARS_CONF_KEY_NAME);
if (StringUtils.isBlank(libjars)) {
libjars = originalLibJars;
} else if (StringUtils.isNotBlank(originalLibJars)) {
libjars = libjars + "," + originalLibJars;
}
propertiesBuilder.conf.set(LIBJARS_CONF_KEY_NAME, libjars);
processLibJars(libjars, clUrls);
for (URL baseURL : clUrls) {
LOG.debug("Dependency: {}", baseURL);
}
this.launchDependencies = clUrls;
}
Aggregations