This project has retired. For details please refer to its Attic page.
Source code
001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.examples.helloCLR;
020
021import org.apache.reef.client.DriverConfiguration;
022import org.apache.reef.client.DriverLauncher;
023import org.apache.reef.client.LauncherStatus;
024import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
025import org.apache.reef.tang.Configuration;
026import org.apache.reef.tang.exceptions.BindException;
027import org.apache.reef.tang.exceptions.InjectionException;
028import org.apache.reef.tang.formats.ConfigurationModule;
029import org.apache.reef.tang.formats.OptionalParameter;
030import org.apache.reef.util.EnvironmentUtils;
031
032import java.io.File;
033import java.util.logging.Level;
034import java.util.logging.Logger;
035
036/**
037 * The Client for Hello REEF example.
038 */
039public final class HelloCLR {
040
041  /**
042   * The name of the class hierarchy file.
043   */
044  // TODO: Make this a config option
045  public static final String CLASS_HIERARCHY_FILENAME = "HelloTask.bin";
046
047  private static final Logger LOG = Logger.getLogger(HelloCLR.class.getName());
048
049  /**
050   * Number of milliseconds to wait for the job to complete.
051   */
052  private static final int JOB_TIMEOUT = 1000000; // 1000 sec.
053
054  private static ConfigurationModule addAll(final ConfigurationModule conf, final OptionalParameter<String> param, final File folder) {
055    ConfigurationModule result = conf;
056    for (final File f : folder.listFiles()) {
057      if (f.canRead() && f.exists() && f.isFile()) {
058        result = result.set(param, f.getAbsolutePath());
059      }
060    }
061    return result;
062  }
063
064  public static LauncherStatus runHelloCLR(final Configuration runtimeConf, final int timeOut, final File clrFolder)
065      throws BindException, InjectionException {
066
067    ConfigurationModule driverConf =
068        addAll(DriverConfiguration.CONF, DriverConfiguration.GLOBAL_FILES, clrFolder)
069            .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
070            .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloCLR")
071            .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
072            .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class);
073
074    return DriverLauncher.getLauncher(runtimeConf).run(driverConf.build(), timeOut);
075  }
076
077  /**
078   * Start Hello REEF job. Runs method runHelloReef().
079   *
080   * @param args command line parameters.
081   * @throws org.apache.reef.tang.exceptions.BindException      configuration error.
082   * @throws org.apache.reef.tang.exceptions.InjectionException configuration error.
083   */
084  public static void main(final String[] args) throws BindException, InjectionException {
085    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
086        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
087        .build();
088
089    final File dotNetFolder = new File(args[0]).getAbsoluteFile();
090    final LauncherStatus status = runHelloCLR(runtimeConfiguration, JOB_TIMEOUT, dotNetFolder);
091    LOG.log(Level.INFO, "REEF job completed: {0}", status);
092  }
093}