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.driver.api; 020 021import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID; 022import org.apache.reef.tang.Configuration; 023import org.apache.reef.tang.JavaConfigurationBuilder; 024import org.apache.reef.tang.Tang; 025import org.apache.reef.tang.annotations.Name; 026import org.apache.reef.tang.annotations.NamedParameter; 027import org.apache.reef.tang.exceptions.BindException; 028import org.apache.reef.util.Builder; 029 030/** 031 * @deprecated Runtimes are advised to create their own ConfigurationModules instead of subclassing this class. 032 */ 033@Deprecated 034public abstract class AbstractDriverRuntimeConfiguration implements Builder<Configuration> { 035 036 protected JavaConfigurationBuilder builder = Tang.Factory.getTang().newConfigurationBuilder(); 037 038 protected AbstractDriverRuntimeConfiguration( 039 final Class<? extends ResourceLaunchHandler> resourceLaunchHandlerClass, 040 final Class<? extends ResourceReleaseHandler> resourceReleaseHandlerClass, 041 final Class<? extends ResourceRequestHandler> resourceRequestHandlerClass) { 042 try { 043 this.builder.bind(ResourceLaunchHandler.class, resourceLaunchHandlerClass); 044 this.builder.bind(ResourceReleaseHandler.class, resourceReleaseHandlerClass); 045 this.builder.bind(ResourceRequestHandler.class, resourceRequestHandlerClass); 046 047 } catch (final BindException e) { 048 throw new RuntimeException(e); 049 } 050 } 051 052 public final Configuration build() { 053 return this.builder.build(); 054 } 055 056 public final AbstractDriverRuntimeConfiguration addClientConfiguration(final Configuration conf) { 057 try { 058 this.builder.addConfiguration(conf); 059 return this; 060 } catch (final BindException e) { 061 throw new RuntimeException(e); 062 } 063 } 064 065 public final AbstractDriverRuntimeConfiguration setJobIdentifier(final String id) { 066 try { 067 this.builder.bindNamedParameter(JobIdentifier.class, id.toString()); 068 return this; 069 } catch (final BindException e) { 070 throw new RuntimeException(e); 071 } 072 } 073 074 public final AbstractDriverRuntimeConfiguration setClientRemoteIdentifier(final String rid) { 075 try { 076 this.builder.bindNamedParameter(ClientRemoteIdentifier.class, rid.toString()); 077 return this; 078 } catch (final BindException e) { 079 throw new RuntimeException(e); 080 } 081 } 082 083 public final AbstractDriverRuntimeConfiguration setDriverProcessMemory(final int memory) { 084 try { 085 this.builder.bindNamedParameter(DriverProcessMemory.class, Integer.toString(memory)); 086 return this; 087 } catch (final BindException e) { 088 throw new RuntimeException(e); 089 } 090 } 091 092 public final AbstractDriverRuntimeConfiguration setEvaluatorTimeout(final long value) { 093 try { 094 this.builder.bindNamedParameter(EvaluatorTimeout.class, Long.toString(value)); 095 return this; 096 } catch (final BindException e) { 097 throw new RuntimeException(e); 098 } 099 } 100 101 @NamedParameter(doc = "The job identifier.") 102 public final static class JobIdentifier implements Name<String> { 103 } 104 105 @NamedParameter(doc = "The client remote identifier.", default_value = ClientRemoteIdentifier.NONE) 106 public final static class ClientRemoteIdentifier implements Name<String> { 107 /** 108 * Indicates that there is no Client. 109 */ 110 public static final String NONE = ErrorHandlerRID.NONE; 111 } 112 113 @NamedParameter(doc = "The evaluator timeout (how long to wait before deciding an evaluator is dead.", default_value = "60000") 114 public final static class EvaluatorTimeout implements Name<Long> { 115 } 116 117 /** 118 * This parameter denotes that the driver process should actually be 119 * started in a separate process with the given amount of JVM memory. 120 */ 121 @NamedParameter(doc = "The driver process memory.", default_value = "512") 122 public final static class DriverProcessMemory implements Name<Integer> { 123 } 124}