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