|
@@ -24,11 +24,17 @@ import java.util.Set;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
|
import org.apache.hadoop.classification.InterfaceStability.Evolving;
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.service.CompositeService;
|
|
|
+import org.apache.hadoop.util.ReflectionUtils;
|
|
|
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
|
|
|
import org.apache.hadoop.yarn.server.sharedcachemanager.AppChecker;
|
|
|
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* An abstract class for the data store used by the shared cache manager
|
|
@@ -39,13 +45,27 @@ import org.apache.hadoop.yarn.server.sharedcachemanager.AppChecker;
|
|
|
@Evolving
|
|
|
public abstract class SCMStore extends CompositeService {
|
|
|
|
|
|
- protected final AppChecker appChecker;
|
|
|
+ protected AppChecker appChecker;
|
|
|
+
|
|
|
+ protected SCMStore(String name) {
|
|
|
+ super(name);
|
|
|
+ }
|
|
|
|
|
|
- protected SCMStore(String name, AppChecker appChecker) {
|
|
|
+ @VisibleForTesting
|
|
|
+ SCMStore(String name, AppChecker appChecker) {
|
|
|
super(name);
|
|
|
this.appChecker = appChecker;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void serviceInit(Configuration conf) throws Exception {
|
|
|
+ if (this.appChecker == null) {
|
|
|
+ this.appChecker = createAppCheckerService(conf);
|
|
|
+ }
|
|
|
+ addService(appChecker);
|
|
|
+ super.serviceInit(conf);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Add a resource to the shared cache and it's associated filename. The
|
|
|
* resource is identified by a unique key. If the key already exists no action
|
|
@@ -164,4 +184,30 @@ public abstract class SCMStore extends CompositeService {
|
|
|
@Private
|
|
|
public abstract boolean isResourceEvictable(String key, FileStatus file);
|
|
|
|
|
|
+ /**
|
|
|
+ * Create an instance of the AppChecker service via reflection based on the
|
|
|
+ * {@link YarnConfiguration#SCM_APP_CHECKER_CLASS} parameter.
|
|
|
+ *
|
|
|
+ * @param conf
|
|
|
+ * @return an instance of the AppChecker class
|
|
|
+ */
|
|
|
+ @Private
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public static AppChecker createAppCheckerService(Configuration conf) {
|
|
|
+ Class<? extends AppChecker> defaultCheckerClass;
|
|
|
+ try {
|
|
|
+ defaultCheckerClass =
|
|
|
+ (Class<? extends AppChecker>) Class
|
|
|
+ .forName(YarnConfiguration.DEFAULT_SCM_APP_CHECKER_CLASS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new YarnRuntimeException("Invalid default scm app checker class"
|
|
|
+ + YarnConfiguration.DEFAULT_SCM_APP_CHECKER_CLASS, e);
|
|
|
+ }
|
|
|
+
|
|
|
+ AppChecker checker =
|
|
|
+ ReflectionUtils.newInstance(conf.getClass(
|
|
|
+ YarnConfiguration.SCM_APP_CHECKER_CLASS, defaultCheckerClass,
|
|
|
+ AppChecker.class), conf);
|
|
|
+ return checker;
|
|
|
+ }
|
|
|
}
|