SLIDER-35 providers to publish registry information -slider AM publishes its (existing) registration info from a new provider
git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1595950 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/providers/AbstractProviderService.java b/slider-core/src/main/java/org/apache/slider/providers/AbstractProviderService.java
index df97226..2c82b15 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/AbstractProviderService.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/AbstractProviderService.java
@@ -30,15 +30,8 @@
import org.apache.slider.core.main.ExitCodeProvider;
import org.apache.slider.core.registry.info.RegisteredEndpoint;
import org.apache.slider.core.registry.info.ServiceInstanceData;
-import org.apache.slider.providers.agent.AgentProviderService;
import org.apache.slider.server.appmaster.state.StateAccessForProviders;
import org.apache.slider.server.appmaster.web.rest.agent.AgentRestOperations;
-import org.apache.slider.server.appmaster.web.rest.agent.HeartBeat;
-import org.apache.slider.server.appmaster.web.rest.agent.HeartBeatResponse;
-import org.apache.slider.server.appmaster.web.rest.agent.Register;
-import org.apache.slider.server.appmaster.web.rest.agent.RegistrationResponse;
-import org.apache.slider.server.appmaster.web.rest.agent.RegistrationStatus;
-import org.apache.slider.server.services.curator.RegistryBinderService;
import org.apache.slider.server.services.registry.RegistryViewForProviders;
import org.apache.slider.server.services.utility.ForkedProcessService;
import org.apache.slider.server.services.utility.Parent;
@@ -51,7 +44,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -271,7 +263,7 @@
*/
@Override
public Map<String, String> buildProviderStatus() {
- return new HashMap<String, String>();
+ return new HashMap<>();
}
/*
@@ -311,4 +303,11 @@
}
}
}
+ @Override
+ public void applyInitialRegistryDefinitions(URL amWebAPI,
+ ServiceInstanceData registryInstanceData) throws MalformedURLException,
+ IOException {
+
+ //no-op
+ }
}
diff --git a/slider-core/src/main/java/org/apache/slider/providers/ProviderService.java b/slider-core/src/main/java/org/apache/slider/providers/ProviderService.java
index 15e19b8..47a8cc3 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/ProviderService.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/ProviderService.java
@@ -39,6 +39,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
@@ -154,4 +155,13 @@
* @param details
*/
void buildEndpointDetails(Map<String, String> details);
+
+ /**
+ * Prior to going live -register the initial service registry data
+ * @param amWebAPI
+ * @param registryInstanceData
+ */
+ void applyInitialRegistryDefinitions(URL amWebAPI,
+ ServiceInstanceData registryInstanceData) throws MalformedURLException,
+ IOException;
}
diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java
index 656a3fe..8435c4e 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java
@@ -41,6 +41,7 @@
import org.apache.slider.core.launch.CommandLineBuilder;
import org.apache.slider.core.launch.ContainerLauncher;
import org.apache.slider.core.registry.docstore.PublishedConfiguration;
+import org.apache.slider.core.registry.info.CustomRegistryConstants;
import org.apache.slider.core.registry.info.RegisteredEndpoint;
import org.apache.slider.core.registry.info.ServiceInstanceData;
import org.apache.slider.providers.AbstractProviderService;
@@ -51,7 +52,6 @@
import org.apache.slider.providers.agent.application.metadata.Export;
import org.apache.slider.providers.agent.application.metadata.ExportGroup;
import org.apache.slider.providers.agent.application.metadata.Metainfo;
-import org.apache.slider.providers.agent.application.metadata.MetainfoParser;
import org.apache.slider.providers.agent.application.metadata.Service;
import org.apache.slider.server.appmaster.state.StateAccessForProviders;
import org.apache.slider.server.appmaster.web.rest.agent.AgentCommandType;
@@ -71,22 +71,23 @@
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_AGENTS;
+
/** This class implements the server-side aspects of an agent deployment */
public class AgentProviderService extends AbstractProviderService implements
ProviderCore,
@@ -752,4 +753,20 @@
}
}
+ @Override
+ public void applyInitialRegistryDefinitions(URL amWebAPI,
+ ServiceInstanceData instanceData) throws IOException {
+ super.applyInitialRegistryDefinitions(amWebAPI, instanceData);
+
+ try {
+ instanceData.internalView.endpoints.put(
+ CustomRegistryConstants.AGENT_REST_API,
+ new RegisteredEndpoint(
+ new URL(amWebAPI, SLIDER_PATH_AGENTS),
+ "Agent REST API") );
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+
+ }
}
diff --git a/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMProviderService.java b/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMProviderService.java
new file mode 100644
index 0000000..bf6ddd0
--- /dev/null
+++ b/slider-core/src/main/java/org/apache/slider/providers/slideram/SliderAMProviderService.java
@@ -0,0 +1,191 @@
+/*
+ * 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.providers.slideram;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.yarn.api.records.Container;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.slider.common.SliderKeys;
+import org.apache.slider.common.tools.ConfigHelper;
+import org.apache.slider.common.tools.SliderFileSystem;
+import org.apache.slider.core.conf.AggregateConf;
+import org.apache.slider.core.conf.MapOperations;
+import org.apache.slider.core.exceptions.BadCommandArgumentsException;
+import org.apache.slider.core.exceptions.SliderException;
+import org.apache.slider.core.launch.ContainerLauncher;
+import org.apache.slider.core.registry.docstore.PublishedConfiguration;
+import org.apache.slider.core.registry.info.CommonRegistryConstants;
+import org.apache.slider.core.registry.info.CustomRegistryConstants;
+import org.apache.slider.core.registry.info.RegisteredEndpoint;
+import org.apache.slider.core.registry.info.RegistryView;
+import org.apache.slider.core.registry.info.ServiceInstanceData;
+import org.apache.slider.providers.AbstractProviderService;
+import org.apache.slider.providers.ProviderCore;
+import org.apache.slider.providers.ProviderRole;
+import org.apache.slider.providers.agent.AgentKeys;
+import org.apache.slider.server.appmaster.PublishedArtifacts;
+import org.apache.slider.server.appmaster.state.StateAccessForProviders;
+import org.apache.slider.server.appmaster.web.rest.RestPaths;
+import org.apache.slider.server.services.utility.EventCallback;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_AGENTS;
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_MANAGEMENT;
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_PUBLISHER;
+
+/**
+ * Exists just to move some functionality out of AppMaster into a peer class
+ * of the actual service provider doing the real work
+ */
+public class SliderAMProviderService extends AbstractProviderService implements
+ ProviderCore,
+ AgentKeys,
+ SliderKeys {
+
+ public SliderAMProviderService() {
+ super("SliderAMProviderService");
+ }
+
+ @Override
+ public Configuration loadProviderConfigurationInformation(File confDir) throws
+ BadCommandArgumentsException,
+ IOException {
+ return null;
+ }
+
+ @Override
+ public void buildContainerLaunchContext(ContainerLauncher containerLauncher,
+ AggregateConf instanceDefinition,
+ Container container,
+ String role,
+ SliderFileSystem sliderFileSystem,
+ Path generatedConfPath,
+ MapOperations resourceComponent,
+ MapOperations appComponent,
+ Path containerTmpDirPath) throws IOException, SliderException {
+
+ }
+
+ @Override
+ public boolean exec(AggregateConf instanceDefinition,
+ File confDir,
+ Map<String, String> env,
+ EventCallback execInProgress) throws IOException, SliderException {
+ return false;
+ }
+
+ @Override
+ public List<ProviderRole> getRoles() {
+ return new ArrayList<>(0);
+ }
+
+ @Override
+ public void validateInstanceDefinition(AggregateConf instanceDefinition) throws
+ SliderException {
+
+ }
+
+ @Override
+ public void applyInitialRegistryDefinitions(URL amWebAPI,
+ ServiceInstanceData instanceData) throws IOException {
+ super.applyInitialRegistryDefinitions(amWebAPI, instanceData);
+
+ // now publish site.xml files
+ YarnConfiguration defaultYarnConfig = new YarnConfiguration();
+ stateAccessor.getPublishedConfigurations().put(
+ PublishedArtifacts.COMPLETE_CONFIG,
+ new PublishedConfiguration(
+ "Complete slider application settings",
+ getConfig(), getConfig())
+ );
+ stateAccessor.getPublishedConfigurations().put(
+ PublishedArtifacts.YARN_SITE_CONFIG,
+ new PublishedConfiguration(
+ "YARN site settings",
+ ConfigHelper.loadFromResource("yarn-site.xml"),
+ defaultYarnConfig)
+ );
+
+ stateAccessor.getPublishedConfigurations().put(
+ PublishedArtifacts.CORE_SITE_CONFIG,
+ new PublishedConfiguration(
+ "Core site settings",
+ ConfigHelper.loadFromResource("core-site.xml"),
+ defaultYarnConfig)
+ );
+ stateAccessor.getPublishedConfigurations().put(
+ PublishedArtifacts.HDFS_SITE_CONFIG,
+ new PublishedConfiguration(
+ "HDFS site settings",
+ ConfigHelper.loadFromResource("hdfs-site.xml"),
+ new HdfsConfiguration(true))
+ );
+
+
+ try {
+ RegistryView externalView = instanceData.externalView;
+ RegisteredEndpoint webUI =
+ new RegisteredEndpoint(amWebAPI, "Application Master Web UI");
+
+ externalView.endpoints.put(CommonRegistryConstants.WEB_UI, webUI);
+
+ externalView.endpoints.put(
+ CustomRegistryConstants.MANAGEMENT_REST_API,
+ new RegisteredEndpoint(
+ new URL(amWebAPI, SLIDER_PATH_MANAGEMENT),
+ "Management REST API")
+ );
+
+ externalView.endpoints.put(
+ CustomRegistryConstants.REGISTRY_REST_API,
+ new RegisteredEndpoint(
+ new URL(amWebAPI, RestPaths.SLIDER_PATH_REGISTRY + "/" +
+ RestPaths.REGISTRY_SERVICE),
+ "Registry Web Service"
+ )
+ );
+
+ URL publisherURL = new URL(amWebAPI, SLIDER_PATH_PUBLISHER);
+ externalView.endpoints.put(
+ CustomRegistryConstants.PUBLISHER_REST_API,
+ new RegisteredEndpoint(
+ publisherURL,
+ "Publisher Service")
+ );
+
+ /*
+ * Set the configurations URL.
+ */
+ externalView.configurationsURL = publisherURL.toExternalForm();
+
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+
+ }
+}
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 63983ea..f72f507 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
@@ -23,7 +23,6 @@
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys;
-import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.ipc.ProtocolSignature;
import org.apache.hadoop.security.Credentials;
@@ -85,16 +84,15 @@
import org.apache.slider.core.main.RunService;
import org.apache.slider.core.main.ServiceLauncher;
import org.apache.slider.core.persist.ConfTreeSerDeser;
-import org.apache.slider.core.registry.docstore.PublishedConfiguration;
-import org.apache.slider.core.registry.info.CommonRegistryConstants;
import org.apache.slider.core.registry.info.CustomRegistryConstants;
import org.apache.slider.core.registry.info.RegisteredEndpoint;
-import org.apache.slider.core.registry.info.RegistryView;
+import org.apache.slider.core.registry.info.RegistryNaming;
import org.apache.slider.core.registry.info.ServiceInstanceData;
import org.apache.slider.providers.ProviderRole;
import org.apache.slider.providers.ProviderService;
import org.apache.slider.providers.SliderProviderFactory;
import org.apache.slider.providers.slideram.SliderAMClientProvider;
+import org.apache.slider.providers.slideram.SliderAMProviderService;
import org.apache.slider.server.appmaster.rpc.RpcBinder;
import org.apache.slider.server.appmaster.rpc.SliderAMPolicyProvider;
import org.apache.slider.server.appmaster.rpc.SliderClusterProtocolPBImpl;
@@ -111,7 +109,6 @@
import org.apache.slider.server.appmaster.web.WebAppApi;
import org.apache.slider.server.appmaster.web.WebAppApiImpl;
import org.apache.slider.server.appmaster.web.rest.RestPaths;
-import org.apache.slider.core.registry.info.RegistryNaming;
import org.apache.slider.server.services.registry.SliderRegistryService;
import org.apache.slider.server.services.utility.AbstractSliderLaunchedService;
import org.apache.slider.server.services.utility.EventCallback;
@@ -137,9 +134,6 @@
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
-import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_AGENTS;
-import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_MANAGEMENT;
-import static org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_PUBLISHER;
import static org.apache.slider.server.appmaster.web.rest.RestPaths.WS_CONTEXT_ROOT;
/**
@@ -286,6 +280,7 @@
private SliderAMWebApp webApp;
private InetSocketAddress rpcServiceAddress;
+ private ProviderService sliderAMProvider;
/**
* Service Constructor
@@ -461,6 +456,9 @@
providerService = factory.createServerProvider();
// init the provider BUT DO NOT START IT YET
initAndAddService(providerService);
+ // create a slider AM provider
+ sliderAMProvider = new SliderAMProviderService();
+ initAndAddService(sliderAMProvider);
InetSocketAddress address = SliderUtils.getRmSchedulerAddress(conf);
log.info("RM is at {}", address);
@@ -553,13 +551,11 @@
//registry
-
-
registry = startRegistrationService();
//build the role map
List<ProviderRole> providerRoles =
- new ArrayList<ProviderRole>(providerService.getRoles());
+ new ArrayList<>(providerService.getRoles());
providerRoles.addAll(SliderAMClientProvider.ROLES);
// Start up the WebApp and track the URL for it
@@ -670,9 +666,15 @@
//Give the provider restricted access to the state, registry
providerService.bind(appState, registry);
+ sliderAMProvider.bind(appState, registry);
+
+ // now do the registration
registerServiceInstance(clustername, appid);
+ sliderAMProvider.start();
+
+
// launch the provider; this is expected to trigger a callback that
// starts the node review process
launchProviderService(instanceDefinition, confDir);
@@ -699,7 +701,7 @@
private void registerServiceInstance(String instanceName,
ApplicationId appid) throws Exception {
// the registry is running, so register services
- URL amWeb = new URL(appMasterTrackingUrl);
+ URL amWebAPI = new URL(appMasterTrackingUrl);
String serviceName = SliderKeys.APP_TYPE;
int id = appid.getId();
String appServiceType = RegistryNaming.createRegistryServiceType(
@@ -713,98 +715,34 @@
List<String> serviceInstancesRunning = registry.instanceIDs(serviceName);
log.info("service instances already running: {}", serviceInstancesRunning);
-
- // now publish site.xml files
- YarnConfiguration defaultYarnConfig = new YarnConfiguration();
- appState.getPublishedConfigurations().put(
- PublishedArtifacts.COMPLETE_CONFIG,
- new PublishedConfiguration(
- "Complete slider application settings",
- getConfig(), getConfig()));
- appState.getPublishedConfigurations().put(
- PublishedArtifacts.YARN_SITE_CONFIG,
- new PublishedConfiguration(
- "YARN site settings",
- ConfigHelper.loadFromResource("yarn-site.xml"),
- defaultYarnConfig));
-
- appState.getPublishedConfigurations().put(
- PublishedArtifacts.CORE_SITE_CONFIG,
- new PublishedConfiguration(
- "Core site settings",
- ConfigHelper.loadFromResource("core-site.xml"),
- defaultYarnConfig));
- appState.getPublishedConfigurations().put(
- PublishedArtifacts.HDFS_SITE_CONFIG,
- new PublishedConfiguration(
- "HDFS site settings",
- ConfigHelper.loadFromResource("hdfs-site.xml"),
- new HdfsConfiguration(true)));
-
ServiceInstanceData instanceData = new ServiceInstanceData();
instanceData.id = registryId;
instanceData.serviceType = appServiceType;
- RegisteredEndpoint webUI =
- new RegisteredEndpoint(amWeb, "Application Master Web UI");
-
-
- // public REST services
-
- RegistryView externalView = instanceData.externalView;
- externalView.endpoints.put(CommonRegistryConstants.WEB_UI, webUI);
-
- externalView.endpoints.put(
- CustomRegistryConstants.MANAGEMENT_REST_API,
- new RegisteredEndpoint(
- new URL(amWeb, SLIDER_PATH_MANAGEMENT),
- "Management REST API" )
- );
-
- externalView.endpoints.put(
- CustomRegistryConstants.REGISTRY_REST_API,
- new RegisteredEndpoint(
- new URL(amWeb, RestPaths.SLIDER_PATH_REGISTRY + "/"+
- RestPaths.REGISTRY_SERVICE),
- "Registry Web Service" )
- );
-
- URL publisherURL = new URL(amWeb, SLIDER_PATH_PUBLISHER);
- externalView.endpoints.put(
- CustomRegistryConstants.PUBLISHER_REST_API,
- new RegisteredEndpoint(
- publisherURL,
- "Publisher Service" )
- );
// IPC services
- externalView.endpoints.put(
+ instanceData.externalView.endpoints.put(
CustomRegistryConstants.AM_IPC_PROTOCOL,
new RegisteredEndpoint(rpcServiceAddress,
RegisteredEndpoint.PROTOCOL_HADOOP_PROTOBUF,
"Slider AM RPC") );
- /**
- * Set the configurations URL.
- */
- externalView.configurationsURL = publisherURL.toExternalForm();
-
// internal services
+
+ sliderAMProvider.applyInitialRegistryDefinitions(amWebAPI, instanceData);
- instanceData.internalView.endpoints.put(
- CustomRegistryConstants.AGENT_REST_API,
- new RegisteredEndpoint(
- new URL(amWeb, SLIDER_PATH_AGENTS),
- "Agent REST API" )
- );
+ // provider service dynamic definitions.
+ providerService.applyInitialRegistryDefinitions(amWebAPI, instanceData);
+ // push the registration info to ZK
+
registry.registerSelf(
appServiceType,
registryId,
- amWeb,
+ amWebAPI,
instanceData);
}
diff --git a/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryViewForProviders.java b/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryViewForProviders.java
index 93579a4..f50e9bd 100644
--- a/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryViewForProviders.java
+++ b/slider-core/src/main/java/org/apache/slider/server/services/registry/RegistryViewForProviders.java
@@ -30,5 +30,9 @@
List<ServiceInstanceData> listInstancesByType(String serviceType) throws
IOException;
+ /**
+ * Get the registration of slider itself
+ * @return the registration of slider
+ */
ServiceInstanceData getSelfRegistration();
}
diff --git a/slider-core/src/test/groovy/org/apache/slider/server/appmaster/model/mock/MockProviderService.groovy b/slider-core/src/test/groovy/org/apache/slider/server/appmaster/model/mock/MockProviderService.groovy
index 91ef68d..2199043 100644
--- a/slider-core/src/test/groovy/org/apache/slider/server/appmaster/model/mock/MockProviderService.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/server/appmaster/model/mock/MockProviderService.groovy
@@ -31,6 +31,7 @@
import org.apache.slider.core.exceptions.BadCommandArgumentsException
import org.apache.slider.core.exceptions.SliderException
import org.apache.slider.core.launch.ContainerLauncher
+import org.apache.slider.core.registry.info.ServiceInstanceData
import org.apache.slider.providers.ProviderRole
import org.apache.slider.providers.ProviderService
import org.apache.slider.server.appmaster.state.StateAccessForProviders
@@ -217,7 +218,15 @@
}
@Override
- void buildEndpointDetails(Map<String, URL> details) {
+ void buildEndpointDetails(Map<String, String> details) {
+
+ }
+
+ @Override
+ void applyInitialRegistryDefinitions(
+ URL amWebAPI,
+ ServiceInstanceData registryInstanceData)
+ throws MalformedURLException, IOException {
}
}