From bcbd2f6333af7191790fcc6fcc6b99163f33af51 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 31 Oct 2014 09:51:45 -0400 Subject: [PATCH 01/20] Remove strict check for 'amqp' scheme in AmqpServiceInfo --- .../cloud/service/common/AmqpServiceInfo.java | 4 ++-- .../cloud/service/rabbit/RabbitServiceInfoTest.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index aa7bb98..23982c2 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -31,8 +31,8 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { @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) { diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java index f6d33e2..7a3cdbf 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java @@ -21,10 +21,15 @@ 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"); + } + + public void amqpsSchemeAccepted() { + AmqpServiceInfo serviceInfo = new AmqpServiceInfo("id", "amqps://myuser:mypass@myhost:12345/myvhost"); + assertEquals("amqps", serviceInfo.getScheme()); } @Test(expected=IllegalArgumentException.class) From 90aae2e6020e6e5e039338e223107d520ce0fb20 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 31 Oct 2014 10:23:58 -0400 Subject: [PATCH 02/20] wip --- .../RabbitConnectionFactoryCreator.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java index 1ff8679..7ca878c 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java @@ -12,22 +12,31 @@ import org.springframework.cloud.service.common.AmqpServiceInfo; * @author Ramnivas Laddad * @author Dave Syer * @author Thomas Risberg - * + * @author Mark Fisher */ - public class RabbitConnectionFactoryCreator extends AbstractServiceConnectorCreator { + @Override public ConnectionFactory create(AmqpServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfiguration) { - CachingConnectionFactory connectionFactory = new CachingConnectionFactory(serviceInfo.getHost()); + com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); + connectionFactory.setHost(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()); + if ("amqps".equals(serviceInfo.getScheme())) { + try { + connectionFactory.useSslProtocol(); + } + catch (Exception e) { + throw new IllegalStateException("failed to configure SSL protocol", e); + } } - - return connectionFactory; + connectionFactory.setPort(serviceInfo.getPort()); + CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory); + if (serviceConnectorConfiguration != null) { + cachingConnectionFactory.setChannelCacheSize(((RabbitConnectionFactoryConfig)serviceConnectorConfiguration).getChannelCacheSize()); + } + return cachingConnectionFactory; } + } From fd9b380727e9219c6ec9d911d00bdd3ac08a6814 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 31 Oct 2014 14:33:17 -0400 Subject: [PATCH 03/20] Upgraded Spring AMQP to 1.3.6 Creating Rabbit ConnectionFactory by passing the URI from AmqpServiceInfo. --- build.gradle | 2 +- .../RabbitConnectionFactoryCreator.java | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 2598d51..06e471b 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ ext { springVersion = "3.1.4.RELEASE" tomcatVersion = "7.0.53" - springAmqpVersion = "1.0.0.RELEASE" + springAmqpVersion = "1.3.6.RELEASE" springDataRedisVersion = "1.1.1.RELEASE" springDataMongoVersion = "1.2.4.RELEASE" diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java index 7ca878c..a32db74 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/messaging/RabbitConnectionFactoryCreator.java @@ -19,19 +19,12 @@ public class RabbitConnectionFactoryCreator extends AbstractServiceConnectorCrea @Override public ConnectionFactory create(AmqpServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfiguration) { com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory(); - connectionFactory.setHost(serviceInfo.getHost()); - connectionFactory.setVirtualHost(serviceInfo.getVirtualHost()); - connectionFactory.setUsername(serviceInfo.getUserName()); - connectionFactory.setPassword(serviceInfo.getPassword()); - if ("amqps".equals(serviceInfo.getScheme())) { - try { - connectionFactory.useSslProtocol(); - } - catch (Exception e) { - throw new IllegalStateException("failed to configure SSL protocol", e); - } + try { + connectionFactory.setUri(serviceInfo.getUri()); + } + catch (Exception e) { + throw new IllegalArgumentException("failed to create ConnectionFactory", e); } - connectionFactory.setPort(serviceInfo.getPort()); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory); if (serviceConnectorConfiguration != null) { cachingConnectionFactory.setChannelCacheSize(((RabbitConnectionFactoryConfig)serviceConnectorConfiguration).getChannelCacheSize()); From 786f48aa9df6d1811da503e59b553b71cb91d2cf Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 31 Oct 2014 14:54:33 -0400 Subject: [PATCH 04/20] Removed port defaulting behavior --- .../cloud/service/common/AmqpServiceInfo.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index 23982c2..231ab9e 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -39,11 +39,6 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { 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(); @@ -62,6 +57,6 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { 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 new UriInfo(uriInfo.getScheme(), uriInfo.getHost(), uriInfo.getPort(), uriInfo.getUserName(), uriInfo.getPassword(), path); } } From 20c7aba1f670434d86031135dc08893c9b86aea7 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Fri, 31 Oct 2014 15:33:51 -0500 Subject: [PATCH 05/20] Add support for multiple URI schemes for service type detection. Add verification of detected ServiceInfo type in CloudFoundryConnector tests. --- .../cloudfoundry/AmqpServiceInfoCreator.java | 7 +- .../CloudFoundryServiceInfoCreator.java | 54 ++++++++----- .../cloudfoundry/MongoServiceInfoCreator.java | 9 +-- .../cloudfoundry/MysqlServiceInfoCreator.java | 4 +- .../OracleServiceInfoCreator.java | 2 +- .../PostgresqlServiceInfoCreator.java | 2 +- .../cloudfoundry/RedisServiceInfoCreator.java | 12 ++- .../RelationalServiceInfoCreator.java | 16 ++-- .../cloudfoundry/SmtpServiceInfoCreator.java | 15 ++-- .../AbstractCloudFoundryConnectorTest.java | 15 +++- .../CloudFoundryConnectorAmqpServiceTest.java | 38 ++++++--- ...oudFoundryConnectorMongodbServiceTest.java | 78 +++++++++---------- ...FoundryConnectorMonitoringServiceTest.java | 4 +- ...CloudFoundryConnectorMysqlServiceTest.java | 18 ++--- ...loudFoundryConnectorOracleServiceTest.java | 2 +- ...FoundryConnectorPostgresqlServiceTest.java | 11 +-- ...CloudFoundryConnectorRedisServiceTest.java | 10 +-- .../CloudFoundryConnectorSmtpServiceTest.java | 2 +- ...t-rabbit-info-no-label-no-tags-secure.json | 6 ++ .../cloudfoundry/test-ups-info-no-uri.json | 3 +- .../service/UriBasedServiceInfoCreator.java | 36 +++++---- .../cloud/service/common/AmqpServiceInfo.java | 31 +++----- .../service/common/MongoServiceInfo.java | 4 +- .../service/common/MysqlServiceInfo.java | 6 +- .../service/common/OracleServiceInfo.java | 4 +- .../service/common/PostgresqlServiceInfo.java | 4 +- .../service/common/RedisServiceInfo.java | 4 +- .../cloud/service/common/SmtpServiceInfo.java | 4 +- .../cloud/heroku/AmqpServiceInfoCreator.java | 2 +- .../heroku/HerokuServiceInfoCreator.java | 4 +- .../cloud/heroku/MongoServiceInfoCreator.java | 2 +- .../cloud/heroku/MysqlServiceInfoCreator.java | 2 +- .../heroku/PostgresqlServiceInfoCreator.java | 2 +- .../cloud/heroku/RedisServiceInfoCreator.java | 2 +- .../HerokuConnectorMysqlServiceTest.java | 2 +- .../HerokuConnectorPostgresqlServiceTest.java | 2 +- .../localconfig/AmqpServiceInfoCreator.java | 2 +- .../LocalConfigServiceInfoCreator.java | 4 +- .../localconfig/MongoServiceInfoCreator.java | 2 +- .../localconfig/MysqlServiceInfoCreator.java | 2 +- .../PostgresqlServiceInfoCreator.java | 2 +- .../localconfig/RedisServiceInfoCreator.java | 2 +- .../service/rabbit/RabbitServiceInfoTest.java | 14 +--- 43 files changed, 243 insertions(+), 204 deletions(-) create mode 100644 spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info-no-label-no-tags-secure.json diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java index af68eee..e1b868e 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java @@ -12,16 +12,15 @@ import org.springframework.cloud.service.common.AmqpServiceInfo; public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator { public AmqpServiceInfoCreator() { - super(new Tags("rabbitmq"), AmqpServiceInfo.URI_SCHEME); + super(new Tags("rabbitmq"), AmqpServiceInfo.AMQP_SCHEME, AmqpServiceInfo.AMQPS_SCHEME); } public AmqpServiceInfo createServiceInfo(Map serviceData) { - @SuppressWarnings("unchecked") - Map credentials = (Map) serviceData.get("credentials"); + Map credentials = getCredentials(serviceData); String id = (String) serviceData.get("name"); - String uri = getStringFromCredentials(credentials, "uri", "url"); + String uri = getUriFromCredentials(credentials); return new AmqpServiceInfo(id, uri); } diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java index d2d95f2..69c9989 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java @@ -12,15 +12,11 @@ import org.springframework.cloud.service.ServiceInfo; public abstract class CloudFoundryServiceInfoCreator implements ServiceInfoCreator> { 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 serviceData) { @@ -39,24 +35,30 @@ public abstract class CloudFoundryServiceInfoCreator imp } protected boolean uriMatchesScheme(Map serviceData) { - if (uriScheme == null) { + if (uriSchemes == null) { return false; } - @SuppressWarnings("unchecked") - Map credentials = (Map) 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; } + @SuppressWarnings("unchecked") + protected Map getCredentials(Map serviceData) { + return (Map) serviceData.get("credentials"); + } + + protected String getUriFromCredentials(Map credentials) { + return getStringFromCredentials(credentials, "uri", "url"); + } + protected String getStringFromCredentials(Map credentials, String... keys) { for (String key : keys) { if (credentials.containsKey(key)) { @@ -66,7 +68,21 @@ public abstract class CloudFoundryServiceInfoCreator imp return null; } - public String getUriScheme() { - return uriScheme; + protected int getIntFromCredentials(Map 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]; } } diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MongoServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MongoServiceInfoCreator.java index ac963c5..1749e77 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MongoServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MongoServiceInfoCreator.java @@ -12,17 +12,14 @@ import org.springframework.cloud.service.common.MongoServiceInfo; public class MongoServiceInfoCreator extends CloudFoundryServiceInfoCreator { 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 serviceData) { - @SuppressWarnings("unchecked") - Map credentials = (Map) 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); } diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MysqlServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MysqlServiceInfoCreator.java index b5c6e15..fb64ddd 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MysqlServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/MysqlServiceInfoCreator.java @@ -10,8 +10,8 @@ import org.springframework.cloud.service.common.MysqlServiceInfo; public class MysqlServiceInfoCreator extends RelationalServiceInfoCreator { 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 diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/OracleServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/OracleServiceInfoCreator.java index 1d82ab3..85ee4ce 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/OracleServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/OracleServiceInfoCreator.java @@ -4,7 +4,7 @@ import org.springframework.cloud.service.common.OracleServiceInfo; public class OracleServiceInfoCreator extends RelationalServiceInfoCreator { public OracleServiceInfoCreator() { - super(new Tags(), OracleServiceInfo.URI_SCHEME); + super(new Tags(), OracleServiceInfo.ORACLE_SCHEME); } @Override diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/PostgresqlServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/PostgresqlServiceInfoCreator.java index abfbde1..6426f08 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/PostgresqlServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/PostgresqlServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo; public class PostgresqlServiceInfoCreator extends RelationalServiceInfoCreator { public PostgresqlServiceInfoCreator() { - super(new Tags("postgresql"), PostgresqlServiceInfo.URI_SCHEME); + super(new Tags("postgresql"), PostgresqlServiceInfo.POSTGRES_SCHEME); } @Override diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RedisServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RedisServiceInfoCreator.java index f8fcfa3..d038cd3 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RedisServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RedisServiceInfoCreator.java @@ -12,21 +12,19 @@ import org.springframework.cloud.service.common.RedisServiceInfo; public class RedisServiceInfoCreator extends CloudFoundryServiceInfoCreator { 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 serviceData) { - @SuppressWarnings("unchecked") - Map credentials = (Map) serviceData.get("credentials"); - String id = (String) serviceData.get("name"); - String uri = getStringFromCredentials(credentials, "uri", "url"); + Map 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); diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RelationalServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RelationalServiceInfoCreator.java index d61fcfa..8a4247e 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RelationalServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/RelationalServiceInfoCreator.java @@ -12,30 +12,28 @@ import org.springframework.cloud.util.UriInfo; */ public abstract class RelationalServiceInfoCreator extends CloudFoundryServiceInfoCreator { - 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 serviceData) { - @SuppressWarnings("unchecked") - Map credentials = (Map) serviceData.get("credentials"); - + public SI createServiceInfo(Map serviceData) { String id = (String) serviceData.get("name"); - String uri = getStringFromCredentials(credentials, "uri", "url"); + Map 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); diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java index 10bd6e5..d64e144 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java @@ -15,26 +15,25 @@ public class SmtpServiceInfoCreator extends CloudFoundryServiceInfoCreator serviceData) { String id = (String) serviceData.get("name"); - @SuppressWarnings("unchecked") - Map credentials = (Map) serviceData.get("credentials"); + Map credentials = getCredentials(serviceData); String host = (String) credentials.get("hostname"); - int port = DEFAULT_SMTP_PORT; - if (credentials.containsKey("port")) { - port = Integer.parseInt(credentials.get("port").toString()); + int port = getIntFromCredentials(credentials, "port"); + if (port == -1) { + port = DEFAULT_SMTP_PORT; } String username = (String) credentials.get("username"); String password = (String) credentials.get("password"); - String uri = new UriInfo(SmtpServiceInfo.URI_SCHEME, host, port, username, password).toString(); + String uri = new UriInfo(SmtpServiceInfo.SMTP_SCHEME, host, port, username, password).toString(); return new SmtpServiceInfo(id, uri); } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/AbstractCloudFoundryConnectorTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/AbstractCloudFoundryConnectorTest.java index 5bab776..5809a08 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/AbstractCloudFoundryConnectorTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/AbstractCloudFoundryConnectorTest.java @@ -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 type) { + assertNotNull(serviceInfo); + assertThat(serviceInfo, new InstanceOf(type)); + } + + protected static void assertServiceFoundOfType(List serviceInfos, String serviceId, Class type) { + ServiceInfo serviceInfo = getServiceInfo(serviceInfos, serviceId); + assertServiceFoundOfType(serviceInfo, type); + } } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorAmqpServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorAmqpServiceTest.java index 0478a7e..56a4289 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorAmqpServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorAmqpServiceTest.java @@ -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.AmqpServiceInfo; /** * @@ -22,8 +22,8 @@ public class CloudFoundryConnectorAmqpServiceTest extends AbstractCloudFoundryCo getRabbitServicePayloadWithTags("rabbit-2", hostname, port, username, password, "q-2", "vhost2"))); List 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 @@ -34,20 +34,32 @@ public class CloudFoundryConnectorAmqpServiceTest extends AbstractCloudFoundryCo getRabbitServicePayloadWithoutTags("rabbit-2", hostname, port, username, password, "q-2", "vhost2"))); List 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 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 serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); + assertServiceFoundOfType(serviceInfos, "rabbit-2", AmqpServiceInfo.class); } private String getRabbitServicePayloadWithoutTags(String serviceName, @@ -66,6 +78,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, diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMongodbServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMongodbServiceTest.java index b28987c..1b13919 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMongodbServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMongodbServiceTest.java @@ -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 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 serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class); + assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class); + } - List 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; + } } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMonitoringServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMonitoringServiceTest.java index 4962782..b0e8999 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMonitoringServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMonitoringServiceTest.java @@ -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 serviceInfos = testCloudConnector.getServiceInfos(); - assertNotNull(getServiceInfo(serviceInfos, "monitoring-1")); + assertServiceFoundOfType(serviceInfos, "monitoring-1", MonitoringServiceInfo.class); } private String getMonitoringServicePayload(String serviceName) { diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMysqlServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMysqlServiceTest.java index 34cfd5c..a622097 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMysqlServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorMysqlServiceTest.java @@ -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()); } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorOracleServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorOracleServiceTest.java index d11ecf0..7a23916 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorOracleServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorOracleServiceTest.java @@ -27,7 +27,7 @@ public class CloudFoundryConnectorOracleServiceTest extends AbstractUserProvided List serviceInfos = testCloudConnector.getServiceInfos(); OracleServiceInfo info = (OracleServiceInfo) getServiceInfo(serviceInfos, SERVICE_NAME); - assertNotNull(info); + assertServiceFoundOfType(info, OracleServiceInfo.class); assertEquals(getOracleJdbcUrl(INSTANCE_NAME), info.getJdbcUrl()); } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorPostgresqlServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorPostgresqlServiceTest.java index 939fe5d..428b6b3 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorPostgresqlServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorPostgresqlServiceTest.java @@ -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 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 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()); } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorRedisServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorRedisServiceTest.java index de2e8e1..1be5666 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorRedisServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorRedisServiceTest.java @@ -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 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 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, diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java index 261a540..346c7bc 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java @@ -28,7 +28,7 @@ public class CloudFoundryConnectorSmtpServiceTest extends AbstractCloudFoundryCo assertEquals(hostname, smptServiceInfo.getHost()); assertEquals(587, smptServiceInfo.getPort()); assertEquals(username, smptServiceInfo.getUserName()); - assertEquals(password, smptServiceInfo.getPassword()); + assertEquals(password, smptServiceInfo.getPassword()); } private String getSmtpServicePayload(String serviceName, String hostname, diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info-no-label-no-tags-secure.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info-no-label-no-tags-secure.json new file mode 100644 index 0000000..8b2742b --- /dev/null +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info-no-label-no-tags-secure.json @@ -0,0 +1,6 @@ +{ + "name":"$serviceName", + "credentials":{ + "uri": "amqps://$username:$password@$hostname/$virtualHost" + } +} diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-ups-info-no-uri.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-ups-info-no-uri.json index e868710..e27a0b2 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-ups-info-no-uri.json +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-ups-info-no-uri.json @@ -7,6 +7,7 @@ "port": "$port", "username": "$user", "password": "$password", - "name": "$name" + "name": "$name", + "integer": 123 } } \ No newline at end of file diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java index a76ab3b..9741b1f 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfoCreator.java @@ -2,24 +2,30 @@ package org.springframework.cloud.service; import org.springframework.cloud.ServiceInfoCreator; -public abstract class UriBasedServiceInfoCreator implements - ServiceInfoCreator { +public abstract class UriBasedServiceInfoCreator + implements ServiceInfoCreator { - 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()); + } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index 23982c2..75acd5e 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -9,18 +9,20 @@ 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"; public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost) { - super(id, URI_SCHEME, host, port, username, password, virtualHost); + super(id, AMQP_SCHEME, host, port, username, password, virtualHost); } - public AmqpServiceInfo(String id, String uri) throws CloudException { + public AmqpServiceInfo(String id, String uri) throws CloudException { super(id, uri); } @@ -32,36 +34,27 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { @Override protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { if (uriInfo.getScheme() == null) { - throw new IllegalArgumentException("missing scheme in amqp URI: " + uriInfo); + 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; } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MongoServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MongoServiceInfo.java index a332b65..7bc4369 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MongoServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MongoServiceInfo.java @@ -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) { diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MysqlServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MysqlServiceInfo.java index f4609eb..289d503 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MysqlServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/MysqlServiceInfo.java @@ -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); } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java index 6d2289d..a73d107 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java @@ -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); diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/PostgresqlServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/PostgresqlServiceInfo.java index edcace5..ed168ca 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/PostgresqlServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/PostgresqlServiceInfo.java @@ -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); diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/RedisServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/RedisServiceInfo.java index ab35a8e..485e300 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/RedisServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/RedisServiceInfo.java @@ -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) { diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/SmtpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/SmtpServiceInfo.java index f973626..52ca165 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/SmtpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/SmtpServiceInfo.java @@ -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) { diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/AmqpServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/AmqpServiceInfoCreator.java index 86621f8..303639e 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/AmqpServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/AmqpServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.AmqpServiceInfo; public class AmqpServiceInfoCreator extends HerokuServiceInfoCreator { public AmqpServiceInfoCreator() { - super(AmqpServiceInfo.URI_SCHEME); + super(AmqpServiceInfo.AMQP_SCHEME, AmqpServiceInfo.AMQPS_SCHEME); } @Override diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java index 81094eb..20c65c8 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/HerokuServiceInfoCreator.java @@ -10,8 +10,8 @@ import org.springframework.cloud.service.UriBasedServiceInfoCreator; */ public abstract class HerokuServiceInfoCreator extends UriBasedServiceInfoCreator { - public HerokuServiceInfoCreator(String uriScheme) { - super(uriScheme); + public HerokuServiceInfoCreator(String... uriSchemes) { + super(uriSchemes); } /** diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MongoServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MongoServiceInfoCreator.java index d75299e..8694216 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MongoServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MongoServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MongoServiceInfo; public class MongoServiceInfoCreator extends HerokuServiceInfoCreator { public MongoServiceInfoCreator() { - super(MongoServiceInfo.URI_SCHEME); + super(MongoServiceInfo.MONGODB_SCHEME); } @Override diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MysqlServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MysqlServiceInfoCreator.java index 73bb8eb..19646bb 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MysqlServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/MysqlServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MysqlServiceInfo; public class MysqlServiceInfoCreator extends RelationalServiceInfoCreator { public MysqlServiceInfoCreator() { - super(MysqlServiceInfo.URI_SCHEME); + super(MysqlServiceInfo.MYSQL_SCHEME); } @Override diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/PostgresqlServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/PostgresqlServiceInfoCreator.java index 70f47de..837f0fe 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/PostgresqlServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/PostgresqlServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo; public class PostgresqlServiceInfoCreator extends RelationalServiceInfoCreator { public PostgresqlServiceInfoCreator() { - super(PostgresqlServiceInfo.URI_SCHEME); + super(PostgresqlServiceInfo.POSTGRES_SCHEME); } @Override diff --git a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/RedisServiceInfoCreator.java b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/RedisServiceInfoCreator.java index 1757bd7..1f4bd51 100644 --- a/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/RedisServiceInfoCreator.java +++ b/spring-cloud-heroku-connector/src/main/java/org/springframework/cloud/heroku/RedisServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.RedisServiceInfo; public class RedisServiceInfoCreator extends HerokuServiceInfoCreator { public RedisServiceInfoCreator() { - super(RedisServiceInfo.URI_SCHEME); + super(RedisServiceInfo.REDIS_SCHEME); } @Override diff --git a/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorMysqlServiceTest.java b/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorMysqlServiceTest.java index 439a854..c8c94ed 100644 --- a/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorMysqlServiceTest.java +++ b/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorMysqlServiceTest.java @@ -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 diff --git a/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorPostgresqlServiceTest.java b/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorPostgresqlServiceTest.java index 52d7398..2e03a14 100644 --- a/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorPostgresqlServiceTest.java +++ b/spring-cloud-heroku-connector/src/test/java/org/springframework/cloud/heroku/HerokuConnectorPostgresqlServiceTest.java @@ -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 diff --git a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/AmqpServiceInfoCreator.java b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/AmqpServiceInfoCreator.java index b9dc631..3ce1495 100644 --- a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/AmqpServiceInfoCreator.java +++ b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/AmqpServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.AmqpServiceInfo; public class AmqpServiceInfoCreator extends LocalConfigServiceInfoCreator{ public AmqpServiceInfoCreator() { - super(AmqpServiceInfo.URI_SCHEME); + super(AmqpServiceInfo.AMQP_SCHEME, AmqpServiceInfo.AMQPS_SCHEME); } @Override diff --git a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/LocalConfigServiceInfoCreator.java b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/LocalConfigServiceInfoCreator.java index 98a8669..184ca46 100644 --- a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/LocalConfigServiceInfoCreator.java +++ b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/LocalConfigServiceInfoCreator.java @@ -5,7 +5,7 @@ import org.springframework.cloud.service.UriBasedServiceInfoCreator; public abstract class LocalConfigServiceInfoCreator extends UriBasedServiceInfoCreator { - protected LocalConfigServiceInfoCreator(String uriScheme) { - super(uriScheme); + protected LocalConfigServiceInfoCreator(String... uriSchemes) { + super(uriSchemes); } } diff --git a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MongoServiceInfoCreator.java b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MongoServiceInfoCreator.java index 68671ac..411443d 100644 --- a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MongoServiceInfoCreator.java +++ b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MongoServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MongoServiceInfo; public class MongoServiceInfoCreator extends LocalConfigServiceInfoCreator{ public MongoServiceInfoCreator() { - super(MongoServiceInfo.URI_SCHEME); + super(MongoServiceInfo.MONGODB_SCHEME); } @Override diff --git a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MysqlServiceInfoCreator.java b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MysqlServiceInfoCreator.java index 0d39262..4978a15 100644 --- a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MysqlServiceInfoCreator.java +++ b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/MysqlServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.MysqlServiceInfo; public class MysqlServiceInfoCreator extends LocalConfigServiceInfoCreator{ public MysqlServiceInfoCreator() { - super(MysqlServiceInfo.URI_SCHEME); + super(MysqlServiceInfo.MYSQL_SCHEME); } @Override diff --git a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/PostgresqlServiceInfoCreator.java b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/PostgresqlServiceInfoCreator.java index 282da2f..7192404 100644 --- a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/PostgresqlServiceInfoCreator.java +++ b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/PostgresqlServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.PostgresqlServiceInfo; public class PostgresqlServiceInfoCreator extends LocalConfigServiceInfoCreator{ public PostgresqlServiceInfoCreator() { - super(PostgresqlServiceInfo.URI_SCHEME); + super(PostgresqlServiceInfo.POSTGRES_SCHEME); } @Override diff --git a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/RedisServiceInfoCreator.java b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/RedisServiceInfoCreator.java index 7a9e06f..cef97a2 100644 --- a/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/RedisServiceInfoCreator.java +++ b/spring-cloud-localconfig-connector/src/main/java/org/springframework/cloud/localconfig/RedisServiceInfoCreator.java @@ -10,7 +10,7 @@ import org.springframework.cloud.service.common.RedisServiceInfo; public class RedisServiceInfoCreator extends LocalConfigServiceInfoCreator{ public RedisServiceInfoCreator() { - super(RedisServiceInfo.URI_SCHEME); + super(RedisServiceInfo.REDIS_SCHEME); } @Override diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java index 7a3cdbf..e106c4a 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/rabbit/RabbitServiceInfoTest.java @@ -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()); @@ -27,6 +27,7 @@ public class RabbitServiceInfoTest { 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()); @@ -37,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"); @@ -53,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) From 735b82d0858e0dcec013afe0e71bfb2a52a22a30 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Mon, 3 Nov 2014 10:50:20 -0600 Subject: [PATCH 06/20] Drop spring-amqp dependency version down to 1.1.1 Spring Cloud Connector dependencies on other Spring projects (e.g. Spring AMQP, Spring Data) are not transient, but only necessary for compiling the Spring Cloud Connector code itself. Users of Spring Cloud Connectors are responsible for providing their own Spring dependencies of an appropriate version. Spring Cloud Connector should depend on the oldest version of a Spring project that provides all the APIs necessary for compilation. In the case of Spring AMQP, this is 1.1.1. --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 06e471b..6afba09 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ ext { springVersion = "3.1.4.RELEASE" tomcatVersion = "7.0.53" - springAmqpVersion = "1.3.6.RELEASE" + springAmqpVersion = "1.1.1.RELEASE" springDataRedisVersion = "1.1.1.RELEASE" springDataMongoVersion = "1.2.4.RELEASE" @@ -188,7 +188,7 @@ ext { "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"], + "amqp13" : [springAmqpVersion: "1.3.6.RELEASE"], "spring32": [springVersion : "3.2.9.RELEASE"], "spring40": [springVersion : "4.0.5.RELEASE"] ] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 77c676f..3587769 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 From e7d5d169198f471efbe92555c3f69a02dc2f939e Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Mon, 3 Nov 2014 10:51:48 -0600 Subject: [PATCH 07/20] Apply consistent formatting to build file. --- build.gradle | 242 +++++++++++++++++++++++++-------------------------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/build.gradle b/build.gradle index 6afba09..8f7159b 100644 --- a/build.gradle +++ b/build.gradle @@ -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.1.1.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" + + log4jVersion = "1.2.17" + + junitVersion = "4.11" + mockitoVersion = "1.9.5" - 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.6.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' } From a3108638904b3a10f0a0c07f39706891151ce751 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Mon, 17 Nov 2014 13:34:05 -0600 Subject: [PATCH 08/20] Made parsing of SMTP credentials on Cloud Foundry more flexible. Changed Spring connector for SMTP to return JavaMailSender instead of MailSender. --- .../cloudfoundry/SmtpServiceInfoCreator.java | 29 ++++++++------ .../CloudFoundryConnectorSmtpServiceTest.java | 38 ++++++++++++++++--- .../cloudfoundry/test-smtp-info-uri.json | 6 +++ .../cloud/cloudfoundry/test-smtp-info.json | 18 ++++----- .../cloud/service/smtp/MailSenderCreator.java | 19 +++++----- .../cloud/service/smtp/MailSenderFactory.java | 6 +-- .../service/smtp/MailSenderFactoryTest.java | 12 +++--- .../smtp/SmtpServiceConnectorCreatorTest.java | 1 - 8 files changed, 82 insertions(+), 47 deletions(-) create mode 100644 spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info-uri.json diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java index d64e144..36cbdf6 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/SmtpServiceInfoCreator.java @@ -8,6 +8,7 @@ import org.springframework.cloud.util.UriInfo; /** * * @author Ramnivas Laddad + * @author Scott Frederick * */ public class SmtpServiceInfoCreator extends CloudFoundryServiceInfoCreator { @@ -15,26 +16,30 @@ public class SmtpServiceInfoCreator extends CloudFoundryServiceInfoCreator serviceData) { + public SmtpServiceInfo createServiceInfo(Map serviceData) { String id = (String) serviceData.get("name"); - Map credentials = getCredentials(serviceData); - String host = (String) credentials.get("hostname"); + Map credentials = getCredentials(serviceData); - int port = getIntFromCredentials(credentials, "port"); - if (port == -1) { - port = DEFAULT_SMTP_PORT; + 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.SMTP_SCHEME, host, port, username, password).toString(); - return new SmtpServiceInfo(id, uri); } diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java index 346c7bc..a1ffba6 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryConnectorSmtpServiceTest.java @@ -23,12 +23,26 @@ public class CloudFoundryConnectorSmtpServiceTest extends AbstractCloudFoundryCo .thenReturn(getServicesPayload(getSmtpServicePayload("smtp-1", hostname, username, password))); List 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 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; + } } diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info-uri.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info-uri.json new file mode 100644 index 0000000..c2f1c9c --- /dev/null +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info-uri.json @@ -0,0 +1,6 @@ +{ + "name": "$serviceName", + "credentials": { + "uri": "smtp://$username:$password@$hostname:$port" + } +} diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info.json index 798e990..3694a92 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info.json +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-smtp-info.json @@ -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" + } } diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderCreator.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderCreator.java index dd34d31..e8fdc34 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderCreator.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderCreator.java @@ -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 { +public class MailSenderCreator extends AbstractServiceConnectorCreator { @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; } } diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderFactory.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderFactory.java index ee4ab39..9e9ef13 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderFactory.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/smtp/MailSenderFactory.java @@ -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 { +public class MailSenderFactory extends AbstractCloudServiceConnectorFactory { public MailSenderFactory(String serviceId, ServiceConnectorConfig serviceConnectorConfiguration) { - super(serviceId, MailSender.class, serviceConnectorConfiguration); + super(serviceId, JavaMailSender.class, serviceConnectorConfiguration); } } diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/MailSenderFactoryTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/MailSenderFactoryTest.java index 3b7a5ae..48de6ed 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/MailSenderFactoryTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/MailSenderFactoryTest.java @@ -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 { - @Mock MailSender mockConnector; +public class MailSenderFactoryTest extends AbstractCloudServiceConnectorFactoryTest { + @Mock JavaMailSender mockConnector; public MailSenderFactory createTestCloudServiceConnectorFactory(String id, ServiceConnectorConfig config) { return new MailSenderFactory(id, config); } - public Class getConnectorType() { - return MailSender.class; + public Class getConnectorType() { + return JavaMailSender.class; } - public MailSender getMockConnector() { + public JavaMailSender getMockConnector() { return mockConnector; } diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/SmtpServiceConnectorCreatorTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/SmtpServiceConnectorCreatorTest.java index e65c4fc..09d4794 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/SmtpServiceConnectorCreatorTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/smtp/SmtpServiceConnectorCreatorTest.java @@ -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 From f2be5e94305446d4698636a9037bf44185f418ed Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Mon, 24 Nov 2014 14:07:10 -0500 Subject: [PATCH 09/20] GitHub issue #96: Direct dependency on log4j framework * Remove log4j dependency from spring-cloud-spring-service-connector build.gradle & version var in main build.gradle * Remove log4j.properties files from test resource packages --- build.gradle | 2 -- .../src/test/resources/log4j.properties | 6 ------ spring-cloud-core/src/test/resources/log4j.properties | 6 ------ .../src/test/resources/log4j.properties | 6 ------ .../src/test/resources/log4j.properties | 6 ------ spring-cloud-spring-service-connector/build.gradle | 1 - .../src/test/resources/log4j.properties | 6 ------ 7 files changed, 33 deletions(-) delete mode 100644 spring-cloud-cloudfoundry-connector/src/test/resources/log4j.properties delete mode 100644 spring-cloud-core/src/test/resources/log4j.properties delete mode 100644 spring-cloud-heroku-connector/src/test/resources/log4j.properties delete mode 100644 spring-cloud-pcf-connector/src/test/resources/log4j.properties delete mode 100644 spring-cloud-spring-service-connector/src/test/resources/log4j.properties diff --git a/build.gradle b/build.gradle index 8f7159b..5eb7362 100644 --- a/build.gradle +++ b/build.gradle @@ -33,8 +33,6 @@ ext { jacksonVersion = "2.3.3" - log4jVersion = "1.2.17" - junitVersion = "4.11" mockitoVersion = "1.9.5" diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/log4j.properties b/spring-cloud-cloudfoundry-connector/src/test/resources/log4j.properties deleted file mode 100644 index 11492f1..0000000 --- a/spring-cloud-cloudfoundry-connector/src/test/resources/log4j.properties +++ /dev/null @@ -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 - diff --git a/spring-cloud-core/src/test/resources/log4j.properties b/spring-cloud-core/src/test/resources/log4j.properties deleted file mode 100644 index 89c2a13..0000000 --- a/spring-cloud-core/src/test/resources/log4j.properties +++ /dev/null @@ -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 - diff --git a/spring-cloud-heroku-connector/src/test/resources/log4j.properties b/spring-cloud-heroku-connector/src/test/resources/log4j.properties deleted file mode 100644 index 11492f1..0000000 --- a/spring-cloud-heroku-connector/src/test/resources/log4j.properties +++ /dev/null @@ -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 - diff --git a/spring-cloud-pcf-connector/src/test/resources/log4j.properties b/spring-cloud-pcf-connector/src/test/resources/log4j.properties deleted file mode 100644 index 11492f1..0000000 --- a/spring-cloud-pcf-connector/src/test/resources/log4j.properties +++ /dev/null @@ -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 - diff --git a/spring-cloud-spring-service-connector/build.gradle b/spring-cloud-spring-service-connector/build.gradle index 9b68e47..26caf24 100644 --- a/spring-cloud-spring-service-connector/build.gradle +++ b/spring-cloud-spring-service-connector/build.gradle @@ -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") diff --git a/spring-cloud-spring-service-connector/src/test/resources/log4j.properties b/spring-cloud-spring-service-connector/src/test/resources/log4j.properties deleted file mode 100644 index 89c2a13..0000000 --- a/spring-cloud-spring-service-connector/src/test/resources/log4j.properties +++ /dev/null @@ -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 - From 3f765c5515df99e25f7f50c0b5a79a9f2f78af4f Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Thu, 4 Dec 2014 11:38:00 -0500 Subject: [PATCH 10/20] Support for MongoDB replica sets GH issue #86 --- .gitignore | 2 + .../cloud/service/UriBasedServiceInfo.java | 156 ++++++++++-------- .../cloud/util/StandardUriInfoFactory.java | 3 +- .../springframework/cloud/util/UriInfo.java | 15 +- .../document/MongoDbFactoryCreator.java | 85 +++++----- .../org/springframework/cloud/CloudTest.java | 31 +++- .../cloud/StubCloudConnectorTest.java | 9 +- .../MongoServiceConnectorCreatorTest.java | 75 ++++++--- 8 files changed, 234 insertions(+), 142 deletions(-) diff --git a/.gitignore b/.gitignore index 1eb96eb..b88feb1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ Servers .gradle _site /bin +.idea +*.iml diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java index fda552c..698d495 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/UriBasedServiceInfo.java @@ -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() + "]"; + } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/util/StandardUriInfoFactory.java b/spring-cloud-core/src/main/java/org/springframework/cloud/util/StandardUriInfoFactory.java index 8032b55..c5e89ba 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/util/StandardUriInfoFactory.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/util/StandardUriInfoFactory.java @@ -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) { diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/util/UriInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/util/UriInfo.java index 0a0310b..26f6c35 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/util/UriInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/util/UriInfo.java @@ -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; diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java index ef301c8..850a13c 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/service/document/MongoDbFactoryCreator.java @@ -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 { @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 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 getServerAddresses(MongoClientURI mongoClientURI) throws UnknownHostException { + List servers = mongoClientURI.getHosts(); + List serverAddressList = new ArrayList(); + + 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 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 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> 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")); diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/StubCloudConnectorTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/StubCloudConnectorTest.java index 2c442e8..9a7eb20 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/StubCloudConnectorTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/StubCloudConnectorTest.java @@ -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"); } diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/mongo/MongoServiceConnectorCreatorTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/mongo/MongoServiceConnectorCreatorTest.java index 9b8a770..5169e7c 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/mongo/MongoServiceConnectorCreatorTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/service/mongo/MongoServiceConnectorCreatorTest.java @@ -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 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 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()); } } From c7bca2009d7e7f6c9b4dd8dcb3808ce4c85f16fc Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Mon, 15 Dec 2014 20:44:24 -0500 Subject: [PATCH 11/20] PCF spring cloud connector for Eureka --- build.gradle | 2 + spring-cloud-pcf-connector/build.gradle | 6 +- .../EurekaClientConfigurationCreator.java | 191 ++++++++++++++++++ .../cloud/pcf/eureka/EurekaServiceInfo.java | 16 ++ .../pcf/eureka/EurekaServiceInfoCreator.java | 29 +++ ...loudfoundry.CloudFoundryServiceInfoCreator | 1 + ...work.cloud.service.ServiceConnectorCreator | 3 +- .../EurekaClientConfigurationCreatorTest.java | 42 ++++ .../eureka/EurekaServiceInfoCreatorTest.java | 45 +++++ .../cloud/pcf/eureka/test-eureka-info.json | 11 + 10 files changed, 343 insertions(+), 3 deletions(-) create mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java create mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java create mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java create mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java create mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java create mode 100644 spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json diff --git a/build.gradle b/build.gradle index 5eb7362..ec520ba 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,8 @@ ext { junitVersion = "4.11" mockitoVersion = "1.9.5" + eurekaClientVersion = "1.1.135" + hadoopCommonVersion = "2.2.0" javadocLinks = [ 'http://docs.oracle.com/javase/7/docs/api/', diff --git a/spring-cloud-pcf-connector/build.gradle b/spring-cloud-pcf-connector/build.gradle index 90c4307..d2f3536 100644 --- a/spring-cloud-pcf-connector/build.gradle +++ b/spring-cloud-pcf-connector/build.gradle @@ -1,9 +1,11 @@ description = 'Spring-Cloud Support for Pivotal CF' dependencies { + compile project(':spring-cloud-core') compile project(':spring-cloud-cloudfoundry-connector') compile project(':spring-cloud-spring-service-connector') - optional("org.apache.hadoop:hadoop-common:2.2.0") - + optional("org.apache.hadoop:hadoop-common:$hadoopCommonVersion") + optional("com.netflix.eureka:eureka-client:$eurekaClientVersion") + testCompile project(path: ':spring-cloud-cloudfoundry-connector', configuration: 'tests') } diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java new file mode 100644 index 0000000..d066eea --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java @@ -0,0 +1,191 @@ +package org.springframework.cloud.pcf.eureka; + +import com.netflix.discovery.EurekaClientConfig; +import org.springframework.cloud.service.AbstractServiceConnectorCreator; +import org.springframework.cloud.service.ServiceConnectorConfig; + +import javax.annotation.Nullable; +import java.util.Arrays; +import java.util.List; + +/** + * + * Connector creator for Eureka client services + * + * @author Chris Schaefer + */ +public class EurekaClientConfigurationCreator extends AbstractServiceConnectorCreator { + @Override + public EurekaClientConfig create(EurekaServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { + return getEurekaClientConfig(serviceInfo); + } + + protected EurekaClientConfig getEurekaClientConfig(EurekaServiceInfo serviceInfo) { + return new DefaultPcfEurekaClientConfig(serviceInfo.getUri()); + } + + private static final class DefaultPcfEurekaClientConfig implements EurekaClientConfig { + private static final int MINUTES = 60; + private static final String REGION = "default"; + private static final String DEFAULT_ZONE = "defaultZone"; + private static final String EUREKA_API_PREFIX = "/eureka/"; + + private final String uri; + + public DefaultPcfEurekaClientConfig(String uri) { + this.uri = uri + EUREKA_API_PREFIX; + } + + @Override + public int getRegistryFetchIntervalSeconds() { + return 5; + } + + @Override + public int getInstanceInfoReplicationIntervalSeconds() { + return 30; + } + + @Override + public int getInitialInstanceInfoReplicationIntervalSeconds() { + return 40; + } + + @Override + public int getEurekaServiceUrlPollIntervalSeconds() { + return 5 * MINUTES; + } + + @Override + public String getProxyHost() { + return null; + } + + @Override + public String getProxyPort() { + return null; + } + + @Override + public boolean shouldGZipContent() { + return true; + } + + @Override + public int getEurekaServerReadTimeoutSeconds() { + return 8; + } + + @Override + public int getEurekaServerConnectTimeoutSeconds() { + return 5; + } + + @Override + public String getBackupRegistryImpl() { + return null; + } + + @Override + public int getEurekaServerTotalConnections() { + return 200; + } + + @Override + public int getEurekaServerTotalConnectionsPerHost() { + return 50; + } + + @Override + public String getEurekaServerURLContext() { + return null; + } + + @Override + public String getEurekaServerPort() { + return null; + } + + @Override + public String getEurekaServerDNSName() { + return null; + } + + @Override + public boolean shouldUseDnsForFetchingServiceUrls() { + return false; + } + + @Override + public boolean shouldRegisterWithEureka() { + return true; + } + + @Override + public boolean shouldPreferSameZoneEureka() { + return true; + } + + @Override + public boolean shouldLogDeltaDiff() { + return false; + } + + @Override + public boolean shouldDisableDelta() { + return false; + } + + @Nullable + @Override + public String fetchRegistryForRemoteRegions() { + return null; + } + + @Override + public String getRegion() { + return REGION; + } + + @Override + public String[] getAvailabilityZones(String region) { + return new String[] { DEFAULT_ZONE }; + } + + @Override + public List getEurekaServerServiceUrls(String myZone) { + return Arrays.asList(uri); + } + + @Override + public boolean shouldFilterOnlyUpInstances() { + return true; + } + + @Override + public int getEurekaConnectionIdleTimeoutSeconds() { + return 30; + } + + @Override + public boolean shouldFetchRegistry() { + return true; + } + + @Nullable + @Override + public String getRegistryRefreshSingleVipAddress() { + return null; + } + + @Override + public int getHeartbeatExecutorThreadPoolSize() { + return 2; + } + + @Override + public int getCacheRefreshExecutorThreadPoolSize() { + return 2; + } + } +} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java new file mode 100644 index 0000000..790c8d5 --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java @@ -0,0 +1,16 @@ +package org.springframework.cloud.pcf.eureka; + +import org.springframework.cloud.service.ServiceInfo; +import org.springframework.cloud.service.UriBasedServiceInfo; + +/** + * Information to access Eureka services + * + * @author Chris Schaefer + */ +@ServiceInfo.ServiceLabel("eureka") +public class EurekaServiceInfo extends UriBasedServiceInfo { + public EurekaServiceInfo(String id, String uriString) { + super(id, uriString); + } +} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java new file mode 100644 index 0000000..c9321a6 --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java @@ -0,0 +1,29 @@ +package org.springframework.cloud.pcf.eureka; + +import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator; +import org.springframework.cloud.cloudfoundry.Tags; + +import java.util.Map; + +/** + * + * Service info creator for Eureka services + * + * @author Chris Schaefer + */ +public class EurekaServiceInfoCreator extends CloudFoundryServiceInfoCreator { + private static final String CREDENTIALS_ID_KEY = "name"; + private static final String EUREKA_SERVICE_TAG_NAME = "eureka"; + + public EurekaServiceInfoCreator() { + super(new Tags(EUREKA_SERVICE_TAG_NAME)); + } + + @Override + public EurekaServiceInfo createServiceInfo(Map serviceData) { + String id = (String) serviceData.get(CREDENTIALS_ID_KEY); + String uri = getUriFromCredentials(getCredentials(serviceData)); + + return new EurekaServiceInfo(id, uri); + } +} diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator index 304d95f..1486458 100644 --- a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator +++ b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator @@ -1 +1,2 @@ org.springframework.cloud.pcf.phd.PhdServiceInfoCreator +org.springframework.cloud.pcf.eureka.EurekaServiceInfoCreator diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator index e99f33c..3840a00 100644 --- a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator +++ b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator @@ -1,2 +1,3 @@ org.springframework.cloud.pcf.hadoop.HadoopConfigurationCreator -org.springframework.cloud.pcf.gemfire.GemfireXDDataSourceCreator \ No newline at end of file +org.springframework.cloud.pcf.gemfire.GemfireXDDataSourceCreator +org.springframework.cloud.pcf.eureka.EurekaClientConfigurationCreator diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java new file mode 100644 index 0000000..2e3a4dd --- /dev/null +++ b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java @@ -0,0 +1,42 @@ +package org.springframework.cloud.pcf.eureka; + +import com.netflix.discovery.EurekaClientConfig; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * Test cases around the Eureka client configuration creator + * + * @author Chris Schaefer + */ +public class EurekaClientConfigurationCreatorTest { + private static final String REGION = "default"; + private static final String SERVICE_INFO_ID = "id"; + private static final int REGISTRY_FETCH_INTERVAL_SECS = 5; + private static final String AVAILABLITY_ZONE = "defaultZone"; + private static final String URI = "http://user:pass@192.168.23.4:1234"; + private static final String EUREKA_API_PREFIX = "/eureka/"; + + private EurekaClientConfigurationCreator eurekaClientConfigurationCreator = new EurekaClientConfigurationCreator(); + + @Test + public void testClientConfiguration() { + EurekaServiceInfo eurekaServiceInfo = new EurekaServiceInfo(SERVICE_INFO_ID, URI); + + EurekaClientConfig eurekaClientConfig = eurekaClientConfigurationCreator.create(eurekaServiceInfo, null); + List serviceUrls = eurekaClientConfig.getEurekaServerServiceUrls(null); + + assertEquals(1, serviceUrls.size()); + assertEquals(URI + EUREKA_API_PREFIX, serviceUrls.get(0)); + assertEquals(REGION, eurekaClientConfig.getRegion()); + assertEquals(REGISTRY_FETCH_INTERVAL_SECS, eurekaClientConfig.getRegistryFetchIntervalSeconds()); + + String[] availablityZones = eurekaClientConfig.getAvailabilityZones(null); + + assertEquals(1, availablityZones.length); + assertEquals(AVAILABLITY_ZONE, availablityZones[0]); + } +} diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java new file mode 100644 index 0000000..43ba2ff --- /dev/null +++ b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java @@ -0,0 +1,45 @@ +package org.springframework.cloud.pcf.eureka; + +import org.junit.Test; +import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest; +import org.springframework.cloud.service.ServiceInfo; + +import java.util.List; + +import static org.mockito.Mockito.when; + +/** + * Connector tests for Eureka services + * + * @author Chris Schaefer + */ +public class EurekaServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest { + private static final String EUREKA_SERVICE_TAG_NAME = "myEurekaInstance"; + private static final String VCAP_SERVICES_ENV_KEY = "VCAP_SERVICES"; + private static final String PAYLOAD_FILE_NAME = "test-eureka-info.json"; + private static final String PAYLOAD_TEMPLATE_SERVICE_NAME = "$serviceName"; + private static final String PAYLOAD_TEMPLATE_HOSTNAME = "$hostname"; + private static final String PAYLOAD_TEMPLATE_PORT = "$port"; + private static final String PAYLOAD_TEMPLATE_USER = "$user"; + private static final String PAYLOAD_TEMPLATE_PASS = "$pass"; + + @Test + public void eurekaServiceCreationWithTags() { + when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY)) + .thenReturn(getServicesPayload(getEurekaServicePayload(EUREKA_SERVICE_TAG_NAME, hostname, port, username, password))); + + List serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, EUREKA_SERVICE_TAG_NAME, EurekaServiceInfo.class); + } + + private String getEurekaServicePayload(String serviceName, String hostname, int port, String user, String password) { + String payload = readTestDataFile(PAYLOAD_FILE_NAME); + payload = payload.replace(PAYLOAD_TEMPLATE_SERVICE_NAME, serviceName); + payload = payload.replace(PAYLOAD_TEMPLATE_HOSTNAME, hostname); + payload = payload.replace(PAYLOAD_TEMPLATE_PORT, Integer.toString(port)); + payload = payload.replace(PAYLOAD_TEMPLATE_USER, user); + payload = payload.replace(PAYLOAD_TEMPLATE_PASS, password); + + return payload; + } +} diff --git a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json new file mode 100644 index 0000000..527deb4 --- /dev/null +++ b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json @@ -0,0 +1,11 @@ +{ + "name":"$serviceName", + "label":"p-eureka", + "plan":"standard", + "tags":[ + "eureka" + ], + "credentials":{ + "uri":"http://$username:$password@$hostname:$port/" + } +} From 38e48bc3f0b32f3c0e9633df6f33f6886625a45e Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Fri, 9 Jan 2015 14:31:57 -0500 Subject: [PATCH 12/20] Spring cloud connector for Config server --- .../ConfigServerServiceConnector.java | 75 +++++++++++++++++++ .../configserver/ConfigServerServiceInfo.java | 14 ++++ .../ConfigServerServiceInfoCreator.java | 28 +++++++ ...loudfoundry.CloudFoundryServiceInfoCreator | 1 + .../main/resources/META-INF/spring.factories | 2 + .../ConfigServerServiceInfoCreatorTest.java | 46 ++++++++++++ .../configserver/test-config-server-info.json | 11 +++ 7 files changed, 177 insertions(+) create mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java create mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java create mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java create mode 100644 spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories create mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java create mode 100644 spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java new file mode 100644 index 0000000..9f9f1a9 --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java @@ -0,0 +1,75 @@ +package org.springframework.cloud.pcf.configserver; + +import org.springframework.cloud.Cloud; +import org.springframework.cloud.CloudFactory; +import org.springframework.cloud.service.ServiceInfo; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.util.ReflectionUtils; + +import java.lang.reflect.Method; +import java.util.Collections; + +/** + * Connector to Config Server service + * + * @author Chris Schaefer + */ +@Configuration +public class ConfigServerServiceConnector implements ApplicationListener, Ordered { + /** + * TODO: + * Bind ApplicationListener to ApplicationEnvironmentPreparedEvent, remove reflection + * and add test after repo migration in which we will have a direct dependency on boot. + */ + + private static final String PROPERTY_SOURCE_NAME = "vcapConfigServerUri"; + private static final String EVENT_ENVIRONMENT_METHOD_NAME = "getEnvironment"; + private static final String SPRING_CLOUD_CONFIG_URI = "spring.cloud.config.uri"; + private static final String EVENT_CLASS_NAME = "org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent"; + + private Cloud cloud; + + @Override + public void onApplicationEvent(ApplicationEvent event) { + if(!supports(event.getClass().getName()) || cloud != null) { + return; + } + + cloud = new CloudFactory().getCloud(); + + for(ServiceInfo serviceInfo : cloud.getServiceInfos()) { + if(serviceInfo instanceof ConfigServerServiceInfo) { + String uri = ((ConfigServerServiceInfo) serviceInfo).getUri(); + + MapPropertySource mapPropertySource = new MapPropertySource(PROPERTY_SOURCE_NAME, + Collections.singletonMap(SPRING_CLOUD_CONFIG_URI, uri)); + + getEnvironment(event).getPropertySources().addFirst(mapPropertySource); + } + } + } + + private boolean supports(String className) { + return EVENT_CLASS_NAME.equals(className); + } + + private ConfigurableEnvironment getEnvironment(ApplicationEvent event) { + Method method = ReflectionUtils.findMethod(event.getClass(), EVENT_ENVIRONMENT_METHOD_NAME); + + try { + return (ConfigurableEnvironment) method.invoke(event); + } catch (Exception e) { + throw new RuntimeException("Error obtaining Environment from event", e); + } + } + + @Override + public int getOrder() { + return Ordered.HIGHEST_PRECEDENCE + 4; + } +} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java new file mode 100644 index 0000000..f2c0d2d --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java @@ -0,0 +1,14 @@ +package org.springframework.cloud.pcf.configserver; + +import org.springframework.cloud.service.UriBasedServiceInfo; + +/** + * Service info to access Config Server services + * + * @author Chris Schaefer + */ +public class ConfigServerServiceInfo extends UriBasedServiceInfo { + public ConfigServerServiceInfo(String id, String uriString) { + super(id, uriString); + } +} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java new file mode 100644 index 0000000..1d8d1f9 --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java @@ -0,0 +1,28 @@ +package org.springframework.cloud.pcf.configserver; + +import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator; +import org.springframework.cloud.cloudfoundry.Tags; + +import java.util.Map; + +/** + * Service info creator for Config Server services + * + * @author Chris Schaefer + */ +public class ConfigServerServiceInfoCreator extends CloudFoundryServiceInfoCreator { + private static final String CREDENTIALS_ID_KEY = "name"; + private static final String CONFIG_SERVER_SERVICE_TAG_NAME = "configuration"; + + public ConfigServerServiceInfoCreator() { + super(new Tags(CONFIG_SERVER_SERVICE_TAG_NAME)); + } + + @Override + public ConfigServerServiceInfo createServiceInfo(Map serviceData) { + String id = (String) serviceData.get(CREDENTIALS_ID_KEY); + String uri = getUriFromCredentials(getCredentials(serviceData)); + + return new ConfigServerServiceInfo(id, uri); + } +} diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator index 1486458..da1e07c 100644 --- a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator +++ b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator @@ -1,2 +1,3 @@ org.springframework.cloud.pcf.phd.PhdServiceInfoCreator org.springframework.cloud.pcf.eureka.EurekaServiceInfoCreator +org.springframework.cloud.pcf.configserver.ConfigServerServiceInfoCreator diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories b/spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..155b64b --- /dev/null +++ b/spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.context.ApplicationListener=\ +org.springframework.cloud.pcf.configserver.ConfigServerServiceConnector diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java new file mode 100644 index 0000000..8ff29d3 --- /dev/null +++ b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java @@ -0,0 +1,46 @@ +package org.springframework.cloud.pcf.configserver; + +import org.junit.Test; +import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest; +import org.springframework.cloud.service.ServiceInfo; + +import java.util.List; + +import static org.mockito.Mockito.when; + +/** + * Connector tests for Config Server services + * + * @author Chris Schaefer + */ +public class ConfigServerServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest { + private static final String CONFIG_SERVER_SERVICE_TAG_NAME = "myConfigServerService"; + private static final String VCAP_SERVICES_ENV_KEY = "VCAP_SERVICES"; + private static final String PAYLOAD_FILE_NAME = "test-config-server-info.json"; + private static final String PAYLOAD_TEMPLATE_SERVICE_NAME = "$serviceName"; + private static final String PAYLOAD_TEMPLATE_HOSTNAME = "$hostname"; + private static final String PAYLOAD_TEMPLATE_PORT = "$port"; + private static final String PAYLOAD_TEMPLATE_USER = "$user"; + private static final String PAYLOAD_TEMPLATE_PASS = "$pass"; + + @Test + public void configServerServiceCreationWithTags() { + when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY)) + .thenReturn(getServicesPayload(getConfigServerServicePayload(CONFIG_SERVER_SERVICE_TAG_NAME, + hostname, port, username, password))); + + List serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, CONFIG_SERVER_SERVICE_TAG_NAME, ConfigServerServiceInfo.class); + } + + private String getConfigServerServicePayload(String serviceName, String hostname, int port, String user, String password) { + String payload = readTestDataFile(PAYLOAD_FILE_NAME); + payload = payload.replace(PAYLOAD_TEMPLATE_SERVICE_NAME, serviceName); + payload = payload.replace(PAYLOAD_TEMPLATE_HOSTNAME, hostname); + payload = payload.replace(PAYLOAD_TEMPLATE_PORT, Integer.toString(port)); + payload = payload.replace(PAYLOAD_TEMPLATE_USER, user); + payload = payload.replace(PAYLOAD_TEMPLATE_PASS, password); + + return payload; + } +} diff --git a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json new file mode 100644 index 0000000..44dad0d --- /dev/null +++ b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json @@ -0,0 +1,11 @@ +{ + "name":"$serviceName", + "label":"p-config", + "plan":"standard", + "tags":[ + "configuration" + ], + "credentials":{ + "uri":"http://$username:$password@$hostname:$port/" + } +} From 58ef61296a9b53abf817635ce07d994c1d9485a5 Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Mon, 12 Jan 2015 22:18:20 -0500 Subject: [PATCH 13/20] Move spring-cloud-pcf-connector to its own repo, modify test jar creation in spring-cloud-cloudfoundry-connector to build a jar with the classes --- publish-maven.gradle | 5 + settings.gradle | 2 +- .../build.gradle | 5 +- spring-cloud-pcf-connector/.gitignore | 2 - spring-cloud-pcf-connector/README.md | 3 - spring-cloud-pcf-connector/build.gradle | 11 - .../publish-maven.gradle | 65 ------ .../ConfigServerServiceConnector.java | 75 ------- .../configserver/ConfigServerServiceInfo.java | 14 -- .../ConfigServerServiceInfoCreator.java | 28 --- .../EurekaClientConfigurationCreator.java | 191 ------------------ .../cloud/pcf/eureka/EurekaServiceInfo.java | 16 -- .../pcf/eureka/EurekaServiceInfoCreator.java | 29 --- .../gemfire/GemfireXDDataSourceCreator.java | 20 -- .../pcf/gemfire/GemfireXDServiceInfo.java | 20 -- .../hadoop/HadoopConfigurationCreator.java | 25 --- .../cloud/pcf/hadoop/HadoopServiceInfo.java | 42 ---- .../cloud/pcf/phd/PhdServiceInfoCreator.java | 79 -------- ...loudfoundry.CloudFoundryServiceInfoCreator | 3 - ...work.cloud.service.ServiceConnectorCreator | 3 - .../main/resources/META-INF/spring.factories | 2 - .../HadoopConfigurationCreatorTest.java | 26 --- .../cloud/pcf/PhdServiceInfoCreatorTest.java | 142 ------------- .../ConfigServerServiceInfoCreatorTest.java | 46 ----- .../EurekaClientConfigurationCreatorTest.java | 42 ---- .../eureka/EurekaServiceInfoCreatorTest.java | 45 ----- .../configserver/test-config-server-info.json | 11 - .../cloud/pcf/eureka/test-eureka-info.json | 11 - .../cloud/pcf/test-phd-info.json | 31 --- 29 files changed, 9 insertions(+), 985 deletions(-) delete mode 100644 spring-cloud-pcf-connector/.gitignore delete mode 100644 spring-cloud-pcf-connector/README.md delete mode 100644 spring-cloud-pcf-connector/build.gradle delete mode 100644 spring-cloud-pcf-connector/publish-maven.gradle delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDDataSourceCreator.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDServiceInfo.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopConfigurationCreator.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopServiceInfo.java delete mode 100644 spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/phd/PhdServiceInfoCreator.java delete mode 100644 spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator delete mode 100644 spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator delete mode 100644 spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories delete mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/hadoop/HadoopConfigurationCreatorTest.java delete mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/PhdServiceInfoCreatorTest.java delete mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java delete mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java delete mode 100644 spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java delete mode 100644 spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json delete mode 100644 spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json delete mode 100644 spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/test-phd-info.json diff --git a/publish-maven.gradle b/publish-maven.gradle index 44c6719..2d1ac74 100644 --- a/publish-maven.gradle +++ b/publish-maven.gradle @@ -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' + } } } } diff --git a/settings.gradle b/settings.gradle index a4a8bc9..1eca68b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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" + diff --git a/spring-cloud-cloudfoundry-connector/build.gradle b/spring-cloud-cloudfoundry-connector/build.gradle index 7d8d955..c16f64a 100644 --- a/spring-cloud-cloudfoundry-connector/build.gradle +++ b/spring-cloud-cloudfoundry-connector/build.gradle @@ -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 -} \ No newline at end of file + archives testJar +} diff --git a/spring-cloud-pcf-connector/.gitignore b/spring-cloud-pcf-connector/.gitignore deleted file mode 100644 index bd39306..0000000 --- a/spring-cloud-pcf-connector/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -dependency-reduced-pom.xml -/bin diff --git a/spring-cloud-pcf-connector/README.md b/spring-cloud-pcf-connector/README.md deleted file mode 100644 index 6990824..0000000 --- a/spring-cloud-pcf-connector/README.md +++ /dev/null @@ -1,3 +0,0 @@ -#Spring Cloud PCF extension - -Currently supports the Hadoop service on Pivotal Cloud Foundry \ No newline at end of file diff --git a/spring-cloud-pcf-connector/build.gradle b/spring-cloud-pcf-connector/build.gradle deleted file mode 100644 index d2f3536..0000000 --- a/spring-cloud-pcf-connector/build.gradle +++ /dev/null @@ -1,11 +0,0 @@ -description = 'Spring-Cloud Support for Pivotal CF' - -dependencies { - compile project(':spring-cloud-core') - compile project(':spring-cloud-cloudfoundry-connector') - compile project(':spring-cloud-spring-service-connector') - optional("org.apache.hadoop:hadoop-common:$hadoopCommonVersion") - optional("com.netflix.eureka:eureka-client:$eurekaClientVersion") - - testCompile project(path: ':spring-cloud-cloudfoundry-connector', configuration: 'tests') -} diff --git a/spring-cloud-pcf-connector/publish-maven.gradle b/spring-cloud-pcf-connector/publish-maven.gradle deleted file mode 100644 index 632359e..0000000 --- a/spring-cloud-pcf-connector/publish-maven.gradle +++ /dev/null @@ -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 = "" - } - } - } - } -} \ No newline at end of file diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java deleted file mode 100644 index 9f9f1a9..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceConnector.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.springframework.cloud.pcf.configserver; - -import org.springframework.cloud.Cloud; -import org.springframework.cloud.CloudFactory; -import org.springframework.cloud.service.ServiceInfo; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.MapPropertySource; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Method; -import java.util.Collections; - -/** - * Connector to Config Server service - * - * @author Chris Schaefer - */ -@Configuration -public class ConfigServerServiceConnector implements ApplicationListener, Ordered { - /** - * TODO: - * Bind ApplicationListener to ApplicationEnvironmentPreparedEvent, remove reflection - * and add test after repo migration in which we will have a direct dependency on boot. - */ - - private static final String PROPERTY_SOURCE_NAME = "vcapConfigServerUri"; - private static final String EVENT_ENVIRONMENT_METHOD_NAME = "getEnvironment"; - private static final String SPRING_CLOUD_CONFIG_URI = "spring.cloud.config.uri"; - private static final String EVENT_CLASS_NAME = "org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent"; - - private Cloud cloud; - - @Override - public void onApplicationEvent(ApplicationEvent event) { - if(!supports(event.getClass().getName()) || cloud != null) { - return; - } - - cloud = new CloudFactory().getCloud(); - - for(ServiceInfo serviceInfo : cloud.getServiceInfos()) { - if(serviceInfo instanceof ConfigServerServiceInfo) { - String uri = ((ConfigServerServiceInfo) serviceInfo).getUri(); - - MapPropertySource mapPropertySource = new MapPropertySource(PROPERTY_SOURCE_NAME, - Collections.singletonMap(SPRING_CLOUD_CONFIG_URI, uri)); - - getEnvironment(event).getPropertySources().addFirst(mapPropertySource); - } - } - } - - private boolean supports(String className) { - return EVENT_CLASS_NAME.equals(className); - } - - private ConfigurableEnvironment getEnvironment(ApplicationEvent event) { - Method method = ReflectionUtils.findMethod(event.getClass(), EVENT_ENVIRONMENT_METHOD_NAME); - - try { - return (ConfigurableEnvironment) method.invoke(event); - } catch (Exception e) { - throw new RuntimeException("Error obtaining Environment from event", e); - } - } - - @Override - public int getOrder() { - return Ordered.HIGHEST_PRECEDENCE + 4; - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java deleted file mode 100644 index f2c0d2d..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfo.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.springframework.cloud.pcf.configserver; - -import org.springframework.cloud.service.UriBasedServiceInfo; - -/** - * Service info to access Config Server services - * - * @author Chris Schaefer - */ -public class ConfigServerServiceInfo extends UriBasedServiceInfo { - public ConfigServerServiceInfo(String id, String uriString) { - super(id, uriString); - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java deleted file mode 100644 index 1d8d1f9..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreator.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.springframework.cloud.pcf.configserver; - -import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator; -import org.springframework.cloud.cloudfoundry.Tags; - -import java.util.Map; - -/** - * Service info creator for Config Server services - * - * @author Chris Schaefer - */ -public class ConfigServerServiceInfoCreator extends CloudFoundryServiceInfoCreator { - private static final String CREDENTIALS_ID_KEY = "name"; - private static final String CONFIG_SERVER_SERVICE_TAG_NAME = "configuration"; - - public ConfigServerServiceInfoCreator() { - super(new Tags(CONFIG_SERVER_SERVICE_TAG_NAME)); - } - - @Override - public ConfigServerServiceInfo createServiceInfo(Map serviceData) { - String id = (String) serviceData.get(CREDENTIALS_ID_KEY); - String uri = getUriFromCredentials(getCredentials(serviceData)); - - return new ConfigServerServiceInfo(id, uri); - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java deleted file mode 100644 index d066eea..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreator.java +++ /dev/null @@ -1,191 +0,0 @@ -package org.springframework.cloud.pcf.eureka; - -import com.netflix.discovery.EurekaClientConfig; -import org.springframework.cloud.service.AbstractServiceConnectorCreator; -import org.springframework.cloud.service.ServiceConnectorConfig; - -import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.List; - -/** - * - * Connector creator for Eureka client services - * - * @author Chris Schaefer - */ -public class EurekaClientConfigurationCreator extends AbstractServiceConnectorCreator { - @Override - public EurekaClientConfig create(EurekaServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { - return getEurekaClientConfig(serviceInfo); - } - - protected EurekaClientConfig getEurekaClientConfig(EurekaServiceInfo serviceInfo) { - return new DefaultPcfEurekaClientConfig(serviceInfo.getUri()); - } - - private static final class DefaultPcfEurekaClientConfig implements EurekaClientConfig { - private static final int MINUTES = 60; - private static final String REGION = "default"; - private static final String DEFAULT_ZONE = "defaultZone"; - private static final String EUREKA_API_PREFIX = "/eureka/"; - - private final String uri; - - public DefaultPcfEurekaClientConfig(String uri) { - this.uri = uri + EUREKA_API_PREFIX; - } - - @Override - public int getRegistryFetchIntervalSeconds() { - return 5; - } - - @Override - public int getInstanceInfoReplicationIntervalSeconds() { - return 30; - } - - @Override - public int getInitialInstanceInfoReplicationIntervalSeconds() { - return 40; - } - - @Override - public int getEurekaServiceUrlPollIntervalSeconds() { - return 5 * MINUTES; - } - - @Override - public String getProxyHost() { - return null; - } - - @Override - public String getProxyPort() { - return null; - } - - @Override - public boolean shouldGZipContent() { - return true; - } - - @Override - public int getEurekaServerReadTimeoutSeconds() { - return 8; - } - - @Override - public int getEurekaServerConnectTimeoutSeconds() { - return 5; - } - - @Override - public String getBackupRegistryImpl() { - return null; - } - - @Override - public int getEurekaServerTotalConnections() { - return 200; - } - - @Override - public int getEurekaServerTotalConnectionsPerHost() { - return 50; - } - - @Override - public String getEurekaServerURLContext() { - return null; - } - - @Override - public String getEurekaServerPort() { - return null; - } - - @Override - public String getEurekaServerDNSName() { - return null; - } - - @Override - public boolean shouldUseDnsForFetchingServiceUrls() { - return false; - } - - @Override - public boolean shouldRegisterWithEureka() { - return true; - } - - @Override - public boolean shouldPreferSameZoneEureka() { - return true; - } - - @Override - public boolean shouldLogDeltaDiff() { - return false; - } - - @Override - public boolean shouldDisableDelta() { - return false; - } - - @Nullable - @Override - public String fetchRegistryForRemoteRegions() { - return null; - } - - @Override - public String getRegion() { - return REGION; - } - - @Override - public String[] getAvailabilityZones(String region) { - return new String[] { DEFAULT_ZONE }; - } - - @Override - public List getEurekaServerServiceUrls(String myZone) { - return Arrays.asList(uri); - } - - @Override - public boolean shouldFilterOnlyUpInstances() { - return true; - } - - @Override - public int getEurekaConnectionIdleTimeoutSeconds() { - return 30; - } - - @Override - public boolean shouldFetchRegistry() { - return true; - } - - @Nullable - @Override - public String getRegistryRefreshSingleVipAddress() { - return null; - } - - @Override - public int getHeartbeatExecutorThreadPoolSize() { - return 2; - } - - @Override - public int getCacheRefreshExecutorThreadPoolSize() { - return 2; - } - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java deleted file mode 100644 index 790c8d5..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.springframework.cloud.pcf.eureka; - -import org.springframework.cloud.service.ServiceInfo; -import org.springframework.cloud.service.UriBasedServiceInfo; - -/** - * Information to access Eureka services - * - * @author Chris Schaefer - */ -@ServiceInfo.ServiceLabel("eureka") -public class EurekaServiceInfo extends UriBasedServiceInfo { - public EurekaServiceInfo(String id, String uriString) { - super(id, uriString); - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java deleted file mode 100644 index c9321a6..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreator.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.springframework.cloud.pcf.eureka; - -import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator; -import org.springframework.cloud.cloudfoundry.Tags; - -import java.util.Map; - -/** - * - * Service info creator for Eureka services - * - * @author Chris Schaefer - */ -public class EurekaServiceInfoCreator extends CloudFoundryServiceInfoCreator { - private static final String CREDENTIALS_ID_KEY = "name"; - private static final String EUREKA_SERVICE_TAG_NAME = "eureka"; - - public EurekaServiceInfoCreator() { - super(new Tags(EUREKA_SERVICE_TAG_NAME)); - } - - @Override - public EurekaServiceInfo createServiceInfo(Map serviceData) { - String id = (String) serviceData.get(CREDENTIALS_ID_KEY); - String uri = getUriFromCredentials(getCredentials(serviceData)); - - return new EurekaServiceInfo(id, uri); - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDDataSourceCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDDataSourceCreator.java deleted file mode 100644 index 5116cbb..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDDataSourceCreator.java +++ /dev/null @@ -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 { - - 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); - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDServiceInfo.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDServiceInfo.java deleted file mode 100644 index 02bb1de..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/gemfire/GemfireXDServiceInfo.java +++ /dev/null @@ -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); - } -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopConfigurationCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopConfigurationCreator.java deleted file mode 100644 index 7fe6c30..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopConfigurationCreator.java +++ /dev/null @@ -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 { - - @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; - } - - -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopServiceInfo.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopServiceInfo.java deleted file mode 100644 index 5db42db..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/hadoop/HadoopServiceInfo.java +++ /dev/null @@ -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; - } - -} diff --git a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/phd/PhdServiceInfoCreator.java b/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/phd/PhdServiceInfoCreator.java deleted file mode 100644 index 9672f6d..0000000 --- a/spring-cloud-pcf-connector/src/main/java/org/springframework/cloud/pcf/phd/PhdServiceInfoCreator.java +++ /dev/null @@ -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 { - - public PhdServiceInfoCreator() { - super(new Tags("p-hd")); - } - - @SuppressWarnings("unchecked") - public BaseCompositeServiceInfo createServiceInfo(Map serviceData) { - String id = (String) serviceData.get("name"); - - Map credentials = (Map) 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 credentials) { - Map hdfs = (Map) credentials.get("hdfs"); - Map hdfsConfig = (Map) hdfs.get("configuration"); - String defaultHdfsUri = (String) hdfsConfig.get("fs.defaultFS"); - - Map yarn = (Map) credentials.get("yarn"); - Map yarnConfig = (Map) 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 credentials) { - String key = "hawq"; - - return new PostgresqlServiceInfo(id + "/" + key, extractDataSourceUri(id, key, credentials)); - } - - private RelationalServiceInfo createGemfireXDServiceInfo(String id, Map credentials) { - String key = "gemfirexd"; - - return new GemfireXDServiceInfo(id + "/" + key, extractDataSourceUri(id, key, credentials)); - } - - private String extractDataSourceUri(String id, String key, Map credentials) { - @SuppressWarnings("unchecked") - Map hawq = (Map) credentials.get(key); - - String uri = (String) hawq.get("uri"); - - String jdbcUriPrefix = "jdbc:"; - - if (uri.startsWith(jdbcUriPrefix)) { - uri.substring(jdbcUriPrefix.length()); - } - - return uri; - } -} diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator deleted file mode 100644 index da1e07c..0000000 --- a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.cloud.pcf.phd.PhdServiceInfoCreator -org.springframework.cloud.pcf.eureka.EurekaServiceInfoCreator -org.springframework.cloud.pcf.configserver.ConfigServerServiceInfoCreator diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator b/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator deleted file mode 100644 index 3840a00..0000000 --- a/spring-cloud-pcf-connector/src/main/resources/META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator +++ /dev/null @@ -1,3 +0,0 @@ -org.springframework.cloud.pcf.hadoop.HadoopConfigurationCreator -org.springframework.cloud.pcf.gemfire.GemfireXDDataSourceCreator -org.springframework.cloud.pcf.eureka.EurekaClientConfigurationCreator diff --git a/spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories b/spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 155b64b..0000000 --- a/spring-cloud-pcf-connector/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.context.ApplicationListener=\ -org.springframework.cloud.pcf.configserver.ConfigServerServiceConnector diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/hadoop/HadoopConfigurationCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/hadoop/HadoopConfigurationCreatorTest.java deleted file mode 100644 index 2a78595..0000000 --- a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/hadoop/HadoopConfigurationCreatorTest.java +++ /dev/null @@ -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")); - } -} diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/PhdServiceInfoCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/PhdServiceInfoCreatorTest.java deleted file mode 100644 index 99ed062..0000000 --- a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/PhdServiceInfoCreatorTest.java +++ /dev/null @@ -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 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 extractServiceInfo(List serviceInfos, Class 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; - } -} diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java deleted file mode 100644 index 8ff29d3..0000000 --- a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/configserver/ConfigServerServiceInfoCreatorTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.springframework.cloud.pcf.configserver; - -import org.junit.Test; -import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest; -import org.springframework.cloud.service.ServiceInfo; - -import java.util.List; - -import static org.mockito.Mockito.when; - -/** - * Connector tests for Config Server services - * - * @author Chris Schaefer - */ -public class ConfigServerServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest { - private static final String CONFIG_SERVER_SERVICE_TAG_NAME = "myConfigServerService"; - private static final String VCAP_SERVICES_ENV_KEY = "VCAP_SERVICES"; - private static final String PAYLOAD_FILE_NAME = "test-config-server-info.json"; - private static final String PAYLOAD_TEMPLATE_SERVICE_NAME = "$serviceName"; - private static final String PAYLOAD_TEMPLATE_HOSTNAME = "$hostname"; - private static final String PAYLOAD_TEMPLATE_PORT = "$port"; - private static final String PAYLOAD_TEMPLATE_USER = "$user"; - private static final String PAYLOAD_TEMPLATE_PASS = "$pass"; - - @Test - public void configServerServiceCreationWithTags() { - when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY)) - .thenReturn(getServicesPayload(getConfigServerServicePayload(CONFIG_SERVER_SERVICE_TAG_NAME, - hostname, port, username, password))); - - List serviceInfos = testCloudConnector.getServiceInfos(); - assertServiceFoundOfType(serviceInfos, CONFIG_SERVER_SERVICE_TAG_NAME, ConfigServerServiceInfo.class); - } - - private String getConfigServerServicePayload(String serviceName, String hostname, int port, String user, String password) { - String payload = readTestDataFile(PAYLOAD_FILE_NAME); - payload = payload.replace(PAYLOAD_TEMPLATE_SERVICE_NAME, serviceName); - payload = payload.replace(PAYLOAD_TEMPLATE_HOSTNAME, hostname); - payload = payload.replace(PAYLOAD_TEMPLATE_PORT, Integer.toString(port)); - payload = payload.replace(PAYLOAD_TEMPLATE_USER, user); - payload = payload.replace(PAYLOAD_TEMPLATE_PASS, password); - - return payload; - } -} diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java deleted file mode 100644 index 2e3a4dd..0000000 --- a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaClientConfigurationCreatorTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.springframework.cloud.pcf.eureka; - -import com.netflix.discovery.EurekaClientConfig; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * Test cases around the Eureka client configuration creator - * - * @author Chris Schaefer - */ -public class EurekaClientConfigurationCreatorTest { - private static final String REGION = "default"; - private static final String SERVICE_INFO_ID = "id"; - private static final int REGISTRY_FETCH_INTERVAL_SECS = 5; - private static final String AVAILABLITY_ZONE = "defaultZone"; - private static final String URI = "http://user:pass@192.168.23.4:1234"; - private static final String EUREKA_API_PREFIX = "/eureka/"; - - private EurekaClientConfigurationCreator eurekaClientConfigurationCreator = new EurekaClientConfigurationCreator(); - - @Test - public void testClientConfiguration() { - EurekaServiceInfo eurekaServiceInfo = new EurekaServiceInfo(SERVICE_INFO_ID, URI); - - EurekaClientConfig eurekaClientConfig = eurekaClientConfigurationCreator.create(eurekaServiceInfo, null); - List serviceUrls = eurekaClientConfig.getEurekaServerServiceUrls(null); - - assertEquals(1, serviceUrls.size()); - assertEquals(URI + EUREKA_API_PREFIX, serviceUrls.get(0)); - assertEquals(REGION, eurekaClientConfig.getRegion()); - assertEquals(REGISTRY_FETCH_INTERVAL_SECS, eurekaClientConfig.getRegistryFetchIntervalSeconds()); - - String[] availablityZones = eurekaClientConfig.getAvailabilityZones(null); - - assertEquals(1, availablityZones.length); - assertEquals(AVAILABLITY_ZONE, availablityZones[0]); - } -} diff --git a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java b/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java deleted file mode 100644 index 43ba2ff..0000000 --- a/spring-cloud-pcf-connector/src/test/java/org/springframework/cloud/pcf/eureka/EurekaServiceInfoCreatorTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.springframework.cloud.pcf.eureka; - -import org.junit.Test; -import org.springframework.cloud.cloudfoundry.AbstractCloudFoundryConnectorTest; -import org.springframework.cloud.service.ServiceInfo; - -import java.util.List; - -import static org.mockito.Mockito.when; - -/** - * Connector tests for Eureka services - * - * @author Chris Schaefer - */ -public class EurekaServiceInfoCreatorTest extends AbstractCloudFoundryConnectorTest { - private static final String EUREKA_SERVICE_TAG_NAME = "myEurekaInstance"; - private static final String VCAP_SERVICES_ENV_KEY = "VCAP_SERVICES"; - private static final String PAYLOAD_FILE_NAME = "test-eureka-info.json"; - private static final String PAYLOAD_TEMPLATE_SERVICE_NAME = "$serviceName"; - private static final String PAYLOAD_TEMPLATE_HOSTNAME = "$hostname"; - private static final String PAYLOAD_TEMPLATE_PORT = "$port"; - private static final String PAYLOAD_TEMPLATE_USER = "$user"; - private static final String PAYLOAD_TEMPLATE_PASS = "$pass"; - - @Test - public void eurekaServiceCreationWithTags() { - when(mockEnvironment.getEnvValue(VCAP_SERVICES_ENV_KEY)) - .thenReturn(getServicesPayload(getEurekaServicePayload(EUREKA_SERVICE_TAG_NAME, hostname, port, username, password))); - - List serviceInfos = testCloudConnector.getServiceInfos(); - assertServiceFoundOfType(serviceInfos, EUREKA_SERVICE_TAG_NAME, EurekaServiceInfo.class); - } - - private String getEurekaServicePayload(String serviceName, String hostname, int port, String user, String password) { - String payload = readTestDataFile(PAYLOAD_FILE_NAME); - payload = payload.replace(PAYLOAD_TEMPLATE_SERVICE_NAME, serviceName); - payload = payload.replace(PAYLOAD_TEMPLATE_HOSTNAME, hostname); - payload = payload.replace(PAYLOAD_TEMPLATE_PORT, Integer.toString(port)); - payload = payload.replace(PAYLOAD_TEMPLATE_USER, user); - payload = payload.replace(PAYLOAD_TEMPLATE_PASS, password); - - return payload; - } -} diff --git a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json deleted file mode 100644 index 44dad0d..0000000 --- a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/configserver/test-config-server-info.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name":"$serviceName", - "label":"p-config", - "plan":"standard", - "tags":[ - "configuration" - ], - "credentials":{ - "uri":"http://$username:$password@$hostname:$port/" - } -} diff --git a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json deleted file mode 100644 index 527deb4..0000000 --- a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/eureka/test-eureka-info.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name":"$serviceName", - "label":"p-eureka", - "plan":"standard", - "tags":[ - "eureka" - ], - "credentials":{ - "uri":"http://$username:$password@$hostname:$port/" - } -} diff --git a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/test-phd-info.json b/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/test-phd-info.json deleted file mode 100644 index a922f08..0000000 --- a/spring-cloud-pcf-connector/src/test/resources/org/springframework/cloud/pcf/test-phd-info.json +++ /dev/null @@ -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" - } - } -} \ No newline at end of file From 32e278b284ac85a36687411907a43676341a3bf9 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Tue, 13 Jan 2015 12:59:15 -0600 Subject: [PATCH 14/20] Added detection of Cloud Foundry service type based on uriScheme in credentials key. --- .../CloudFoundryServiceInfoCreator.java | 34 +++- .../CloudFoundryServiceInfoCreatorTest.java | 191 ++++++++++++++++++ 2 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreatorTest.java diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java index 69c9989..ce8a834 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreator.java @@ -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,6 +10,7 @@ import org.springframework.cloud.service.ServiceInfo; /** * @author Ramnivas Laddad + * @author Scott Frederick */ public abstract class CloudFoundryServiceInfoCreator implements ServiceInfoCreator> { @@ -20,7 +23,8 @@ public abstract class CloudFoundryServiceInfoCreator imp } public boolean accept(Map serviceData) { - return tagsMatch(serviceData) || labelStartsWithTag(serviceData) || uriMatchesScheme(serviceData); + return tagsMatch(serviceData) || labelStartsWithTag(serviceData) || + uriMatchesScheme(serviceData) || uriKeyMatchesScheme(serviceData); } @SuppressWarnings("unchecked") @@ -50,13 +54,39 @@ public abstract class CloudFoundryServiceInfoCreator imp return false; } + protected boolean uriKeyMatchesScheme(Map serviceData) { + if (uriSchemes == null) { + return false; + } + + Map 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 getCredentials(Map serviceData) { return (Map) serviceData.get("credentials"); } protected String getUriFromCredentials(Map credentials) { - return getStringFromCredentials(credentials, "uri", "url"); + List keys = new ArrayList(); + 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 credentials, String... keys) { diff --git a/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreatorTest.java b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreatorTest.java new file mode 100644 index 0000000..8d88a9f --- /dev/null +++ b/spring-cloud-cloudfoundry-connector/src/test/java/org/springframework/cloud/cloudfoundry/CloudFoundryServiceInfoCreatorTest.java @@ -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 serviceData = new ServiceDataBuilder().withCredentials(key, value).build(); + + Map credentials = serviceInfoCreator.getCredentials(serviceData); + String uri = serviceInfoCreator.getUriFromCredentials(credentials); + + assertEquals(value, uri); + } + + private void assertAcceptedWithTags(DummyServiceInfoCreator serviceInfoCreator, String... tags) { + Map serviceData = new ServiceDataBuilder().withTags(tags).build(); + assertTrue(serviceInfoCreator.accept(serviceData)); + } + + private void assertNotAcceptedWithTags(DummyServiceInfoCreator serviceInfoCreator, String... tags) { + Map serviceData = new ServiceDataBuilder().withTags(tags).build(); + assertFalse(serviceInfoCreator.accept(serviceData)); + } + + private void assertAcceptedWithLabel(DummyServiceInfoCreator serviceInfoCreator, String label) { + Map serviceData = new ServiceDataBuilder().withLabel(label).build(); + assertTrue(serviceInfoCreator.accept(serviceData)); + } + + private void assertNotAcceptedWithLabel(DummyServiceInfoCreator serviceInfoCreator, String label) { + Map serviceData = new ServiceDataBuilder().withLabel(label).build(); + assertFalse(serviceInfoCreator.accept(serviceData)); + } + + private void assertAcceptedWithCredentials(DummyServiceInfoCreator serviceInfoCreator, String key, String value) { + Map serviceData = new ServiceDataBuilder().withCredentials(key, value).build(); + assertTrue(serviceInfoCreator.accept(serviceData)); + } + + private void assertNotAcceptedWithCredentials(DummyServiceInfoCreator serviceInfoCreator, String key, String value) { + Map 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 credentials = new HashMap(); + + 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 build() { + Map serviceData = new HashMap(); + + serviceData.put("tags", Arrays.asList(tags)); + serviceData.put("label", label); + serviceData.put("credentials", credentials); + + return serviceData; + } + } + + private class DummyServiceInfoCreator extends CloudFoundryServiceInfoCreator { + public DummyServiceInfoCreator(Tags tags) { + super(tags); + } + + public DummyServiceInfoCreator(Tags tags, String... uriSchemes) { + super(tags, uriSchemes); + } + + @Override + public DummyServiceInfo createServiceInfo(Map serviceData) { + return new DummyServiceInfo("test"); + } + } + + private class DummyServiceInfo extends BaseServiceInfo { + public DummyServiceInfo(String id) { + super(id); + } + + @Override + public String getId() { + return null; + } + } +} \ No newline at end of file From 1b51eced7e4ea00a7e0edbba9d4a8b36a3642964 Mon Sep 17 00:00:00 2001 From: Spring Buildmaster Date: Thu, 15 Jan 2015 14:29:56 -0800 Subject: [PATCH 15/20] Release version 1.1.1.RELEASE --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 95ccaf8..777a140 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=1.1.1.BUILD-SNAPSHOT +version=1.1.1.RELEASE group=org.springframework.cloud From db169b10c22f1455396e3987c84ec5b45aaedb04 Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Thu, 15 Jan 2015 18:37:39 -0500 Subject: [PATCH 16/20] Increment version to 1.1.2.BUILD-SNAPSHOT --- gradle.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 777a140..1c405b7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,3 @@ -version=1.1.1.RELEASE +version=1.1.2.BUILD-SNAPSHOT group=org.springframework.cloud + From 4bdaf1180d764232999c87f9bdcaea7b8785cea6 Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Fri, 16 Jan 2015 07:42:15 -0500 Subject: [PATCH 17/20] Update docs to reflect 1.1.1.RELEASE --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7064240..f5964e0 100644 --- a/README.md +++ b/README.md @@ -55,21 +55,21 @@ particular environment. org.springframework.cloud spring-cloud-localconfig-connector - 1.1.0.RELEASE + 1.1.1.RELEASE org.springframework.cloud spring-cloud-cloudfoundry-connector - 1.1.0.RELEASE + 1.1.1.RELEASE org.springframework.cloud spring-cloud-heroku-connector - 1.1.0.RELEASE + 1.1.1.RELEASE ```` @@ -82,28 +82,28 @@ addition to your cloud connectors: org.springframework.cloud spring-cloud-spring-service-connector - 1.1.0.RELEASE + 1.1.1.RELEASE org.springframework.cloud spring-cloud-localconfig-connector - 1.1.0.RELEASE + 1.1.1.RELEASE org.springframework.cloud spring-cloud-cloudfoundry-connector - 1.1.0.RELEASE + 1.1.1.RELEASE org.springframework.cloud spring-cloud-heroku-connector - 1.1.0.RELEASE + 1.1.1.RELEASE ```` @@ -115,4 +115,5 @@ the `` 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. \ No newline at end of file +Then follow the [instructions](spring-cloud-core) on using the Spring Cloud API. + From 96ba6f7c0ce4e7c86af9cb2a8b8f6aaa33e68db4 Mon Sep 17 00:00:00 2001 From: Vinicius Carvalho Date: Thu, 12 Feb 2015 22:25:40 -0500 Subject: [PATCH 18/20] Adding support for ServiceConnectorConfig on generic services --- .../config/java/AbstractCloudConfig.java | 5 ++++ .../java/GenericServiceJavaConfigTest.java | 24 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/config/java/AbstractCloudConfig.java b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/config/java/AbstractCloudConfig.java index 7156a59..8a1e5f3 100644 --- a/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/config/java/AbstractCloudConfig.java +++ b/spring-cloud-spring-service-connector/src/main/java/org/springframework/cloud/config/java/AbstractCloudConfig.java @@ -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 service(String serviceId, Class serviceConnectorType) { return cloud.getServiceConnector(serviceId, serviceConnectorType, null); } + + public T service(String serviceId, Class serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig){ + return cloud.getServiceConnector(serviceId, serviceConnectorType, serviceConnectorConfig); + } } } diff --git a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/GenericServiceJavaConfigTest.java b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/GenericServiceJavaConfigTest.java index f8b2a89..4037304 100644 --- a/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/GenericServiceJavaConfigTest.java +++ b/spring-cloud-spring-service-connector/src/test/java/org/springframework/cloud/config/java/GenericServiceJavaConfigTest.java @@ -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 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); + } } + + From e689f15739065a785645f91d02216af7b4aac471 Mon Sep 17 00:00:00 2001 From: Allan Baril Date: Fri, 20 Feb 2015 14:19:31 -0500 Subject: [PATCH 19/20] @xtreme-allan: Added support for pulling out "http_api_uri" for the CF AMQP connector [Finished #104] --- .../cloudfoundry/AmqpServiceInfoCreator.java | 3 +- .../CloudFoundryConnectorAmqpServiceTest.java | 32 ++++++++++++++++++- .../cloud/cloudfoundry/test-rabbit-info.json | 3 +- .../cloud/service/common/AmqpServiceInfo.java | 19 +++++++++-- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java index e1b868e..2c508b0 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java @@ -21,8 +21,9 @@ public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator 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 serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); + AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0); + assertNull(amqpServiceInfo.getManagementUri()); + } + + @Test public void rabbitServiceCreationWithoutTags() { when(mockEnvironment.getEnvValue("VCAP_SERVICES")) .thenReturn(getServicesPayload( diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json index 16e3428..0edb30e 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json @@ -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" } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index 75acd5e..119c65d 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -18,12 +18,24 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { public static final String AMQP_SCHEME = "amqp"; public static final String AMQPS_SCHEME = "amqps"; - public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost) { + private String managementUri; + + public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost) { + this(id, host, port, username, password, virtualHost, null); + } + + 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 { + 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") @@ -31,6 +43,9 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { return getUriInfo().getPath(); } + @ServiceProperty(category="connection") + public String getManagementUri() { return managementUri; } + @Override protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) { if (uriInfo.getScheme() == null) { From 085f1033fcec28ed7175994a022e1b29d1993dfb Mon Sep 17 00:00:00 2001 From: Allan Baril Date: Mon, 23 Feb 2015 12:15:12 -0500 Subject: [PATCH 20/20] @xtreme-allan: Switched indentation to tabs instead of spaces. --- .../cloudfoundry/AmqpServiceInfoCreator.java | 2 +- .../CloudFoundryConnectorAmqpServiceTest.java | 44 +++++++++---------- .../cloud/cloudfoundry/test-rabbit-info.json | 2 +- .../cloud/service/common/AmqpServiceInfo.java | 30 ++++++------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java index 2c508b0..b1d36a5 100644 --- a/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java +++ b/spring-cloud-cloudfoundry-connector/src/main/java/org/springframework/cloud/cloudfoundry/AmqpServiceInfoCreator.java @@ -21,7 +21,7 @@ public class AmqpServiceInfoCreator extends CloudFoundryServiceInfoCreator serviceInfos = testCloudConnector.getServiceInfos(); - assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); - AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0); - assertEquals(amqpServiceInfo.getManagementUri(), expectedManagementUri); - } + List 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"))); + @Test + public void rabbitServiceCreationWithoutManagementUri() { + when(mockEnvironment.getEnvValue("VCAP_SERVICES")) + .thenReturn(getServicesPayload( + getRabbitServicePayloadNoLabelNoTags("rabbit-1", hostname, port, username, password, "q-1", "vhost1"))); - List serviceInfos = testCloudConnector.getServiceInfos(); - assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); - AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0); - assertNull(amqpServiceInfo.getManagementUri()); - } + List serviceInfos = testCloudConnector.getServiceInfos(); + assertServiceFoundOfType(serviceInfos, "rabbit-1", AmqpServiceInfo.class); + AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) serviceInfos.get(0); + assertNull(amqpServiceInfo.getManagementUri()); + } - @Test + @Test public void rabbitServiceCreationWithoutTags() { when(mockEnvironment.getEnvValue("VCAP_SERVICES")) .thenReturn(getServicesPayload( diff --git a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json index 0edb30e..6e4f299 100644 --- a/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json +++ b/spring-cloud-cloudfoundry-connector/src/test/resources/org/springframework/cloud/cloudfoundry/test-rabbit-info.json @@ -5,6 +5,6 @@ "tags":["amqp","rabbitmq"], "credentials":{ "uri": "amqp://$username:$password@$hostname/$virtualHost", - "http_api_uri": "http://$user:$pass@$hostname/api" + "http_api_uri": "http://$user:$pass@$hostname/api" } } diff --git a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java index 119c65d..81feb83 100644 --- a/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java +++ b/spring-cloud-core/src/main/java/org/springframework/cloud/service/common/AmqpServiceInfo.java @@ -18,24 +18,24 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { public static final String AMQP_SCHEME = "amqp"; public static final String AMQPS_SCHEME = "amqps"; - private String managementUri; + private String managementUri; - public AmqpServiceInfo(String id, String host, int port, String username, String password, String virtualHost) { - this(id, host, port, username, password, virtualHost, null); - } - - 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 host, int port, String username, String password, String virtualHost) { + this(id, host, port, username, password, virtualHost, null); } - public AmqpServiceInfo(String id, String uri) throws CloudException { - this(id, uri, null); - } + 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, String managementUri) throws CloudException { + 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; + this.managementUri = managementUri; } @ServiceProperty(category="connection") @@ -43,8 +43,8 @@ public class AmqpServiceInfo extends UriBasedServiceInfo { return getUriInfo().getPath(); } - @ServiceProperty(category="connection") - public String getManagementUri() { return managementUri; } + @ServiceProperty(category="connection") + public String getManagementUri() { return managementUri; } @Override protected UriInfo validateAndCleanUriInfo(UriInfo uriInfo) {