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());
}
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");
}
Aggregations