Search in sources :

Example 1 with ContainerInfo

use of com.datatorrent.stram.webapp.ContainerInfo in project apex-core by apache.

the class FSStatsRecorder method recordContainers.

@Override
public void recordContainers(Map<String, StreamingContainerAgent> containerMap, long timestamp) throws IOException {
    for (Map.Entry<String, StreamingContainerAgent> entry : containerMap.entrySet()) {
        StreamingContainerAgent sca = entry.getValue();
        ContainerInfo containerInfo = sca.getContainerInfo();
        if (!containerInfo.state.equals("ACTIVE")) {
            continue;
        }
        int containerIndex;
        if (!knownContainers.containsKey(entry.getKey())) {
            containerIndex = knownContainers.size();
            knownContainers.put(entry.getKey(), containerIndex);
            Map<String, Object> fieldMap = extractRecordFields(containerInfo, "meta");
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Slice f = streamCodec.toByteArray(fieldMap);
            bos.write((String.valueOf(containerIndex) + ":").getBytes());
            bos.write(f.buffer, f.offset, f.length);
            bos.write("\n".getBytes());
            queue.add(new WriteOperation(containersStorage, bos.toByteArray(), true));
        } else {
            containerIndex = knownContainers.get(entry.getKey());
        }
        Map<String, Object> fieldMap = extractRecordFields(containerInfo, "stats");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Slice f = streamCodec.toByteArray(fieldMap);
        bos.write((String.valueOf(containerIndex) + ":").getBytes());
        bos.write((String.valueOf(timestamp) + ":").getBytes());
        bos.write(f.buffer, f.offset, f.length);
        bos.write("\n".getBytes());
        queue.add(new WriteOperation(containersStorage, bos.toByteArray(), false));
    }
}
Also used : Slice(com.datatorrent.netlet.util.Slice) ContainerInfo(com.datatorrent.stram.webapp.ContainerInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ContainerInfo

use of com.datatorrent.stram.webapp.ContainerInfo in project apex-core by apache.

the class StreamingContainerManager method getAppMasterContainerInfo.

public final ContainerInfo getAppMasterContainerInfo() {
    ContainerInfo ci = new ContainerInfo();
    ci.id = System.getenv(ApplicationConstants.Environment.CONTAINER_ID.toString());
    String nmHost = System.getenv(ApplicationConstants.Environment.NM_HOST.toString());
    String nmPort = System.getenv(ApplicationConstants.Environment.NM_PORT.toString());
    String nmHttpPort = System.getenv(ApplicationConstants.Environment.NM_HTTP_PORT.toString());
    ci.state = "ACTIVE";
    ci.jvmName = ManagementFactory.getRuntimeMXBean().getName();
    ci.numOperators = 0;
    YarnConfiguration conf = new YarnConfiguration();
    if (nmHost != null) {
        if (nmPort != null) {
            ci.host = nmHost + ":" + nmPort;
        }
        if (nmHttpPort != null) {
            String nodeHttpAddress = nmHost + ":" + nmHttpPort;
            if (allocatedMemoryMB == 0) {
                String url = ConfigUtils.getSchemePrefix(conf) + nodeHttpAddress + "/ws/v1/node/containers/" + ci.id;
                WebServicesClient webServicesClient = new WebServicesClient();
                try {
                    String content = webServicesClient.process(url, String.class, new WebServicesClient.GetWebServicesHandler<String>());
                    JSONObject json = new JSONObject(content);
                    int totalMemoryNeededMB = json.getJSONObject("container").getInt("totalMemoryNeededMB");
                    if (totalMemoryNeededMB > 0) {
                        allocatedMemoryMB = totalMemoryNeededMB;
                    } else {
                        LOG.warn("Could not determine the memory allocated for the streaming application master.  Node manager is reporting {} MB from {}", totalMemoryNeededMB, url);
                    }
                } catch (Exception ex) {
                    LOG.warn("Could not determine the memory allocated for the streaming application master", ex);
                }
            }
            ci.containerLogsUrl = ConfigUtils.getSchemePrefix(conf) + nodeHttpAddress + "/node/containerlogs/" + ci.id + "/" + System.getenv(ApplicationConstants.Environment.USER.toString());
            ci.rawContainerLogsUrl = ConfigUtils.getRawContainerLogsUrl(conf, nodeHttpAddress, plan.getLogicalPlan().getAttributes().get(LogicalPlan.APPLICATION_ID), ci.id);
        }
    }
    ci.memoryMBAllocated = allocatedMemoryMB;
    ci.memoryMBFree = ((int) (Runtime.getRuntime().freeMemory() / (1024 * 1024)));
    ci.lastHeartbeat = -1;
    ci.startedTime = startTime;
    ci.finishedTime = -1;
    return ci;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ContainerInfo(com.datatorrent.stram.webapp.ContainerInfo) WebServicesClient(com.datatorrent.stram.util.WebServicesClient) Checkpoint(com.datatorrent.stram.api.Checkpoint) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) KryoException(com.esotericsoftware.kryo.KryoException)

Example 3 with ContainerInfo

use of com.datatorrent.stram.webapp.ContainerInfo in project apex-core by apache.

the class StreamingContainerAgent method getContainerInfo.

public ContainerInfo getContainerInfo() {
    ContainerInfo ci = new ContainerInfo();
    ci.id = container.getExternalId();
    ci.host = container.host;
    ci.state = container.getState().name();
    ci.jvmName = this.jvmName;
    ci.numOperators = container.getOperators().size();
    ci.operators = new TreeMap<>();
    for (PTOperator ptOperator : container.getOperators()) {
        ci.operators.put(ptOperator.getId(), ptOperator.getName());
    }
    ci.memoryMBAllocated = container.getAllocatedMemoryMB();
    ci.lastHeartbeat = lastHeartbeatMillis;
    ci.memoryMBFree = this.memoryMBFree;
    ci.gcCollectionCount = this.gcCollectionCount;
    ci.gcCollectionTime = this.gcCollectionTime;
    ci.startedTime = container.getStartedTime();
    ci.finishedTime = container.getFinishedTime();
    if (this.container.nodeHttpAddress != null) {
        YarnConfiguration conf = new YarnConfiguration();
        ci.containerLogsUrl = ConfigUtils.getSchemePrefix(conf) + this.container.nodeHttpAddress + "/node/containerlogs/" + ci.id + "/" + System.getenv(ApplicationConstants.Environment.USER.toString());
        ci.rawContainerLogsUrl = ConfigUtils.getRawContainerLogsUrl(conf, container.nodeHttpAddress, container.getPlan().getLogicalPlan().getAttributes().get(LogicalPlan.APPLICATION_ID), ci.id);
    }
    return ci;
}
Also used : PTOperator(com.datatorrent.stram.plan.physical.PTOperator) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ContainerInfo(com.datatorrent.stram.webapp.ContainerInfo)

Aggregations

ContainerInfo (com.datatorrent.stram.webapp.ContainerInfo)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 Slice (com.datatorrent.netlet.util.Slice)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)1 WebServicesClient (com.datatorrent.stram.util.WebServicesClient)1 KryoException (com.esotericsoftware.kryo.KryoException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1