Search in sources :

Example 1 with Arguments

use of com.continuuity.weave.internal.Arguments in project weave by continuuity.

the class WeaveContainerMain method main.

/**
   * Main method for launching a {@link WeaveContainerService} which runs
   * a {@link com.continuuity.weave.api.WeaveRunnable}.
   */
public static void main(final String[] args) throws Exception {
    // Try to load the secure store from localized file, which AM requested RM to localize it for this container.
    loadSecureStore();
    String zkConnectStr = System.getenv(EnvKeys.WEAVE_ZK_CONNECT);
    File weaveSpecFile = new File(Constants.Files.WEAVE_SPEC);
    RunId appRunId = RunIds.fromString(System.getenv(EnvKeys.WEAVE_APP_RUN_ID));
    RunId runId = RunIds.fromString(System.getenv(EnvKeys.WEAVE_RUN_ID));
    String runnableName = System.getenv(EnvKeys.WEAVE_RUNNABLE_NAME);
    int instanceId = Integer.parseInt(System.getenv(EnvKeys.WEAVE_INSTANCE_ID));
    int instanceCount = Integer.parseInt(System.getenv(EnvKeys.WEAVE_INSTANCE_COUNT));
    ZKClientService zkClientService = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnectStr).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS))));
    DiscoveryService discoveryService = new ZKDiscoveryService(zkClientService);
    WeaveSpecification weaveSpec = loadWeaveSpec(weaveSpecFile);
    renameLocalFiles(weaveSpec.getRunnables().get(runnableName));
    WeaveRunnableSpecification runnableSpec = weaveSpec.getRunnables().get(runnableName).getRunnableSpecification();
    ContainerInfo containerInfo = new EnvContainerInfo();
    Arguments arguments = decodeArgs();
    BasicWeaveContext context = new BasicWeaveContext(runId, appRunId, containerInfo.getHost(), arguments.getRunnableArguments().get(runnableName).toArray(new String[0]), arguments.getArguments().toArray(new String[0]), runnableSpec, instanceId, discoveryService, instanceCount, containerInfo.getMemoryMB(), containerInfo.getVirtualCores());
    Configuration conf = new YarnConfiguration(new HdfsConfiguration(new Configuration()));
    Service service = new WeaveContainerService(context, containerInfo, getContainerZKClient(zkClientService, appRunId, runnableName), runId, runnableSpec, getClassLoader(), createAppLocation(conf));
    new WeaveContainerMain().doMain(zkClientService, service);
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) EnvContainerInfo(com.continuuity.weave.internal.EnvContainerInfo) Arguments(com.continuuity.weave.internal.Arguments) DiscoveryService(com.continuuity.weave.discovery.DiscoveryService) ZKDiscoveryService(com.continuuity.weave.discovery.ZKDiscoveryService) ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) Service(com.google.common.util.concurrent.Service) WeaveSpecification(com.continuuity.weave.api.WeaveSpecification) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) WeaveRunnableSpecification(com.continuuity.weave.api.WeaveRunnableSpecification) ZKDiscoveryService(com.continuuity.weave.discovery.ZKDiscoveryService) ZKClientService(com.continuuity.weave.zookeeper.ZKClientService) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) EnvContainerInfo(com.continuuity.weave.internal.EnvContainerInfo) ContainerInfo(com.continuuity.weave.internal.ContainerInfo) BasicWeaveContext(com.continuuity.weave.internal.BasicWeaveContext) RunId(com.continuuity.weave.api.RunId) DiscoveryService(com.continuuity.weave.discovery.DiscoveryService) ZKDiscoveryService(com.continuuity.weave.discovery.ZKDiscoveryService) LocalFile(com.continuuity.weave.api.LocalFile) File(java.io.File)

Example 2 with Arguments

use of com.continuuity.weave.internal.Arguments in project weave by continuuity.

the class ArgumentsCodec method deserialize.

@Override
public Arguments deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();
    List<String> arguments = context.deserialize(jsonObj.get("arguments"), new TypeToken<List<String>>() {
    }.getType());
    Map<String, Collection<String>> args = context.deserialize(jsonObj.get("runnableArguments"), new TypeToken<Map<String, Collection<String>>>() {
    }.getType());
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    for (Map.Entry<String, Collection<String>> entry : args.entrySet()) {
        builder.putAll(entry.getKey(), entry.getValue());
    }
    return new Arguments(arguments, builder.build());
}
Also used : TypeToken(com.google.common.reflect.TypeToken) Arguments(com.continuuity.weave.internal.Arguments) JsonObject(com.google.gson.JsonObject) Collection(java.util.Collection) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Map(java.util.Map)

Example 3 with Arguments

use of com.continuuity.weave.internal.Arguments in project weave by continuuity.

the class YarnWeavePreparer method start.

