Search in sources :

Example 1 with RuntimeSpecification

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

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;
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) WeaveSpecification(com.continuuity.weave.api.WeaveSpecification) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification)

Example 3 with RuntimeSpecification

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));
        }
    }
}
Also used : RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification)

Example 4 with RuntimeSpecification

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);
    }
}
Also used : DefaultRuntimeSpecification(com.continuuity.weave.internal.DefaultRuntimeSpecification) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification) Location(com.continuuity.weave.filesystem.Location)

Example 5 with RuntimeSpecification

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));
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) WeaveSpecification(com.continuuity.weave.api.WeaveSpecification) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification)

Aggregations

RuntimeSpecification (com.continuuity.weave.api.RuntimeSpecification)7 Location (com.continuuity.weave.filesystem.Location)3 DefaultRuntimeSpecification (com.continuuity.weave.internal.DefaultRuntimeSpecification)3 EventHandlerSpecification (com.continuuity.weave.api.EventHandlerSpecification)2 WeaveSpecification (com.continuuity.weave.api.WeaveSpecification)2 DefaultWeaveSpecification (com.continuuity.weave.internal.DefaultWeaveSpecification)2 Resource (org.apache.hadoop.yarn.api.records.Resource)2 LocalFile (com.continuuity.weave.api.LocalFile)1 DefaultEventHandlerSpecification (com.continuuity.weave.internal.DefaultEventHandlerSpecification)1 DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)1 LogOnlyEventHandler (com.continuuity.weave.internal.LogOnlyEventHandler)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 URI (java.net.URI)1