SLIDER-62 add functional test for registry entries against hbase provider
git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1594990 13f79535-47bb-0310-9956-ffa450edef68
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 1b71234..bd9ff7c 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
@@ -1953,31 +1953,25 @@
// as this is also a test entry point, validate
// the arguments
registryArgs.validate();
- if (registryArgs.list) {
- actionRegistryList(registryArgs);
- } else if (registryArgs.listConf) {
- // list the configurations
- try {
+ try {
+ if (registryArgs.list) {
+ actionRegistryList(registryArgs);
+ } else if (registryArgs.listConf) {
+ // list the configurations
actionRegistryListConfigs(registryArgs);
- } catch (FileNotFoundException e) {
- return EXIT_NOT_FOUND;
- }
- } else if (SliderUtils.isSet(registryArgs.getConf)) {
- // get a configuration
- try {
+ } else if (SliderUtils.isSet(registryArgs.getConf)) {
+ // get a configuration
PublishedConfiguration publishedConfiguration =
actionRegistryGetConfig(registryArgs);
outputConfig(publishedConfiguration, registryArgs);
- } catch (FileNotFoundException e) {
- //there's no configuration here, so raise an error
- throw new SliderException(EXIT_NOT_FOUND, e,
- "Unknown configuration \"%s\"",
- registryArgs.getConf);
+ } else {
+ // it's an unknown command
+ throw new BadCommandArgumentsException(
+ "Bad command arguments for " + ACTION_REGISTRY + " " +
+ registryArgs);
}
- } else {
- // it's an unknown command
- throw new BadCommandArgumentsException(
- "Bad command arguments for "+ ACTION_REGISTRY +" " + registryArgs);
+ } catch (FileNotFoundException e) {
+ return EXIT_NOT_FOUND;
}
return EXIT_SUCCESS;
}
@@ -1995,13 +1989,19 @@
ActionRegistryArgs registryArgs)
throws YarnException, IOException {
SliderRegistryService registryService = getRegistry();
+ String serviceType = registryArgs.serviceType;
+ String name = registryArgs.name;
List<CuratorServiceInstance<ServiceInstanceData>> instances =
- registryService.findInstances(registryArgs.serviceType, registryArgs.name
- );
- List<ServiceInstanceData> sids = new ArrayList<>(instances.size());
+ registryService.findInstances(serviceType, name);
+ int size = instances.size();
+ if (size == 0) {
+ throw new FileNotFoundException("No entries for servicetype "
+ + serviceType
+ + " name " + name);
+ }
+ List<ServiceInstanceData> sids = new ArrayList<>(size);
for (CuratorServiceInstance<ServiceInstanceData> instance : instances) {
ServiceInstanceData payload = instance.payload;
-
logInstance(payload, registryArgs.verbose);
sids.add(payload);
}
diff --git a/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java b/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java
index e55a2a9..bd5cf27 100644
--- a/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java
+++ b/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java
@@ -26,7 +26,7 @@
*/
public class RegistryNaming {
- public static String SLIDER_INSTANCE_NAME_FORMAT = "%s-%s";
+ public static String SLIDER_INSTANCE_NAME_FORMAT = "%2$s";
public static String createRegistryServiceType(String instanceName,
String userName,
@@ -34,12 +34,13 @@
return serviceName;
}
- public static String createUniqueInstanceId(String instanceName,
- String userName,
- String serviceName,
- int appId) {
+ public static String createRegistryName(String instanceName,
+ String userName,
+ String serviceName,
+ int appId) {
return String.format(Locale.ENGLISH,
- SLIDER_INSTANCE_NAME_FORMAT, userName,
+ SLIDER_INSTANCE_NAME_FORMAT,
+ userName,
instanceName,
serviceName,
appId);
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
index f2b55c6..0e3bd28 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
@@ -132,7 +132,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@@ -707,7 +706,8 @@
service_user_name,
serviceName);
String registryId =
- RegistryNaming.createUniqueInstanceId(instanceName, service_user_name, serviceName, id);
+ RegistryNaming.createRegistryName(instanceName, service_user_name,
+ serviceName, id);
List<String> serviceInstancesRunning = registry.instanceIDs(serviceName);
log.info("service instances already running: {}", serviceInstancesRunning);
diff --git a/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java b/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java
index 72b7400..db6b2ed 100644
--- a/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java
+++ b/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java
@@ -27,18 +27,14 @@
import org.apache.curator.x.discovery.ServiceInstanceBuilder;
import org.apache.curator.x.discovery.ServiceType;
import org.apache.curator.x.discovery.UriSpec;
-import org.apache.hadoop.yarn.exceptions.YarnException;
-import org.apache.slider.common.params.ActionRegistryArgs;
-import org.apache.slider.common.tools.SliderUtils;
import org.apache.slider.core.exceptions.BadClusterStateException;
import org.apache.slider.core.exceptions.UnknownApplicationInstanceException;
import org.apache.slider.core.persist.JsonSerDeser;
-import org.apache.slider.core.registry.info.ServiceInstanceData;
-import org.apache.slider.server.services.registry.SliderRegistryService;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -191,15 +187,17 @@
*/
public CuratorServiceInstance<Payload> queryForInstance(String servicetype, String id) throws
Exception {
-
+ CuratorServiceInstance<Payload> instance = null;
String path = pathForInstance(servicetype, id);
try {
byte[] bytes = getCurator().getData().forPath(path);
- return deser.fromBytes(bytes);
+ if (bytes!=null && bytes.length>0) {
+ instance = deser.fromBytes(bytes);
+ }
} catch (KeeperException.NoNodeException ignore) {
// ignore
}
- return null;
+ return instance;
}
/**
@@ -217,7 +215,9 @@
for (String instanceID : instanceIDs) {
CuratorServiceInstance<Payload> instance =
queryForInstance(servicetype, instanceID);
- instances.add(instance);
+ if (instance != null) {
+ instances.add(instance);
+ }
}
return instances;
} catch (IOException e) {
@@ -231,7 +231,7 @@
* Find an instance with a given ID
* @param instances instances
* @param name ID to look for
- * @return
+ * @return the discovered instance or null
*/
public CuratorServiceInstance<Payload> findByID(List<CuratorServiceInstance<Payload>> instances, String name) {
Preconditions.checkNotNull(name);
@@ -249,26 +249,24 @@
* @param serviceType service type
* @param name an optional name
* @return the (non-empty) list of instances that match the criteria
- * @throws UnknownApplicationInstanceException if there were no matches
- * @throws IOException
+ * @throws FileNotFoundException if there were no matches
+ * @throws IOException any network problem
*/
public List<CuratorServiceInstance<Payload>> findInstances(String serviceType,
String name)
- throws UnknownApplicationInstanceException, IOException {
+ throws FileNotFoundException, IOException {
List<CuratorServiceInstance<Payload>> instances =
listInstances(serviceType);
if (instances.isEmpty()) {
- throw new UnknownApplicationInstanceException(
- "No registry entries for service type %s",
- serviceType);
+ throw new FileNotFoundException(
+ "No registry entries for service type " + serviceType);
}
if (StringUtils.isNotEmpty(name)) {
CuratorServiceInstance<Payload> foundInstance = findByID(instances, name);
if (foundInstance == null) {
- throw new UnknownApplicationInstanceException(
- "No registry entries for service name %s of service type %s",
- name,
- serviceType);
+ throw new FileNotFoundException(
+ "No registry entries for service name " + name
+ + " and service type " + serviceType);
}
instances.clear();
instances.add(foundInstance);
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
index 2897c9c..182939a 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
@@ -257,7 +257,7 @@
registryArgs.name = "unknown"
try {
client.actionRegistryList(registryArgs)
- } catch (UnknownApplicationInstanceException ignored) {
+ } catch (FileNotFoundException expected) {
// expected
}
@@ -267,10 +267,16 @@
registryArgs.serviceType = "org.apache.hadoop"
try {
client.actionRegistryList(registryArgs)
- } catch (UnknownApplicationInstanceException ignored) {
+ } catch (FileNotFoundException expected) {
// expected
}
+ registryArgs.serviceType = ""
+ try {
+ client.actionRegistryList(registryArgs)
+ } catch (FileNotFoundException expected) {
+ // expected
+ }
//set the name
registryArgs.name = serviceInstanceData.id;
registryArgs.serviceType = SliderKeys.APP_TYPE
@@ -325,14 +331,7 @@
def unknownFilename = "undefined-file"
registryArgs.getConf = unknownFilename
- try {
- client.actionRegistry(registryArgs)
- fail("attempt to retrieve the file $unknownFilename succeeded")
- } catch (SliderException expected) {
- assertExceptionDetails(expected, SliderExitCodes.EXIT_NOT_FOUND,
- unknownFilename)
- }
-
+ assert SliderExitCodes.EXIT_NOT_FOUND == client.actionRegistry(registryArgs)
describe "freeze cluster"
//now kill that cluster
diff --git a/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy b/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy
index 9b15903..f750f84 100644
--- a/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy
@@ -122,7 +122,7 @@
"bilbo",
SliderKeys.APP_TYPE);
String hobbitId =
- RegistryNaming.createUniqueInstanceId(
+ RegistryNaming.createRegistryName(
"hobbiton",
"bilbo",
SliderKeys.APP_TYPE,
@@ -131,7 +131,7 @@
"bilbo",
SliderKeys.APP_TYPE);
String mordorId =
- RegistryNaming.createUniqueInstanceId(
+ RegistryNaming.createRegistryName(
"mordor",
"bilbo",
SliderKeys.APP_TYPE,
diff --git a/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy b/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
index 4dba0bd..df5c23b 100644
--- a/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
@@ -54,7 +54,7 @@
private String id(String instanceName) {
- RegistryNaming.createUniqueInstanceId(
+ RegistryNaming.createRegistryName(
instanceName,
UserGroupInformation.getCurrentUser().getUserName(),
SliderKeys.APP_TYPE,
diff --git a/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy b/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy
index 30c423b..4c5a1b1 100644
--- a/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy
+++ b/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy
@@ -26,12 +26,14 @@
import org.apache.slider.common.SliderXmlConfKeys
import org.apache.slider.api.ClusterDescription
import org.apache.slider.api.RoleKeys
+import org.apache.slider.core.registry.info.RegistryNaming
import org.apache.slider.funtest.framework.FuntestProperties
import org.apache.slider.common.tools.ConfigHelper
import org.apache.slider.common.params.Arguments
import org.apache.slider.client.SliderClient
import org.apache.slider.providers.hbase.HBaseConfigFileOptions
import org.apache.slider.providers.hbase.HBaseTestUtils
+import org.apache.slider.server.appmaster.PublishedArtifacts
import org.apache.zookeeper.*
import org.junit.After
import org.junit.Before
@@ -165,11 +167,39 @@
//grab some registry bits
registry([ARG_LIST])
- registry([ARG_LIST, ARG_SERVICETYPE, SliderKeys.APP_TYPE ])
- registry([ARG_LIST, ARG_SERVICETYPE, ""])
- registry([ARG_LIST, ARG_SERVICETYPE, ""])
+ registry([ARG_LIST, ARG_SERVICETYPE, SliderKeys.APP_TYPE , ARG_VERBOSE])
+ //unknown service type
+ registry(EXIT_NOT_FOUND,
+ [ARG_LIST, ARG_SERVICETYPE, "org.apache.something"])
+ registry(EXIT_NOT_FOUND,
+ [ARG_LIST, ARG_SERVICETYPE, ""])
+
+ registry(EXIT_NOT_FOUND,
+ [ARG_LIST, ARG_NAME, "cluster-with-no-name"])
+
+ // how to work out the current service name?
+ def name = RegistryNaming.createRegistryName(clustername,
+ System.getProperty("user.name"),
+ SliderKeys.APP_TYPE,
+ 1)
+ registry([ARG_LIST, ARG_VERBOSE, ARG_NAME, name])
+ registry([ARG_LISTCONF, ARG_NAME, name])
+ registry(EXIT_NOT_FOUND, [ARG_LISTCONF, ARG_NAME, name, ARG_INTERNAL])
+ registry(EXIT_NOT_FOUND, [ARG_LISTCONF, ARG_NAME, "unknown"])
+ registry([ARG_GETCONF, PublishedArtifacts.COMPLETE_CONFIG,
+ ARG_NAME, name])
+ registry([ARG_GETCONF, "no-such-config",
+ ARG_NAME, name])
+
+ registry([ARG_GETCONF, "illegal config name!",
+ ARG_NAME, name])
+
+ registry(EXIT_NOT_FOUND,[ARG_GETCONF, PublishedArtifacts.COMPLETE_CONFIG,
+ ARG_NAME, name, ARG_INTERNAL])
+
+
}
}
diff --git a/src/site/markdown/manpage.md b/src/site/markdown/manpage.md
index 228a020..6dc94cb 100644
--- a/src/site/markdown/manpage.md
+++ b/src/site/markdown/manpage.md
@@ -367,7 +367,7 @@
in [Exit Codes](exitcodes.md)
1. If there is no matching service then the operation fails with the
-`EXIT_UNKNOWN_INSTANCE` code (70).
+`EXIT_NOT_FOUND` code (77).
2. If there are no configurations in a listing, or the named configuration
is not found, the command returns the exit code `EXIT_NOT_FOUND` (77)