You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/05/15 19:59:44 UTC
svn commit: r1594990 - in /incubator/slider/trunk:
slider-core/src/main/java/org/apache/slider/client/
slider-core/src/main/java/org/apache/slider/core/registry/info/
slider-core/src/main/java/org/apache/slider/server/appmaster/
slider-core/src/main/ja...
Author: stevel
Date: Thu May 15 17:59:43 2014
New Revision: 1594990
URL: http://svn.apache.org/r1594990
Log:
SLIDER-62 add functional test for registry entries against hbase provider
Modified:
incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java
incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java
incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy
incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
incubator/slider/trunk/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy
incubator/slider/trunk/src/site/markdown/manpage.md
Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/client/SliderClient.java Thu May 15 17:59:43 2014
@@ -1953,31 +1953,25 @@ public class SliderClient extends Abstra
// 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 @@ public class SliderClient extends Abstra
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);
}
Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/info/RegistryNaming.java Thu May 15 17:59:43 2014
@@ -26,7 +26,7 @@ import java.util.Locale;
*/
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 @@ public class RegistryNaming {
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);
Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java Thu May 15 17:59:43 2014
@@ -132,7 +132,6 @@ import java.util.Iterator;
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 @@ public class SliderAppMaster extends Abs
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);
Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/services/curator/RegistryBinderService.java Thu May 15 17:59:43 2014
@@ -27,18 +27,14 @@ import org.apache.curator.x.discovery.Se
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 class RegistryBinderService<Paylo
*/
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 @@ public class RegistryBinderService<Paylo
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 @@ public class RegistryBinderService<Paylo
* 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 @@ public class RegistryBinderService<Paylo
* @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);
Modified: incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy (original)
+++ incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy Thu May 15 17:59:43 2014
@@ -257,7 +257,7 @@ class TestStandaloneRegistryAM extends A
registryArgs.name = "unknown"
try {
client.actionRegistryList(registryArgs)
- } catch (UnknownApplicationInstanceException ignored) {
+ } catch (FileNotFoundException expected) {
// expected
}
@@ -267,10 +267,16 @@ class TestStandaloneRegistryAM extends A
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 @@ class TestStandaloneRegistryAM extends A
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
Modified: incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy (original)
+++ incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestLocalRegistry.groovy Thu May 15 17:59:43 2014
@@ -122,7 +122,7 @@ class TestLocalRegistry {
"bilbo",
SliderKeys.APP_TYPE);
String hobbitId =
- RegistryNaming.createUniqueInstanceId(
+ RegistryNaming.createRegistryName(
"hobbiton",
"bilbo",
SliderKeys.APP_TYPE,
@@ -131,7 +131,7 @@ class TestLocalRegistry {
"bilbo",
SliderKeys.APP_TYPE);
String mordorId =
- RegistryNaming.createUniqueInstanceId(
+ RegistryNaming.createRegistryName(
"mordor",
"bilbo",
SliderKeys.APP_TYPE,
Modified: incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy (original)
+++ incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy Thu May 15 17:59:43 2014
@@ -54,7 +54,7 @@ class TestRegistryRestResources extends
private String id(String instanceName) {
- RegistryNaming.createUniqueInstanceId(
+ RegistryNaming.createRegistryName(
instanceName,
UserGroupInformation.getCurrentUser().getUserName(),
SliderKeys.APP_TYPE,
Modified: incubator/slider/trunk/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy (original)
+++ incubator/slider/trunk/slider-providers/hbase/hbase-funtests/src/test/groovy/org/apache/slider/providers/hbase/funtest/TestFunctionalHBaseCluster.groovy Thu May 15 17:59:43 2014
@@ -26,12 +26,14 @@ import org.apache.slider.common.SliderKe
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 @@ public class TestFunctionalHBaseCluster
//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])
+
+
}
}
Modified: incubator/slider/trunk/src/site/markdown/manpage.md
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/src/site/markdown/manpage.md?rev=1594990&r1=1594989&r2=1594990&view=diff
==============================================================================
--- incubator/slider/trunk/src/site/markdown/manpage.md (original)
+++ incubator/slider/trunk/src/site/markdown/manpage.md Thu May 15 17:59:43 2014
@@ -367,7 +367,7 @@ There are two common exit codes, the exa
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)