Move spring-cloud-pcf-connector to its own repo, modify test jar creation in spring-cloud-cloudfoundry-connector to build a jar with the classes

This commit is contained in:
Chris Schaefer
2015-01-12 22:18:20 -05:00
parent 38e48bc3f0
commit 58ef61296a
29 changed files with 9 additions and 985 deletions

View File

@@ -52,6 +52,11 @@ def customizePom(pom, gradleProject) {
name = 'Ramnivas Laddad'
email = 'rladdad@gopivotal.com'
}
developer {
id = 'cschaefer'
name = 'Chris Schaefer'
email = 'cschaefer@pivotal.io'
}
}
}
}

View File

@@ -5,4 +5,4 @@ include "${rootProject.name}-cloudfoundry-connector"
include "${rootProject.name}-spring-service-connector"
include "${rootProject.name}-heroku-connector"
include "${rootProject.name}-localconfig-connector"
include "${rootProject.name}-pcf-connector"

View File

@@ -46,11 +46,12 @@ configurations {
task testJar(type: Jar) {
classifier = 'tests'
from sourceSets.test.output.classesDir
from sourceSets.test.output
}
build.dependsOn testJar
artifacts {
tests testJar
}
archives testJar
}

View File

@@ -1,2 +0,0 @@
dependency-reduced-pom.xml
/bin

View File

@@ -1,3 +0,0 @@
#Spring Cloud PCF extension
Currently supports the Hadoop service on Pivotal Cloud Foundry

View File

@@ -1,11 +0,0 @@
description = 'Spring-Cloud Support for Pivotal CF'
dependencies {
compile project(':spring-cloud-core')
compile project(':spring-cloud-cloudfoundry-connector')
compile project(':spring-cloud-spring-service-connector')
optional("org.apache.hadoop:hadoop-common:$hadoopCommonVersion")
optional("com.netflix.eureka:eureka-client:$eurekaClientVersion")
testCompile project(path: ':spring-cloud-cloudfoundry-connector', configuration: 'tests')
}

View File

@@ -1,65 +0,0 @@
apply plugin: "maven"
ext.optionalDeps = []
ext.providedDeps = []
ext.optional = { optionalDeps << it }
ext.provided = { providedDeps << it }
install {
repositories.mavenInstaller {
customizePom(pom, project)
}
}
def customizePom(pom, gradleProject) {
pom.whenConfigured { generatedPom ->
// respect "optional" and "provided" dependencies
gradleProject.optionalDeps.each { dep ->
generatedPom.dependencies.findAll { it.artifactId == dep.name }*.optional = true
}
gradleProject.providedDeps.each { dep ->
generatedPom.dependencies.findAll { it.artifactId == dep.name }*.scope = "provided"
}
// eliminate test-scoped dependencies (no need in maven central poms)
generatedPom.dependencies.removeAll { dep ->
dep.scope == "test"
}
// Remove jackson dependencies, since we shade them in
generatedPom.dependencies.removeAll { dep ->
dep.groupId == "com.fasterxml.jackson.core"
}
// add all items necessary for maven central publication
generatedPom.project {
name = gradleProject.description
description = gradleProject.description
url = "https://github.com/spring-projects/spring-cloud"
organization {
name = "Spring IO"
url = "http://projects.spring.io/spring-cloud"
}
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
scm {
url = "https://github.com/spring-projects/spring-cloud"
connection = "scm:git:git://github.com/spring-projects/spring-cloud"
developerConnection = "scm:git:git://github.com/spring-projects/spring-cloud"
}
developers {
developer {
id = "ramnivas"
name = "Ramnivas Laddad"
email = ""
}
}
}
}
}

View File

