Merge upstream master into branch

This commit is contained in:
Joshua Chaitin-Pollak
2015-03-12 03:14:07 -04:00
89 changed files with 1017 additions and 1039 deletions

2
.gitignore vendored
View File

@@ -8,3 +8,5 @@ Servers
.gradle
_site
/bin
.idea
*.iml

View File

@@ -55,21 +55,21 @@ particular environment.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-localconfig-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
<!-- If you intend to deploy the app to Cloud Foundry -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
<!-- If you intend to deploy the app to Heroku -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-heroku-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
````
@@ -82,28 +82,28 @@ addition to your cloud connectors:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-spring-service-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
<!-- to use Spring Cloud for development -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-localconfig-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
<!-- If you intend to deploy the app to Cloud Foundry -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
<!-- If you intend to deploy the app to Heroku -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-heroku-connector</artifactId>
<version>1.1.0.RELEASE</version>
<version>1.1.1.RELEASE</version>
</dependency>
````
@@ -115,4 +115,5 @@ the `<cloud>` namespace](spring-cloud-spring-service-connector).
The [`spring-cloud-core`](core) dependency is included by each cloud connector,
so simply include the connectors for the platforms you want.
Then follow the [instructions](spring-cloud-core) on using the Spring Cloud API.
Then follow the [instructions](spring-cloud-core) on using the Spring Cloud API.

View File

@@ -1,43 +1,43 @@
apply plugin: 'base'
description = "Spring Cloud"
buildscript {
repositories {
maven { url 'http://repo.springsource.org/plugins-release' }
}
dependencies {
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.5'
classpath 'org.springframework.build.gradle:spring-io-plugin:0.0.3.RELEASE'
}
repositories {
maven { url 'http://repo.springsource.org/plugins-release' }
}
dependencies {
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.5'
classpath 'org.springframework.build.gradle:spring-io-plugin:0.0.3.RELEASE'
}
}
ext {
springVersion = "3.1.4.RELEASE"
tomcatVersion = "7.0.53"
springVersion = "3.1.4.RELEASE"
tomcatVersion = "7.0.53"
springAmqpVersion = "1.0.0.RELEASE"
springDataRedisVersion = "1.1.1.RELEASE"
springDataMongoVersion = "1.2.4.RELEASE"
jedisVersion = "2.1.0"
springAmqpVersion = "1.1.1.RELEASE"
springDataRedisVersion = "1.1.1.RELEASE"
springDataMongoVersion = "1.2.4.RELEASE"
commonDbcpVersion = "1.4"
commonDbcp2Version = "2.0"
jedisVersion = "2.1.0"
mysqlDriverVersion = "5.1.29"
mariadbDriverVersion = "1.1.3"
postgresDriverVersion = "9.0-801.jdbc4"
javaxMailVersion = "1.4.7"
cglibVersion = "3.1"
commonDbcpVersion = "1.4"
commonDbcp2Version = "2.0"
jacksonVersion = "2.3.3"
mysqlDriverVersion = "5.1.29"
mariadbDriverVersion = "1.1.3"
postgresDriverVersion = "9.0-801.jdbc4"
javaxMailVersion = "1.4.7"
cglibVersion = "3.1"
log4jVersion = "1.2.17"
jacksonVersion = "2.3.3"
junitVersion = "4.11"
mockitoVersion = "1.9.5"
eurekaClientVersion = "1.1.135"
hadoopCommonVersion = "2.2.0"
junitVersion = "4.11"
mockitoVersion = "1.9.5"
javadocLinks = [
'http://docs.oracle.com/javase/7/docs/api/',
'http://docs.oracle.com/javaee/6/api/',
@@ -45,70 +45,70 @@ ext {
'http://docs.spring.io/spring-amqp/docs/latest-ga/api/',
'http://docs.spring.io/spring-data/data-mongo/docs/current/api/',
'http://docs.spring.io/spring-data/data-redis/docs/current/api/'
] as String[]
] as String[]
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply from: "${rootProject.projectDir}/publish-maven.gradle"
apply plugin: 'propdeps'
apply plugin: 'propdeps-maven'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
if (project.hasProperty('platformVersion')) {
apply plugin: 'spring-io'
apply from: "${rootProject.projectDir}/publish-maven.gradle"
// necessary to resolve the Spring IO versions (which may include snapshots)
repositories {
maven { url "https://repo.spring.io/libs-snapshot" }
}
if (project.hasProperty('platformVersion')) {
apply plugin: 'spring-io'
dependencies {
springIoVersions "io.spring.platform:platform-versions:${platformVersion}@properties"
}
}
// necessary to resolve the Spring IO versions (which may include snapshots)
repositories {
maven { url "https://repo.spring.io/libs-snapshot" }
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
dependencies {
springIoVersions "io.spring.platform:platform-versions:${platformVersion}@properties"
}
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
javadoc {
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
options.author = true
options.header = project.name
}
task packageSources(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
options.author = true
options.header = project.name
}
task packageSources(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
classifier = "javadoc"
from javadoc
}
classifier = "javadoc"
from javadoc
}
artifacts {
archives packageSources
archives javadocJar
}
artifacts {
archives packageSources
archives javadocJar
}
dependencies {
testCompile("junit:junit:$junitVersion")
testCompile("org.mockito:mockito-core:$mockitoVersion")
}
dependencies {
testCompile("junit:junit:$junitVersion")
testCompile("org.mockito:mockito-core:$mockitoVersion")
}
repositories {
mavenLocal()
mavenLocal()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.maven.apache.org/maven2" }
}
}
@@ -117,80 +117,80 @@ configure(rootProject) {
group = 'Distribution'
classifier = 'schema'
description = "Builds -${classifier} archive containing all " +
"XSDs for deployment at static.springframework.org/schema."
"XSDs for deployment at static.springframework.org/schema."
subprojects.each { subproject ->
def Properties schemas = new Properties();
def shortName = subproject.name
subproject.sourceSets.main.resources.find {
it.path.endsWith('META-INF/spring.schemas')
}?.withInputStream { schemas.load(it) }
for (def key : schemas.keySet()) {
File xsdFile = subproject.sourceSets.main.resources.find {
it.path.endsWith(schemas.get(key))
}
assert xsdFile != null
into ("cloud") {
into("cloud") {
from xsdFile.path
}
}
}
}
task api(type: Javadoc) {
group = "Documentation"
description = "Generates aggregated Javadoc API documentation."
title = "${rootProject.description} ${version} API"
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
options.author = true
options.header = rootProject.description
options.links(project.ext.javadocLinks)
group = "Documentation"
description = "Generates aggregated Javadoc API documentation."
title = "${rootProject.description} ${version} API"
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
options.author = true
options.header = rootProject.description
options.links(project.ext.javadocLinks)
source subprojects.collect { project ->
project.sourceSets.main.allJava
}
source subprojects.collect { project ->
project.sourceSets.main.allJava
}
classpath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
classpath = files(subprojects.collect { project ->
project.sourceSets.main.compileClasspath
})
maxMemory = "1024m"
destinationDir = new File(buildDir, "api")
}
maxMemory = "1024m"
destinationDir = new File(buildDir, "api")
}
task docsZip(type: Zip) {
group = 'Distribution'
classifier = 'docs'
description = "Builds -${classifier} archive containing api and reference " +
"for deployment at docs.spring.io/spring-cloud/docs."
"for deployment at docs.spring.io/spring-cloud/docs."
from (api) {
from(api) {
into 'api'
}
}
artifacts {
archives docsZip
archives docsZip
archives schemaZip
}
}
ext {
matrix = [
"mongo13" : [springDataMongoVersion : "1.3.5.RELEASE"],
"mongo14" : [springDataMongoVersion : "1.4.2.RELEASE"],
"mongo15" : [springDataMongoVersion : "1.5.0.RELEASE"],
"jedis22-redis11" : [jedisVersion : "2.2.1", springDataRedisVersion : "1.1.1.RELEASE"],
"jedis23-redis12" : [jedisVersion : "2.3.1", springDataRedisVersion : "1.2.1.RELEASE"],
"jedis23-redis13" : [jedisVersion : "2.3.1", springDataRedisVersion : "1.3.0.RELEASE"],
"jedis24-redis13" : [jedisVersion : "2.4.2", springDataRedisVersion : "1.3.0.RELEASE"],
"amqp11" : [springAmqpVersion: "1.1.4.RELEASE"],
"amqp12" : [springAmqpVersion: "1.2.2.RELEASE"],
"amqp13" : [springAmqpVersion: "1.3.3.RELEASE"],
"spring32": [springVersion : "3.2.9.RELEASE"],
"spring40": [springVersion : "4.0.5.RELEASE"]
"mongo13" : [springDataMongoVersion: "1.3.5.RELEASE"],
"mongo14" : [springDataMongoVersion: "1.4.2.RELEASE"],
"mongo15" : [springDataMongoVersion: "1.5.0.RELEASE"],
"jedis22-redis11": [jedisVersion: "2.2.1", springDataRedisVersion: "1.1.1.RELEASE"],
"jedis23-redis12": [jedisVersion: "2.3.1", springDataRedisVersion: "1.2.1.RELEASE"],
"jedis23-redis13": [jedisVersion: "2.3.1", springDataRedisVersion: "1.3.0.RELEASE"],
"jedis24-redis13": [jedisVersion: "2.4.2", springDataRedisVersion: "1.3.0.RELEASE"],
"amqp11" : [springAmqpVersion: "1.1.4.RELEASE"],
"amqp12" : [springAmqpVersion: "1.2.2.RELEASE"],
"amqp13" : [springAmqpVersion: "1.3.6.RELEASE"],
"spring32" : [springVersion: "3.2.9.RELEASE"],
"spring40" : [springVersion: "4.0.5.RELEASE"]
]
}
@@ -198,15 +198,15 @@ task matrixTests
task defineMatrixTests {
def createTestTask = { name, props ->
task "$name"(type: GradleBuild) {
tasks = ['test']
startParameter.projectProperties = props
}
task "$name"(type: GradleBuild) {
tasks = ['test']
startParameter.projectProperties = props
}
}
matrix.each { sp ->
def testTask = createTestTask(sp.key, sp.value)
matrixTests.dependsOn(testTask.name)
}
}
}
@@ -216,5 +216,5 @@ task dist(dependsOn: assemble) {
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
gradleVersion = '1.12'
}

View File

@@ -1,2 +1,3 @@
version=1.1.1.BUILD-SNAPSHOT
version=1.1.2.BUILD-SNAPSHOT
group=org.springframework.cloud

View File

@@ -1,6 +1,6 @@
#Wed May 14 18:01:52 PDT 2014
#Fri Oct 31 16:08:34 CDT 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

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

