Search in sources :

Example 6 with JSONException

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 7 with JSONException

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;
}
Also used : LogicalOperatorInfo(com.datatorrent.stram.webapp.LogicalOperatorInfo) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) IOException(java.io.IOException) JSONObject(org.codehaus.jettison.json.JSONObject) JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.datatorrent.common.util.Pair)

Example 8 with JSONException

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;
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException)

Example 9 with JSONException

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) Map(java.util.Map) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 10 with JSONException

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;
}
Also used : Path(org.apache.hadoop.fs.Path) LinkedHashSet(java.util.LinkedHashSet) StringWriter(java.io.StringWriter) JSONObject(org.codehaus.jettison.json.JSONObject) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) JSONException(org.codehaus.jettison.json.JSONException) URL(java.net.URL)

Aggregations

JSONException (org.codehaus.jettison.json.JSONException)281 JSONObject (org.codehaus.jettison.json.JSONObject)256 Response (javax.ws.rs.core.Response)183 Builder (javax.ws.rs.client.Invocation.Builder)179 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)179 Test (org.testng.annotations.Test)174 BaseTest (org.xdi.oxauth.BaseTest)174 Parameters (org.testng.annotations.Parameters)171 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)68 JSONArray (org.codehaus.jettison.json.JSONArray)44 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)43 URISyntaxException (java.net.URISyntaxException)35 TokenRequest (org.xdi.oxauth.client.TokenRequest)35 ResponseType (org.xdi.oxauth.model.common.ResponseType)35 WebApplicationException (javax.ws.rs.WebApplicationException)18 IOException (java.io.IOException)17 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)17 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14