@@ -1,75 +0,0 @@
package org.springframework.cloud.pcf.configserver;
import org.springframework.cloud.Cloud;
import org.springframework.cloud.CloudFactory;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
import java.util.Collections;
/**
* Connector to Config Server service
*
* @author Chris Schaefer
*/
@Configuration
public class ConfigServerServiceConnector implements ApplicationListener<ApplicationEvent>, Ordered {
/**
* TODO:
* Bind ApplicationListener to ApplicationEnvironmentPreparedEvent, remove reflection
* and add test after repo migration in which we will have a direct dependency on boot.
*/
private static final String PROPERTY_SOURCE_NAME = "vcapConfigServerUri";
private static final String EVENT_ENVIRONMENT_METHOD_NAME = "getEnvironment";
private static final String SPRING_CLOUD_CONFIG_URI = "spring.cloud.config.uri";
private static final String EVENT_CLASS_NAME = "org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent";
private Cloud cloud;
@Override
public void onApplicationEvent(ApplicationEvent event) {
if(!supports(event.getClass().getName()) || cloud != null) {
return;
}
cloud = new CloudFactory().getCloud();
for(ServiceInfo serviceInfo : cloud.getServiceInfos()) {
if(serviceInfo instanceof ConfigServerServiceInfo) {
String uri = ((ConfigServerServiceInfo) serviceInfo).getUri();
MapPropertySource mapPropertySource = new MapPropertySource(PROPERTY_SOURCE_NAME,
Collections.<String, Object>singletonMap(SPRING_CLOUD_CONFIG_URI, uri));
getEnvironment(event).getPropertySources().addFirst(mapPropertySource);
}
}
}
private boolean supports(String className) {
return EVENT_CLASS_NAME.equals(className);
}
private ConfigurableEnvironment getEnvironment(ApplicationEvent event) {
Method method = ReflectionUtils.findMethod(event.getClass(), EVENT_ENVIRONMENT_METHOD_NAME);
try {
return (ConfigurableEnvironment) method.invoke(event);
} catch (Exception e) {
throw new RuntimeException("Error obtaining Environment from event", e);
}
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE + 4;
}
}

View File

@@ -1,14 +0,0 @@
package org.springframework.cloud.pcf.configserver;
import org.springframework.cloud.service.UriBasedServiceInfo;
/**
* Service info to access Config Server services
*
* @author Chris Schaefer
*/
public class ConfigServerServiceInfo extends UriBasedServiceInfo {
public ConfigServerServiceInfo(String id, String uriString) {
super(id, uriString);
}
}

View File

@@ -1,28 +0,0 @@
package org.springframework.cloud.pcf.configserver;
import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator;
import org.springframework.cloud.cloudfoundry.Tags;
import java.util.Map;
/**
* Service info creator for Config Server services
*
* @author Chris Schaefer
*/
public class ConfigServerServiceInfoCreator extends CloudFoundryServiceInfoCreator<ConfigServerServiceInfo> {
private static final String CREDENTIALS_ID_KEY = "name";
private static final String CONFIG_SERVER_SERVICE_TAG_NAME = "configuration";
public ConfigServerServiceInfoCreator() {
super(new Tags(CONFIG_SERVER_SERVICE_TAG_NAME));
}
@Override
public ConfigServerServiceInfo createServiceInfo(Map<String, Object> serviceData) {
String id = (String) serviceData.get(CREDENTIALS_ID_KEY);
String uri = getUriFromCredentials(getCredentials(serviceData));
return new ConfigServerServiceInfo(id, uri);
}
}

View File

