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   * TODO[JIRA REEF-919] delete this constant
044   */
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,
055                                            final OptionalParameter<String> param,
056                                            final File folder) {
057    ConfigurationModule result = conf;
058    final File[] files = folder.listFiles();
059    if (files != null) {
060      for (final File f : files) {
061        if (f.canRead() && f.exists() && f.isFile()) {
062          result = result.set(param, f.getAbsolutePath());
063        }
064      }
065    }
066    return result;
067  }
068
069  public static LauncherStatus runHelloCLR(final Configuration runtimeConf, final int timeOut, final File clrFolder)
070      throws BindException, InjectionException {
071
072    final ConfigurationModule driverConf =
073        addAll(DriverConfiguration.CONF, DriverConfiguration.GLOBAL_FILES, clrFolder)
074            .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
075            .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloCLR")
076            .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
077            .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class);
078
079    return DriverLauncher.getLauncher(runtimeConf).run(driverConf.build(), timeOut);
080  }
081
082  /**
083   * Start Hello REEF job. Runs method runHelloCLR().
084   *
085   * @param args command line parameters.
086   * @throws org.apache.reef.tang.exceptions.BindException      configuration error.
087   * @throws org.apache.reef.tang.exceptions.InjectionException configuration error.
088   */
089  public static void main(final String[] args) throws BindException, InjectionException {
090    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
091        .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, 2)
092        .build();
093
094    final File dotNetFolder = new File(args[0]).getAbsoluteFile();
095    final LauncherStatus status = runHelloCLR(runtimeConfiguration, JOB_TIMEOUT, dotNetFolder);
096    LOG.log(Level.INFO, "REEF job completed: {0}", status);
097  }
098
099  /**
100   * Empty private constructor to prohibit instantiation of utility class.
101   */
102  private HelloCLR() {
103  }
104}