Search in sources :

Example 1 with DefaultLocalFile

use of com.continuuity.weave.internal.DefaultLocalFile in project weave by continuuity.

the class LocalFileCodec method deserialize.

@Override
public LocalFile deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    String name = jsonObj.get("name").getAsString();
    URI uri = URI.create(jsonObj.get("uri").getAsString());
    long lastModified = jsonObj.get("lastModified").getAsLong();
    long size = jsonObj.get("size").getAsLong();
    boolean archive = jsonObj.get("archive").getAsBoolean();
    JsonElement pattern = jsonObj.get("pattern");
    return new DefaultLocalFile(name, uri, lastModified, size, archive, (pattern == null || pattern.isJsonNull()) ? null : pattern.getAsString());
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) URI(java.net.URI)

Example 2 with DefaultLocalFile

use of com.continuuity.weave.internal.DefaultLocalFile 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

DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)2 URI (java.net.URI)2 LocalFile (com.continuuity.weave.api.LocalFile)1 RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)1 Location (com.continuuity.weave.filesystem.Location)1 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 URL (java.net.URL)1 Map (java.util.Map)1