@@ -1,191 +0,0 @@
package org.springframework.cloud.pcf.eureka;
import com.netflix.discovery.EurekaClientConfig;
import org.springframework.cloud.service.AbstractServiceConnectorCreator;
import org.springframework.cloud.service.ServiceConnectorConfig;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
/**
*
* Connector creator for Eureka client services
*
* @author Chris Schaefer
*/
public class EurekaClientConfigurationCreator extends AbstractServiceConnectorCreator<EurekaClientConfig, EurekaServiceInfo> {
@Override
public EurekaClientConfig create(EurekaServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) {
return getEurekaClientConfig(serviceInfo);
}
protected EurekaClientConfig getEurekaClientConfig(EurekaServiceInfo serviceInfo) {
return new DefaultPcfEurekaClientConfig(serviceInfo.getUri());
}
private static final class DefaultPcfEurekaClientConfig implements EurekaClientConfig {
private static final int MINUTES = 60;
private static final String REGION = "default";
private static final String DEFAULT_ZONE = "defaultZone";
private static final String EUREKA_API_PREFIX = "/eureka/";
private final String uri;
public DefaultPcfEurekaClientConfig(String uri) {
this.uri = uri + EUREKA_API_PREFIX;
}
@Override
public int getRegistryFetchIntervalSeconds() {
return 5;
}
@Override
public int getInstanceInfoReplicationIntervalSeconds() {
return 30;
}
@Override
public int getInitialInstanceInfoReplicationIntervalSeconds() {
return 40;
}
@Override
public int getEurekaServiceUrlPollIntervalSeconds() {
return 5 * MINUTES;
}
@Override
public String getProxyHost() {
return null;
}
@Override
public String getProxyPort() {
return null;
}
@Override
public boolean shouldGZipContent() {
return true;
}
@Override
public int getEurekaServerReadTimeoutSeconds() {
return 8;
}
@Override
public int getEurekaServerConnectTimeoutSeconds() {
return 5;
}
@Override
public String getBackupRegistryImpl() {
return null;
}
@Override
public int getEurekaServerTotalConnections() {
return 200;
}
@Override
public int getEurekaServerTotalConnectionsPerHost() {
return 50;
}
@Override
public String getEurekaServerURLContext() {
return null;
}
@Override
public String getEurekaServerPort() {
return null;
}
@Override
public String getEurekaServerDNSName() {
return null;
}
@Override
public boolean shouldUseDnsForFetchingServiceUrls() {
return false;
}
@Override
public boolean shouldRegisterWithEureka() {
return true;
}
@Override
public boolean shouldPreferSameZoneEureka() {
return true;
}
@Override
public boolean shouldLogDeltaDiff() {
return false;
}
@Override
public boolean shouldDisableDelta() {
return false;
}
@Nullable
@Override
public String fetchRegistryForRemoteRegions() {
return null;
}
@Override
public String getRegion() {
return REGION;
}
@Override
public String[] getAvailabilityZones(String region) {
return new String[] { DEFAULT_ZONE };
}
@Override
public List<String> getEurekaServerServiceUrls(String myZone) {
return Arrays.asList(uri);
}
@Override
public boolean shouldFilterOnlyUpInstances() {
return true;
}
@Override
public int getEurekaConnectionIdleTimeoutSeconds() {
return 30;
}
@Override
public boolean shouldFetchRegistry() {
return true;
}
@Nullable
@Override
public String getRegistryRefreshSingleVipAddress() {
return null;
}
@Override
public int getHeartbeatExecutorThreadPoolSize() {
return 2;
}
@Override
public int getCacheRefreshExecutorThreadPoolSize() {
return 2;
}
}
}

View File

@@ -1,16 +0,0 @@
package org.springframework.cloud.pcf.eureka;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.UriBasedServiceInfo;
/**
* Information to access Eureka services
*
* @author Chris Schaefer
*/
@ServiceInfo.ServiceLabel("eureka")
public class EurekaServiceInfo extends UriBasedServiceInfo {
public EurekaServiceInfo(String id, String uriString) {
super(id, uriString);
}
}

View File

@@ -1,29 +0,0 @@
package org.springframework.cloud.pcf.eureka;
import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator;
import org.springframework.cloud.cloudfoundry.Tags;
import java.util.Map;
/**
*
* Service info creator for Eureka services
*
* @author Chris Schaefer
*/
public class EurekaServiceInfoCreator extends CloudFoundryServiceInfoCreator<EurekaServiceInfo> {
private static final String CREDENTIALS_ID_KEY = "name";
private static final String EUREKA_SERVICE_TAG_NAME = "eureka";
public EurekaServiceInfoCreator() {
super(new Tags(EUREKA_SERVICE_TAG_NAME));
}
@Override
public EurekaServiceInfo createServiceInfo(Map<String, Object> serviceData) {
String id = (String) serviceData.get(CREDENTIALS_ID_KEY);
String uri = getUriFromCredentials(getCredentials(serviceData));
return new EurekaServiceInfo(id, uri);
}
}

View File

@@ -1,20 +0,0 @@
package org.springframework.cloud.pcf.gemfire;
import org.springframework.cloud.service.relational.DataSourceCreator;
/**
*
* @author Ramnivas Laddad
*
*/
public class GemfireXDDataSourceCreator extends DataSourceCreator<GemfireXDServiceInfo> {
private static final String[] DRIVERS = new String[]{"com.pivotal.gemfirexd.internal.jdbc.ClientConnectionPoolDataSource"};
private static final String VALIDATION_QUERY = null;
public GemfireXDDataSourceCreator() {
super("spring-cloud.gemfirexd.driver", DRIVERS, VALIDATION_QUERY);
}
}

View File

@@ -1,20 +0,0 @@
package org.springframework.cloud.pcf.gemfire;
import org.springframework.cloud.service.ServiceInfo.ServiceLabel;
import org.springframework.cloud.service.common.RelationalServiceInfo;
/**
*
* @author Ramnivas Laddad
*
*/
@ServiceLabel("gemfirexd")
public class GemfireXDServiceInfo extends RelationalServiceInfo {
public static final String JDBC_URL_TYPE = "gemfirexd";
public GemfireXDServiceInfo(String id, String url) {
super(id, url, JDBC_URL_TYPE);
}
}