@Override
public WeaveController start() {
    try {
        final ProcessLauncher<ApplicationId> launcher = yarnAppClient.createLauncher(user, weaveSpec);
        final ApplicationId appId = launcher.getContainerInfo();
        Callable<ProcessController<YarnApplicationReport>> submitTask = new Callable<ProcessController<YarnApplicationReport>>() {

            @Override
            public ProcessController<YarnApplicationReport> call() throws Exception {
                String fsUser = locationFactory.getHomeLocation().getName();
                // Local files needed by AM
                Map<String, LocalFile> localFiles = Maps.newHashMap();
                // Local files declared by runnables
                Multimap<String, LocalFile> runnableLocalFiles = HashMultimap.create();
                String vmOpts = jvmOpts.get();
                createAppMasterJar(createBundler(), localFiles);
                createContainerJar(createBundler(), localFiles);
                populateRunnableLocalFiles(weaveSpec, runnableLocalFiles);
                saveWeaveSpec(weaveSpec, runnableLocalFiles, localFiles);
                saveLogback(localFiles);
                saveLauncher(localFiles);
                saveKafka(localFiles);
                saveVmOptions(vmOpts, localFiles);
                saveArguments(new Arguments(arguments, runnableArgs), localFiles);
                saveLocalFiles(localFiles, ImmutableSet.of(Constants.Files.WEAVE_SPEC, Constants.Files.LOGBACK_TEMPLATE, Constants.Files.CONTAINER_JAR, Constants.Files.LAUNCHER_JAR, Constants.Files.ARGUMENTS));
                LOG.debug("Submit AM container spec: {}", appId);
                //     false
                return launcher.prepareLaunch(ImmutableMap.<String, String>builder().put(EnvKeys.WEAVE_FS_USER, fsUser).put(EnvKeys.WEAVE_APP_DIR, getAppLocation().toURI().toASCIIString()).put(EnvKeys.WEAVE_ZK_CONNECT, zkClient.getConnectString()).put(EnvKeys.WEAVE_RUN_ID, runId.getId()).put(EnvKeys.WEAVE_RESERVED_MEMORY_MB, Integer.toString(reservedMemory)).put(EnvKeys.WEAVE_APP_NAME, weaveSpec.getName()).build(), localFiles.values(), credentials).noResources().noEnvironment().withCommands().add("java", "-Djava.io.tmpdir=tmp", "-Dyarn.appId=$" + EnvKeys.YARN_APP_ID_STR, "-Dweave.app=$" + EnvKeys.WEAVE_APP_NAME, "-cp", Constants.Files.LAUNCHER_JAR + ":$HADOOP_CONF_DIR", "-Xmx" + (Constants.APP_MASTER_MEMORY_MB - Constants.APP_MASTER_RESERVED_MEMORY_MB) + "m", vmOpts, WeaveLauncher.class.getName(), Constants.Files.APP_MASTER_JAR, ApplicationMasterMain.class.getName(), Boolean.FALSE.toString()).redirectOutput(Constants.STDOUT).redirectError(Constants.STDERR).launch();
            }
        };
        YarnWeaveController controller = controllerFactory.create(runId, logHandlers, submitTask);
        controller.start();
        return controller;
    } catch (Exception e) {
        LOG.error("Failed to submit application {}", weaveSpec.getName(), e);
        throw Throwables.propagate(e);
    }
}
Also used : YarnApplicationReport(com.continuuity.weave.internal.yarn.YarnApplicationReport) Arguments(com.continuuity.weave.internal.Arguments) Callable(java.util.concurrent.Callable) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) LocalFile(com.continuuity.weave.api.LocalFile) DefaultLocalFile(com.continuuity.weave.internal.DefaultLocalFile) ProcessController(com.continuuity.weave.internal.ProcessController) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId)

Aggregations

Arguments (com.continuuity.weave.internal.Arguments)3 LocalFile (com.continuuity.weave.api.LocalFile)2 RunId (com.continuuity.weave.api.RunId)1 WeaveRunnableSpecification (com.continuuity.weave.api.WeaveRunnableSpecification)1 WeaveSpecification (com.continuuity.weave.api.WeaveSpecification)1 DiscoveryService (com.continuuity.weave.discovery.DiscoveryService)1 ZKDiscoveryService (com.continuuity.weave.discovery.ZKDiscoveryService)1 BasicWeaveContext (com.continuuity.weave.internal.BasicWeaveContext)1 ContainerInfo (com.continuuity.weave.internal.ContainerInfo)1 DefaultLocalFile (com.continuuity.weave.internal.DefaultLocalFile)1 EnvContainerInfo (com.continuuity.weave.internal.EnvContainerInfo)1 ProcessController (com.continuuity.weave.internal.ProcessController)1 YarnApplicationReport (com.continuuity.weave.internal.yarn.YarnApplicationReport)1 ZKClientService (com.continuuity.weave.zookeeper.ZKClientService)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 TypeToken (com.google.common.reflect.TypeToken)1 Service (com.google.common.util.concurrent.Service)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 IOException (java.io.IOException)1