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.bridge.client;
020
021import org.apache.reef.runtime.common.driver.parameters.ClientRemoteIdentifier;
022import org.apache.reef.runtime.local.client.PreparedDriverFolderLauncher;
023import org.apache.reef.tang.Configuration;
024import org.apache.reef.tang.Tang;
025import org.apache.reef.tang.exceptions.InjectionException;
026
027import javax.inject.Inject;
028import java.io.File;
029import java.io.IOException;
030import java.util.logging.Level;
031import java.util.logging.Logger;
032
033/**
034 * Submits a folder containing a Driver to the local runtime.
035 */
036public final class LocalClient {
037
038  private static final Logger LOG = Logger.getLogger(LocalClient.class.getName());
039  private static final String CLIENT_REMOTE_ID = ClientRemoteIdentifier.NONE;
040  private final PreparedDriverFolderLauncher launcher;
041  private final LocalRuntimeDriverConfigurationGenerator configurationGenerator;
042
043  @Inject
044  private LocalClient(final PreparedDriverFolderLauncher launcher,
045                      final LocalRuntimeDriverConfigurationGenerator configurationGenerator) {
046    this.launcher = launcher;
047    this.configurationGenerator = configurationGenerator;
048  }
049
050  private void submit(final LocalSubmissionFromCS localSubmissionFromCS) throws IOException {
051    final File driverFolder = new File(localSubmissionFromCS.getJobFolder(),
052        PreparedDriverFolderLauncher.DRIVER_FOLDER_NAME);
053    if (!driverFolder.exists()) {
054      throw new IOException("The Driver folder " + driverFolder.getAbsolutePath() + " doesn't exist.");
055    }
056
057    configurationGenerator.writeConfiguration(localSubmissionFromCS.getJobFolder(),
058        localSubmissionFromCS.getJobId(), CLIENT_REMOTE_ID);
059    launcher.launch(driverFolder, localSubmissionFromCS.getDriverStdoutPath(),
060        localSubmissionFromCS.getDriverStderrPath());
061  }
062
063  public static void main(final String[] args) throws IOException, InjectionException {
064    final File jobSubmissionParametersFile = new File(args[0]);
065    final File localAppSubmissionParametersFile = new File(args[1]);
066
067    if (!(jobSubmissionParametersFile.exists() && jobSubmissionParametersFile.canRead())) {
068      throw new IOException("Unable to open and read " + jobSubmissionParametersFile.getAbsolutePath());
069    }
070
071    if (!(localAppSubmissionParametersFile.exists() && localAppSubmissionParametersFile.canRead())) {
072      throw new IOException("Unable to open and read " + localAppSubmissionParametersFile.getAbsolutePath());
073    }
074
075    final LocalSubmissionFromCS localSubmissionFromCS =
076        LocalSubmissionFromCS.fromSubmissionParameterFiles(
077            jobSubmissionParametersFile, localAppSubmissionParametersFile);
078    LOG.log(Level.INFO, "Local job submission received from C#: {0}", localSubmissionFromCS);
079    final Configuration runtimeConfiguration = localSubmissionFromCS.getRuntimeConfiguration();
080
081    final LocalClient client = Tang.Factory.getTang()
082        .newInjector(runtimeConfiguration)
083        .getInstance(LocalClient.class);
084
085    client.submit(localSubmissionFromCS);
086  }
087}