View File

@@ -1,25 +0,0 @@
package org.springframework.cloud.pcf.hadoop;
import org.apache.hadoop.conf.Configuration;
import org.springframework.cloud.service.AbstractServiceConnectorCreator;
import org.springframework.cloud.service.ServiceConnectorConfig;
/**
*
* @author Ramnivas Laddad
*
*/
public class HadoopConfigurationCreator extends AbstractServiceConnectorCreator<Configuration, HadoopServiceInfo> {
@Override
public Configuration create(HadoopServiceInfo hadoopServiceInfo, ServiceConnectorConfig serviceConnectorConfig) {
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", hadoopServiceInfo.getDefaultFS());
configuration.set("yarn.resourcemanager.address", hadoopServiceInfo.getYarnResourceManagerAddress());
configuration.set("yarn.resourcemanager.scheduler.address", hadoopServiceInfo.getYarnResourceManagerSchedulerAddress());
return configuration;
}
}

View File

@@ -1,42 +0,0 @@
package org.springframework.cloud.pcf.hadoop;
import org.springframework.cloud.service.BaseServiceInfo;
import org.springframework.cloud.service.ServiceInfo;
/**
* Hadoop service info (also considers yarn properties).
*
* @author Ramnivas Laddad
*
*/
public class HadoopServiceInfo extends BaseServiceInfo {
private String defaultHdfsUri;
private String yarnResourceManagerAddress;
private String yarnResourceManagerSchedulerAddress;
public HadoopServiceInfo(String id, String defaultHdfsUri,
String yarnResourceManagerAddress, String yarnResourceManagerSchedulerAddress) {
super(id);
this.defaultHdfsUri = defaultHdfsUri;
this.yarnResourceManagerAddress = yarnResourceManagerAddress;
this.yarnResourceManagerSchedulerAddress = yarnResourceManagerSchedulerAddress;
}
@ServiceInfo.ServiceProperty(category = "connection")
public String getDefaultFS() {
return defaultHdfsUri;
}
@ServiceInfo.ServiceProperty(category = "connection")
public String getYarnResourceManagerAddress() {
return yarnResourceManagerAddress;
}
@ServiceInfo.ServiceProperty(category = "connection")
public String getYarnResourceManagerSchedulerAddress() {
return yarnResourceManagerSchedulerAddress;
}
}

View File

@@ -1,79 +0,0 @@
package org.springframework.cloud.pcf.phd;
import java.util.Map;
import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator;
import org.springframework.cloud.cloudfoundry.Tags;
import org.springframework.cloud.pcf.gemfire.GemfireXDServiceInfo;
import org.springframework.cloud.pcf.hadoop.HadoopServiceInfo;
import org.springframework.cloud.service.BaseCompositeServiceInfo;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.PostgresqlServiceInfo;
import org.springframework.cloud.service.common.RelationalServiceInfo;
/**
*
* @author Ramnivas Laddad
*
*/
public class PhdServiceInfoCreator extends CloudFoundryServiceInfoCreator<BaseCompositeServiceInfo> {
public PhdServiceInfoCreator() {
super(new Tags("p-hd"));
}
@SuppressWarnings("unchecked")
public BaseCompositeServiceInfo createServiceInfo(Map<String,Object> serviceData) {
String id = (String) serviceData.get("name");
Map<String,Object> credentials = (Map<String, Object>) serviceData.get("credentials");
ServiceInfo hadoopServiceInfo = createHadoopServiceInfo(id, credentials);
ServiceInfo hawqServiceInfo = createHawqServiceInfo(id, credentials);
ServiceInfo gemfirexdServiceInfo = createGemfireXDServiceInfo(id, credentials);
return new BaseCompositeServiceInfo(id, hadoopServiceInfo, hawqServiceInfo, gemfirexdServiceInfo);
}
@SuppressWarnings("unchecked")
private HadoopServiceInfo createHadoopServiceInfo(String id, Map<String,Object> credentials) {
Map<String, Object> hdfs = (Map<String, Object>) credentials.get("hdfs");
Map<String, Object> hdfsConfig = (Map<String, Object>) hdfs.get("configuration");
String defaultHdfsUri = (String) hdfsConfig.get("fs.defaultFS");
Map<String, Object> yarn = (Map<String, Object>) credentials.get("yarn");
Map<String, Object> yarnConfig = (Map<String, Object>) yarn.get("configuration");
String yarnResourceManagerAddress = (String) yarnConfig.get("yarn.resourcemanager.address");
String yarnResourceManagerSchedulerAddress = (String) yarnConfig.get("yarn.resourcemanager.scheduler.address");
return new HadoopServiceInfo(id + "/hadoop", defaultHdfsUri,
yarnResourceManagerAddress, yarnResourceManagerSchedulerAddress);
}
private RelationalServiceInfo createHawqServiceInfo(String id, Map<String,Object> credentials) {
String key = "hawq";
return new PostgresqlServiceInfo(id + "/" + key, extractDataSourceUri(id, key, credentials));
}
private RelationalServiceInfo createGemfireXDServiceInfo(String id, Map<String,Object> credentials) {
String key = "gemfirexd";
return new GemfireXDServiceInfo(id + "/" + key, extractDataSourceUri(id, key, credentials));
}
private String extractDataSourceUri(String id, String key, Map<String,Object> credentials) {
@SuppressWarnings("unchecked")
Map<String, Object> hawq = (Map<String, Object>) credentials.get(key);
String uri = (String) hawq.get("uri");
String jdbcUriPrefix = "jdbc:";
if (uri.startsWith(jdbcUriPrefix)) {
uri.substring(jdbcUriPrefix.length());
}
return uri;
}
}

