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.runtime.common.launch;
020
021import org.apache.commons.lang.StringUtils;
022import org.apache.reef.util.Optional;
023
024import java.io.File;
025import java.util.LinkedList;
026import java.util.List;
027import java.util.logging.Level;
028import java.util.logging.Logger;
029
030/**
031 * A builder for the command line to launch a CLR Evaluator.
032 */
033public class CLRLaunchCommandBuilder implements LaunchCommandBuilder {
034  private static final Logger LOG = Logger.getLogger(CLRLaunchCommandBuilder.class.getName());
035  private static final String EVALUATOR_PATH = "reef/global/Org.Apache.Reef.Evaluator.exe";
036
037  private String standardErrPath = null;
038  private String standardOutPath = null;
039  private int megaBytes = 0;
040  private Optional<List<String>> evaluatorConfigurationPaths = Optional.empty();
041
042  @Override
043  public List<String> build() {
044    final List<String> result = new LinkedList<>();
045    final File f = new File(EVALUATOR_PATH);
046    if (!f.exists()) {
047      LOG.log(Level.WARNING, "file can NOT be found: {0}", f.getAbsolutePath());
048    }
049    result.add(f.getPath());
050    if (evaluatorConfigurationPaths.isPresent()) {
051      for (final String evaluatorConfigurationPath : evaluatorConfigurationPaths.get()) {
052        result.add(evaluatorConfigurationPath);
053      }
054    }
055    if (null != this.standardOutPath && !standardOutPath.isEmpty()) {
056      result.add(">" + this.standardOutPath);
057    }
058    if (null != this.standardErrPath && !standardErrPath.isEmpty()) {
059      result.add("2>" + this.standardErrPath);
060    }
061    LOG.log(Level.FINE, "Launch Exe: {0}", StringUtils.join(result, ' '));
062    return result;
063  }
064
065  @Override
066  @SuppressWarnings("checkstyle:hiddenfield")
067  public CLRLaunchCommandBuilder setMemory(final int megaBytes) {
068    this.megaBytes = megaBytes;
069    return this;
070  }
071
072  @Override
073  public CLRLaunchCommandBuilder setConfigurationFilePaths(final List<String> configurationFilePaths) {
074    this.evaluatorConfigurationPaths = Optional.of(configurationFilePaths);
075    return this;
076  }
077
078  @Override
079  public CLRLaunchCommandBuilder setStandardOut(final String standardOut) {
080    this.standardOutPath = standardOut;
081    return this;
082  }
083
084  @Override
085  public CLRLaunchCommandBuilder setStandardErr(final String standardErr) {
086    this.standardErrPath = standardErr;
087    return this;
088  }
089}