use of com.continuuity.weave.api.RuntimeSpecification 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.api.RuntimeSpecification in project weave by continuuity.
the class ApplicationMasterService method initContainerRequests.
private Queue<RunnableContainerRequest> initContainerRequests() {
// Orderly stores container requests.
Queue<RunnableContainerRequest> requests = Lists.newLinkedList();
// For each order in the weaveSpec, create container request for each runnable.
for (WeaveSpecification.Order order : weaveSpec.getOrders()) {
// Group container requests based on resource requirement.
ImmutableMultimap.Builder<Resource, RuntimeSpecification> builder = ImmutableMultimap.builder();
for (String runnableName : order.getNames()) {
RuntimeSpecification runtimeSpec = weaveSpec.getRunnables().get(runnableName);
Resource capability = createCapability(runtimeSpec.getResourceSpecification());
builder.put(capability, runtimeSpec);
}
requests.add(new RunnableContainerRequest(order.getType(), builder.build()));
}
return requests;
}
use of com.continuuity.weave.api.RuntimeSpecification in project weave by continuuity.
the class ApplicationMasterService method addContainerRequests.
/**
* Adds container requests with the given resource capability for each runtime.
*/
private void addContainerRequests(Resource capability, Collection<RuntimeSpecification> runtimeSpecs, Queue<ProvisionRequest> provisioning) {
for (RuntimeSpecification runtimeSpec : runtimeSpecs) {
String name = runtimeSpec.getName();
int newContainers = expectedContainers.getExpected(name) - runningContainers.count(name);
if (newContainers > 0) {
// TODO: Allow user to set priority?
LOG.info("Request {} container with capability {}", newContainers, capability);
String requestId = amClient.addContainerRequest(capability, newContainers).setPriority(0).apply();
provisioning.add(new ProvisionRequest(runtimeSpec, requestId, newContainers));
}
}
}
use of com.continuuity.weave.api.RuntimeSpecification in project weave by continuuity.
the class YarnWeavePreparer method createContainerJar.
private void createContainerJar(ApplicationBundler bundler, Map<String, LocalFile> localFiles) throws IOException {
try {
Set<Class<?>> classes = Sets.newIdentityHashSet();
classes.add(WeaveContainerMain.class);
classes.addAll(dependencies);
ClassLoader classLoader = getClassLoader();
for (RuntimeSpecification spec : weaveSpec.getRunnables().values()) {
classes.add(classLoader.loadClass(spec.getRunnableSpecification().getClassName()));
}
LOG.debug("Create and copy {}", Constants.Files.CONTAINER_JAR);
Location location = createTempLocation(Constants.Files.CONTAINER_JAR);
bundler.createBundle(location, classes, resources);
LOG.debug("Done {}", Constants.Files.CONTAINER_JAR);
localFiles.put(Constants.Files.CONTAINER_JAR, createLocalFile(Constants.Files.CONTAINER_JAR, location));
} catch (ClassNotFoundException e) {
throw Throwables.propagate(e);
}
}
use of com.continuuity.weave.api.RuntimeSpecification in project weave by continuuity.
the class ApplicationMasterService method createRunnableContainerRequest.
private RunnableContainerRequest createRunnableContainerRequest(final String runnableName) {
// Find the current order of the given runnable in order to create a RunnableContainerRequest.
WeaveSpecification.Order order = Iterables.find(weaveSpec.getOrders(), new Predicate<WeaveSpecification.Order>() {
@Override
public boolean apply(WeaveSpecification.Order input) {
return (input.getNames().contains(runnableName));
}
});
RuntimeSpecification runtimeSpec = weaveSpec.getRunnables().get(runnableName);
Resource capability = createCapability(runtimeSpec.getResourceSpecification());
return new RunnableContainerRequest(order.getType(), ImmutableMultimap.of(capability, runtimeSpec));
}
Aggregations