View File

@@ -1,3 +0,0 @@
org.springframework.cloud.pcf.phd.PhdServiceInfoCreator
org.springframework.cloud.pcf.eureka.EurekaServiceInfoCreator
org.springframework.cloud.pcf.configserver.ConfigServerServiceInfoCreator

View File

@@ -1,3 +0,0 @@
org.springframework.cloud.pcf.hadoop.HadoopConfigurationCreator
org.springframework.cloud.pcf.gemfire.GemfireXDDataSourceCreator
org.springframework.cloud.pcf.eureka.EurekaClientConfigurationCreator

View File

@@ -1,2 +0,0 @@
org.springframework.context.ApplicationListener=\
org.springframework.cloud.pcf.configserver.ConfigServerServiceConnector

View File

@@ -1,26 +0,0 @@
package org.springframework.cloud.hadoop;
import static org.junit.Assert.*;
import org.apache.hadoop.conf.Configuration;
import org.junit.Test;
import org.springframework.cloud.pcf.hadoop.HadoopConfigurationCreator;
import org.springframework.cloud.pcf.hadoop.HadoopServiceInfo;
/**
*
* @author Ramnivas Laddad
*
*/
public class HadoopConfigurationCreatorTest {
private HadoopConfigurationCreator creator = new HadoopConfigurationCreator();
@Test
public void hadoopConfigurationCreation() {
HadoopServiceInfo serviceInfo = new HadoopServiceInfo("phd-hadoop", "hdfs://hdfshost:1234", "yrm:2345", "yrsm:3456");
Configuration configuration = creator.create(serviceInfo, null);
assertEquals("hdfs://hdfshost:1234", configuration.get("fs.defaultFS"));
assertEquals("yrm:2345", configuration.get("yarn.resourcemanager.address"));
assertEquals("yrsm:3456", configuration.get("yarn.resourcemanager.scheduler.address"));
}
}

View File

