Search in sources :

Example 1 with ServiceDiscovery

use of org.apache.knox.gateway.topology.discovery.ServiceDiscovery in project knox by apache.

the class AmbariServiceDiscoveryTest method testBulkClusterDiscovery.

@Test
public void testBulkClusterDiscovery() throws Exception {
    final String discoveryAddress = "http://ambarihost:8080";
    final String clusterName = "anotherCluster";
    ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
    GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.replay(gc);
    ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
    EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
    EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
    EasyMock.replay(sdc);
    Map<String, ServiceDiscovery.Cluster> clusters = sd.discover(gc, sdc);
    assertNotNull(clusters);
    assertEquals(1, clusters.size());
    ServiceDiscovery.Cluster cluster = clusters.get(clusterName);
    assertNotNull(cluster);
    assertEquals(clusterName, cluster.getName());
    assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
    assertEquals(6, ((AmbariCluster) cluster).getComponents().size());
// printServiceURLs(cluster, "NAMENODE", "WEBHCAT", "OOZIE", "RESOURCEMANAGER");
}
Also used : ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 2 with ServiceDiscovery

use of org.apache.knox.gateway.topology.discovery.ServiceDiscovery in project knox by apache.

the class AmbariServiceDiscoveryTest method testClusterDiscoveryWithExternalComponentConfigAugmentation.

@Test
public void testClusterDiscoveryWithExternalComponentConfigAugmentation() throws Exception {
    final String discoveryAddress = "http://ambarihost:8080";
    final String clusterName = "myCluster";
    GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.replay(gc);
    // Create component config mapping override
    Properties compConfOverrideProps = new Properties();
    compConfOverrideProps.setProperty("DISCOVERY_TEST", "test-site");
    File compConfOverrides = File.createTempFile(getClass().getName() + "component-conf-overrides", ".properties");
    compConfOverrideProps.store(new FileOutputStream(compConfOverrides), "Test Config Overrides");
    System.setProperty(AmbariServiceDiscovery.COMPONENT_CONFIG_MAPPING_SYSTEM_PROPERTY, compConfOverrides.getAbsolutePath());
    // Create URL mapping override
    final String URL_MAPPING_OVERRIDES = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<service-discovery-url-mappings>\n" + "  <service name=\"DISCOVERYTEST\">\n" + "    <url-pattern>{TEST_ADDRESS}/discoveryTest</url-pattern>\n" + "    <properties>\n" + "      <property name=\"TEST_ADDRESS\">\n" + "        <component>DISCOVERY_TEST</component>\n" + "        <config-property>discovery.test.base.url</config-property>\n" + "      </property>\n" + "    </properties>\n" + "  </service>\n" + "</service-discovery-url-mappings>\n";
    File urlMappingOverrides = File.createTempFile(getClass().getName() + "_url-overrides", ".xml");
    FileUtils.writeStringToFile(urlMappingOverrides, URL_MAPPING_OVERRIDES, java.nio.charset.Charset.forName("utf-8"));
    System.setProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY, urlMappingOverrides.getAbsolutePath());
    // Re-initialize the component config mappings to include the extension
    AmbariServiceDiscovery.initializeComponentConfigMappings();
    ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
    ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
    EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
    EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
    EasyMock.replay(sdc);
    try {
        ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, clusterName);
        assertNotNull(cluster);
        assertEquals(clusterName, cluster.getName());
        assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
        assertEquals(7, ((AmbariCluster) cluster).getComponents().size());
        List<String> discTestURLs = cluster.getServiceURLs("DISCOVERYTEST");
        assertNotNull(discTestURLs);
        assertEquals(1, discTestURLs.size());
        assertEquals("http://c6402.ambari.apache.org:11999/discoveryTest", discTestURLs.get(0));
    } finally {
        System.clearProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY);
        System.clearProperty(AmbariServiceDiscovery.COMPONENT_CONFIG_MAPPING_SYSTEM_PROPERTY);
        FileUtils.deleteQuietly(compConfOverrides);
        // Re-initialize the component config mappings without the extension
        AmbariServiceDiscovery.initializeComponentConfigMappings();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery) Test(org.junit.Test)

Example 3 with ServiceDiscovery

use of org.apache.knox.gateway.topology.discovery.ServiceDiscovery in project knox by apache.

the class AmbariServiceDiscoveryTest method testSingleClusterDiscovery.

@Test
public void testSingleClusterDiscovery() throws Exception {
    final String discoveryAddress = "http://ambarihost:8080";
    final String clusterName = "testCluster";
    ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
    GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.replay(gc);
    ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
    EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
    EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
    EasyMock.replay(sdc);
    ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, clusterName);
    assertNotNull(cluster);
    assertEquals(clusterName, cluster.getName());
    assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
    assertEquals(6, ((AmbariCluster) cluster).getComponents().size());
// printServiceURLs(cluster);
}
Also used : ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 4 with ServiceDiscovery

use of org.apache.knox.gateway.topology.discovery.ServiceDiscovery in project knox by apache.

the class SimpleDescriptorHandler method performDiscovery.

private static ServiceDiscovery.Cluster performDiscovery(GatewayConfig config, SimpleDescriptor desc, Service... gatewayServices) {
    DefaultServiceDiscoveryConfig sdc = new DefaultServiceDiscoveryConfig(desc.getDiscoveryAddress());
    sdc.setUser(desc.getDiscoveryUser());
    sdc.setPasswordAlias(desc.getDiscoveryPasswordAlias());
    // Use the discovery type from the descriptor. If it's unspecified, employ the default type.
    String discoveryType = desc.getDiscoveryType();
    if (discoveryType == null) {
        discoveryType = DEFAULT_DISCOVERY_TYPE;
    }
    // Use the cached discovery object for the required type, if it has already been loaded
    ServiceDiscovery sd = discoveryInstances.get(discoveryType);
    if (sd == null) {
        sd = ServiceDiscoveryFactory.get(discoveryType, gatewayServices);
        discoveryInstances.put(discoveryType, sd);
    }
    return sd.discover(config, sdc, desc.getClusterName());
}
Also used : DefaultServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.DefaultServiceDiscoveryConfig) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery)

Aggregations

ServiceDiscovery (org.apache.knox.gateway.topology.discovery.ServiceDiscovery)4 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)3 ServiceDiscoveryConfig (org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig)3 Test (org.junit.Test)3 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Properties (java.util.Properties)1 DefaultServiceDiscoveryConfig (org.apache.knox.gateway.topology.discovery.DefaultServiceDiscoveryConfig)1