Make environment variables override any properties loaded from a file.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/584cf973 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/584cf973 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/584cf973 Branch: refs/heads/master Commit: 584cf973831e9d7a5225b15bfc12eb052db91776 Parents: e6003b0 Author: Michael Russo <[email protected]> Authored: Wed Feb 24 14:43:24 2016 -0800 Committer: Michael Russo <[email protected]> Committed: Wed Feb 24 14:43:24 2016 -0800 ---------------------------------------------------------------------- .../usergrid/corepersistence/GuiceFactory.java | 5 --- .../main/resources/usergrid-core-context.xml | 8 ++--- .../usergrid/persistence/index/IndexFig.java | 5 --- .../persistence/index/impl/EsProvider.java | 35 +++++++------------- .../resources/usergrid-rest-deploy-context.xml | 7 ++++ 5 files changed, 21 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/584cf973/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java index dbab22d..1e7d9df 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java @@ -90,11 +90,6 @@ public class GuiceFactory implements FactoryBean<Injector> { String hostsString = ""; - String pcf_hosts = systemProperties.getProperty("pcf_cassandra_hosts"); - if(pcf_hosts != null && !pcf_hosts.isEmpty()){ - chc.setHosts(pcf_hosts); - } - CassandraHost[] hosts = chc.buildCassandraHosts(); if ( hosts.length == 0 ) { throw new RuntimeException( "Fatal error: no Cassandra hosts configured" ); http://git-wip-us.apache.org/repos/asf/usergrid/blob/584cf973/stack/core/src/main/resources/usergrid-core-context.xml ---------------------------------------------------------------------- diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml index cb0d243..4b216e3 100644 --- a/stack/core/src/main/resources/usergrid-core-context.xml +++ b/stack/core/src/main/resources/usergrid-core-context.xml @@ -35,12 +35,11 @@ <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties" ref="properties" /> - <property name="systemPropertiesModeName"> + <property name="systemPropertiesModeName"> <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value> </property> </bean> - <!-- The Time Resolution used for the cluster --> <bean id="microsecondsTimeResolution" class="me.prettyprint.cassandra.service.clock.MicrosecondsClockResolution" /> <bean id="traceTagManager" class="org.apache.usergrid.persistence.cassandra.util.TraceTagManager"/> @@ -51,10 +50,7 @@ </bean> <bean id="cassandraHostConfigurator" class="me.prettyprint.cassandra.service.CassandraHostConfigurator"> - <constructor-arg value="#{(systemProperties['pcf_cassandra_hosts'] == '' - || systemProperties['pcf_cassandra_hosts'] == null ) ? - '${cassandra.url}' : systemProperties['pcf_cassandra_hosts'] }" /> - + <constructor-arg value="${cassandra.url}"/> <!-- set the pool size if it's available. If not go with 50 --> <property name="maxActive" value="${cassandra.connections:15}"/> <property name="cassandraThriftSocketTimeout" value="${cassandra.thriftSocketTimeout:5000}" /> http://git-wip-us.apache.org/repos/asf/usergrid/blob/584cf973/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java index eb098d3..df5f38f 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java @@ -32,8 +32,6 @@ public interface IndexFig extends GuicyFig { String ELASTICSEARCH_HOSTS = "elasticsearch.hosts"; - String PFC_ELASTICSEARCH_HOSTS = "pcf_elasticsearch_hosts"; - String ELASTICSEARCH_PORT = "elasticsearch.port"; String ELASTICSEARCH_CLUSTER_NAME = "elasticsearch.cluster_name"; @@ -74,9 +72,6 @@ public interface IndexFig extends GuicyFig { @Key( ELASTICSEARCH_HOSTS ) String getHosts(); - @Default( VALIDATION_DEFAULT_VALUE ) - @Key( PFC_ELASTICSEARCH_HOSTS ) - String getPfcHosts(); /** * The port used when connecting to Elasticsearch. http://git-wip-us.apache.org/repos/asf/usergrid/blob/584cf973/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java index 5fddfe9..e81aa0f 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java @@ -124,7 +124,7 @@ public class EsProvider { final int port = indexFig.getPort(); ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put( "cluster.name", clusterName ) - .put( "client.transport.sniff", true ); + .put( "client.transport.sniff", true ); String nodeName = indexFig.getNodeName(); @@ -144,13 +144,8 @@ public class EsProvider { TransportClient transportClient = new TransportClient( settings.build() ); - String finalHosts = indexFig.getPfcHosts(); - if( finalHosts == null || finalHosts.isEmpty() || finalHosts.equalsIgnoreCase(IndexFig.VALIDATION_DEFAULT_VALUE)){ - finalHosts = indexFig.getHosts(); - } - logger.info("Elasticsearch hosts used: {}", finalHosts); // we will connect to ES on all configured hosts - for ( String host : finalHosts.split( "," ) ) { + for ( String host : indexFig.getHosts().split( "," ) ) { transportClient.addTransportAddress( new InetSocketTransportAddress( host, port ) ); } @@ -176,13 +171,7 @@ public class EsProvider { */ final StringBuffer hosts = new StringBuffer(); - String finalHosts = indexFig.getPfcHosts(); - if( finalHosts == null || finalHosts.isEmpty() || finalHosts.equalsIgnoreCase(IndexFig.VALIDATION_DEFAULT_VALUE)){ - finalHosts = indexFig.getHosts(); - } - - logger.info("Elasticsearch hosts used: {}", finalHosts); - for ( String host : finalHosts.split( "," ) ) { + for ( String host : indexFig.getHosts().split( "," ) ) { hosts.append( host ).append( ":" ).append( port ).append( "," ); } @@ -194,18 +183,18 @@ public class EsProvider { Settings settings = ImmutableSettings.settingsBuilder() - .put( "cluster.name", clusterName ) + .put( "cluster.name", clusterName ) - // this assumes that we're using zen for host discovery. Putting an - // explicit set of bootstrap hosts ensures we connect to a valid cluster. - .put( "discovery.zen.ping.unicast.hosts", hostString ) - .put( "discovery.zen.ping.multicast.enabled", "false" ).put( "http.enabled", false ) + // this assumes that we're using zen for host discovery. Putting an + // explicit set of bootstrap hosts ensures we connect to a valid cluster. + .put( "discovery.zen.ping.unicast.hosts", hostString ) + .put( "discovery.zen.ping.multicast.enabled", "false" ).put( "http.enabled", false ) - .put( "client.transport.ping_timeout", 2000 ) // milliseconds - .put( "client.transport.nodes_sampler_interval", 100 ).put( "network.tcp.blocking", true ) - .put( "node.client", true ).put( "node.name", nodeName ) + .put( "client.transport.ping_timeout", 2000 ) // milliseconds + .put( "client.transport.nodes_sampler_interval", 100 ).put( "network.tcp.blocking", true ) + .put( "node.client", true ).put( "node.name", nodeName ) - .build(); + .build(); if (logger.isTraceEnabled()) { logger.trace("Creating ElasticSearch client with settings: {}", settings.getAsMap()); http://git-wip-us.apache.org/repos/asf/usergrid/blob/584cf973/stack/rest/src/main/resources/usergrid-rest-deploy-context.xml ---------------------------------------------------------------------- diff --git a/stack/rest/src/main/resources/usergrid-rest-deploy-context.xml b/stack/rest/src/main/resources/usergrid-rest-deploy-context.xml index 4438bbd..50983b7 100644 --- a/stack/rest/src/main/resources/usergrid-rest-deploy-context.xml +++ b/stack/rest/src/main/resources/usergrid-rest-deploy-context.xml @@ -28,6 +28,8 @@ <bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> + <property name="properties" ref="sysProps"/> + <property name="localOverride" value="true"/> <property name="singleton" value="true" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> @@ -38,4 +40,9 @@ </property> </bean> + <bean id="sysProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> + <property name="targetClass"><value>java.lang.System</value></property> + <property name="targetMethod"><value>getProperties</value></property> + </bean> + </beans>
