IDE review of package org.apache.slider packages
git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1595998 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java b/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
index d875d66..d5869a6 100644
--- a/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
+++ b/slider-core/src/main/java/org/apache/slider/api/ClusterDescription.java
@@ -165,40 +165,40 @@
* the Slider AM and the application that it deploys
*/
public Map<String, String> options =
- new HashMap<String, String>();
+ new HashMap<>();
/**
* cluster information
* This is only valid when querying the cluster status.
*/
public Map<String, String> info =
- new HashMap<String, String>();
+ new HashMap<>();
/**
* Statistics. This is only relevant when querying the cluster status
*/
public Map<String, Map<String, Integer>> statistics =
- new HashMap<String, Map<String, Integer>>();
+ new HashMap<>();
/**
* Instances: role->count
*/
public Map<String, List<String>> instances =
- new HashMap<String, List<String>>();
+ new HashMap<>();
/**
* Role options,
* role -> option -> value
*/
public Map<String, Map<String, String>> roles =
- new HashMap<String, Map<String, String>>();
+ new HashMap<>();
/**
* List of key-value pairs to add to a client config to set up the client
*/
public Map<String, String> clientProperties =
- new HashMap<String, String>();
+ new HashMap<>();
/**
* Status information
@@ -569,7 +569,7 @@
*/
@JsonIgnore
public Set<String> getRoleNames() {
- return new HashSet<String>(roles.keySet());
+ return new HashSet<>(roles.keySet());
}
/**
diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index 978c75d..8665622 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -608,13 +608,14 @@
* @param name cluster name
* @param resolved flag to indicate the cluster should be resolved
* @return the loaded configuration
- * @throws IOException
- * @throws SliderException
+ * @throws IOException IO problems
+ * @throws SliderException slider explicit issues
* @throws UnknownApplicationInstanceException if the file is not found
*/
- public AggregateConf loadInstanceDefinition(String name, boolean resolved) throws
- IOException,
- SliderException {
+ public AggregateConf loadInstanceDefinition(String name,
+ boolean resolved) throws
+ IOException,
+ SliderException {
Path clusterDirectory = sliderFileSystem.buildClusterDirPath(name);
AggregateConf instanceDefinition = loadInstanceDefinitionUnresolved(
@@ -692,7 +693,7 @@
// add the tags if available
Set<String> applicationTags = provider.getApplicationTags(sliderFileSystem,
- appOperations.getGlobalOptions().get(AgentKeys.APP_DEF));
+ appOperations.getGlobalOptions().get(AgentKeys.APP_DEF));
AppMasterLauncher amLauncher = new AppMasterLauncher(clustername,
SliderKeys.APP_TYPE,
config,
diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java b/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java
index 26130ee..0c83e0c 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java
@@ -69,10 +69,10 @@
*/
public List<ApplicationReport> listInstances(String user)
throws YarnException, IOException {
- Set<String> types = new HashSet<String>(1);
+ Set<String> types = new HashSet<>(1);
types.add(SliderKeys.APP_TYPE);
List<ApplicationReport> allApps = getApplications(types);
- List<ApplicationReport> results = new ArrayList<ApplicationReport>();
+ List<ApplicationReport> results = new ArrayList<>();
for (ApplicationReport report : allApps) {
if (user == null || user.equals(report.getUser())) {
results.add(report);
@@ -96,7 +96,7 @@
YarnException {
List<ApplicationReport> instances = listInstances(user);
List<ApplicationReport> results =
- new ArrayList<ApplicationReport>(instances.size());
+ new ArrayList<>(instances.size());
for (ApplicationReport report : instances) {
if (report.getName().equals(appname)) {
results.add(report);
@@ -239,7 +239,7 @@
IOException {
List<ApplicationReport> instances = listInstances(user);
List<ApplicationReport> results =
- new ArrayList<ApplicationReport>(instances.size());
+ new ArrayList<>(instances.size());
for (ApplicationReport app : instances) {
if (app.getName().equals(appname)
&& isApplicationLive(app)) {
diff --git a/slider-core/src/main/java/org/apache/slider/core/conf/ConfTree.java b/slider-core/src/main/java/org/apache/slider/core/conf/ConfTree.java
index f989726..2cbfd54 100644
--- a/slider-core/src/main/java/org/apache/slider/core/conf/ConfTree.java
+++ b/slider-core/src/main/java/org/apache/slider/core/conf/ConfTree.java
@@ -55,15 +55,14 @@
/**
* Metadata
*/
- public Map<String, Object> metadata = new HashMap<String, Object>(
- INITAL_MAP_CAPACITY);
+ public Map<String, Object> metadata = new HashMap<>(INITAL_MAP_CAPACITY);
/**
* Global options
*/
public Map<String, String> global =
- new HashMap<String, String>(INITAL_MAP_CAPACITY);
+ new HashMap<>(INITAL_MAP_CAPACITY);
/**
@@ -71,7 +70,7 @@
* role -> option -> value
*/
public Map<String, Map<String, String>> components =
- new HashMap<String, Map<String, String>>(INITAL_MAP_CAPACITY);
+ new HashMap<>(INITAL_MAP_CAPACITY);
/**
diff --git a/slider-core/src/main/java/org/apache/slider/core/conf/ConfTreeOperations.java b/slider-core/src/main/java/org/apache/slider/core/conf/ConfTreeOperations.java
index bb17547..1cb537a 100644
--- a/slider-core/src/main/java/org/apache/slider/core/conf/ConfTreeOperations.java
+++ b/slider-core/src/main/java/org/apache/slider/core/conf/ConfTreeOperations.java
@@ -148,7 +148,7 @@
return operations;
}
//create a new instances
- Map<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<>();
confTree.components.put(name, map);
return new MapOperations(name, map);
}
@@ -159,7 +159,7 @@
*/
@JsonIgnore
public Set<String> getComponentNames() {
- return new HashSet<String>(confTree.components.keySet());
+ return new HashSet<>(confTree.components.keySet());
}
diff --git a/slider-core/src/main/java/org/apache/slider/core/conf/MapOperations.java b/slider-core/src/main/java/org/apache/slider/core/conf/MapOperations.java
index 0050d04..bb57b94 100644
--- a/slider-core/src/main/java/org/apache/slider/core/conf/MapOperations.java
+++ b/slider-core/src/main/java/org/apache/slider/core/conf/MapOperations.java
@@ -46,7 +46,7 @@
public final String name;
public MapOperations() {
- options = new HashMap<String, String>();
+ options = new HashMap<>();
name = "";
}
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/AMRestartSupport.java b/slider-core/src/main/java/org/apache/slider/core/launch/AMRestartSupport.java
deleted file mode 100644
index e7bf25d..0000000
--- a/slider-core/src/main/java/org/apache/slider/core/launch/AMRestartSupport.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.slider.core.launch;
-
-import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
-import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl;
-import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
-import org.apache.hadoop.yarn.api.records.Container;
-import org.apache.slider.server.services.utility.SliderServiceUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-
-/**
- * Logic needed to enable AM restart support in both submission and
- * operation
- */
-public class AMRestartSupport {
- public static final String REGISTER_AM_RESPONSE =
- "RegisterApplicationMasterResponse.getContainersFromPreviousAttempts()";
- private static final Logger
- log = LoggerFactory.getLogger(SliderServiceUtils.class);
-
- /**
- * Request that containers are kept across submissions.
- * @param submissionContext context to query
- * @return true if the method was applied.
- */
-
- public static boolean keepContainersAcrossSubmissions(
- ApplicationSubmissionContext submissionContext) {
- Method m = null;
- String methName =
- "ApplicationSubmissionContext.setKeepContainersAcrossApplicationAttempts()";
- Class<? extends ApplicationSubmissionContext> cls =
- submissionContext.getClass();
- try {
- m = cls.getDeclaredMethod("setKeepContainersAcrossApplicationAttempts",
- boolean.class);
- m.setAccessible(true);
- } catch (NoSuchMethodException e) {
- log.debug(methName + " not found");
- } catch (SecurityException e) {
- log.debug("No access to " + methName);
- }
- // AM-RESTART-SUPPORT: AM wants its old containers back on a restart
- if (m != null) {
- try {
- m.invoke(submissionContext, true);
- return true;
- } catch (InvocationTargetException ite) {
- log.error(methName + " got", ite);
- } catch (IllegalAccessException iae) {
- log.error(methName + " got", iae);
- }
- }
- return false;
- }
-
- /**
- * Get the containers from a previous attempt
- * @param response AM registration response
- * @return a list of containers (possibly empty) if the AM provided
- * that field in its registration, and the hadoop JAR has the relevant
- * method to access it.
- */
- public static List<Container> retrieveContainersFromPreviousAttempt(
- RegisterApplicationMasterResponse response) {
- List<Container> liveContainers = null;
- Method m = extractRetrieveContainersMethod(response);
- if (m != null) {
- try {
- Object obj = m.invoke(response);
- if (obj instanceof List) {
- liveContainers = (List<Container>) obj;
-
- }
- } catch (InvocationTargetException ite) {
- log.error(REGISTER_AM_RESPONSE + " got", ite);
- } catch (IllegalAccessException iae) {
- log.error(REGISTER_AM_RESPONSE + " got", iae);
- }
- }
- return liveContainers;
- }
-
- /**
- * Get the method to retrieve containers. The presence of this
- * method indicates the Hadoop libraries are compiled with the
- * extra fields, and that, if the client requested it, the AM
- * will be given a list of existing containers on a restart
- * @param response registration response
- * @return a method or null if it is not present.
- */
- public static Method extractRetrieveContainersMethod(
- RegisterApplicationMasterResponse response) {
- Method m = null;
- Class<? extends RegisterApplicationMasterResponse> cls =
- response.getClass();
- try {
- m = cls.getDeclaredMethod("getContainersFromPreviousAttempts");
- } catch (NoSuchMethodException e) {
- log.debug(REGISTER_AM_RESPONSE + " not found");
- } catch (SecurityException e) {
- log.debug("No access to " + REGISTER_AM_RESPONSE);
- }
- return m;
- }
-
- public static boolean isAMRestartInHadoopLibrary() {
- RegisterApplicationMasterResponse response =
- new RegisterApplicationMasterResponsePBImpl();
- return null != extractRetrieveContainersMethod(response);
- }
-}
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java b/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
index fa37219..d8c3522 100644
--- a/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/AbstractLauncher.java
@@ -57,15 +57,15 @@
/**
* Env vars; set up at final launch stage
*/
- protected final Map<String, String> envVars = new HashMap<String, String>();
+ protected final Map<String, String> envVars = new HashMap<>();
protected final MapOperations env = new MapOperations("env", envVars);
protected final ContainerLaunchContext containerLaunchContext =
Records.newRecord(ContainerLaunchContext.class);
- protected final List<String> commands = new ArrayList<String>(20);
+ protected final List<String> commands = new ArrayList<>(20);
protected final Map<String, LocalResource> localResources =
- new HashMap<String, LocalResource>();
+ new HashMap<>();
private final Map<String, ByteBuffer> serviceData =
- new HashMap<String, ByteBuffer>();
+ new HashMap<>();
// security
Credentials credentials = new Credentials();
@@ -266,7 +266,7 @@
public String[] dumpEnvToString() {
- List<String> nodeEnv = new ArrayList<String>();
+ List<String> nodeEnv = new ArrayList<>();
for (Map.Entry<String, String> entry : env.entrySet()) {
String envElt = String.format("%s=\"%s\"",
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/ClasspathConstructor.java b/slider-core/src/main/java/org/apache/slider/core/launch/ClasspathConstructor.java
index 4b3297e..ee4c4d1 100644
--- a/slider-core/src/main/java/org/apache/slider/core/launch/ClasspathConstructor.java
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/ClasspathConstructor.java
@@ -40,7 +40,7 @@
// public static final String CLASS_PATH_SEPARATOR = ApplicationConstants.CLASS_PATH_SEPARATOR;
public static final String CLASS_PATH_SEPARATOR = File.pathSeparator;
- private final List<String> pathElements = new ArrayList<String>();
+ private final List<String> pathElements = new ArrayList<>();
public ClasspathConstructor() {
}
@@ -54,8 +54,8 @@
String[] cp = config.getTrimmedStrings(
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH);
- return cp!= null ? Arrays.asList(cp) : new ArrayList<String>(0);
-
+ return cp != null ? Arrays.asList(cp) : new ArrayList<String>(0);
+
}
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java b/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
index 013bff6..dbaa981 100644
--- a/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/CommandLineBuilder.java
@@ -30,12 +30,12 @@
* Special support for JVM command buildup.
*/
public class CommandLineBuilder {
- protected final List<String> argumentList = new ArrayList<String>(20);
+ protected final List<String> argumentList = new ArrayList<>(20);
/**
* Add an entry to the command list
- * @param arg argument -this will be converted to a string
+ * @param args arguments -these will be converted strings
*/
public void add(Object... args) {
for (Object arg : args) {
diff --git a/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java b/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
index 40bded0..8b68e9e 100644
--- a/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
+++ b/slider-core/src/main/java/org/apache/slider/core/main/ServiceLauncher.java
@@ -30,6 +30,7 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -86,7 +87,7 @@
private volatile S service;
private int serviceExitCode;
- private final List<IrqHandler> interruptHandlers = new ArrayList<IrqHandler>(1);
+ private final List<IrqHandler> interruptHandlers = new ArrayList<>(1);
private Configuration configuration;
private String serviceClassName;
private static AtomicBoolean signalAlreadyReceived = new AtomicBoolean(false);
@@ -217,14 +218,16 @@
ClassNotFoundException,
InstantiationException,
IllegalAccessException,
- ExitUtil.ExitException {
+ ExitUtil.ExitException,
+ NoSuchMethodException,
+ InvocationTargetException {
configuration = conf;
//Instantiate the class -this requires the service to have a public
// zero-argument constructor
Class<?> serviceClass =
this.getClass().getClassLoader().loadClass(serviceClassName);
- Object instance = serviceClass.newInstance();
+ Object instance = serviceClass.getConstructor().newInstance();
if (!(instance instanceof Service)) {
//not a service
throw new ExitUtil.ExitException(EXIT_BAD_CONFIGURATION,
@@ -341,7 +344,7 @@
/**
* Parse the command line, building a configuration from it, then
* launch the service and wait for it to finish. finally, exit
- * passing the status code to the {@link #exit(int)} method.
+ * passing the status code to the #exit(int) method.
* @param args arguments to the service. arg[0] is
* assumed to be the service classname and is automatically
*/
@@ -371,7 +374,7 @@
if (argCount <= 1 ) {
return new String[0];
}
- List<String> argsList = new ArrayList<String>(argCount);
+ List<String> argsList = new ArrayList<>(argCount);
ListIterator<String> arguments = args.listIterator();
//skip that first entry
arguments.next();
diff --git a/slider-core/src/main/java/org/apache/slider/core/main/ServiceShutdownHook.java b/slider-core/src/main/java/org/apache/slider/core/main/ServiceShutdownHook.java
index 96cfdb3..82e0e27 100644
--- a/slider-core/src/main/java/org/apache/slider/core/main/ServiceShutdownHook.java
+++ b/slider-core/src/main/java/org/apache/slider/core/main/ServiceShutdownHook.java
@@ -39,7 +39,7 @@
private Runnable hook;
public ServiceShutdownHook(Service service) {
- serviceRef = new WeakReference<Service>(service);
+ serviceRef = new WeakReference<>(service);
}
public void register(int priority) {
diff --git a/slider-core/src/main/java/org/apache/slider/core/persist/ConfPersister.java b/slider-core/src/main/java/org/apache/slider/core/persist/ConfPersister.java
index 7e5925a..60717f6 100644
--- a/slider-core/src/main/java/org/apache/slider/core/persist/ConfPersister.java
+++ b/slider-core/src/main/java/org/apache/slider/core/persist/ConfPersister.java
@@ -70,7 +70,7 @@
LoggerFactory.getLogger(ConfPersister.class);
- private final ConfTreeSerDeser confTreeSerDeser =new ConfTreeSerDeser();
+ private final ConfTreeSerDeser confTreeSerDeser = new ConfTreeSerDeser();
private final CoreFileSystem coreFS;
private final FileSystem fileSystem;
diff --git a/slider-core/src/main/java/org/apache/slider/core/registry/zk/ZKIntegration.java b/slider-core/src/main/java/org/apache/slider/core/registry/zk/ZKIntegration.java
index 7e044b5..c3ab0a5 100644
--- a/slider-core/src/main/java/org/apache/slider/core/registry/zk/ZKIntegration.java
+++ b/slider-core/src/main/java/org/apache/slider/core/registry/zk/ZKIntegration.java
@@ -198,7 +198,7 @@
CreateMode createMode) throws KeeperException, InterruptedException {
//initial create of full path
assert acl != null;
- assert acl.size() > 0;
+ assert !acl.isEmpty();
assert parent != null;
String path = parent;
if (entry != null) {
@@ -226,7 +226,7 @@
CreateMode createMode) throws KeeperException, InterruptedException {
String history = "/";
for (String entry : paths) {
- createPath(history, ((String) entry), acl, createMode);
+ createPath(history, entry, acl, createMode);
history = history + entry + "/";
}
}
@@ -236,7 +236,7 @@
* @return an unordered list of clusters under a user
*/
public List<String> getClusters() throws KeeperException, InterruptedException {
- return zookeeper.getChildren(userPath, (Watcher) null);
+ return zookeeper.getChildren(userPath, null);
}
/**
diff --git a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestSliderServiceUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestSliderServiceUtils.groovy
deleted file mode 100644
index b513e94..0000000
--- a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestSliderServiceUtils.groovy
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.slider.common.tools
-
-import groovy.util.logging.Slf4j
-import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl
-import org.apache.slider.core.launch.AMRestartSupport
-import org.apache.slider.test.SliderTestBase
-import org.junit.Test
-
-@Slf4j
-class TestSliderServiceUtils extends SliderTestBase {
-
- @Test
- public void testRetrieveContainers() throws Throwable {
- RegisterApplicationMasterResponsePBImpl registration = new RegisterApplicationMasterResponsePBImpl()
-
- def method = AMRestartSupport.retrieveContainersFromPreviousAttempt(
- registration)
- def hasMethod = method != null
- def containers = AMRestartSupport.retrieveContainersFromPreviousAttempt(
- registration)
- def success = containers != null;
-
- assert (hasMethod == success)
- log.info("AM container recovery support=$hasMethod")
- }
-}