use of com.continuuity.weave.internal.DefaultRuntimeSpecification in project weave by continuuity.
the class YarnWeavePreparer method saveWeaveSpec.
private void saveWeaveSpec(WeaveSpecification spec, final Multimap<String, LocalFile> runnableLocalFiles, Map<String, LocalFile> localFiles) throws IOException {
// Rewrite LocalFiles inside weaveSpec
Map<String, RuntimeSpecification> runtimeSpec = Maps.transformEntries(spec.getRunnables(), new Maps.EntryTransformer<String, RuntimeSpecification, RuntimeSpecification>() {
@Override
public RuntimeSpecification transformEntry(String key, RuntimeSpecification value) {
return new DefaultRuntimeSpecification(value.getName(), value.getRunnableSpecification(), value.getResourceSpecification(), runnableLocalFiles.get(key));
}
});
// Serialize into a local temp file.
LOG.debug("Create and copy {}", Constants.Files.WEAVE_SPEC);
Location location = createTempLocation(Constants.Files.WEAVE_SPEC);
Writer writer = new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
try {
EventHandlerSpecification eventHandler = spec.getEventHandler();
if (eventHandler == null) {
eventHandler = new LogOnlyEventHandler().configure();
}
WeaveSpecificationAdapter.create().toJson(new DefaultWeaveSpecification(spec.getName(), runtimeSpec, spec.getOrders(), eventHandler), writer);
} finally {
writer.close();
}
LOG.debug("Done {}", Constants.Files.WEAVE_SPEC);
localFiles.put(Constants.Files.WEAVE_SPEC, createLocalFile(Constants.Files.WEAVE_SPEC, location));
}
use of com.continuuity.weave.internal.DefaultRuntimeSpecification in project weave by continuuity.
the class RuntimeSpecificationCodec method deserialize.
@Override
public RuntimeSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
WeaveRunnableSpecification runnable = context.deserialize(jsonObj.get("runnable"), WeaveRunnableSpecification.class);
ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), ResourceSpecification.class);
Collection<LocalFile> files = context.deserialize(jsonObj.get("files"), new TypeToken<Collection<LocalFile>>() {
}.getType());
return new DefaultRuntimeSpecification(name, runnable, resources, files);
}
Aggregations