Search in sources :

Example 1 with LogOnlyEventHandler

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

Aggregations

EventHandlerSpecification (com.continuuity.weave.api.EventHandlerSpecification)1 RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)1 Location (com.continuuity.weave.filesystem.Location)1 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)1 DefaultWeaveSpecification (com.continuuity.weave.internal.DefaultWeaveSpecification)1 LogOnlyEventHandler (com.continuuity.weave.internal.LogOnlyEventHandler)1 Maps (com.google.common.collect.Maps)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1