Search in sources :

Example 1 with ServiceDiscoveryConfig

use of org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig 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 ServiceDiscoveryConfig

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

the class AmbariConfigurationMonitor method getUpdatedConfigVersions.

/**
 * Request the current active configuration version info from Ambari.
 *
 * @param address     The Ambari instance address.
 * @param clusterName The name of the cluster for which the details are desired.
 *
 * @return A Map of service configuration types and their corresponding versions.
 */
Map<String, String> getUpdatedConfigVersions(String address, String clusterName) {
    Map<String, String> configVersions = new HashMap<>();
    ServiceDiscoveryConfig sdc = getDiscoveryConfig(address, clusterName);
    if (sdc != null) {
        Map<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfigs = ambariClient.getActiveServiceConfigurations(clusterName, sdc);
        for (Map<String, AmbariCluster.ServiceConfiguration> serviceConfig : serviceConfigs.values()) {
            for (AmbariCluster.ServiceConfiguration config : serviceConfig.values()) {
                configVersions.put(config.getType(), config.getVersion());
            }
        }
    }
    return configVersions;
}
Also used : HashMap(java.util.HashMap) ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ServiceDiscoveryConfig

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

the class AmbariConfigurationMonitorTest method createTestDiscoveryConfig.

private ServiceDiscoveryConfig createTestDiscoveryConfig(String address, String username, String pwdAlias) {
    ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
    EasyMock.expect(sdc.getAddress()).andReturn(address).anyTimes();
    EasyMock.expect(sdc.getUser()).andReturn(username).anyTimes();
    EasyMock.expect(sdc.getPasswordAlias()).andReturn(pwdAlias).anyTimes();
    EasyMock.replay(sdc);
    return sdc;
}
Also used : ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig)

Example 4 with ServiceDiscoveryConfig

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

the class AmbariConfigurationMonitor method loadDiscoveryConfiguration.

/**
 * Load any previously-persisted service discovery configurations.
 * This is necessary for checking previously-deployed topologies.
 */
private void loadDiscoveryConfiguration() {
    File persistenceDir = getPersistenceDir();
    if (persistenceDir != null) {
        Collection<File> persistedConfigs = FileUtils.listFiles(persistenceDir, new String[] { "conf" }, false);
        for (File persisted : persistedConfigs) {
            Properties props = new Properties();
            FileInputStream in = null;
            try {
                in = new FileInputStream(persisted);
                props.load(in);
                addDiscoveryConfig(props.getProperty(PROP_CLUSTER_NAME), new ServiceDiscoveryConfig() {

                    public String getAddress() {
                        return props.getProperty(PROP_CLUSTER_SOURCE);
                    }

                    public String getUser() {
                        return props.getProperty(PROP_CLUSTER_USER);
                    }

                    public String getPasswordAlias() {
                        return props.getProperty(PROP_CLUSTER_ALIAS);
                    }
                });
            } catch (IOException e) {
                log.failedToLoadClusterMonitorServiceDiscoveryConfig(getType(), e);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    // 
                    }
                }
            }
        }
    }
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) ServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig) FileInputStream(java.io.FileInputStream)

Example 5 with ServiceDiscoveryConfig

use of org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig 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)

Aggregations

ServiceDiscoveryConfig (org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig)6 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)3 ServiceDiscovery (org.apache.knox.gateway.topology.discovery.ServiceDiscovery)3 Test (org.junit.Test)3 File (java.io.File)2 Properties (java.util.Properties)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1