@@ -12,18 +12,18 @@ import org.springframework.cloud.service.common.AmqpServiceInfo;
public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator<AmqpServiceInfo> {
public AmqpServiceInfoCreator() {
super(new Tags("rabbitmq"), AmqpServiceInfo.URI_SCHEME);
super(new Tags("rabbitmq"), AmqpServiceInfo.AMQP_SCHEME, AmqpServiceInfo.AMQPS_SCHEME);
}
public AmqpServiceInfo createServiceInfo(Map<String,Object> serviceData) {
@SuppressWarnings("unchecked")
Map<String,Object> credentials = (Map<String, Object>) serviceData.get("credentials");
Map<String,Object> credentials = getCredentials(serviceData);
String id = (String) serviceData.get("name");
String uri = getStringFromCredentials(credentials, "uri", "url");
String uri = getUriFromCredentials(credentials);
String managementUri = getStringFromCredentials(credentials, "http_api_uri");
return new AmqpServiceInfo(id, uri);
return new AmqpServiceInfo(id, uri, managementUri);
}
}

View File

@@ -1,5 +1,7 @@
package org.springframework.cloud.cloudfoundry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -8,23 +10,21 @@ import org.springframework.cloud.service.ServiceInfo;
/**
* @author Ramnivas Laddad
* @author Scott Frederick
*/
public abstract class CloudFoundryServiceInfoCreator<SI extends ServiceInfo> implements ServiceInfoCreator<SI, Map<String, Object>> {
private Tags tags;
private String uriScheme;
private String[] uriSchemes;
public CloudFoundryServiceInfoCreator(Tags tags, String uriScheme) {
public CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes) {
this.tags = tags;
this.uriScheme = uriScheme;
}
public CloudFoundryServiceInfoCreator(Tags tags) {
this(tags, null);
this.uriSchemes = uriSchemes;
}
public boolean accept(Map<String, Object> serviceData) {
return tagsMatch(serviceData) || labelStartsWithTag(serviceData) || uriMatchesScheme(serviceData);
return tagsMatch(serviceData) || labelStartsWithTag(serviceData) ||
uriMatchesScheme(serviceData) || uriKeyMatchesScheme(serviceData);
}
@SuppressWarnings("unchecked")
@@ -39,24 +39,56 @@ public abstract class CloudFoundryServiceInfoCreator<SI extends ServiceInfo> imp
}
protected boolean uriMatchesScheme(Map<String, Object> serviceData) {
if (uriScheme == null) {
if (uriSchemes == null) {
return false;
}
@SuppressWarnings("unchecked")
Map<String, String> credentials = (Map<String, String>) serviceData.get("credentials");
if (credentials != null) {
String uri = credentials.get("uri");
if (uri == null) {
uri = credentials.get("url");
}
if (uri != null) {
return uri.startsWith(uriScheme + "://");
String uri = getUriFromCredentials(getCredentials(serviceData));
if (uri != null) {
for (String uriScheme : uriSchemes) {
if (uri.startsWith(uriScheme + "://")) {
return true;
}
}
}
return false;
}
protected boolean uriKeyMatchesScheme(Map<String, Object> serviceData) {
if (uriSchemes == null) {
return false;
}
Map<String, Object> credentials = getCredentials(serviceData);
for (String uriScheme : uriSchemes) {
if (credentials.containsKey(uriScheme + "Uri") || credentials.containsKey(uriScheme + "uri") ||
credentials.containsKey(uriScheme + "Url") || credentials.containsKey(uriScheme + "url")) {
return true;
}
}
return false;
}
@SuppressWarnings("unchecked")
protected Map<String, Object> getCredentials(Map<String, Object> serviceData) {
return (Map<String, Object>) serviceData.get("credentials");
}
protected String getUriFromCredentials(Map<String, Object> credentials) {
List<String> keys = new ArrayList<String>();
keys.addAll(Arrays.asList("uri", "url"));
for (String uriScheme : uriSchemes) {
keys.add(uriScheme + "Uri");
keys.add(uriScheme + "uri");
keys.add(uriScheme + "Url");
keys.add(uriScheme + "url");
}
return getStringFromCredentials(credentials, keys.toArray(new String[keys.size()]));
}
protected String getStringFromCredentials(Map<String, Object> credentials, String... keys) {
for (String key : keys) {
if (credentials.containsKey(key)) {
@@ -66,7 +98,21 @@ public abstract class CloudFoundryServiceInfoCreator<SI extends ServiceInfo> imp
return null;
}
public String getUriScheme() {
return uriScheme;
protected int getIntFromCredentials(Map<String, Object> credentials, String... keys) {
for (String key : keys) {
if (credentials.containsKey(key)) {
// allows the value to be quoted as a String or native integer type
return Integer.parseInt(credentials.get(key).toString());
}
}
return -1;
}
public String[] getUriSchemes() {
return uriSchemes;
}
public String getDefaultUriScheme() {
return uriSchemes[0];
}
}

View File

@@ -12,17 +12,14 @@ import org.springframework.cloud.service.common.MongoServiceInfo;
public class MongoServiceInfoCreator extends CloudFoundryServiceInfoCreator<MongoServiceInfo> {
public MongoServiceInfoCreator() {
// the literal in the tag is CloudFoundry-specific
super(new Tags("mongodb"), MongoServiceInfo.URI_SCHEME);
// the literal in the tag is CloudFoundry-specific
super(new Tags("mongodb"), MongoServiceInfo.MONGODB_SCHEME);
}
public MongoServiceInfo createServiceInfo(Map<String,Object> serviceData) {
@SuppressWarnings("unchecked")
Map<String,Object> credentials = (Map<String, Object>) serviceData.get("credentials");
String id = (String) serviceData.get("name");
String uri = getStringFromCredentials(credentials, "uri", "url");
String uri = getUriFromCredentials(getCredentials(serviceData));
return new MongoServiceInfo(id, uri);
}

View File

@@ -10,8 +10,8 @@ import org.springframework.cloud.service.common.MysqlServiceInfo;
public class MysqlServiceInfoCreator extends RelationalServiceInfoCreator<MysqlServiceInfo> {
public MysqlServiceInfoCreator() {
// the literal in the tag is CloudFoundry-specific
super(new Tags("mysql"), MysqlServiceInfo.URI_SCHEME);
// the literal in the tag is CloudFoundry-specific
super(new Tags("mysql"), MysqlServiceInfo.MYSQL_SCHEME);
}
@Override

View File

@@ -4,7 +4,7 @@ import org.springframework.cloud.service.common.OracleServiceInfo;
public class OracleServiceInfoCreator extends RelationalServiceInfoCreator<OracleServiceInfo> {
public OracleServiceInfoCreator() {
super(new Tags(), OracleServiceInfo.URI_SCHEME);
super(new Tags(), OracleServiceInfo.ORACLE_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo;
public class PostgresqlServiceInfoCreator extends RelationalServiceInfoCreator<PostgresqlServiceInfo> {
public PostgresqlServiceInfoCreator() {
super(new Tags("postgresql"), PostgresqlServiceInfo.URI_SCHEME);
super(new Tags("postgresql"), PostgresqlServiceInfo.POSTGRES_SCHEME);
}
@Override

View File

@@ -12,21 +12,19 @@ import org.springframework.cloud.service.common.RedisServiceInfo;
public class RedisServiceInfoCreator extends CloudFoundryServiceInfoCreator<RedisServiceInfo> {
public RedisServiceInfoCreator() {
// the literal in the tag is CloudFoundry-specific
super(new Tags("redis"), RedisServiceInfo.URI_SCHEME);
// the literal in the tag is CloudFoundry-specific
super(new Tags("redis"), RedisServiceInfo.REDIS_SCHEME);
}
public RedisServiceInfo createServiceInfo(Map<String,Object> serviceData) {
@SuppressWarnings("unchecked")
Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials");
String id = (String) serviceData.get("name");
String uri = getStringFromCredentials(credentials, "uri", "url");
Map<String, Object> credentials = getCredentials(serviceData);
String uri = getUriFromCredentials(credentials);
if (uri == null) {
String host = getStringFromCredentials(credentials, "hostname", "host");
Integer port = Integer.parseInt(credentials.get("port").toString());
Integer port = getIntFromCredentials(credentials, "port");
String password = (String) credentials.get("password");
return new RedisServiceInfo(id, host, port, password);

View File

@@ -12,30 +12,28 @@ import org.springframework.cloud.util.UriInfo;
*/
public abstract class RelationalServiceInfoCreator<SI extends RelationalServiceInfo> extends CloudFoundryServiceInfoCreator<SI> {
public RelationalServiceInfoCreator(Tags tags, String uriScheme) {
super(tags, uriScheme);
public RelationalServiceInfoCreator(Tags tags, String... uriSchemes) {
super(tags, uriSchemes);
}
public abstract SI createServiceInfo(String id, String uri);
public SI createServiceInfo(Map<String,Object> serviceData) {
@SuppressWarnings("unchecked")
Map<String,Object> credentials = (Map<String, Object>) serviceData.get("credentials");
public SI createServiceInfo(Map<String, Object> serviceData) {
String id = (String) serviceData.get("name");
String uri = getStringFromCredentials(credentials, "uri", "url");
Map<String,Object> credentials = getCredentials(serviceData);
String uri = getUriFromCredentials(credentials);
if (uri == null) {
String host = getStringFromCredentials(credentials, "hostname", "host");
int port = Integer.parseInt(credentials.get("port").toString()); // allows the port attribute to be quoted or plain
int port = getIntFromCredentials(credentials, "port");
String username = getStringFromCredentials(credentials, "user", "username");
String password = (String) credentials.get("password");
String database = (String) credentials.get("name");
uri = new UriInfo(getUriScheme(), host, port, username, password, database).toString();
uri = new UriInfo(getDefaultUriScheme(), host, port, username, password, database).toString();
}
return createServiceInfo(id, uri);

View File

@@ -8,6 +8,7 @@ import org.springframework.cloud.util.UriInfo;
/**
*
* @author Ramnivas Laddad
* @author Scott Frederick
*
*/
public class SmtpServiceInfoCreator extends CloudFoundryServiceInfoCreator<SmtpServiceInfo> {
@@ -15,27 +16,30 @@ public class SmtpServiceInfoCreator extends CloudFoundryServiceInfoCreator<SmtpS
private static final int DEFAULT_SMTP_PORT = 587;
public SmtpServiceInfoCreator() {
// the literal in the tag is CloudFoundry-specific
super(new Tags("smtp"), SmtpServiceInfo.URI_SCHEME);
super(new Tags("smtp"), SmtpServiceInfo.SMTP_SCHEME);
}
public SmtpServiceInfo createServiceInfo(Map<String,Object> serviceData) {
public SmtpServiceInfo createServiceInfo(Map<String, Object> serviceData) {
String id = (String) serviceData.get("name");
@SuppressWarnings("unchecked")
Map<String,Object> credentials = (Map<String, Object>) serviceData.get("credentials");
String host = (String) credentials.get("hostname");
Map<String, Object> credentials = getCredentials(serviceData);
int port = DEFAULT_SMTP_PORT;
if (credentials.containsKey("port")) {
port = Integer.parseInt(credentials.get("port").toString());
String uri = getUriFromCredentials(credentials);
if (uri == null) {
String host = getStringFromCredentials(credentials, "host", "hostname");
int port = getIntFromCredentials(credentials, "port");
if (port == -1) {
port = DEFAULT_SMTP_PORT;
}
String username = getStringFromCredentials(credentials, "user", "username");
String password = getStringFromCredentials(credentials, "password");
uri = new UriInfo(SmtpServiceInfo.SMTP_SCHEME, host, port, username, password).toString();
}
String username = (String) credentials.get("username");
String password = (String) credentials.get("password");
String uri = new UriInfo(SmtpServiceInfo.URI_SCHEME, host, port, username, password).toString();
return new SmtpServiceInfo(id, uri);
}

View File

@@ -11,11 +11,15 @@ import java.util.Scanner;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.internal.matchers.InstanceOf;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.util.EnvironmentAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* Base test class that provides setup and utility methods to generate test payload
*
@@ -120,5 +124,14 @@ public abstract class AbstractCloudFoundryConnectorTest {
private static String quote(String str) {
return "\"" + str + "\"";
}
protected static void assertServiceFoundOfType(ServiceInfo serviceInfo, Class<? extends ServiceInfo> type) {
assertNotNull(serviceInfo);
assertThat(serviceInfo, new InstanceOf(type));
}
protected static void assertServiceFoundOfType(List<ServiceInfo> serviceInfos, String serviceId, Class<? extends ServiceInfo> type) {
ServiceInfo serviceInfo = getServiceInfo(serviceInfos, serviceId);
assertServiceFoundOfType(serviceInfo, type);
}
}

View File

@@ -1,12 +1,16 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.Test;
import org.mockito.internal.matchers.InstanceOf;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.AmqpServiceInfo;
/**
*
@@ -22,8 +26,34 @@ public class CloudFoundryConnectorAmqpServiceTest extends AbstractCloudFoundryCo
getRabbitServicePayloadWithTags("rabbit-2", hostname, port, username, password, "q-2", "vhost2")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "rabbit-1"));
assertNotNull(getServiceInfo(serviceInfos, "rabbit-2"));
assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class);
}
@Test
public void rabbitServiceCreationWithManagementUri() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getRabbitServicePayloadWithTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1")));
String expectedManagementUri = "http://" + username + ":" + password + "@" + hostname + "/api";
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0);
assertEquals(amqpServiceInfo.getManagementUri(), expectedManagementUri);
}
@Test
public void rabbitServiceCreationWithoutManagementUri() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getRabbitServicePayloadNoLabelNoTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0);
assertNull(amqpServiceInfo.getManagementUri());
}
@Test
@@ -34,20 +64,32 @@ public class CloudFoundryConnectorAmqpServiceTest extends AbstractCloudFoundryCo
getRabbitServicePayloadWithoutTags("rabbit-2", hostname, port, username, password, "q-2", "vhost2")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "rabbit-1"));
assertNotNull(getServiceInfo(serviceInfos, "rabbit-2"));
assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class);
}
@Test
public void rabbitServiceCreationNoLabelNoTags() {
@Test
public void rabbitServiceCreationNoLabelNoTags() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getRabbitServicePayloadNoLabelNoTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1"),
getRabbitServicePayloadNoLabelNoTags("rabbit-2", hostname, port, username, password, "q-2", "vhost2")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "rabbit-1"));
assertNotNull(getServiceInfo(serviceInfos, "rabbit-2"));
assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class);
}
@Test
public void rabbitServiceCreationNoLabelNoTagsSecure() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getRabbitServicePayloadNoLabelNoTagsSecure("rabbit-1", hostname, port, username, password, "q-1", "vhost1"),
getRabbitServicePayloadNoLabelNoTagsSecure("rabbit-2", hostname, port, username, password, "q-2", "vhost2")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class);
}
private String getRabbitServicePayloadWithoutTags(String serviceName,
@@ -66,6 +108,14 @@ public class CloudFoundryConnectorAmqpServiceTest extends AbstractCloudFoundryCo
hostname, port, user, password, name, vHost);
}
private String getRabbitServicePayloadNoLabelNoTagsSecure(String serviceName,
String hostname, int port,
String user, String password, String name,
String vHost) {
return getRabbitServicePayload("test-rabbit-info-no-label-no-tags-secure.json", serviceName,
hostname, port, user, password, name, vHost);
}
private String getRabbitServicePayloadWithTags(String serviceName,
String hostname, int port,
String user, String password, String name,

View File

@@ -1,68 +1,66 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.Test;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.MongoServiceInfo;
/**
*
* @author Ramnivas Laddad
*
*/
public class CloudFoundryConnectorMongodbServiceTest extends AbstractCloudFoundryConnectorTest {
@Test
public void mongoServiceCreation() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getMongoServicePayload("mongo-1", hostname, port, username, password, "inventory-1", "db"),
getMongoServicePayload("mongo-2", hostname, port, username, password, "inventory-2", "db")));
.thenReturn(getServicesPayload(
getMongoServicePayload("mongo-1", hostname, port, username, password, "inventory-1", "db"),
getMongoServicePayload("mongo-2", hostname, port, username, password, "inventory-2", "db")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "mongo-1"));
assertNotNull(getServiceInfo(serviceInfos, "mongo-2"));
assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
@Test
public void mongoServiceCreationNoLabelNoTags() {
@Test
public void mongoServiceCreationNoLabelNoTags() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getMongoServicePayloadNoLabelNoTags("mongo-1", hostname, port, username, password, "inventory-1", "db"),
getMongoServicePayloadNoLabelNoTags("mongo-2", hostname, port, username, password, "inventory-2", "db")));
.thenReturn(getServicesPayload(
getMongoServicePayloadNoLabelNoTags("mongo-1", hostname, port, username, password, "inventory-1", "db"),
getMongoServicePayloadNoLabelNoTags("mongo-2", hostname, port, username, password, "inventory-2", "db")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "mongo-1"));
assertNotNull(getServiceInfo(serviceInfos, "mongo-2"));
}
private String getMongoServicePayload(String serviceName, String hostname, int port,
String username, String password, String db, String name) {
return getMongoServicePayload("test-mongodb-info.json",
serviceName, hostname, port, username, password, db, name);
return getMongoServicePayload("test-mongodb-info.json",
serviceName, hostname, port, username, password, db, name);
}
private String getMongoServicePayloadNoLabelNoTags(String serviceName,
String hostname, int port,
String username, String password, String db, String name) {
return getMongoServicePayload("test-mongodb-info-no-label-no-tags.json",
serviceName, hostname, port, username, password, db, name);
}
private String getMongoServicePayloadNoLabelNoTags(String serviceName,
String hostname, int port,
String username, String password, String db, String name) {
return getMongoServicePayload("test-mongodb-info-no-label-no-tags.json",
serviceName, hostname, port, username, password, db, name);
}
private String getMongoServicePayload(String payloadFile, String serviceName,
String hostname, int port,
String username, String password, String db, String name) {
String payload = readTestDataFile(payloadFile);
payload = payload.replace("$serviceName", serviceName);
payload = payload.replace("$hostname", hostname);
payload = payload.replace("$port", Integer.toString(port));
payload = payload.replace("$username", username);
payload = payload.replace("$password", password);
payload = payload.replace("$db", db);
payload = payload.replace("$name", name);
return payload;
}
private String getMongoServicePayload(String payloadFile, String serviceName,
String hostname, int port,
String username, String password, String db, String name) {
String payload = readTestDataFile(payloadFile);
payload = payload.replace("$serviceName", serviceName);
payload = payload.replace("$hostname", hostname);
payload = payload.replace("$port", Integer.toString(port));
payload = payload.replace("$username", username);
payload = payload.replace("$password", password);
payload = payload.replace("$db", db);
payload = payload.replace("$name", name);
return payload;
}
}

View File

@@ -1,12 +1,12 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.Test;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.MonitoringServiceInfo;
/**
*
@@ -21,7 +21,7 @@ public class CloudFoundryConnectorMonitoringServiceTest extends AbstractCloudFou
.thenReturn(getServicesPayload(getMonitoringServicePayload("monitoring-1")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "monitoring-1"));
assertServiceFoundOfType(serviceInfos, "monitoring-1", MonitoringServiceInfo.class);
}
private String getMonitoringServicePayload(String serviceName) {

View File

@@ -1,7 +1,6 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.List;
@@ -28,8 +27,9 @@ public class CloudFoundryConnectorMysqlServiceTest extends AbstractCloudFoundryC
MysqlServiceInfo info1 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-1");
MysqlServiceInfo info2 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-2");
assertNotNull(info1);
assertNotNull(info2);
assertServiceFoundOfType(info1, MysqlServiceInfo.class);
assertServiceFoundOfType(info2, MysqlServiceInfo.class);
assertEquals(getJdbcUrl("mysql", name1), info1.getJdbcUrl());
assertEquals(getJdbcUrl("mysql", name2), info2.getJdbcUrl());
}
@@ -46,8 +46,8 @@ public class CloudFoundryConnectorMysqlServiceTest extends AbstractCloudFoundryC
MysqlServiceInfo info1 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-1");
MysqlServiceInfo info2 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-2");
assertNotNull(info1);
assertNotNull(info2);
assertServiceFoundOfType(info1, MysqlServiceInfo.class);
assertServiceFoundOfType(info2, MysqlServiceInfo.class);
assertEquals(getJdbcUrl("mysql", name1), info1.getJdbcUrl());
assertEquals(getJdbcUrl("mysql", name2), info2.getJdbcUrl());
}
@@ -64,8 +64,8 @@ public class CloudFoundryConnectorMysqlServiceTest extends AbstractCloudFoundryC
MysqlServiceInfo info1 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-1");
MysqlServiceInfo info2 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-2");
assertNotNull(info1);
assertNotNull(info2);
assertServiceFoundOfType(info1, MysqlServiceInfo.class);
assertServiceFoundOfType(info2, MysqlServiceInfo.class);
assertEquals(getJdbcUrl("mysql", name1), info1.getJdbcUrl());
assertEquals(getJdbcUrl("mysql", name2), info2.getJdbcUrl());
}
@@ -82,8 +82,8 @@ public class CloudFoundryConnectorMysqlServiceTest extends AbstractCloudFoundryC
MysqlServiceInfo info1 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-1");
MysqlServiceInfo info2 = (MysqlServiceInfo) getServiceInfo(serviceInfos, "mysql-2");
assertNotNull(info1);
assertNotNull(info2);
assertServiceFoundOfType(info1, MysqlServiceInfo.class);
assertServiceFoundOfType(info2, MysqlServiceInfo.class);
assertEquals(getJdbcUrl("mysql", name1), info1.getJdbcUrl());
assertEquals(getJdbcUrl("mysql", name2), info2.getJdbcUrl());
}

View File

@@ -27,7 +27,7 @@ public class CloudFoundryConnectorOracleServiceTest extends AbstractUserProvided
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
OracleServiceInfo info = (OracleServiceInfo) getServiceInfo(serviceInfos, SERVICE_NAME);
assertNotNull(info);
assertServiceFoundOfType(info, OracleServiceInfo.class);
assertEquals(getOracleJdbcUrl(INSTANCE_NAME), info.getJdbcUrl());
}

View File

@@ -1,7 +1,6 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.List;
@@ -27,8 +26,9 @@ public class CloudFoundryConnectorPostgresqlServiceTest extends AbstractCloudFou
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
PostgresqlServiceInfo info1 = (PostgresqlServiceInfo) getServiceInfo(serviceInfos, "postgresql-1");
PostgresqlServiceInfo info2 = (PostgresqlServiceInfo) getServiceInfo(serviceInfos, "postgresql-2");
assertNotNull(info1);
assertNotNull(info2);
assertServiceFoundOfType(info1, PostgresqlServiceInfo.class);
assertServiceFoundOfType(info2, PostgresqlServiceInfo.class);
assertEquals(getJdbcUrl("postgres", name1), info1.getJdbcUrl());
assertEquals(getJdbcUrl("postgres", name2), info2.getJdbcUrl());
}
@@ -45,8 +45,9 @@ public class CloudFoundryConnectorPostgresqlServiceTest extends AbstractCloudFou
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
PostgresqlServiceInfo info1 = (PostgresqlServiceInfo) getServiceInfo(serviceInfos, "postgresql-1");
PostgresqlServiceInfo info2 = (PostgresqlServiceInfo) getServiceInfo(serviceInfos, "postgresql-2");
assertNotNull(info1);
assertNotNull(info2);
assertServiceFoundOfType(info1, PostgresqlServiceInfo.class);
assertServiceFoundOfType(info2, PostgresqlServiceInfo.class);
assertEquals(getJdbcUrl("postgres", name1), info1.getJdbcUrl());
assertEquals(getJdbcUrl("postgres", name2), info2.getJdbcUrl());
}

View File

@@ -1,12 +1,12 @@
package org.springframework.cloud.cloudfoundry;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.Test;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.common.RedisServiceInfo;
/**
*
@@ -22,8 +22,8 @@ public class CloudFoundryConnectorRedisServiceTest extends AbstractCloudFoundryC
getRedisServicePayload("redis-2", hostname, port, password, "redis-db")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "redis-1"));
assertNotNull(getServiceInfo(serviceInfos, "redis-2"));
assertServiceFoundOfType(serviceInfos, "redis-1", RedisServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "redis-2", RedisServiceInfo.class);
}
@Test
@@ -34,8 +34,8 @@ public class CloudFoundryConnectorRedisServiceTest extends AbstractCloudFoundryC
getRedisServicePayloadNoLabelNoTags("redis-2", hostname, port, password, "redis-db")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertNotNull(getServiceInfo(serviceInfos, "redis-1"));
assertNotNull(getServiceInfo(serviceInfos, "redis-2"));
assertServiceFoundOfType(serviceInfos, "redis-1", RedisServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "redis-2", RedisServiceInfo.class);
}
private String getRedisServicePayload(String serviceName,

View File

@@ -23,12 +23,26 @@ public class CloudFoundryConnectorSmtpServiceTest extends AbstractCloudFoundryCo
.thenReturn(getServicesPayload(getSmtpServicePayload("smtp-1", hostname, username, password)));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
SmtpServiceInfo smptServiceInfo = (SmtpServiceInfo) getServiceInfo(serviceInfos, "smtp-1");
assertNotNull(smptServiceInfo);
assertEquals(hostname, smptServiceInfo.getHost());
assertEquals(587, smptServiceInfo.getPort());
assertEquals(username, smptServiceInfo.getUserName());
assertEquals(password, smptServiceInfo.getPassword());
SmtpServiceInfo smtpServiceInfo = (SmtpServiceInfo) getServiceInfo(serviceInfos, "smtp-1");
assertNotNull(smtpServiceInfo);
assertEquals(hostname, smtpServiceInfo.getHost());
assertEquals(587, smtpServiceInfo.getPort());
assertEquals(username, smtpServiceInfo.getUserName());
assertEquals(password, smtpServiceInfo.getPassword());
}
@Test
public void smtpServiceCreationWithUri() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(getSmtpServicePayloadWithUri("smtp-1", hostname, port, username, password)));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
SmtpServiceInfo smtpServiceInfo = (SmtpServiceInfo) getServiceInfo(serviceInfos, "smtp-1");
assertNotNull(smtpServiceInfo);
assertEquals(hostname, smtpServiceInfo.getHost());
assertEquals(port, smtpServiceInfo.getPort());
assertEquals(username, smtpServiceInfo.getUserName());
assertEquals(password, smtpServiceInfo.getPassword());
}
private String getSmtpServicePayload(String serviceName, String hostname,
@@ -41,4 +55,16 @@ public class CloudFoundryConnectorSmtpServiceTest extends AbstractCloudFoundryCo
return payload;
}
private String getSmtpServicePayloadWithUri(String serviceName, String hostname, int port,
String user, String password) {
String payload = readTestDataFile("test-smtp-info-uri.json");
payload = payload.replace("$serviceName", serviceName);
payload = payload.replace("$hostname", hostname);
payload = payload.replace("$port", String.valueOf(port));
payload = payload.replace("$username", user);
payload = payload.replace("$password", password);
return payload;
}
}

View File

@@ -0,0 +1,191 @@
package org.springframework.cloud.cloudfoundry;
import org.junit.Test;
import org.springframework.cloud.service.BaseServiceInfo;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
public class CloudFoundryServiceInfoCreatorTest {
@Test
public void tagsMatch() {
DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags("firstTag", "secondTag"));
assertAcceptedWithTags(serviceInfoCreator, "firstTag", "noMatchTag");
assertAcceptedWithTags(serviceInfoCreator, "noMatchTag", "secondTag");
assertAcceptedWithTags(serviceInfoCreator, "firstTag", "secondTag");
assertNotAcceptedWithTags(serviceInfoCreator, "noMatchTag");
assertNotAcceptedWithTags(serviceInfoCreator);
}
@Test
public void labelMatches() {
DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags("testTag"));
assertAcceptedWithLabel(serviceInfoCreator, "testTag");
assertAcceptedWithLabel(serviceInfoCreator, "testTagWithSuffix");
assertNotAcceptedWithLabel(serviceInfoCreator, "withPrefixTestTag");
assertNotAcceptedWithLabel(serviceInfoCreator, "noMatchTag");
}
@Test
public void uriSchemeMatches() {
DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags(), "amqp", "amqps");
assertAcceptedWithCredentials(serviceInfoCreator, "uri", "amqp://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "uri", "amqps://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "url", "amqp://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "url", "amqps://example.com");
assertNotAcceptedWithCredentials(serviceInfoCreator, "uri", "http://example.com");
assertNotAcceptedWithCredentials(serviceInfoCreator, "url", "http://example.com");
assertNotAcceptedWithCredentials(serviceInfoCreator, "otherkey", "amqp://example.com");
assertNotAcceptedWithCredentials(serviceInfoCreator, "otherkey", "amqps://example.com");
}
@Test
public void uriKeyMatchesScheme() {
DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags(), "amqp", "amqps");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpUri", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpsUri", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpUrl", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpsUrl", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpuri", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpsuri", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpurl", "http://example.com");
assertAcceptedWithCredentials(serviceInfoCreator, "amqpsurl", "http://example.com");
}
@Test
public void uriFromCredentials() {
DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags(), "amqp", "amqps");
assertUriRetrieved(serviceInfoCreator, "uri", "amqp://example.com");
assertUriRetrieved(serviceInfoCreator, "uri", "amqps://example.com");
assertUriRetrieved(serviceInfoCreator, "url", "amqp://example.com");
assertUriRetrieved(serviceInfoCreator, "url", "amqps://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpUri", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpsUri", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpUrl", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpsUrl", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpuri", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpsuri", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpurl", "http://example.com");
assertUriRetrieved(serviceInfoCreator, "amqpsurl", "http://example.com");
}
@Test
public void uriFromCredentialsWithNoSchemes() {
DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags());
assertUriRetrieved(serviceInfoCreator, "uri", "amqp://example.com");
assertUriRetrieved(serviceInfoCreator, "url", "amqp://example.com");
}
private void assertUriRetrieved(DummyServiceInfoCreator serviceInfoCreator, String key, String value) {
Map<String, Object> serviceData = new ServiceDataBuilder().withCredentials(key, value).build();
Map<String, Object> credentials = serviceInfoCreator.getCredentials(serviceData);
String uri = serviceInfoCreator.getUriFromCredentials(credentials);
assertEquals(value, uri);
}
private void assertAcceptedWithTags(DummyServiceInfoCreator serviceInfoCreator, String... tags) {
Map<String, Object> serviceData = new ServiceDataBuilder().withTags(tags).build();
assertTrue(serviceInfoCreator.accept(serviceData));
}
private void assertNotAcceptedWithTags(DummyServiceInfoCreator serviceInfoCreator, String... tags) {
Map<String, Object> serviceData = new ServiceDataBuilder().withTags(tags).build();
assertFalse(serviceInfoCreator.accept(serviceData));
}
private void assertAcceptedWithLabel(DummyServiceInfoCreator serviceInfoCreator, String label) {
Map<String, Object> serviceData = new ServiceDataBuilder().withLabel(label).build();
assertTrue(serviceInfoCreator.accept(serviceData));
}
private void assertNotAcceptedWithLabel(DummyServiceInfoCreator serviceInfoCreator, String label) {
Map<String, Object> serviceData = new ServiceDataBuilder().withLabel(label).build();
assertFalse(serviceInfoCreator.accept(serviceData));
}
private void assertAcceptedWithCredentials(DummyServiceInfoCreator serviceInfoCreator, String key, String value) {
Map<String, Object> serviceData = new ServiceDataBuilder().withCredentials(key, value).build();
assertTrue(serviceInfoCreator.accept(serviceData));
}
private void assertNotAcceptedWithCredentials(DummyServiceInfoCreator serviceInfoCreator, String key, String value) {
Map<String, Object> serviceData = new ServiceDataBuilder().withCredentials(key, value).build();
assertFalse(serviceInfoCreator.accept(serviceData));
}
private class ServiceDataBuilder {
private String[] tags = new String[0];
private String label = "";
private Map<String, Object> credentials = new HashMap<String, Object>();
public ServiceDataBuilder withTags(String... tags) {
this.tags = tags;
return this;
}
public ServiceDataBuilder withCredentials(String key, String value) {
credentials.put(key, value);
return this;
}
public ServiceDataBuilder withLabel(String label) {
this.label = label;
return this;
}
public Map<String, Object> build() {
Map<String, Object> serviceData = new HashMap<String, Object>();
serviceData.put("tags", Arrays.asList(tags));
serviceData.put("label", label);
serviceData.put("credentials", credentials);
return serviceData;
}
}
private class DummyServiceInfoCreator extends CloudFoundryServiceInfoCreator<DummyServiceInfo> {
public DummyServiceInfoCreator(Tags tags) {
super(tags);
}
public DummyServiceInfoCreator(Tags tags, String... uriSchemes) {
super(tags, uriSchemes);
}
@Override
public DummyServiceInfo createServiceInfo(Map<String, Object> serviceData) {
return new DummyServiceInfo("test");
}
}
private class DummyServiceInfo extends BaseServiceInfo {
public DummyServiceInfo(String id) {
super(id);
}
@Override
public String getId() {
return null;
}
}
}

View File

@@ -1,6 +0,0 @@
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n

View File

@@ -0,0 +1,6 @@
{
"name":"$serviceName",
"credentials":{
"uri": "amqps://$username:$password@$hostname/$virtualHost"
}
}

View File

@@ -4,6 +4,7 @@
"plan":"free",
"tags":["amqp","rabbitmq"],
"credentials":{
"uri": "amqp://$username:$password@$hostname/$virtualHost"
"uri": "amqp://$username:$password@$hostname/$virtualHost",
"http_api_uri": "http://$user:$pass@$hostname/api"
}
}

View File

@@ -0,0 +1,6 @@
{
"name": "$serviceName",
"credentials": {
"uri": "smtp://$username:$password@$hostname:$port"
}
}

View File

@@ -1,11 +1,11 @@
{
"name": "$serviceName",
"label": "sendgrid",
"plan": "free",
"tags":["smtp"],
"credentials": {
"hostname" : "$hostname",
"username" : "$username",
"password" : "$password"
}
"name": "$serviceName",
"label": "sendgrid",
"plan": "free",
"tags": ["smtp"],
"credentials": {
"hostname": "$hostname",
"username": "$username",
"password": "$password"
}
}

View File

@@ -7,6 +7,7 @@
"port": "$port",
"username": "$user",
"password": "$password",
"name": "$name"
"name": "$name",
"integer": 123
}
}

View File

@@ -11,91 +11,103 @@ import org.springframework.cloud.util.UriInfoFactory;
*
*/
public abstract class UriBasedServiceInfo extends BaseServiceInfo {
private UriInfo uriInfo;
private UriInfo uriInfo;
private static UriInfoFactory uriFactory = new StandardUriInfoFactory();
private static UriInfoFactory uriFactory = new StandardUriInfoFactory();
public UriBasedServiceInfo(String id, String scheme, String host, int port, String username, String password, String path) {
super(id);
this.uriInfo = getUriInfoFactory().createUri(scheme, host, port, username, password, path);
this.uriInfo = validateAndCleanUriInfo(uriInfo);
}
public UriBasedServiceInfo(String id, String scheme, String host, int port, String username, String password, String path) {
super(id);
this.uriInfo = getUriInfoFactory().createUri(scheme, host, port, username, password, path);
this.uriInfo = validateAndCleanUriInfo(uriInfo);
}
public UriBasedServiceInfo(String id, String uriString) {
super(id);
this.uriInfo = getUriInfoFactory().createUri(uriString);
this.uriInfo = validateAndCleanUriInfo(uriInfo);
}
public UriBasedServiceInfo(String id, String uriString) {
super(id);
this.uriInfo = getUriInfoFactory().createUri(uriString);
this.uriInfo = validateAndCleanUriInfo(uriInfo);
}
/**
* For URI-based (@link ServiceInfo}s which don't conform to the standard URI
* format, override this method in your own ServiceInfo class to return a {@link UriInfoFactory} which will create the
* appropriate URIs.
*
* @return your special UriInfoFactory
*/
public UriInfoFactory getUriInfoFactory() {
return uriFactory;
}
/**
* For URI-based (@link ServiceInfo}s which don't conform to the standard URI
* format, override this method in your own ServiceInfo class to return a {@link UriInfoFactory} which will create the
* appropriate URIs.
*
* @return your special UriInfoFactory
*/
public UriInfoFactory getUriInfoFactory() {
return uriFactory;
}
@ServiceProperty(category = "connection")
public String getUri() {
return uriInfo.getUri().toString();
}
@ServiceProperty(category = "connection")
public String getUri() {
// converting a URI string that contains multiple hosts, ports, etc won't parse correctly.
// first attempt to use the parsed URI from the UriInfo, otherwise return the raw URI string
// that will be passed to the underlying driver / properties.
//
// TODO: either simply use URI strings or provide better support for URI's containing multiple hosts, etc.
//
if (uriInfo.getHost() != null) {
return uriInfo.getUri().toString();
}
@ServiceProperty(category = "connection")
public String getUserName() {
return uriInfo.getUserName();
}
return uriInfo.getRawUriString();
}
@ServiceProperty(category = "connection")
public String getPassword() {
return uriInfo.getPassword();
}
@ServiceProperty(category = "connection")
public String getUserName() {
return uriInfo.getUserName();
}
@ServiceProperty(category = "connection")
public String getHost() {
return uriInfo.getHost();
}
@ServiceProperty(category = "connection")
public String getPassword() {
return uriInfo.getPassword();
}
@ServiceProperty(category = "connection")
public int getPort() {
return uriInfo.getPort();
}
@ServiceProperty(category = "connection")
public String getHost() {
return uriInfo.getHost();
}
@ServiceProperty(category = "connection")
public String getPath() {
return uriInfo.getPath();
}
@ServiceProperty(category = "connection")
public int getPort() {
return uriInfo.getPort();
}
@ServiceProperty(category = "connection")
public String getQuery() {
return uriInfo.getQuery();
}
@ServiceProperty(category = "connection")
public String getPath() {
return uriInfo.getPath();
}
@ServiceProperty(category = "connection")
public String getScheme() {
return uriInfo.getScheme();
}
@ServiceProperty(category = "connection")
public String getQuery() {
return uriInfo.getQuery();
}
/**
* Validate the URI and clean it up by using defaults for any missing information, if possible.
*
* @param uriInfo
* uri info based on parsed payload
* @return cleaned up uri info
*/
protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) {
return uriInfo;
}
@ServiceProperty(category = "connection")
public String getScheme() {
return uriInfo.getScheme();
}
protected UriInfo getUriInfo() {
return uriInfo;
}
/**
* Validate the URI and clean it up by using defaults for any missing information, if possible.
*
* @param uriInfo
* uri info based on parsed payload
* @return cleaned up uri info
*/
protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) {
return uriInfo;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + getScheme() + "://" + getUserName() + ":****@" + getHost() + ":" + getPort()
+ "/" + getPath() + "]";
}
protected UriInfo getUriInfo() {
return uriInfo;
}
@Override
public String toString() {
// TODO: when using a simple URI string (see comments in getUri), the result of uriInfo.getRawUriString()
// would display the password which does not seem ideal.
return getClass().getSimpleName() + "[" + getScheme() + "://" + getUserName() + ":****@" + getHost() + ":" + getPort()
+ "/" + getPath() + "]";
}
}

View File

@@ -2,24 +2,30 @@ package org.springframework.cloud.service;
import org.springframework.cloud.ServiceInfoCreator;
public abstract class UriBasedServiceInfoCreator<SI extends ServiceInfo> implements
ServiceInfoCreator<ServiceInfo, UriBasedServiceData> {
public abstract class UriBasedServiceInfoCreator<SI extends ServiceInfo>
implements ServiceInfoCreator<ServiceInfo, UriBasedServiceData> {
private final String uriScheme;
private final String[] uriSchemes;
public UriBasedServiceInfoCreator(String uriScheme) {
this.uriScheme = uriScheme;
}
public UriBasedServiceInfoCreator(String... uriSchemes) {
this.uriSchemes = uriSchemes;
}
@Override
public boolean accept(UriBasedServiceData serviceData) {
return serviceData.getUri().toString().startsWith(uriScheme + "://");
}
@Override
public boolean accept(UriBasedServiceData serviceData) {
String uriString = serviceData.getUri();
for (String uriScheme : uriSchemes) {
if (uriString.startsWith(uriScheme + "://")) {
return true;
}
}
return false;
}
public abstract SI createServiceInfo(String id, String uri);
public abstract SI createServiceInfo(String id, String uri);
@Override
public SI createServiceInfo(UriBasedServiceData serviceData) {
return createServiceInfo(serviceData.getKey(), serviceData.getUri());
}
@Override
public SI createServiceInfo(UriBasedServiceData serviceData) {
return createServiceInfo(serviceData.getKey(), serviceData.getUri());
}
}

View File

@@ -9,19 +9,33 @@ import org.springframework.cloud.util.UriInfo;
* Information to access RabbitMQ service.
*
* @author Ramnivas Laddad
* @author Scott Frederick
*
*/
@ServiceLabel("rabbitmq")
public class AmqpServiceInfo extends UriBasedServiceInfo {
public static final String URI_SCHEME = "amqp";
public static final String AMQP_SCHEME = "amqp";
public static final String AMQPS_SCHEME = "amqps";
private String managementUri;
public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost) {
super(id, URI_SCHEME, host, port, username, password, virtualHost);
this(id, host, port, username, password, virtualHost, null);
}
public AmqpServiceInfo(String id, String uri) throws CloudException {
public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost, String managementUri) {
super(id, AMQP_SCHEME, host, port, username, password, virtualHost);
this.managementUri = managementUri;
}
public AmqpServiceInfo(String id, String uri) throws CloudException {
this(id, uri, null);
}
public AmqpServiceInfo(String id, String uri, String managementUri) throws CloudException {
super(id, uri);
this.managementUri = managementUri;
}
@ServiceProperty(category="connection")
@@ -29,39 +43,33 @@ public class AmqpServiceInfo extends UriBasedServiceInfo {
return getUriInfo().getPath();
}
@ServiceProperty(category="connection")
public String getManagementUri() { return managementUri; }
@Override
protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) {
if (!URI_SCHEME.equals(uriInfo.getScheme())) {
throw new IllegalArgumentException("wrong scheme in amqp URI: " + uriInfo);
if (uriInfo.getScheme() == null) {
throw new IllegalArgumentException("Missing scheme in amqp URI: " + uriInfo);
}
if (uriInfo.getHost() == null) {
throw new IllegalArgumentException("missing authority in amqp URI: " + uriInfo);
throw new IllegalArgumentException("Missing authority in amqp URI: " + uriInfo);
}
int port = uriInfo.getPort();
if (port == -1) {
port = 5672;
}
String userName = uriInfo.getUserName();
String password = uriInfo.getPassword();
if (userName == null || password == null) {
throw new IllegalArgumentException("missing userinfo in amqp URI: " + uriInfo);
if (uriInfo.getUserName() == null || uriInfo.getPassword() == null) {
throw new IllegalArgumentException("Missing userinfo in amqp URI: " + uriInfo);
}
String path = uriInfo.getPath();
if (path == null) {
// The RabbitMQ default vhost
path = "/";
throw new IllegalArgumentException("Missing virtual host in amqp URI: " + uriInfo);
} else {
// Check that the path only has a single segment. As we have an authority component
// in the URI, paths always begin with a slash.
if (path.indexOf('/') != -1) {
throw new IllegalArgumentException("multiple segments in path of amqp URI: " + uriInfo);
throw new IllegalArgumentException("Multiple segments in path of amqp URI: " + uriInfo);
}
}
return new UriInfo(uriInfo.getScheme(), uriInfo.getHost(), port, uriInfo.getUserName(), uriInfo.getPassword(), path);
return uriInfo;
}
}

View File

@@ -11,10 +11,10 @@ import org.springframework.cloud.service.ServiceInfo.ServiceLabel;
@ServiceLabel("mongo")
public class MongoServiceInfo extends UriBasedServiceInfo {
public static final String URI_SCHEME = "mongodb";
public static final String MONGODB_SCHEME = "mongodb";
public MongoServiceInfo(String id, String host, int port, String username, String password, String db) {
super(id, URI_SCHEME, host, port, username, password, db);
super(id, MONGODB_SCHEME, host, port, username, password, db);
}
public MongoServiceInfo(String id, String uri) {

View File

@@ -10,11 +10,11 @@ import org.springframework.cloud.service.ServiceInfo.ServiceLabel;
@ServiceLabel("mysql")
public class MysqlServiceInfo extends RelationalServiceInfo {
public static final String JDBC_URL_TYPE = "mysql";
private static final String JDBC_URL_TYPE = "mysql";
public static final String URI_SCHEME = JDBC_URL_TYPE;
public static final String MYSQL_SCHEME = JDBC_URL_TYPE;
public MysqlServiceInfo(String id, String url) {
super(id, url, URI_SCHEME);
super(id, url, MYSQL_SCHEME);
}
}

View File

@@ -5,9 +5,9 @@ import org.springframework.cloud.service.ServiceInfo;
@ServiceInfo.ServiceLabel("oracle")
public class OracleServiceInfo extends RelationalServiceInfo {
public static final String JDBC_URL_TYPE = "oracle";
private static final String JDBC_URL_TYPE = "oracle";
public static final String URI_SCHEME = JDBC_URL_TYPE;
public static final String ORACLE_SCHEME = JDBC_URL_TYPE;
public OracleServiceInfo(String id, String url) {
super(id, url, JDBC_URL_TYPE);

View File

@@ -11,9 +11,9 @@ import org.springframework.cloud.service.ServiceInfo.ServiceLabel;
@ServiceLabel("postgresql")
public class PostgresqlServiceInfo extends RelationalServiceInfo {
public static final String JDBC_URL_TYPE = "postgresql";
private static final String JDBC_URL_TYPE = "postgresql";
public static final String URI_SCHEME = "postgres";
public static final String POSTGRES_SCHEME = "postgres";
public PostgresqlServiceInfo(String id, String url) {
super(id, url, JDBC_URL_TYPE);

View File

@@ -11,10 +11,10 @@ import org.springframework.cloud.service.ServiceInfo.ServiceLabel;
@ServiceLabel("redis")
public class RedisServiceInfo extends UriBasedServiceInfo {
public static final String URI_SCHEME = "redis";
public static final String REDIS_SCHEME = "redis";
public RedisServiceInfo(String id, String host, int port, String password) {
super(id, URI_SCHEME, host, port, null, password, null);
super(id, REDIS_SCHEME, host, port, null, password, null);
}
public RedisServiceInfo(String id, String uri) {

View File

@@ -4,10 +4,10 @@ import org.springframework.cloud.service.UriBasedServiceInfo;
public class SmtpServiceInfo extends UriBasedServiceInfo {
public static final String URI_SCHEME = "smtp";
public static final String SMTP_SCHEME = "smtp";
public SmtpServiceInfo(String id, String host, int port, String username, String password) {
super(id, URI_SCHEME, host, port, username, password, "");
super(id, SMTP_SCHEME, host, port, username, password, "");
}
public SmtpServiceInfo(String id, String url) {

View File

@@ -30,8 +30,7 @@ public class StandardUriInfoFactory implements UriInfoFactory {
String password = uriDecode(userInfo[1]);
return new UriInfo(tmpUri.getScheme(), tmpUri.getHost(), tmpUri.getPort(),
userName, password,
parsePath(tmpUri), tmpUri.getRawQuery());
userName, password, parsePath(tmpUri), tmpUri.getRawQuery(), uriString);
}
private URI createTmpUri(String uriString) {

View File

@@ -18,16 +18,20 @@ public class UriInfo {
private String path;
private URI uri;
private String query;
private String rawUriString;
public UriInfo(String scheme, String host, int port, String username, String password) {
this(scheme, host, port, username, password, "");
this(scheme, host, port, username, password,
String.format("%s://%s:%s@%s:%s/", scheme, username, password, host, port));
}
public UriInfo(String scheme, String host, int port, String username, String password, String path) {
this(scheme, host, port, username, password, path, null);
this(scheme, host, port, username, password, path, null,
String.format("%s://%s:%s@%s:%s/%s", scheme, username, password, host, port, path));
}
public UriInfo(String scheme, String host, int port, String username, String password, String path, String query) {
public UriInfo(String scheme, String host, int port, String username, String password, String path,
String query, String rawUriString) {
this.scheme = scheme;
this.host = host;
this.port = port;
@@ -35,6 +39,7 @@ public class UriInfo {
this.password = password;
this.path = path;
this.query = query;
this.rawUriString = rawUriString;
this.uri = buildUri();
}
@@ -71,6 +76,10 @@ public class UriInfo {
return uri;
}
public String getRawUriString() {
return rawUriString;
}
private URI buildUri() {
String userInfo = null;

View File

@@ -1,6 +0,0 @@
log4j.rootCategory=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.AmqpServiceInfo;
public class AmqpServiceInfoCreator extends HerokuServiceInfoCreator<AmqpServiceInfo> {
public AmqpServiceInfoCreator() {
super(AmqpServiceInfo.URI_SCHEME);
super(AmqpServiceInfo.AMQP_SCHEME, AmqpServiceInfo.AMQPS_SCHEME);
}
@Override

View File

@@ -10,8 +10,8 @@ import org.springframework.cloud.service.UriBasedServiceInfoCreator;
*/
public abstract class HerokuServiceInfoCreator<SI extends ServiceInfo> extends UriBasedServiceInfoCreator<SI> {
public HerokuServiceInfoCreator(String uriScheme) {
super(uriScheme);
public HerokuServiceInfoCreator(String... uriSchemes) {
super(uriSchemes);
}
/**

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MongoServiceInfo;
public class MongoServiceInfoCreator extends HerokuServiceInfoCreator<MongoServiceInfo> {
public MongoServiceInfoCreator() {
super(MongoServiceInfo.URI_SCHEME);
super(MongoServiceInfo.MONGODB_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MysqlServiceInfo;
public class MysqlServiceInfoCreator extends RelationalServiceInfoCreator<MysqlServiceInfo> {
public MysqlServiceInfoCreator() {
super(MysqlServiceInfo.URI_SCHEME);
super(MysqlServiceInfo.MYSQL_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo;
public class PostgresqlServiceInfoCreator extends RelationalServiceInfoCreator<PostgresqlServiceInfo> {
public PostgresqlServiceInfoCreator() {
super(PostgresqlServiceInfo.URI_SCHEME);
super(PostgresqlServiceInfo.POSTGRES_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.RedisServiceInfo;
public class RedisServiceInfoCreator extends HerokuServiceInfoCreator<RedisServiceInfo> {
public RedisServiceInfoCreator() {
super(RedisServiceInfo.URI_SCHEME);
super(RedisServiceInfo.REDIS_SCHEME);
}
@Override

View File

@@ -19,7 +19,7 @@ import org.springframework.cloud.service.common.MysqlServiceInfo;
*/
public class HerokuConnectorMysqlServiceTest extends AbstractHerokuConnectorRelationalServiceTest {
public HerokuConnectorMysqlServiceTest() {
super(MysqlServiceInfo.URI_SCHEME);
super(MysqlServiceInfo.MYSQL_SCHEME);
}
@Test

View File

@@ -19,7 +19,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo;
*/
public class HerokuConnectorPostgresqlServiceTest extends AbstractHerokuConnectorRelationalServiceTest {
public HerokuConnectorPostgresqlServiceTest() {
super(PostgresqlServiceInfo.URI_SCHEME);
super(PostgresqlServiceInfo.POSTGRES_SCHEME);
}
@Test

View File

@@ -1,6 +0,0 @@
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.AmqpServiceInfo;
public class AmqpServiceInfoCreator extends LocalConfigServiceInfoCreator<AmqpServiceInfo>{
public AmqpServiceInfoCreator() {
super(AmqpServiceInfo.URI_SCHEME);
super(AmqpServiceInfo.AMQP_SCHEME, AmqpServiceInfo.AMQPS_SCHEME);
}
@Override

View File

@@ -5,7 +5,7 @@ import org.springframework.cloud.service.UriBasedServiceInfoCreator;
public abstract class LocalConfigServiceInfoCreator<SI extends ServiceInfo> extends UriBasedServiceInfoCreator<SI> {
protected LocalConfigServiceInfoCreator(String uriScheme) {
super(uriScheme);
protected LocalConfigServiceInfoCreator(String... uriSchemes) {
super(uriSchemes);
}
}

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MongoServiceInfo;
public class MongoServiceInfoCreator extends LocalConfigServiceInfoCreator<MongoServiceInfo>{
public MongoServiceInfoCreator() {
super(MongoServiceInfo.URI_SCHEME);
super(MongoServiceInfo.MONGODB_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MysqlServiceInfo;
public class MysqlServiceInfoCreator extends LocalConfigServiceInfoCreator<MysqlServiceInfo>{
public MysqlServiceInfoCreator() {
super(MysqlServiceInfo.URI_SCHEME);
super(MysqlServiceInfo.MYSQL_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo;
public class PostgresqlServiceInfoCreator extends LocalConfigServiceInfoCreator<PostgresqlServiceInfo>{
public PostgresqlServiceInfoCreator() {
super(PostgresqlServiceInfo.URI_SCHEME);
super(PostgresqlServiceInfo.POSTGRES_SCHEME);
}
@Override

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.RedisServiceInfo;
public class RedisServiceInfoCreator extends LocalConfigServiceInfoCreator<RedisServiceInfo>{
public RedisServiceInfoCreator() {
super(RedisServiceInfo.URI_SCHEME);
super(RedisServiceInfo.REDIS_SCHEME);
}
@Override

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,9 +0,0 @@
description = 'Spring-Cloud Support for Pivotal CF'
dependencies {
compile project(':spring-cloud-cloudfoundry-connector')
compile project(':spring-cloud-spring-service-connector')
optional("org.apache.hadoop:hadoop-common:2.2.0")
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,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,2 +0,0 @@
org.springframework.cloud.pcf.hadoop.HadoopConfigurationCreator
org.springframework.cloud.pcf.gemfire.GemfireXDDataSourceCreator

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,6 +0,0 @@
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n

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"
}
}
}

View File

@@ -5,7 +5,6 @@ dependencies {
compile project(':spring-cloud-core')
compile("org.springframework:spring-context:$springVersion")
compile("log4j:log4j:$log4jVersion")
testCompile("org.springframework:spring-test:$springVersion")
testCompile("mysql:mysql-connector-java:$mysqlDriverVersion")

View File

@@ -14,6 +14,7 @@ import org.springframework.cloud.Cloud;
import org.springframework.cloud.CloudException;
import org.springframework.cloud.CloudFactory;
import org.springframework.cloud.service.PooledServiceConnectorConfig;
import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.cloud.service.document.MongoDbFactoryConfig;
import org.springframework.cloud.service.messaging.RabbitConnectionFactoryConfig;
import org.springframework.cloud.service.relational.DataSourceConfig;
@@ -419,5 +420,9 @@ public abstract class AbstractCloudConfig implements BeanFactoryAware {
public <T> T service(String serviceId, Class<T> serviceConnectorType) {
return cloud.getServiceConnector(serviceId, serviceConnectorType, null);
}
public <T> T service(String serviceId, Class<T> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig){
return cloud.getServiceConnector(serviceId, serviceConnectorType, serviceConnectorConfig);
}
}
}

View File

@@ -4,7 +4,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import com.mongodb.MongoClientURI;
import org.springframework.cloud.service.AbstractServiceConnectorCreator;
import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.cloud.service.ServiceConnectorCreationException;
@@ -27,22 +30,21 @@ import com.mongodb.WriteConcern;
*
* @author Ramnivas Laddad
* @author Thomas Risberg
*
* @author Chris Schaefer
*/
public class MongoDbFactoryCreator extends AbstractServiceConnectorCreator<MongoDbFactory, MongoServiceInfo> {
@Override
public MongoDbFactory create(MongoServiceInfo serviceInfo, ServiceConnectorConfig config) {
try {
MongoClientOptions mongoOptionsToUse = getMongoOptions((MongoDbFactoryConfig) config);
ServerAddress serverAddress = null;
if (serviceInfo.getPort() == -1) {
serverAddress = new ServerAddress(serviceInfo.getHost());
} else {
serverAddress = new ServerAddress(serviceInfo.getHost(), serviceInfo.getPort());
}
MongoClient mongo = new MongoClient(serverAddress, mongoOptionsToUse);
UserCredentials credentials = new UserCredentials(serviceInfo.getUserName(), serviceInfo.getPassword());
SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongo, serviceInfo.getDatabase(), credentials);
MongoClientURI mongoClientURI = new MongoClientURI(serviceInfo.getUri());
List<ServerAddress> serverAddressList = getServerAddresses(mongoClientURI);
MongoClient mongo = new MongoClient(serverAddressList, mongoOptionsToUse);
UserCredentials credentials = new UserCredentials(mongoClientURI.getUsername(), new String(mongoClientURI.getPassword()));
SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongo, mongoClientURI.getDatabase(), credentials);
return configure(mongoDbFactory, (MongoDbFactoryConfig) config);
} catch (UnknownHostException e) {
throw new ServiceConnectorCreationException(e);
@@ -51,43 +53,53 @@ public class MongoDbFactoryCreator extends AbstractServiceConnectorCreator<Mongo
}
}
private List<ServerAddress> getServerAddresses(MongoClientURI mongoClientURI) throws UnknownHostException {
List<String> servers = mongoClientURI.getHosts();
List<ServerAddress> serverAddressList = new ArrayList<ServerAddress>();
for(String server : servers) {
serverAddressList.add(new ServerAddress(server));
}
return serverAddressList;
}
private MongoClientOptions getMongoOptions(MongoDbFactoryConfig config) {
MongoClientOptions.Builder builder = null;
MongoClientOptions.Builder builder;
Method builderMethod = ClassUtils.getMethodIfAvailable(MongoClientOptions.class, "builder");
if (builderMethod != null) {
builder = (Builder) ReflectionUtils.invokeMethod(builderMethod, null);
builder = (Builder) ReflectionUtils.invokeMethod(builderMethod, null);
} else {
Constructor<Builder> builderConstructor = ClassUtils.getConstructorIfAvailable(MongoClientOptions.Builder.class);
try {
builder = builderConstructor.newInstance(new Object[0]);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
}
Constructor<Builder> builderConstructor = ClassUtils.getConstructorIfAvailable(MongoClientOptions.Builder.class);
try {
builder = builderConstructor.newInstance(new Object[0]);
} catch (InstantiationException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
}
}
if (config != null) {
if (config.getConnectionsPerHost() != null) {
builder.connectionsPerHost(config.getConnectionsPerHost());
}
if (config.getMaxWaitTime() != null) {
builder.maxWaitTime(config.getMaxWaitTime());
}
if (config.getWriteConcern() != null) {
builder.writeConcern(new WriteConcern(config.getWriteConcern()));
}
}
if (config.getConnectionsPerHost() != null) {
builder.connectionsPerHost(config.getConnectionsPerHost());
}
if (config.getMaxWaitTime() != null) {
builder.maxWaitTime(config.getMaxWaitTime());
}
if (config.getWriteConcern() != null) {
builder.writeConcern(new WriteConcern(config.getWriteConcern()));
}
}
return builder.build();
}
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) {
if (config != null && config.getWriteConcern() != null) {
WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern());
@@ -97,5 +109,4 @@ public class MongoDbFactoryCreator extends AbstractServiceConnectorCreator<Mongo
}
return mongoDbFactory;
}
}

View File

@@ -12,22 +12,24 @@ import org.springframework.cloud.service.common.AmqpServiceInfo;
* @author Ramnivas Laddad
* @author Dave Syer
* @author Thomas Risberg
*
* @author Mark Fisher
*/
public class RabbitConnectionFactoryCreator extends AbstractServiceConnectorCreator<ConnectionFactory, AmqpServiceInfo> {
@Override
public ConnectionFactory create(AmqpServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfiguration) {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(serviceInfo.getHost());
connectionFactory.setVirtualHost(serviceInfo.getVirtualHost());
connectionFactory.setUsername(serviceInfo.getUserName());
connectionFactory.setPassword(serviceInfo.getPassword());
connectionFactory.setPort(serviceInfo.getPort());
if (serviceConnectorConfiguration != null) {
connectionFactory.setChannelCacheSize(((RabbitConnectionFactoryConfig)serviceConnectorConfiguration).getChannelCacheSize());
com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory();
try {
connectionFactory.setUri(serviceInfo.getUri());
}
return connectionFactory;
catch (Exception e) {
throw new IllegalArgumentException("failed to create ConnectionFactory", e);
}
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);
if (serviceConnectorConfiguration != null) {
cachingConnectionFactory.setChannelCacheSize(((RabbitConnectionFactoryConfig)serviceConnectorConfiguration).getChannelCacheSize());
}
return cachingConnectionFactory;
}
}

View File

@@ -3,25 +3,24 @@ package org.springframework.cloud.service.smtp;
import org.springframework.cloud.service.AbstractServiceConnectorCreator;
import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.cloud.service.common.SmtpServiceInfo;
import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
/**
* Simplified access to Spring MailSender.
*
* @author Ramnivas Laddad
*
*/
public class MailSenderCreator extends AbstractServiceConnectorCreator<MailSender, SmtpServiceInfo> {
public class MailSenderCreator extends AbstractServiceConnectorCreator<JavaMailSender, SmtpServiceInfo> {
@Override
public MailSender create(SmtpServiceInfo serviceInfo, ServiceConnectorConfig config) {
public JavaMailSender create(SmtpServiceInfo serviceInfo, ServiceConnectorConfig config) {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(serviceInfo.getHost());
mailSender.setPort(serviceInfo.getPort());
mailSender.setUsername(serviceInfo.getUserName());
mailSender.setPassword(serviceInfo.getPassword());
return mailSender;
mailSender.setHost(serviceInfo.getHost());
mailSender.setPort(serviceInfo.getPort());
mailSender.setUsername(serviceInfo.getUserName());
mailSender.setPassword(serviceInfo.getPassword());
return mailSender;
}
}

View File

@@ -2,7 +2,7 @@ package org.springframework.cloud.service.smtp;
import org.springframework.cloud.service.AbstractCloudServiceConnectorFactory;
import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSender;
/**
* Spring factory bean for SMTP service.
@@ -10,8 +10,8 @@ import org.springframework.mail.MailSender;
* @author Ramnivas Laddad
*
*/
public class MailSenderFactory extends AbstractCloudServiceConnectorFactory<MailSender> {
public class MailSenderFactory extends AbstractCloudServiceConnectorFactory<JavaMailSender> {
public MailSenderFactory(String serviceId, ServiceConnectorConfig serviceConnectorConfiguration) {
super(serviceId, MailSender.class, serviceConnectorConfiguration);
super(serviceId, JavaMailSender.class, serviceConnectorConfiguration);
}
}

View File

@@ -25,12 +25,12 @@ import org.springframework.cloud.service.common.RelationalServiceInfo;
import org.springframework.cloud.service.relational.MysqlDataSourceCreator;
/**
*
* @author Ramnivas Laddad
* Test cases for service properties
*
* @author Ramnivas Laddad
* @author Chris Schaefer
*/
public class CloudTest extends StubCloudConnectorTest {
private List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceCreators;
@Before
@@ -74,7 +74,6 @@ public class CloudTest extends StubCloudConnectorTest {
assertNull(cloudProperties.get("cloud.services.mysql.connection.host"));
}
@Test
public void servicePropsOneServiceOfTheSameLabel() {
MysqlServiceInfo mysqlServiceInfo = createMysqlService("my-mysql");
@@ -101,7 +100,7 @@ public class CloudTest extends StubCloudConnectorTest {
assertBasicProps("cloud.services.my-redis", redisServiceInfo, cloudProperties);
assertBasicProps("cloud.services.redis", redisServiceInfo, cloudProperties);
}
@Test
public void servicePropsRabbit() {
String serviceId = "my-rabbit";
@@ -113,6 +112,28 @@ public class CloudTest extends StubCloudConnectorTest {
assertRabbitProps("cloud.services.my-rabbit", rabbitServiceInfo, cloudProperties);
assertRabbitProps("cloud.services.rabbitmq", rabbitServiceInfo, cloudProperties);
}
@Test
public void servicePropsMongoMultipleHostsUriString() {
String serviceId = "my-mongo-multiple-hosts-uri";
MongoServiceInfo mongoServiceInfo = createMongoServiceWithMultipleHostsByUri(serviceId);
CloudConnector stubCloudConnector = getTestCloudConnector(mongoServiceInfo);
Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);
Properties cloudProperties = testCloud.getCloudProperties();
assertMongoPropsWithMultipleHostsByUri("cloud.services.my-mongo-multiple-hosts-uri", mongoServiceInfo, cloudProperties);
assertMongoPropsWithMultipleHostsByUri("cloud.services.mongo", mongoServiceInfo, cloudProperties);
}
private void assertMongoPropsWithMultipleHostsByUri(String leadKey, MongoServiceInfo serviceInfo, Properties cloudProperties) {
assertEquals(serviceInfo.getId(), cloudProperties.get(leadKey + ".id"));
assertEquals(serviceInfo.getUri(), cloudProperties.get(leadKey + ".connection.uri"));
assertEquals(-1, cloudProperties.get(leadKey + ".connection.port"));
assertNull(cloudProperties.get(leadKey + ".connection.host"));
assertNull(cloudProperties.get(leadKey + ".connection.username"));
assertNull(cloudProperties.get(leadKey + ".connection.password"));
}
private void assertBasicProps(String leadKey, UriBasedServiceInfo serviceInfo, Properties cloudProperties) {
assertEquals(serviceInfo.getId(), cloudProperties.get(leadKey + ".id"));

View File

@@ -15,10 +15,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* Base class for close-to-integration tests that use a stub {@link CloudConnector} to avoid the need for a real cloud environment.
*
* @author Ramnivas Laddad
*
* @author Chris Schaefer
*/
abstract public class StubCloudConnectorTest {
private static final String MOCK_CLOUD_BEAN_NAME = "mockCloud";
protected ApplicationContext getTestApplicationContext(String fileName, ServiceInfo... serviceInfos) {
@@ -63,7 +62,11 @@ abstract public class StubCloudConnectorTest {
protected MongoServiceInfo createMongoService(String id) {
return new MongoServiceInfo(id, "10.20.30.40", 1234, "username", "password", "db");
}
protected MongoServiceInfo createMongoServiceWithMultipleHostsByUri(String id) {
return new MongoServiceInfo(id, "mongo://username:password@10.20.30.40,10.20.30.41,10.20.30.42:1234/db");
}
protected AmqpServiceInfo createRabbitService(String id) {
return new AmqpServiceInfo(id, "10.20.30.40", 1234, "username", "password", "vh");
}

View File

@@ -5,7 +5,11 @@ import static org.junit.Assert.assertNotNull;
import javax.sql.DataSource;
import org.junit.Test;
import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.cloud.service.ServiceInfo;
import org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig;
import org.springframework.cloud.service.relational.DataSourceConfig;
import org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -23,6 +27,7 @@ public class GenericServiceJavaConfigTest extends AbstractServiceJavaConfigTest<
return createMysqlService(id);
}
protected Class<DataSource> getConnectorType() {
return DataSource.class;
}
@@ -36,7 +41,9 @@ public class GenericServiceJavaConfigTest extends AbstractServiceJavaConfigTest<
testContext.getBean("myServiceWithTypeWithServiceName", DataSource.class));
assertNotNull("Getting service with connector type (unique service)",
testContext.getBean("myServiceWithTypeWithoutServiceName", DataSource.class));
testContext.getBean("myServiceWithTypeWithoutServiceName", DataSource.class));
assertNotNull("Getting service with connector type (unique service)",
testContext.getBean("myServiceWithTypeWithServiceNameAndConfig", DataSource.class));
}
}
@@ -49,6 +56,10 @@ class GenericServiceWithId extends AbstractCloudConfig {
}
class GenericServiceConnectorConfig implements ServiceConnectorConfig {
}
class GenericServiceWithoutId extends AbstractCloudConfig {
@Bean(name="my-service")
public Object testService() {
@@ -66,4 +77,15 @@ class GenericServiceWithConnectorType extends AbstractCloudConfig {
public DataSource myServiceWithTypeWithoutServiceName() {
return connectionFactory().service(DataSource.class);
}
@Bean
public DataSource myServiceWithTypeWithServiceNameAndConfig(){
PoolConfig poolConfig = new PoolConfig(20, 200);
ConnectionConfig connectionConfig = new ConnectionConfig("sessionVariables=sql_mode='ANSI';characterEncoding=UTF-8");
DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig, connectionConfig);
return connectionFactory().service("my-service",DataSource.class,serviceConfig);
}
}

View File

@@ -14,53 +14,88 @@ import org.springframework.test.util.ReflectionTestUtils;
import com.mongodb.Mongo;
import com.mongodb.ServerAddress;
import org.springframework.util.StringUtils;
/**
*
* @author Ramnivas Laddad
* Test cases for Mongo service connector creators.
*
* @author Ramnivas Laddad
* @author Chris Schaefer
*/
public class MongoServiceConnectorCreatorTest {
private static final String TEST_HOST = "10.20.30.40";
private static final String TEST_HOST_1 = "10.20.30.41";
private static final String TEST_HOST_2 = "10.20.30.42";
private static final int TEST_PORT = 1234;
private static final int TEST_PORT_DEFAULT = 27017;
private static final String TEST_USERNAME = "myuser";
private static final String TEST_PASSWORD = "mypass";
private static final String TEST_DB = "mydb";
private static final String MONGODB_SCHEME = "mongodb";
private static final String[] TEST_HOSTS = new String[] { TEST_HOST, TEST_HOST_1, TEST_HOST_2 };
private MongoDbFactoryCreator testCreator = new MongoDbFactoryCreator();
@Test
public void cloudMongoCreationNoConfig() throws Exception {
MongoServiceInfo serviceInfo = createServiceInfo();
MongoServiceInfo serviceInfo = new MongoServiceInfo("id", TEST_HOST, TEST_PORT, TEST_USERNAME, TEST_PASSWORD, TEST_DB);
MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);
assertConnectorProperties(serviceInfo, mongoDbFactory);
}
assertNotNull(mongoDbFactory);
public MongoServiceInfo createServiceInfo() {
return new MongoServiceInfo("id", TEST_HOST, TEST_PORT, TEST_DB, TEST_USERNAME, TEST_PASSWORD);
}
private void assertConnectorProperties(MongoServiceInfo serviceInfo, MongoDbFactory connector) {
assertNotNull(connector);
Mongo mongo = (Mongo) ReflectionTestUtils.getField(connector, "mongo");
UserCredentials credentials = (UserCredentials) ReflectionTestUtils.getField(connector, "credentials");
Mongo mongo = (Mongo) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
UserCredentials credentials = (UserCredentials) ReflectionTestUtils.getField(mongoDbFactory, "credentials");
assertNotNull(mongo);
List<ServerAddress> addresses = mongo.getAllAddress();
assertEquals(1, addresses.size());
ServerAddress address = addresses.get(0);
assertEquals(serviceInfo.getHost(), address.getHost());
assertEquals(serviceInfo.getPort(), address.getPort());
assertEquals(serviceInfo.getUserName(), ReflectionTestUtils.getField(credentials, "username"));
assertEquals(serviceInfo.getPassword(), ReflectionTestUtils.getField(credentials, "password"));
// Don't do connector.getDatabase().getName() as that will try to initiate the connection
assertEquals(serviceInfo.getDatabase(), ReflectionTestUtils.getField(connector, "databaseName"));
assertEquals(serviceInfo.getDatabase(), ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
}
@Test
public void cloudMongoCreationWithMultipleHostsByUri() throws Exception {
String uri = String.format("%s://%s:%s@%s:%s/%s", MONGODB_SCHEME, TEST_USERNAME, TEST_PASSWORD,
StringUtils.arrayToDelimitedString(TEST_HOSTS, ","), TEST_PORT, TEST_DB);
MongoServiceInfo serviceInfo = new MongoServiceInfo("id", uri);
MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);
assertNotNull(mongoDbFactory);
Mongo mongo = (Mongo) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
UserCredentials credentials = (UserCredentials) ReflectionTestUtils.getField(mongoDbFactory, "credentials");
assertNotNull(mongo);
List<ServerAddress> addresses = mongo.getAllAddress();
assertEquals(3, addresses.size());
assertEquals(TEST_USERNAME, ReflectionTestUtils.getField(credentials, "username"));
assertEquals(TEST_PASSWORD, ReflectionTestUtils.getField(credentials, "password"));
// Don't do connector.getDatabase().getName() as that will try to initiate the connection
assertEquals(TEST_DB, ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
ServerAddress address1 = addresses.get(0);
assertEquals(TEST_HOST, address1.getHost());
assertEquals(TEST_PORT_DEFAULT, address1.getPort());
ServerAddress address2 = addresses.get(1);
assertEquals(TEST_HOST_1, address2.getHost());
assertEquals(TEST_PORT_DEFAULT, address2.getPort());
ServerAddress address3 = addresses.get(2);
assertEquals(TEST_HOST_2, address3.getHost());
assertEquals(TEST_PORT, address3.getPort());
}
}

View File

@@ -13,7 +13,7 @@ import org.springframework.cloud.service.common.AmqpServiceInfo;
public class RabbitServiceInfoTest {
@Test
public void uriBasedParsing() {
AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345/myvhost");
AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345/myvhost");
assertEquals("myhost", serviceInfo.getHost());
assertEquals(12345, serviceInfo.getPort());
@@ -21,10 +21,16 @@ public class RabbitServiceInfoTest {
assertEquals("mypass", serviceInfo.getPassword());
assertEquals("myvhost", serviceInfo.getVirtualHost());
}
@Test(expected=IllegalArgumentException.class)
public void badProtocol() {
new AmqpServiceInfo("id", "XX://myuser:mypass@myhost:12345/myvhost");
public void missingScheme() {
new AmqpServiceInfo("id", "://myuser:mypass@:12345/myvhost");
}
@Test
public void amqpsSchemeAccepted() {
AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqps://myuser:mypass@myhost:12345/myvhost");
assertEquals("amqps", serviceInfo.getScheme());
}
@Test(expected=IllegalArgumentException.class)
@@ -32,12 +38,6 @@ public class RabbitServiceInfoTest {
new AmqpServiceInfo("id", "amqp://myuser:mypass@:12345/myvhost");
}
@Test
public void missingPort() {
AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost/myvhost");
assertEquals(5672, serviceInfo.getPort()); // the default port is 5672
}
@Test(expected=IllegalArgumentException.class)
public void badUserInfo() {
new AmqpServiceInfo("id", "amqp://myuser@myhost/myvhost");
@@ -48,10 +48,9 @@ public class RabbitServiceInfoTest {
new AmqpServiceInfo("id", "amqp://myhost:12345/myvhost");
}
@Test
@Test(expected=IllegalArgumentException.class)
public void missingVirtualHost() {
AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345");
assertEquals("/", serviceInfo.getVirtualHost());
new AmqpServiceInfo("id", "amqp://myuser:mypass@myhost:12345");
}
@Test(expected=IllegalArgumentException.class)

View File

@@ -4,25 +4,25 @@ import org.mockito.Mock;
import org.springframework.cloud.service.AbstractCloudServiceConnectorFactoryTest;
import org.springframework.cloud.service.ServiceConnectorConfig;
import org.springframework.cloud.service.common.SmtpServiceInfo;
import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSender;
/**
*
* @author Ramnivas Laddad
*
*/
public class MailSenderFactoryTest extends AbstractCloudServiceConnectorFactoryTest<MailSenderFactory, MailSender, SmtpServiceInfo> {
@Mock MailSender mockConnector;
public class MailSenderFactoryTest extends AbstractCloudServiceConnectorFactoryTest<MailSenderFactory, JavaMailSender, SmtpServiceInfo> {
@Mock JavaMailSender mockConnector;
public MailSenderFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) {
return new MailSenderFactory(id, config);
}
public Class<MailSender> getConnectorType() {
return MailSender.class;
public Class<JavaMailSender> getConnectorType() {
return JavaMailSender.class;
}
public MailSender getMockConnector() {
public JavaMailSender getMockConnector() {
return mockConnector;
}

View File

@@ -19,7 +19,6 @@ public class SmtpServiceConnectorCreatorTest {
private static final String TEST_USERNAME = "myuser";
private static final String TEST_PASSWORD = "mypass";
private MailSenderCreator testCreator = new MailSenderCreator();
@Test

View File

@@ -1,6 +0,0 @@
log4j.rootCategory=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n