Author: jmaron Date: Thu May 8 21:08:00 2014 New Revision: 1593419 URL: http://svn.apache.org/r1593419 Log: slider-26 - convenience method for publishing configuration
Added: incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/ incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/ incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy - copied, changed from r1592735, incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/ incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestAgentProviderService.java incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestSliderProviderFactory.java Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/providers/agent/AgentProviderServiceTest.java Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java?rev=1593419&r1=1593418&r2=1593419&view=diff ============================================================================== --- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java (original) +++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java Thu May 8 21:08:00 2014 @@ -38,6 +38,7 @@ import org.apache.slider.core.exceptions import org.apache.slider.core.exceptions.SliderException; 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.RegisteredEndpoint; import org.apache.slider.core.registry.info.ServiceInstanceData; import org.apache.slider.providers.AbstractProviderService; @@ -225,6 +226,15 @@ public class AgentProviderService extend return metainfo; } + protected void publishComponentConfiguration(String name, String description, + Iterable<Map.Entry<String, String>> entries) { + PublishedConfiguration pubconf = new PublishedConfiguration(); + pubconf.description = description; + pubconf.putValues(entries); + log.info("publishing {}", pubconf); + getStateAccessor().getPublishedConfigurations().put(name, pubconf); + } + protected void setRoleHostMapping(String role, String host) { List<String> hosts = roleHostMapping.get(role); if (hosts == null) { Copied: incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy (from r1592735, 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/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy?p2=incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy&p1=incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy&r1=1592735&r2=1593419&rev=1593419&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/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy Thu May 8 21:08:00 2014 @@ -16,55 +16,38 @@ * limitations under the License. */ -package org.apache.slider.registry.curator +package org.apache.slider.server.appmaster.web.rest.publisher import com.sun.jersey.api.client.Client import com.sun.jersey.api.client.ClientResponse -import com.sun.jersey.api.client.UniformInterfaceException import com.sun.jersey.api.client.WebResource import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import org.apache.curator.x.discovery.ServiceType -import org.apache.hadoop.security.UserGroupInformation import org.apache.slider.api.StatusKeys import org.apache.slider.client.SliderClient -import org.apache.slider.common.SliderKeys import org.apache.slider.core.main.ServiceLauncher -import org.apache.slider.core.registry.info.ServiceInstanceData +import org.apache.slider.core.registry.docstore.PublishedConfiguration import org.apache.slider.providers.agent.AgentTestBase import org.apache.slider.server.appmaster.web.rest.RestPaths -import org.apache.slider.server.services.curator.CuratorServiceInstance -import org.apache.slider.server.services.curator.CuratorServiceInstances -import org.apache.slider.server.services.curator.RegistryNaming import org.junit.Test import javax.ws.rs.core.MediaType import static org.apache.slider.common.params.Arguments.ARG_OPTION +import static org.apache.slider.common.params.Arguments.ARG_PROVIDER import static org.apache.slider.providers.agent.AgentKeys.* import static org.apache.slider.providers.agent.AgentTestUtils.createTestClient @CompileStatic @Slf4j -class TestRegistryRestResources extends AgentTestBase { +class TestPublisherRestResources extends AgentTestBase { - public static final String REGISTRY_URI = RestPaths.SLIDER_PATH_REGISTRY; + public static final String PUBLISHER_URI = RestPaths.SLIDER_PATH_PUBLISHER; public static final String WADL = "vnd.sun.wadl+xml" - - private String id(String instanceName) { - - RegistryNaming.createUniqueInstanceId( - instanceName, - UserGroupInformation.getCurrentUser().getUserName(), - SliderKeys.APP_TYPE, - 1); - } - - @Test public void testRestURIs() throws Throwable { - def clustername = "test_registryws" + def clustername = "test_publisherws" createMiniCluster( clustername, configuration, @@ -87,10 +70,11 @@ class TestRegistryRestResources extends ServiceLauncher<SliderClient> launcher = buildAgentCluster(clustername, roles, [ + ARG_PROVIDER, "org.apache.slider.server.appmaster.web.rest.publisher.TestSliderProviderFactory", ARG_OPTION, PACKAGE_PATH, slider_core.absolutePath, ARG_OPTION, APP_DEF, "file://" + app_def_path.absolutePath, ARG_OPTION, AGENT_CONF, "file://" + agt_conf_path.absolutePath, - ARG_OPTION, AGENT_VERSION, "file://" + agt_ver_path.absolutePath, + ARG_OPTION, AGENT_VERSION, "file://" + agt_ver_path.absolutePath ], true, true, true) @@ -98,17 +82,17 @@ class TestRegistryRestResources extends def report = waitForClusterLive(sliderClient) def trackingUrl = report.trackingUrl log.info("tracking URL is $trackingUrl") - def registry_url = appendToURL(trackingUrl, REGISTRY_URI) + def publisher_url = appendToURL(trackingUrl, PUBLISHER_URI) def status = dumpClusterStatus(sliderClient, "agent AM") def liveURL = status.getInfo(StatusKeys.INFO_AM_WEB_URL) if (liveURL) { - registry_url = appendToURL(liveURL, REGISTRY_URI) + publisher_url = appendToURL(liveURL, PUBLISHER_URI) } - log.info("Registry is $registry_url") + log.info("Publisher is $publisher_url") log.info("stacks is ${liveURL}stacks") log.info("conf is ${liveURL}conf") @@ -116,80 +100,24 @@ class TestRegistryRestResources extends //WS get Client client = createTestClient(); - // test the exposed WADL link - WebResource webResource = client.resource(registry_url); - ClientResponse response = webResource.type(MediaType.APPLICATION_XML) - .get(ClientResponse.class); - assert response.status == 200 - assert response.type == (new MediaType("application", WADL)) - // test the available GET URIs - webResource = client.resource( - appendToURL(registry_url, RestPaths.REGISTRY_SERVICE)); - - response = webResource.type(MediaType.APPLICATION_JSON) - .get(ClientResponse.class); - def responseStr = response.getEntity(String.class) - log.info("response is " + responseStr) - - "{\"names\":[\"${SliderKeys.APP_TYPE}\"]}".equals(responseStr) - - webResource = client.resource( - appendToURL(registry_url, - "${RestPaths.REGISTRY_SERVICE}/${SliderKeys.APP_TYPE}")); - CuratorServiceInstances<ServiceInstanceData> services = webResource.type(MediaType.APPLICATION_JSON) - .get(CuratorServiceInstances.class); - assert services.services.size() == 1 - CuratorServiceInstance<ServiceInstanceData> service = services.services.get(0) - validateService(service) - - webResource = client.resource( - appendToURL(registry_url, - "${RestPaths.REGISTRY_SERVICE}/${SliderKeys.APP_TYPE}/"+id("test_registryws"))); - service = webResource.type(MediaType.APPLICATION_JSON) - .get(CuratorServiceInstance.class); - validateService(service) - - webResource = client.resource( - appendToURL( - registry_url, "${RestPaths.REGISTRY_ANYSERVICE}/${SliderKeys.APP_TYPE}")); - service = webResource.type(MediaType.APPLICATION_JSON) - .get(CuratorServiceInstance.class); - validateService(service) + WebResource webResource = client.resource(publisher_url + "/dummy-site"); + + PublishedConfiguration config = webResource.type(MediaType.APPLICATION_JSON) + .get(PublishedConfiguration.class); + assert config != null + Map<String,String> entries = config.entries + log.info("entries are {}", entries) + assert entries.get("prop1").equals("val1") + assert entries.get("prop2").equals("val2") // some negative tests... - webResource = client.resource( - appendToURL(registry_url, "${RestPaths.REGISTRY_SERVICE}/dummy")) - services = webResource.type(MediaType.APPLICATION_JSON) - .get(CuratorServiceInstances.class); - assert services.services.size() == 0 - - try { - webResource = client.resource(appendToURL(registry_url, - "${RestPaths.REGISTRY_SERVICE}/${SliderKeys.APP_TYPE}/test_registryws-99")); - - service = webResource.type(MediaType.APPLICATION_JSON) - .get(CuratorServiceInstance.class); - fail("should throw an exception for a 404 response....") - } catch (UniformInterfaceException e) { - assert e.response.getStatus() == 404 - } + webResource = client.resource(appendToURL(publisher_url, + "/foobar-site")); - try { - webResource = client.resource( - appendToURL(registry_url, "${RestPaths.REGISTRY_ANYSERVICE}/dummy")); - - service = webResource.type(MediaType.APPLICATION_JSON) - .get(CuratorServiceInstance.class); - fail("should throw an exception for a 404 response....") - } catch (UniformInterfaceException e) { - assert e.response.getStatus() == 404 - } + ClientResponse response = webResource.type(MediaType.APPLICATION_JSON) + .get(ClientResponse.class); + assert response.getStatus() == 404 } - private void validateService(CuratorServiceInstance service) { - assert service.name.equals(SliderKeys.APP_TYPE) - assert service.serviceType == ServiceType.DYNAMIC - assert service.id.contains("test_registryws") - } } Modified: incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/providers/agent/AgentProviderServiceTest.java URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/providers/agent/AgentProviderServiceTest.java?rev=1593419&r1=1593418&r2=1593419&view=diff ============================================================================== --- incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/providers/agent/AgentProviderServiceTest.java (original) +++ incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/providers/agent/AgentProviderServiceTest.java Thu May 8 21:08:00 2014 @@ -35,6 +35,7 @@ import org.apache.slider.core.conf.ConfT import org.apache.slider.core.conf.ConfTreeOperations; import org.apache.slider.core.conf.MapOperations; import org.apache.slider.core.exceptions.SliderException; +import org.apache.slider.core.launch.ContainerLauncher; import org.apache.slider.server.appmaster.model.mock.MockContainerId; import org.apache.slider.server.appmaster.model.mock.MockFileSystem; import org.apache.slider.server.appmaster.model.mock.MockNodeId; @@ -127,7 +128,7 @@ public class AgentProviderServiceTest { replay(access, ctx, container, sliderFileSystem); try { - mockAps.buildContainerLaunchContext(null, + mockAps.buildContainerLaunchContext(createNiceMock(ContainerLauncher.class), instanceDefinition, container, role, Added: incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestAgentProviderService.java URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestAgentProviderService.java?rev=1593419&view=auto ============================================================================== --- incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestAgentProviderService.java (added) +++ incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestAgentProviderService.java Thu May 8 21:08:00 2014 @@ -0,0 +1,53 @@ +/* + * 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.server.appmaster.web.rest.publisher; + +import org.apache.slider.providers.agent.AgentProviderService; +import org.apache.slider.server.appmaster.state.StateAccessForProviders; +import org.apache.slider.server.services.registry.RegistryViewForProviders; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +/** + * + */ +public class TestAgentProviderService extends AgentProviderService{ + protected static final Logger log = + LoggerFactory.getLogger(TestAgentProviderService.class); + + public TestAgentProviderService() { + super(); + log.info("TestAgentProviderService created"); + } + + @Override + public void bind(StateAccessForProviders stateAccessor, + RegistryViewForProviders registry) { + super.bind(stateAccessor, registry); + Map<String,String> dummyProps = new HashMap<>(); + dummyProps.put("prop1", "val1"); + dummyProps.put("prop2", "val2"); + log.info("publishing dummy-site.xml with values {}", dummyProps); + publishComponentConfiguration("dummy-site", "dummy configuration", + dummyProps.entrySet()); + + } + +} Added: incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestSliderProviderFactory.java URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestSliderProviderFactory.java?rev=1593419&view=auto ============================================================================== --- incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestSliderProviderFactory.java (added) +++ incubator/slider/trunk/slider-core/src/test/java/org/apache/slider/server/appmaster/web/rest/publisher/TestSliderProviderFactory.java Thu May 8 21:08:00 2014 @@ -0,0 +1,40 @@ +/* + * 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.server.appmaster.web.rest.publisher; + +import org.apache.slider.providers.ProviderService; +import org.apache.slider.providers.agent.AgentProviderFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class TestSliderProviderFactory extends AgentProviderFactory{ + protected static final Logger log = + LoggerFactory.getLogger(TestSliderProviderFactory.class); + + public TestSliderProviderFactory() { + log.info("Created TestSliderProviderFactory"); + } + + @Override + public ProviderService createServerProvider() { + log.info("Creating TestAgentProviderService"); + return new TestAgentProviderService(); + } +}