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 */ 019 020package org.apache.reef.bridge.client; 021 022import org.apache.reef.annotations.audience.Interop; 023import org.apache.reef.runtime.common.REEFLauncher; 024import org.apache.reef.tang.Tang; 025import org.apache.reef.tang.exceptions.InjectionException; 026 027import java.io.IOException; 028import java.util.logging.Level; 029import java.util.logging.Logger; 030 031/** 032 * This is a bootstrap launcher for YARN for submission from C#. It allows for Java Driver 033 * configuration generation directly on the Driver without need of Java dependency if REST 034 * submission is used. Note that the name of the class must contain "REEFLauncher" for the time 035 * being in order for the Interop code to discover the class. 036 */ 037@Interop(CppFiles = "DriverLauncher.cpp") 038public final class YarnBootstrapREEFLauncher { 039 private static final Logger LOG = Logger.getLogger(YarnBootstrapREEFLauncher.class.getName()); 040 041 public static void main(final String[] args) throws IOException, InjectionException { 042 LOG.log(Level.INFO, "Entering BootstrapLauncher.main()."); 043 044 if (args.length != 2) { 045 final StringBuilder sb = new StringBuilder(); 046 sb.append("[ "); 047 for (String arg : args) { 048 sb.append(arg); 049 sb.append(" "); 050 } 051 052 sb.append("]"); 053 054 final String message = "Bootstrap launcher should have two configuration file inputs, one specifying the" + 055 " application submission parameters to be deserialized and the other specifying the job" + 056 " submission parameters to be deserialized to create the YarnDriverConfiguration on the fly." + 057 " Current args are " + sb.toString(); 058 059 throw fatal(message, new IllegalArgumentException(message)); 060 } 061 062 try { 063 final YarnBootstrapDriverConfigGenerator yarnDriverConfigurationGenerator = 064 Tang.Factory.getTang().newInjector().getInstance(YarnBootstrapDriverConfigGenerator.class); 065 REEFLauncher.main(new String[]{yarnDriverConfigurationGenerator.writeDriverConfigurationFile(args[0], args[1])}); 066 } catch (final Exception exception) { 067 if (!(exception instanceof RuntimeException)) { 068 throw fatal("Failed to initialize configurations.", exception); 069 } 070 071 throw exception; 072 } 073 } 074 075 private static RuntimeException fatal(final String msg, final Throwable t) { 076 LOG.log(Level.SEVERE, msg, t); 077 return new RuntimeException(msg, t); 078 } 079 080 private YarnBootstrapREEFLauncher(){ 081 } 082}