@@ -1,142 +0,0 @@
package org.springframework.cloud.pcf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.Test;
import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest;
import org.springframework.cloud.pcf.gemfire.GemfireXDServiceInfo;
import org.springframework.cloud.pcf.hadoop.HadoopServiceInfo;
import org.springframework.cloud.service.BaseCompositeServiceInfo;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.PostgresqlServiceInfo;
/**
*
* @author Ramnivas Laddad
*
*/
public class PhdServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest {
@Test
public void phdServiceCreation() {
String hadoopUsername = "hadoop-user";
String hadoopHost = "hadoop-host";
int hadoopPort = 6000;
String hadoopDirectory = "hadoop-dir";
String yarnResourceHost = "yark-resource-host";
int yarnResourcePort = 7000;
String yarnResourceSchedulerHost = "yarn-resource-scheduler-host";
int yarnResourceSchedulerPort = 8000;
String yarnMapReduceDir = "yarn-map-reduce-dir";
String yarnStagingDir = "yarn-staging-dir";
String hawkHost = "hawk-host";
int hawkPort = 9000;
String hawkUsername = "hawk-user";
String hawkPassword = "hawk-pass";
String gemHost = "gem-host";
int gemPort = 10000;
String gemUsername = "gem-user";
String gemPassword = "gem-pass";
String gemWorkingDir = "gem-working-dir";
when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn(
getServicesPayload(
getPhdServicePayload("phd-1", hadoopUsername, hadoopHost, hadoopPort, hadoopDirectory,
yarnResourceHost, yarnResourcePort,
yarnResourceSchedulerHost, yarnResourceSchedulerPort, yarnMapReduceDir, yarnStagingDir,
hawkHost, hawkPort, hawkUsername, hawkPassword,
gemHost, gemPort, gemUsername, gemPassword, gemWorkingDir)));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
BaseCompositeServiceInfo phdServiceInfo = (BaseCompositeServiceInfo) getServiceInfo(serviceInfos, "phd-1");
assertNotNull(phdServiceInfo);
assertEquals(3, phdServiceInfo.getServiceInfos().size());
HadoopServiceInfo hadoopServiceInfo = extractServiceInfo(phdServiceInfo.getServiceInfos(), HadoopServiceInfo.class);
assertNotNull(hadoopServiceInfo);
assertHadoopServiceInfo("phd-1/hadoop", hadoopHost, hadoopPort,
yarnResourceHost, yarnResourcePort, yarnResourceSchedulerHost, yarnResourceSchedulerPort, hadoopServiceInfo);
PostgresqlServiceInfo hawqServiceInfo = extractServiceInfo(phdServiceInfo.getServiceInfos(), PostgresqlServiceInfo.class);
assertEquals("phd-1/hawq", hawqServiceInfo.getId());
assertNotNull(hawqServiceInfo);
GemfireXDServiceInfo gemfireXDServiceInfo = extractServiceInfo(phdServiceInfo.getServiceInfos(), GemfireXDServiceInfo.class);
assertNotNull(gemfireXDServiceInfo);
assertEquals("phd-1/gemfirexd", gemfireXDServiceInfo.getId());
}
private void assertHadoopServiceInfo(String serviceId, String hadoopHost, int hadoopPort,
String yarnResourceHost, int yarnResourcePort,
String yarnResourceSchedulerHost, int yarnResourceSchedulerPort,
HadoopServiceInfo serviceInfo) {
assertEquals(serviceId, serviceInfo.getId());
assertEquals(String.format("hdfs://%s:%s", hadoopHost, hadoopPort), serviceInfo.getDefaultFS());
assertEquals(String.format("%s:%s", yarnResourceHost, yarnResourcePort), serviceInfo.getYarnResourceManagerAddress());
assertEquals(String.format("%s:%s", yarnResourceSchedulerHost, yarnResourceSchedulerPort), serviceInfo.getYarnResourceManagerSchedulerAddress());
}
@SuppressWarnings("unchecked")
private <T> T extractServiceInfo(List<ServiceInfo> serviceInfos, Class<T> typeToSearch) {
for (ServiceInfo serviceInfo: serviceInfos) {
if (serviceInfo.getClass().equals(typeToSearch)) {
return (T)serviceInfo;
}
}
return null;
}
private String getPhdServicePayload(String serviceName,
String hadoopUsername, String hadoopHost, int hadoopPort, String hadoopDirectory,
String yarnResourceHost, int yarnResourcePort,
String yarnResourceSchedulerHost, int yarnResourceSchedulerPort,
String yarnMapReduceDir, String yarnStagingDir,
String hawkHost, int hawkPort, String hawkUsername, String hawkPassword,
String gemHost, int gemPort, String gemUsername, String gemPassword, String gemWorkingDir) {
return getPhdServicePayload("test-phd-info.json", serviceName, hadoopUsername, hadoopHost, hadoopPort, hadoopDirectory,
yarnResourceHost, yarnResourcePort,
yarnResourceSchedulerHost, yarnResourceSchedulerPort,
yarnMapReduceDir, yarnStagingDir,
hawkHost, hawkPort, hawkUsername, hawkPassword,
gemHost, gemPort, gemUsername, gemPassword, gemWorkingDir);
}
private String getPhdServicePayload(String filename, String serviceName,
String hadoopUsername, String hadoopHost, int hadoopPort, String hadoopDirectory,
String yarnResourceHost, int yarnResourcePort,
String yarnResourceSchedulerHost, int yarnResourceSchedulerPort,
String yarnMapReduceDir, String yarnStagingDir,
String hawkHost, int hawkPort, String hawkUsername, String hawkPassword,
String gemHost, int gemPort, String gemUsername, String gemPassword, String gemWorkingDir) {
String payload = readTestDataFile(filename);
payload = payload.replace("$serviceName", serviceName);
payload = payload.replace("$hadoop-username", hadoopUsername);
payload = payload.replace("$hdfs-host", hadoopHost);
payload = payload.replace("$hdfs-port", Integer.toString(hadoopPort));
payload = payload.replace("$hdfs-directory", hadoopDirectory);
payload = payload.replace("$yarn-resource-host", yarnResourceHost);
payload = payload.replace("$yarn-resource-port", Integer.toString(yarnResourcePort));
payload = payload.replace("$yarn-resource-scheduler-host", yarnResourceSchedulerHost);
payload = payload.replace("$yarn-resource-scheduler-port", Integer.toString(yarnResourceSchedulerPort));
payload = payload.replace("$yarn-map-reduce-dir", yarnMapReduceDir);
payload = payload.replace("$yarn-staging-dir", yarnStagingDir);
payload = payload.replace("$hawk-host", hawkHost);
payload = payload.replace("$hawk-port", Integer.toString(hawkPort));
payload = payload.replace("$hawk-username", hawkUsername);
payload = payload.replace("$hawk-password", hawkPassword);
payload = payload.replace("$gem-host", gemHost);
payload = payload.replace("$gem-port", Integer.toString(gemPort));
payload = payload.replace("$gem-username", gemUsername);
payload = payload.replace("$gem-password", gemPassword);
payload = payload.replace("$gem-working-dir", gemWorkingDir);
return payload;
}
}

