Search in sources :

Example 6 with RuntimeSpecification

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

the class WeaveSpecificationCodec method deserialize.

@Override
public WeaveSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();
    Map<String, RuntimeSpecification> runnables = context.deserialize(jsonObj.get("runnables"), new TypeToken<Map<String, RuntimeSpecification>>() {
    }.getType());
    List<WeaveSpecification.Order> orders = context.deserialize(jsonObj.get("orders"), new TypeToken<List<WeaveSpecification.Order>>() {
    }.getType());
    JsonElement handler = jsonObj.get("handler");
    EventHandlerSpecification eventHandler = null;
    if (handler != null && !handler.isJsonNull()) {
        eventHandler = context.deserialize(handler, EventHandlerSpecification.class);
    }
    return new DefaultWeaveSpecification(name, runnables, orders, eventHandler);
}
Also used : TypeToken(com.google.common.reflect.TypeToken) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) EventHandlerSpecification(com.continuuity.weave.api.EventHandlerSpecification) DefaultEventHandlerSpecification(com.continuuity.weave.internal.DefaultEventHandlerSpecification) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification) DefaultWeaveSpecification(com.continuuity.weave.internal.DefaultWeaveSpecification)

Example 7 with RuntimeSpecification

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

the class YarnWeavePreparer method populateRunnableLocalFiles.

/**
   * Based on the given {@link WeaveSpecification}, upload LocalFiles to Yarn Cluster.
   * @param weaveSpec The {@link WeaveSpecification} for populating resource.
   * @param localFiles A Multimap to store runnable name to transformed LocalFiles.
   * @throws IOException
   */
private void populateRunnableLocalFiles(WeaveSpecification weaveSpec, Multimap<String, LocalFile> localFiles) throws IOException {
    LOG.debug("Populating Runnable LocalFiles");
    for (Map.Entry<String, RuntimeSpecification> entry : weaveSpec.getRunnables().entrySet()) {
        String runnableName = entry.getKey();
        for (LocalFile localFile : entry.getValue().getLocalFiles()) {
            Location location;
            URI uri = localFile.getURI();
            if ("hdfs".equals(uri.getScheme())) {
                // Assuming the location factory is HDFS one. If it is not, it will failed, which is the correct behavior.
                location = locationFactory.create(uri);
            } else {
                URL url = uri.toURL();
                LOG.debug("Create and copy {} : {}", runnableName, url);
                // Preserves original suffix for expansion.
                location = copyFromURL(url, createTempLocation(Paths.appendSuffix(url.getFile(), localFile.getName())));
                LOG.debug("Done {} : {}", runnableName, url);
            }
            localFiles.put(runnableName, new DefaultLocalFile(localFile.getName(), location.toURI(), location.lastModified(), location.length(), localFile.isArchive(), localFile.getPattern()));
        }
    }
    LOG.debug("Done Runnable LocalFiles");
}
Also used : LocalFile(com.continuuity.weave.api.LocalFile) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) DefaultRuntimeSpecification(com.continuuity.weave.internal.DefaultRuntimeSpecification) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URI(java.net.URI) URL(java.net.URL) Location(com.continuuity.weave.filesystem.Location)

Aggregations

RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)7 Location (com.continuuity.weave.filesystem.Location)3 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)3 EventHandlerSpecification (com.continuuity.weave.api.EventHandlerSpecification)2 WeaveSpecification (com.continuuity.weave.api.WeaveSpecification)2 DefaultWeaveSpecification (com.continuuity.weave.internal.DefaultWeaveSpecification)2 Resource (org.apache.hadoop.yarn.api.records.Resource)2 LocalFile (com.continuuity.weave.api.LocalFile)1 DefaultEventHandlerSpecification (com.continuuity.weave.internal.DefaultEventHandlerSpecification)1 DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)1 LogOnlyEventHandler (com.continuuity.weave.internal.LogOnlyEventHandler)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 URI (java.net.URI)1