Search in sources :

Example 1 with ApplicationMasterLiveNodeData

use of com.continuuity.weave.internal.appmaster.ApplicationMasterLiveNodeData in project weave by continuuity.

the class YarnWeaveRunnerService method getApplicationId.

/**
   * Decodes application ID stored inside the node data.
   * @param nodeData The node data to decode from. If it is {@code null}, this method would return {@code null}.
   * @return The ApplicationId or {@code null} if failed to decode.
   */
private ApplicationId getApplicationId(NodeData nodeData) {
    byte[] data = nodeData == null ? null : nodeData.getData();
    if (data == null) {
        return null;
    }
    Gson gson = new Gson();
    JsonElement json = gson.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
    if (!json.isJsonObject()) {
        LOG.warn("Unable to decode live data node.");
        return null;
    }
    JsonObject jsonObj = json.getAsJsonObject();
    json = jsonObj.get("data");
    if (!json.isJsonObject()) {
        LOG.warn("Property data not found in live data node.");
        return null;
    }
    try {
        ApplicationMasterLiveNodeData amLiveNode = gson.fromJson(json, ApplicationMasterLiveNodeData.class);
        return YarnUtils.createApplicationId(amLiveNode.getAppIdClusterTime(), amLiveNode.getAppId());
    } catch (Exception e) {
        LOG.warn("Failed to decode application live node data.", e);
        return null;
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) ApplicationMasterLiveNodeData(com.continuuity.weave.internal.appmaster.ApplicationMasterLiveNodeData) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Aggregations

ApplicationMasterLiveNodeData (com.continuuity.weave.internal.appmaster.ApplicationMasterLiveNodeData)1 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 KeeperException (org.apache.zookeeper.KeeperException)1