View File

@@ -1,46 +0,0 @@
package org.springframework.cloud.pcf.configserver;
import org.junit.Test;
import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest;
import org.springframework.cloud.service.ServiceInfo;
import java.util.List;
import static org.mockito.Mockito.when;
/**
* Connector tests for Config Server services
*
* @author Chris Schaefer
*/
public class ConfigServerServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest {
private static final String CONFIG_SERVER_SERVICE_TAG_NAME = "myConfigServerService";
private static final String VCAP_SERVICES_ENV_KEY = "VCAP_SERVICES";
private static final String PAYLOAD_FILE_NAME = "test-config-server-info.json";
private static final String PAYLOAD_TEMPLATE_SERVICE_NAME = "$serviceName";
private static final String PAYLOAD_TEMPLATE_HOSTNAME = "$hostname";
private static final String PAYLOAD_TEMPLATE_PORT = "$port";
private static final String PAYLOAD_TEMPLATE_USER = "$user";
private static final String PAYLOAD_TEMPLATE_PASS = "$pass";
@Test
public void configServerServiceCreationWithTags() {
when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY))
.thenReturn(getServicesPayload(getConfigServerServicePayload(CONFIG_SERVER_SERVICE_TAG_NAME,
hostname, port, username, password)));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, CONFIG_SERVER_SERVICE_TAG_NAME, ConfigServerServiceInfo.class);
}
private String getConfigServerServicePayload(String serviceName, String hostname, int port, String user, String password) {
String payload = readTestDataFile(PAYLOAD_FILE_NAME);
payload = payload.replace(PAYLOAD_TEMPLATE_SERVICE_NAME, serviceName);
payload = payload.replace(PAYLOAD_TEMPLATE_HOSTNAME, hostname);
payload = payload.replace(PAYLOAD_TEMPLATE_PORT, Integer.toString(port));
payload = payload.replace(PAYLOAD_TEMPLATE_USER, user);
payload = payload.replace(PAYLOAD_TEMPLATE_PASS, password);
return payload;
}
}

View File

@@ -1,42 +0,0 @@
package org.springframework.cloud.pcf.eureka;
import com.netflix.discovery.EurekaClientConfig;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* Test cases around the Eureka client configuration creator
*
* @author Chris Schaefer
*/
public class EurekaClientConfigurationCreatorTest {
private static final String REGION = "default";
private static final String SERVICE_INFO_ID = "id";
private static final int REGISTRY_FETCH_INTERVAL_SECS = 5;
private static final String AVAILABLITY_ZONE = "defaultZone";
private static final String URI = "http://user:pass@192.168.23.4:1234";
private static final String EUREKA_API_PREFIX = "/eureka/";
private EurekaClientConfigurationCreator eurekaClientConfigurationCreator = new EurekaClientConfigurationCreator();
@Test
public void testClientConfiguration() {
EurekaServiceInfo eurekaServiceInfo = new EurekaServiceInfo(SERVICE_INFO_ID, URI);
EurekaClientConfig eurekaClientConfig = eurekaClientConfigurationCreator.create(eurekaServiceInfo, null);
List<String> serviceUrls = eurekaClientConfig.getEurekaServerServiceUrls(null);
assertEquals(1, serviceUrls.size());
assertEquals(URI + EUREKA_API_PREFIX, serviceUrls.get(0));
assertEquals(REGION, eurekaClientConfig.getRegion());
assertEquals(REGISTRY_FETCH_INTERVAL_SECS, eurekaClientConfig.getRegistryFetchIntervalSeconds());
String[] availablityZones = eurekaClientConfig.getAvailabilityZones(null);
assertEquals(1, availablityZones.length);
assertEquals(AVAILABLITY_ZONE, availablityZones[0]);
}
}

