Search in sources :

Example 1 with Location

use of com.continuuity.weave.filesystem.Location in project weave by continuuity.

the class YarnWeavePreparer method saveLocalFiles.

/**
   * Serializes the list of files that needs to localize from AM to Container.
   */
private void saveLocalFiles(Map<String, LocalFile> localFiles, Set<String> includes) throws IOException {
    Map<String, LocalFile> localize = ImmutableMap.copyOf(Maps.filterKeys(localFiles, Predicates.in(includes)));
    LOG.debug("Create and copy {}", Constants.Files.LOCALIZE_FILES);
    Location location = createTempLocation(Constants.Files.LOCALIZE_FILES);
    Writer writer = new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
    try {
        new GsonBuilder().registerTypeAdapter(LocalFile.class, new LocalFileCodec()).create().toJson(localize.values(), new TypeToken<List<LocalFile>>() {
        }.getType(), writer);
    } finally {
        writer.close();
    }
    LOG.debug("Done {}", Constants.Files.LOCALIZE_FILES);
    localFiles.put(Constants.Files.LOCALIZE_FILES, createLocalFile(Constants.Files.LOCALIZE_FILES, location));
}
Also used : LocalFileCodec(com.continuuity.weave.internal.json.LocalFileCodec) LocalFile(com.continuuity.weave.api.LocalFile) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.common.reflect.TypeToken) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Location(com.continuuity.weave.filesystem.Location)

Example 2 with Location

use of com.continuuity.weave.filesystem.Location in project weave by continuuity.

the class YarnWeavePreparer method saveArguments.

private void saveArguments(Arguments arguments, Map<String, LocalFile> localFiles) throws IOException {
    LOG.debug("Create and copy {}", Constants.Files.ARGUMENTS);
    final Location location = createTempLocation(Constants.Files.ARGUMENTS);
    ArgumentsCodec.encode(arguments, new OutputSupplier<Writer>() {

        @Override
        public Writer getOutput() throws IOException {
            return new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
        }
    });
    LOG.debug("Done {}", Constants.Files.ARGUMENTS);
    localFiles.put(Constants.Files.ARGUMENTS, createLocalFile(Constants.Files.ARGUMENTS, location));
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Location(com.continuuity.weave.filesystem.Location)

Example 3 with Location

use of com.continuuity.weave.filesystem.Location in project weave by continuuity.

the class YarnWeavePreparer method createAppMasterJar.

private void createAppMasterJar(ApplicationBundler bundler, Map<String, LocalFile> localFiles) throws IOException {
    try {
        LOG.debug("Create and copy {}", Constants.Files.APP_MASTER_JAR);
        Location location = createTempLocation(Constants.Files.APP_MASTER_JAR);
        List<Class<?>> classes = Lists.newArrayList();
        classes.add(ApplicationMasterMain.class);
        // Stuck in the yarnAppClient class to make bundler being able to pickup the right yarn-client version
        classes.add(yarnAppClient.getClass());
        // Add the WeaveRunnableEventHandler class
        if (weaveSpec.getEventHandler() != null) {
            classes.add(getClassLoader().loadClass(weaveSpec.getEventHandler().getClassName()));
        }
        bundler.createBundle(location, classes);
        LOG.debug("Done {}", Constants.Files.APP_MASTER_JAR);
        localFiles.put(Constants.Files.APP_MASTER_JAR, createLocalFile(Constants.Files.APP_MASTER_JAR, location));
    } catch (ClassNotFoundException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Location(com.continuuity.weave.filesystem.Location)

Example 4 with Location

use of com.continuuity.weave.filesystem.Location 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 5 with Location

use of com.continuuity.weave.filesystem.Location in project weave by continuuity.

the class AbstractWeaveService method handleSecureStoreUpdate.

/**
   * Attempts to handle secure store update.
   *
   * @param message The message received
   * @return {@code true} if the message requests for secure store update, {@code false} otherwise.
   */
protected final boolean handleSecureStoreUpdate(Message message) {
    if (!SystemMessages.SECURE_STORE_UPDATED.equals(message)) {
        return false;
    }
    // If not in secure mode, simply ignore the message.
    if (!UserGroupInformation.isSecurityEnabled()) {
        return true;
    }
    try {
        Credentials credentials = new Credentials();
        Location location = getSecureStoreLocation();
        DataInputStream input = new DataInputStream(new BufferedInputStream(location.getInputStream()));
        try {
            credentials.readTokenStorageStream(input);
        } finally {
            input.close();
        }
        UserGroupInformation.getCurrentUser().addCredentials(credentials);
        this.credentials = credentials;
        LOG.info("Secure store updated from {}.", location.toURI());
    } catch (Throwable t) {
        LOG.error("Failed to update secure store.", t);
    }
    return true;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) Credentials(org.apache.hadoop.security.Credentials) Location(com.continuuity.weave.filesystem.Location)

Aggregations

Location (com.continuuity.weave.filesystem.Location)13 OutputStreamWriter (java.io.OutputStreamWriter)4 Writer (java.io.Writer)4 RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)3 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)3 IOException (java.io.IOException)3 LocalFile (com.continuuity.weave.api.LocalFile)2 DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)2 BufferedInputStream (java.io.BufferedInputStream)2 DataInputStream (java.io.DataInputStream)2 URL (java.net.URL)2 Credentials (org.apache.hadoop.security.Credentials)2 EventHandlerSpecification (com.continuuity.weave.api.EventHandlerSpecification)1 LocalLocationFactory (com.continuuity.weave.filesystem.LocalLocationFactory)1 ApplicationBundler (com.continuuity.weave.internal.ApplicationBundler)1 DefaultWeaveSpecification (com.continuuity.weave.internal.DefaultWeaveSpecification)1 LogOnlyEventHandler (com.continuuity.weave.internal.LogOnlyEventHandler)1 LocalFileCodec (com.continuuity.weave.internal.json.LocalFileCodec)1 Dependencies (com.continuuity.weave.internal.utils.Dependencies)1 WeaveLauncher (com.continuuity.weave.launcher.WeaveLauncher)1