Search in sources :

Example 1 with WeaveRunResources

use of com.continuuity.weave.api.WeaveRunResources in project weave by continuuity.

the class ResourceReportCodec method serialize.

@Override
public JsonElement serialize(ResourceReport src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject json = new JsonObject();
    json.addProperty("appMasterId", src.getApplicationId());
    json.add("appMasterResources", context.serialize(src.getAppMasterResources(), new TypeToken<WeaveRunResources>() {
    }.getType()));
    json.add("runnableResources", context.serialize(src.getResources(), new TypeToken<Map<String, Collection<WeaveRunResources>>>() {
    }.getType()));
    return json;
}
Also used : JsonObject(com.google.gson.JsonObject) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources) Map(java.util.Map)

Example 2 with WeaveRunResources

use of com.continuuity.weave.api.WeaveRunResources in project weave by continuuity.

the class DefaultResourceReport method removeRunnableResources.

/**
   * Remove the resource corresponding to the given runnable and container.
   *
   * @param runnableName name of runnable.
   * @param containerId container id of the runnable.
   */
public void removeRunnableResources(String runnableName, String containerId) {
    WeaveRunResources toRemove = null;
    // report a little more complex, and this does not need to be terribly fast.
    for (WeaveRunResources resources : usedResources.get(runnableName)) {
        if (resources.getContainerId().equals(containerId)) {
            toRemove = resources;
            break;
        }
    }
    usedResources.remove(runnableName, toRemove);
}
Also used : WeaveRunResources(com.continuuity.weave.api.WeaveRunResources)

Example 3 with WeaveRunResources

use of com.continuuity.weave.api.WeaveRunResources in project weave by continuuity.

the class ApplicationMasterService method initRunningContainers.

private RunningContainers initRunningContainers(ContainerId appMasterContainerId, String appMasterHost) throws Exception {
    WeaveRunResources appMasterResources = new DefaultWeaveRunResources(0, appMasterContainerId.toString(), Integer.parseInt(System.getenv(EnvKeys.YARN_CONTAINER_VIRTUAL_CORES)), Integer.parseInt(System.getenv(EnvKeys.YARN_CONTAINER_MEMORY_MB)), appMasterHost);
    String appId = appMasterContainerId.getApplicationAttemptId().getApplicationId().toString();
    return new RunningContainers(appId, appMasterResources);
}
Also used : DefaultWeaveRunResources(com.continuuity.weave.internal.DefaultWeaveRunResources) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources) DefaultWeaveRunResources(com.continuuity.weave.internal.DefaultWeaveRunResources)

Example 4 with WeaveRunResources

use of com.continuuity.weave.api.WeaveRunResources in project weave by continuuity.

the class RunningContainers method start.

void start(String runnableName, ContainerInfo containerInfo, WeaveContainerLauncher launcher) {
    containerLock.lock();
    try {
        int instanceId = getStartInstanceId(runnableName);
        RunId runId = getRunId(runnableName, instanceId);
        WeaveContainerController controller = launcher.start(runId, instanceId, WeaveContainerMain.class, "$HADOOP_CONF_DIR");
        containers.put(runnableName, containerInfo.getId(), controller);
        WeaveRunResources resources = new DefaultWeaveRunResources(instanceId, containerInfo.getId(), containerInfo.getVirtualCores(), containerInfo.getMemoryMB(), containerInfo.getHost().getHostName());
        resourceReport.addRunResources(runnableName, resources);
        if (startSequence.isEmpty() || !runnableName.equals(startSequence.peekLast())) {
            startSequence.addLast(runnableName);
        }
        containerChange.signalAll();
    } finally {
        containerLock.unlock();
    }
}
Also used : DefaultWeaveRunResources(com.continuuity.weave.internal.DefaultWeaveRunResources) WeaveContainerController(com.continuuity.weave.internal.WeaveContainerController) RunId(com.continuuity.weave.api.RunId) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources) DefaultWeaveRunResources(com.continuuity.weave.internal.DefaultWeaveRunResources)

Example 5 with WeaveRunResources

use of com.continuuity.weave.api.WeaveRunResources in project weave by continuuity.

the class ResourceReportCodec method deserialize.

@Override
public ResourceReport deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String appMasterId = jsonObj.get("appMasterId").getAsString();
    WeaveRunResources masterResources = context.deserialize(jsonObj.get("appMasterResources"), WeaveRunResources.class);
    Map<String, Collection<WeaveRunResources>> resources = context.deserialize(jsonObj.get("runnableResources"), new TypeToken<Map<String, Collection<WeaveRunResources>>>() {
    }.getType());
    return new DefaultResourceReport(appMasterId, masterResources, resources);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) DefaultResourceReport(com.continuuity.weave.internal.DefaultResourceReport) JsonObject(com.google.gson.JsonObject) Collection(java.util.Collection) WeaveRunResources(com.continuuity.weave.api.WeaveRunResources)

Aggregations

WeaveRunResources (com.continuuity.weave.api.WeaveRunResources)6 DefaultWeaveRunResources (com.continuuity.weave.internal.DefaultWeaveRunResources)2 JsonObject (com.google.gson.JsonObject)2 Collection (java.util.Collection)2 ResourceReport (com.continuuity.weave.api.ResourceReport)1 RunId (com.continuuity.weave.api.RunId)1 WeaveController (com.continuuity.weave.api.WeaveController)1 WeaveRunner (com.continuuity.weave.api.WeaveRunner)1 PrinterLogHandler (com.continuuity.weave.api.logging.PrinterLogHandler)1 ServiceListenerAdapter (com.continuuity.weave.common.ServiceListenerAdapter)1 Discoverable (com.continuuity.weave.discovery.Discoverable)1 DefaultResourceReport (com.continuuity.weave.internal.DefaultResourceReport)1 WeaveContainerController (com.continuuity.weave.internal.WeaveContainerController)1 TypeToken (com.google.gson.reflect.TypeToken)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1