View File

@@ -1,45 +0,0 @@
package org.springframework.cloud.pcf.eureka;
import org.junit.Test;
import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest;
import org.springframework.cloud.service.ServiceInfo;
import java.util.List;
import static org.mockito.Mockito.when;
/**
* Connector tests for Eureka services
*
* @author Chris Schaefer
*/
public class EurekaServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest {
private static final String EUREKA_SERVICE_TAG_NAME = "myEurekaInstance";
private static final String VCAP_SERVICES_ENV_KEY = "VCAP_SERVICES";
private static final String PAYLOAD_FILE_NAME = "test-eureka-info.json";
private static final String PAYLOAD_TEMPLATE_SERVICE_NAME = "$serviceName";
private static final String PAYLOAD_TEMPLATE_HOSTNAME = "$hostname";
private static final String PAYLOAD_TEMPLATE_PORT = "$port";
private static final String PAYLOAD_TEMPLATE_USER = "$user";
private static final String PAYLOAD_TEMPLATE_PASS = "$pass";
@Test
public void eurekaServiceCreationWithTags() {
when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY))
.thenReturn(getServicesPayload(getEurekaServicePayload(EUREKA_SERVICE_TAG_NAME, hostname, port, username, password)));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, EUREKA_SERVICE_TAG_NAME, EurekaServiceInfo.class);
}
private String getEurekaServicePayload(String serviceName, String hostname, int port, String user, String password) {
String payload = readTestDataFile(PAYLOAD_FILE_NAME);
payload = payload.replace(PAYLOAD_TEMPLATE_SERVICE_NAME, serviceName);
payload = payload.replace(PAYLOAD_TEMPLATE_HOSTNAME, hostname);
payload = payload.replace(PAYLOAD_TEMPLATE_PORT, Integer.toString(port));
payload = payload.replace(PAYLOAD_TEMPLATE_USER, user);
payload = payload.replace(PAYLOAD_TEMPLATE_PASS, password);
return payload;
}
}

View File

@@ -1,11 +0,0 @@
{
"name":"$serviceName",
"label":"p-config",
"plan":"standard",
"tags":[
"configuration"
],
"credentials":{
"uri":"http://$username:$password@$hostname:$port/"
}
}

View File

@@ -1,11 +0,0 @@
{
"name":"$serviceName",
"label":"p-eureka",
"plan":"standard",
"tags":[
"eureka"
],
"credentials":{
"uri":"http://$username:$password@$hostname:$port/"
}
}

View File

@@ -1,31 +0,0 @@
{
"name":"$serviceName",
"label":"p-hd",
"tags":[],
"plan":"Standard",
"credentials":{
"hadoop_username":"$hadoop-username",
"hdfs":{
"configuration":{
"fs.defaultFS":"hdfs://$hdfs-host:$hdfs-port"
},
"directory":"$hdfs-directory"
},
"yarn":{
"configuration":{
"yarn.resourcemanager.address":"$yarn-resource-host:$yarn-resource-port",
"mapreduce.framework.name":"yarn",
"yarn.resourcemanager.scheduler.address":"$yarn-resource-scheduler-host:$yarn-resource-scheduler-port",
"mapreduce.job.working.dir":"$yarn-map-reduce-dir",
"yarn.app.mapreduce.am.staging-dir":"$yarn-staging-dir"
}
},
"hawq":{
"uri":"jdbc:postgresql://$hawk-host:$hawk-port/postgres?user=$hawk-username&password=$hawk-password"
},
"gemfirexd":{
"uri":"jdbc:gemfirexd://$gem-host:$gem-port/;user=$gem-username;password=$gem-password",
"working.dir":"$gem-working-dir"
}
}
}