Search in sources :

Example 1 with DefaultRuntimeSpecification

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));
}
Also used : DefaultRuntimeSpecification(com.continuuity.weave.internal.DefaultRuntimeSpecification) EventHandlerSpecification(com.continuuity.weave.api.EventHandlerSpecification) DefaultRuntimeSpecification(com.continuuity.weave.internal.DefaultRuntimeSpecification) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification) DefaultWeaveSpecification(com.continuuity.weave.internal.DefaultWeaveSpecification) LogOnlyEventHandler(com.continuuity.weave.internal.LogOnlyEventHandler) Maps(com.google.common.collect.Maps) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Location(com.continuuity.weave.filesystem.Location)

Example 2 with DefaultRuntimeSpecification

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);
}
Also used : LocalFile(com.continuuity.weave.api.LocalFile) DefaultRuntimeSpecification(com.continuuity.weave.internal.DefaultRuntimeSpecification) TypeToken(com.google.common.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) ResourceSpecification(com.continuuity.weave.api.ResourceSpecification) WeaveRunnableSpecification(com.continuuity.weave.api.WeaveRunnableSpecification)

Aggregations

DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)2 EventHandlerSpecification (com.continuuity.weave.api.EventHandlerSpecification)1 LocalFile (com.continuuity.weave.api.LocalFile)1 ResourceSpecification (com.continuuity.weave.api.ResourceSpecification)1 RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)1 WeaveRunnableSpecification (com.continuuity.weave.api.WeaveRunnableSpecification)1 Location (com.continuuity.weave.filesystem.Location)1 DefaultWeaveSpecification (com.continuuity.weave.internal.DefaultWeaveSpecification)1 LogOnlyEventHandler (com.continuuity.weave.internal.LogOnlyEventHandler)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonObject (com.google.gson.JsonObject)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1