YARN-913 move to revision 2 of APIs
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/0c05abe7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/0c05abe7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/0c05abe7 Branch: refs/heads/feature/SLIDER-149_Support_a_YARN_service_registry Commit: 0c05abe7f91bc52d6ac8e1ea1fd66636974b5970 Parents: 434a964 Author: Steve Loughran <ste...@apache.org> Authored: Mon Aug 25 16:08:52 2014 +0100 Committer: Steve Loughran <ste...@apache.org> Committed: Mon Aug 25 16:08:52 2014 +0100 ---------------------------------------------------------------------- .../org/apache/slider/client/SliderClient.java | 27 +++++----- .../server/appmaster/SliderAppMaster.java | 47 +++++++++++------ .../server/appmaster/web/SliderAMWebApp.java | 6 +-- .../utility/AbstractSliderLaunchedService.java | 20 ++++--- .../YarnRegistryViewForProviders.java | 55 +++++++++++++++----- .../standalone/TestStandaloneAgentAM.groovy | 2 +- 6 files changed, 102 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0c05abe7/slider-core/src/main/java/org/apache/slider/client/SliderClient.java ---------------------------------------------------------------------- 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 69d6a85..8fcda67 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 @@ -35,7 +35,7 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.registry.client.api.RegistryConstants; import org.apache.hadoop.yarn.registry.client.binding.ZKPathDumper; -import org.apache.hadoop.yarn.registry.client.draft1.RegistryWriterService; +import org.apache.hadoop.yarn.registry.client.services.RegistryOperationsService; import org.apache.slider.api.ClusterDescription; import org.apache.slider.api.ClusterNode; import org.apache.slider.api.InternalKeys; @@ -166,7 +166,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe /** * The YARN registry service */ - private RegistryWriterService yarnRegistry; + private RegistryOperationsService registryOperations; /** * Constructor @@ -1090,7 +1090,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe addMandatoryConfOptionToCLI(commandLine, config, RegistryConstants.REGISTRY_ZK_QUORUM); addMandatoryConfOptionToCLI(commandLine, config, REGISTRY_ZK_QUORUM); define(commandLine, RegistryConstants.REGISTRY_ZK_QUORUM, - getYarnRegistry().getCurrentZookeeperQuorum()); + getRegistryOperations().getCurrentZookeeperQuorum()); if (clusterSecure) { @@ -2484,23 +2484,21 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe * @throws SliderException * @throws IOException */ - private synchronized RegistryWriterService maybeStartYarnRegistry() throws - SliderException, - IOException { + private synchronized RegistryOperationsService maybeStartYarnRegistry() + throws SliderException, IOException { - if (yarnRegistry == null) { - yarnRegistry = startYarnRegistryService(); + if (registryOperations == null) { + registryOperations = startRegistryOperationsService(); } - return yarnRegistry; + return registryOperations; } /** * Get the YARN registry * @return the registry */ - public RegistryWriterService getYarnRegistry() throws - SliderException, - IOException { + public RegistryOperationsService getRegistryOperations() + throws SliderException, IOException { return maybeStartYarnRegistry(); } @@ -2510,8 +2508,9 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe * @return a class that can dump the contents of the registry */ @VisibleForTesting - public ZKPathDumper dumpYarnRegistry(boolean verbose) throws SliderException, IOException { - return getYarnRegistry().dumpPath(); + public ZKPathDumper dumpYarnRegistry(boolean verbose) + throws SliderException, IOException { + return getRegistryOperations().dumpPath(); } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0c05abe7/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java ---------------------------------------------------------------------- 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 c743812..835ef06 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 @@ -52,9 +52,10 @@ import org.apache.hadoop.yarn.client.api.async.impl.NMClientAsyncImpl; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.ipc.YarnRPC; +import org.apache.hadoop.yarn.registry.client.services.RegistryOperationsService; import org.apache.hadoop.yarn.registry.client.types.ServiceRecord; -import org.apache.hadoop.yarn.registry.client.draft1.RegistryWriterService; import org.apache.hadoop.yarn.registry.client.binding.RegistryTypeUtils; +import org.apache.hadoop.yarn.registry.server.services.ResourceManagerRegistryService; import org.apache.hadoop.yarn.security.AMRMTokenIdentifier; import org.apache.hadoop.yarn.security.client.ClientToAMTokenSecretManager; import org.apache.hadoop.yarn.util.ConverterUtils; @@ -331,7 +332,7 @@ public class SliderAppMaster extends AbstractSliderLaunchedService * The YARN registry service */ @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") - private RegistryWriterService yarnRegistry; + private RegistryOperationsService registryOperations; /** @@ -668,8 +669,8 @@ public class SliderAppMaster extends AbstractSliderLaunchedService log.info(registry.toString()); log.info("Starting Yarn registry"); - yarnRegistry = startYarnRegistryService(); - log.info(yarnRegistry.toString()); + registryOperations = startRegistryOperationsService(); + log.info(registryOperations.toString()); //build the role map List<ProviderRole> providerRoles = @@ -684,7 +685,7 @@ public class SliderAppMaster extends AbstractSliderLaunchedService startAgentWebApp(appInformation, serviceConf); - webApp = new SliderAMWebApp(registry, yarnRegistry); + webApp = new SliderAMWebApp(registry, registryOperations); WebApps.$for(SliderAMWebApp.BASE_PATH, WebAppApi.class, new WebAppApiImpl(this, stateForProviders, @@ -875,6 +876,8 @@ public class SliderAppMaster extends AbstractSliderLaunchedService */ private void registerServiceInstance(String instanceName, ApplicationId appid) throws Exception { + + // the registry is running, so register services URL amWebURI = new URL(appMasterTrackingUrl); URL agentOpsURI = new URL(agentOpsUrl); @@ -891,9 +894,10 @@ public class SliderAppMaster extends AbstractSliderLaunchedService //Give the provider restricted access to the state, registry + setupInitialRegistryPaths(); YarnRegistryViewForProviders yarnRegistryView = new YarnRegistryViewForProviders( - yarnRegistry, service_user_name, + registryOperations, service_user_name, SliderKeys.APP_TYPE, instanceName); providerService.bindToYarnRegistry(yarnRegistryView); @@ -945,26 +949,33 @@ public class SliderAppMaster extends AbstractSliderLaunchedService registry.registerSelf( instanceData, amWebURI ); - yarnRegistry.putServiceEntry(service_user_name, - SliderKeys.APP_TYPE, - instanceName, - serviceRecord ); - yarnRegistry.putServiceLiveness(service_user_name, + yarnRegistryView.putService(service_user_name, SliderKeys.APP_TYPE, instanceName, - true, - true); + serviceRecord); + // and an ephemeral binding to the app - yarnRegistry.putComponent(service_user_name, - SliderKeys.APP_TYPE, - instanceName, + yarnRegistryView.putComponent( "appmaster", serviceRecord, true); } + + @Override + protected RegistryOperationsService createRegistryOperationsInstance() { + return new ResourceManagerRegistryService("YarnRegistry"); + } + + protected void setupInitialRegistryPaths() throws IOException { + ResourceManagerRegistryService rmRegOperations = + (ResourceManagerRegistryService) registryOperations; + rmRegOperations.createUserPath(service_user_name); + } + /** + * Handler for {@link RegisterComponentInstance action} * Register/re-register a component (that is already in the app state * @param id the component */ @@ -980,6 +991,8 @@ public class SliderAppMaster extends AbstractSliderLaunchedService } /** + * Handler for {@link UnregisterComponentInstance} + * * unregister a component. At the time this message is received, * the component may already been deleted from/never added to * the app state @@ -988,7 +1001,7 @@ public class SliderAppMaster extends AbstractSliderLaunchedService public void unregisterComponent(ContainerId id) { log.info("Unregistering component {}", id); } - + /** * looks for a specific case where a token file is provided as an environment * variable, yet the file is not there. http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0c05abe7/slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java index 9e9b29c..36e1dad 100644 --- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java +++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/SliderAMWebApp.java @@ -22,7 +22,7 @@ import com.sun.jersey.api.core.ResourceConfig; import com.sun.jersey.guice.spi.container.servlet.GuiceContainer; import com.sun.jersey.spi.container.servlet.ServletContainer; import org.apache.curator.x.discovery.ServiceDiscovery; -import org.apache.hadoop.yarn.registry.client.draft1.RegistryWriterService; +import org.apache.hadoop.yarn.registry.client.services.RegistryOperationsService; import org.apache.hadoop.yarn.webapp.Dispatcher; import org.apache.hadoop.yarn.webapp.GenericExceptionHandler; import org.apache.hadoop.yarn.webapp.WebApp; @@ -49,11 +49,11 @@ public class SliderAMWebApp extends WebApp { public static final String CLUSTER_SPEC = "/spec"; public final SliderRegistryService registry; - private final RegistryWriterService yarnRegistry; + private final RegistryOperationsService yarnRegistry; public SliderAMWebApp(SliderRegistryService registry, - RegistryWriterService yarnRegistry) { + RegistryOperationsService yarnRegistry) { this.yarnRegistry = yarnRegistry; Preconditions.checkArgument(registry != null, "registry null"); this.registry = registry; http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0c05abe7/slider-core/src/main/java/org/apache/slider/server/services/utility/AbstractSliderLaunchedService.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/services/utility/AbstractSliderLaunchedService.java b/slider-core/src/main/java/org/apache/slider/server/services/utility/AbstractSliderLaunchedService.java index 33d3508..81ddfc2 100644 --- a/slider-core/src/main/java/org/apache/slider/server/services/utility/AbstractSliderLaunchedService.java +++ b/slider-core/src/main/java/org/apache/slider/server/services/utility/AbstractSliderLaunchedService.java @@ -22,7 +22,7 @@ package org.apache.slider.server.services.utility; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.registry.client.api.RegistryConstants; -import org.apache.hadoop.yarn.registry.client.draft1.RegistryWriterService; +import org.apache.hadoop.yarn.registry.client.services.RegistryOperationsService; import org.apache.slider.common.SliderXmlConfKeys; import org.apache.slider.common.tools.SliderUtils; import org.apache.slider.core.exceptions.BadCommandArgumentsException; @@ -114,20 +114,28 @@ public abstract class AbstractSliderLaunchedService extends * @param zkPath * @return */ - public RegistryWriterService startYarnRegistryService() + public RegistryOperationsService startRegistryOperationsService() throws BadConfigException { - Configuration conf = getConfig(); // push back the slider registry entry if needed String quorum = lookupZKQuorum(); - conf.set(RegistryConstants.REGISTRY_ZK_QUORUM, quorum); - RegistryWriterService registryWriterService = - new RegistryWriterService("YarnRegistry"); + getConfig().set(RegistryConstants.REGISTRY_ZK_QUORUM, quorum); + RegistryOperationsService registryWriterService = + createRegistryOperationsInstance(); deployChildService(registryWriterService); return registryWriterService; } /** + * Create the registry operations instance. This is to allow + * subclasses to instantiate a subclass service + * @return an instance to match to the lifecycle of this service + */ + protected RegistryOperationsService createRegistryOperationsInstance() { + return new RegistryOperationsService("YarnRegistry"); + } + + /** * Utility method to require an argument to be set (non null, non-empty) * @param argname argument name * @param value value http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0c05abe7/slider-core/src/main/java/org/apache/slider/server/services/yarnregistry/YarnRegistryViewForProviders.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/server/services/yarnregistry/YarnRegistryViewForProviders.java b/slider-core/src/main/java/org/apache/slider/server/services/yarnregistry/YarnRegistryViewForProviders.java index 955c355..adf15b0 100644 --- a/slider-core/src/main/java/org/apache/slider/server/services/yarnregistry/YarnRegistryViewForProviders.java +++ b/slider-core/src/main/java/org/apache/slider/server/services/yarnregistry/YarnRegistryViewForProviders.java @@ -18,23 +18,26 @@ package org.apache.slider.server.services.yarnregistry; -import org.apache.hadoop.yarn.registry.client.draft1.RegistryWriter; +import org.apache.hadoop.yarn.registry.client.binding.BindingUtils; +import org.apache.hadoop.yarn.registry.client.binding.RegistryZKUtils; +import org.apache.hadoop.yarn.registry.client.services.RegistryOperationsService; +import org.apache.hadoop.yarn.registry.client.types.CreateFlags; import org.apache.hadoop.yarn.registry.client.types.ServiceRecord; import java.io.IOException; public class YarnRegistryViewForProviders { - private final RegistryWriter registryWriter; + private final RegistryOperationsService registryOperations; private final String user; private final String sliderServiceclass; private final String instanceName; - public YarnRegistryViewForProviders(RegistryWriter registryWriter, + public YarnRegistryViewForProviders(RegistryOperationsService registryOperations, String user, String sliderServiceclass, String instanceName) { - this.registryWriter = registryWriter; + this.registryOperations = registryOperations; this.user = user; this.sliderServiceclass = sliderServiceclass; this.instanceName = instanceName; @@ -52,8 +55,8 @@ public class YarnRegistryViewForProviders { return instanceName; } - public RegistryWriter getRegistryWriter() { - return registryWriter; + public RegistryOperationsService getRegistryOperationsService() { + return registryOperations; } /** @@ -67,26 +70,50 @@ public class YarnRegistryViewForProviders { ServiceRecord entry, boolean ephemeral) throws IOException { - registryWriter.putComponent(user, sliderServiceclass, instanceName, + putComponent(sliderServiceclass, instanceName, componentName, entry, ephemeral); } /** - * Add a component under the slider name/entry + * Add a component * @param componentName - * @param entry + * @param record * @param ephemeral * @throws IOException */ public void putComponent(String serviceClass, String serviceName, - String componentName, ServiceRecord entry, boolean ephemeral) throws - IOException { - registryWriter.putComponent(user, serviceClass, serviceName, componentName, - entry, - ephemeral); + String componentName, + ServiceRecord record, + boolean ephemeral) throws IOException { + String path = BindingUtils.componentPath( + user, serviceClass, serviceName, componentName); + registryOperations.mkdir(RegistryZKUtils.parentOf(path), true); + registryOperations.create(path, record, + CreateFlags.OVERWRITE + + (ephemeral ? CreateFlags.EPHEMERAL : 0)); + } + + + /** + * Add a service under + * @param componentName + * @param record + * @param ephemeral + * @throws IOException + */ + public void putService(String username, + String serviceClass, + String serviceName, + ServiceRecord record) throws IOException { + + String path = BindingUtils.servicePath( + username, serviceClass, serviceName); + registryOperations.mkdir(RegistryZKUtils.parentOf(path), true); + registryOperations.create(path, record, CreateFlags.OVERWRITE); + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0c05abe7/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentAM.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentAM.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentAM.groovy index 794a3f2..8b29867 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentAM.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAgentAM.groovy @@ -114,7 +114,7 @@ class TestStandaloneAgentAM extends AgentMiniClusterTestBase { describe "end list service registry slider instances" describe "Yarn registry" - def yarnRegistry = client.yarnRegistry + def yarnRegistry = client.registryOperations describe "teardown of cluster instance #1" //now kill that cluster