You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/10/31 03:38:47 UTC
[1/2] git commit: Fixes bug with missing environment variables in
REST tier
Repository: incubator-usergrid
Updated Branches:
refs/heads/es-client-changes [created] 278dfca26
Fixes bug with missing environment variables in REST tier
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0bc8b5d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0bc8b5d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0bc8b5d3
Branch: refs/heads/es-client-changes
Commit: 0bc8b5d30a649f3223c84532be8780f11e48bb47
Parents: 4aab84f
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Oct 30 18:53:20 2014 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 30 18:53:20 2014 -0600
----------------------------------------------------------------------
stack/awscluster/ugcluster-cf.json | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0bc8b5d3/stack/awscluster/ugcluster-cf.json
----------------------------------------------------------------------
diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json
index 0e5570d..17d07f8 100644
--- a/stack/awscluster/ugcluster-cf.json
+++ b/stack/awscluster/ugcluster-cf.json
@@ -856,6 +856,9 @@
"\n",
"export CASSANDRA_REPLICATION_FACTOR=", { "Ref":"CassReplicationFactor" }, "\n",
"\n",
+ "export ES_CLUSTER_NAME=", { "Ref":"ESClusterName" }, "\n",
+ "export ES_NUM_SERVERS=", { "Ref":"ESNumServers" }, "\n",
+ "\n",
"export RELEASE_BUCKET=", { "Ref":"ReleaseBucket" }, "\n",
"\n",
"export SUPER_USER_EMAIL=", { "Ref":"SuperUserEmail" }, "\n",
[2/2] git commit: First pass at refactoring the way the ES client is
used. Embedded startup and discovery not working as expected.
Posted by to...@apache.org.
First pass at refactoring the way the ES client is used. Embedded startup and discovery not working as expected.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/278dfca2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/278dfca2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/278dfca2
Branch: refs/heads/es-client-changes
Commit: 278dfca263e5ad40c3f4c8cc4b0ce31621ce4e53
Parents: 0bc8b5d
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Oct 30 20:38:44 2014 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Oct 30 20:38:44 2014 -0600
----------------------------------------------------------------------
.../usergrid/ConcurrentCoreIteratorITSuite.java | 3 +-
.../org/apache/usergrid/CoreITSetupImpl.java | 4 +-
.../java/org/apache/usergrid/CoreITSuite.java | 5 +-
.../batch/job/AbstractSchedulerRuntimeIT.java | 9 +-
.../persistence/core/test/ITRunner.java | 3 +
.../index/impl/EsEntityIndexImpl.java | 1 -
.../persistence/index/impl/EsProvider.java | 39 ----
.../index/impl/CorePerformanceIT.java | 2 +-
.../index/impl/ElasticSearchResource.java | 160 +++++++++++++++++
.../index/impl/ElasticSearchRule.java | 50 ------
.../impl/EntityConnectionIndexImplTest.java | 5 +-
.../persistence/index/impl/EntityIndexTest.java | 5 +-
.../persistence/index/impl/EsRunner.java | 51 ++++++
.../src/test/resources/usergrid-UNIT.properties | 2 +-
stack/test-utils/pom.xml | 7 +
.../org/apache/usergrid/ElasticSearchMain.java | 107 -----------
.../apache/usergrid/ElasticSearchResource.java | 178 -------------------
17 files changed, 240 insertions(+), 391 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/core/src/test/java/org/apache/usergrid/ConcurrentCoreIteratorITSuite.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/ConcurrentCoreIteratorITSuite.java b/stack/core/src/test/java/org/apache/usergrid/ConcurrentCoreIteratorITSuite.java
index 356e3eb..fec436e 100644
--- a/stack/core/src/test/java/org/apache/usergrid/ConcurrentCoreIteratorITSuite.java
+++ b/stack/core/src/test/java/org/apache/usergrid/ConcurrentCoreIteratorITSuite.java
@@ -23,6 +23,7 @@ import org.junit.runners.Suite;
import org.apache.usergrid.cassandra.CassandraResource;
import org.apache.usergrid.cassandra.Concurrent;
import org.apache.usergrid.cassandra.ConcurrentSuite;
+import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
import org.apache.usergrid.persistence.query.AllInCollectionIT;
import org.apache.usergrid.persistence.query.AllInConnectionIT;
import org.apache.usergrid.persistence.query.AllInConnectionNoTypeIT;
@@ -78,5 +79,5 @@ public class ConcurrentCoreIteratorITSuite {
public static CassandraResource cassandraResource = CassandraResource.newWithAvailablePorts( "coreManager" );
@ClassRule
- public static ElasticSearchResource elasticSearchResource = ElasticSearchResource.instance;
+ public static ElasticSearchResource elasticSearchResource = new ElasticSearchResource().startEs();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
index 1740fbc..fbff413 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@ -28,6 +28,7 @@ import org.apache.usergrid.mq.QueueManagerFactory;
import org.apache.usergrid.persistence.EntityManagerFactory;
import org.apache.usergrid.persistence.IndexBucketLocator;
import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
import org.apache.usergrid.utils.JsonUtils;
@@ -79,7 +80,7 @@ public class CoreITSetupImpl implements CoreITSetup {
*/
protected void before( Description description ) throws Throwable {
LOG.info( "Setting up for {}", description.getDisplayName() );
- elasticSearchResource.before();
+ elasticSearchResource.startEs();
initialize();
}
@@ -98,7 +99,6 @@ public class CoreITSetupImpl implements CoreITSetup {
/** Override to tear down your specific external resource. */
protected void after( Description description ) {
LOG.info( "Tearing down for {}", description.getDisplayName() );
- elasticSearchResource.after();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/core/src/test/java/org/apache/usergrid/CoreITSuite.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSuite.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSuite.java
index 2d19e03..41997ae 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSuite.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSuite.java
@@ -34,6 +34,7 @@ import org.apache.usergrid.persistence.IndexIT;
import org.apache.usergrid.persistence.PathQueryIT;
import org.apache.usergrid.persistence.PermissionsIT;
import org.apache.usergrid.persistence.cassandra.EntityManagerFactoryImplIT;
+import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
import org.apache.usergrid.system.UsergridSystemMonitorIT;
@@ -50,6 +51,8 @@ public class CoreITSuite {
public static CassandraResource cassandraResource = CassandraResource.newWithAvailablePorts( "coreManager" );
@ClassRule
- public static ElasticSearchResource elasticSearchResource = ElasticSearchResource.instance;
+ public static ElasticSearchResource elasticSearchResource = new ElasticSearchResource().startEs();
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/core/src/test/java/org/apache/usergrid/batch/job/AbstractSchedulerRuntimeIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/AbstractSchedulerRuntimeIT.java b/stack/core/src/test/java/org/apache/usergrid/batch/job/AbstractSchedulerRuntimeIT.java
index 822c675..5e7288b 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/AbstractSchedulerRuntimeIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/AbstractSchedulerRuntimeIT.java
@@ -19,12 +19,13 @@ package org.apache.usergrid.batch.job;
import com.google.common.util.concurrent.Service.State;
import java.util.Properties;
-import org.apache.usergrid.ElasticSearchResource;
import org.apache.usergrid.batch.SchedulerITSuite;
import org.apache.usergrid.batch.service.JobSchedulerService;
import org.apache.usergrid.batch.service.SchedulerService;
import org.apache.usergrid.cassandra.CassandraResource;
import org.apache.usergrid.cassandra.SchemaManager;
+import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
+
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -42,7 +43,7 @@ public class AbstractSchedulerRuntimeIT {
protected static final String FAIL_PROP = "usergrid.scheduler.job.maxfail";
public static CassandraResource cassandraResource = SchedulerITSuite.cassandraResource;
- public static ElasticSearchResource elasticSearchResource = ElasticSearchResource.instance;
+ public static ElasticSearchResource elasticSearchResource = new ElasticSearchResource().startEs();
private TestJobListener listener = new TestJobListener();
@@ -57,7 +58,7 @@ public class AbstractSchedulerRuntimeIT {
@BeforeClass
public static void beforeClass() throws Throwable {
- elasticSearchResource.before();
+// elasticSearchResource.before();
SchemaManager sm = cassandraResource.getBean("coreManager", SchemaManager.class);
sm.create();
@@ -66,7 +67,7 @@ public class AbstractSchedulerRuntimeIT {
@AfterClass
public static void afterClass() throws Throwable {
- elasticSearchResource.after();
+// elasticSearchResource.after();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/test/ITRunner.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/test/ITRunner.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/test/ITRunner.java
index eeeaf84..1a800ad 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/test/ITRunner.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/test/ITRunner.java
@@ -43,6 +43,7 @@ public class ITRunner extends BlockJUnit4ClassRunner {// extends JukitoRunner {
//this is fugly, but we have no other way to start cassandra before the jukito runner
static{
CassandraRule rule = new CassandraRule();
+
try {
rule.before();
}
@@ -51,6 +52,8 @@ public class ITRunner extends BlockJUnit4ClassRunner {// extends JukitoRunner {
throwable.printStackTrace();
System.exit( -1 );
}
+
+
}
private Injector injector;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index f8e73c2..739ed77 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -31,7 +31,6 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.client.AdminClient;
-import org.elasticsearch.client.Client;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.FilterBuilder;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/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 eb99e3e..0a06e8f 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
@@ -19,11 +19,8 @@
package org.apache.usergrid.persistence.index.impl;
-import java.io.File;
-import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.util.Properties;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
@@ -33,7 +30,6 @@ import org.elasticsearch.node.NodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.usergrid.persistence.index.IndexFig;
@@ -98,7 +94,6 @@ public class EsProvider {
String allHosts = "";
- if ( "remote".equals( fig.getStartUp() ) ) {
// we will connect to ES on all configured hosts
String SEP = "";
@@ -106,12 +101,6 @@ public class EsProvider {
allHosts = allHosts + SEP + host + ":" + fig.getPort();
SEP = ",";
}
- }
- else {
-
- // we will connect to forked ES on localhost
- allHosts = "localhost:" + System.getProperty( LOCAL_ES_PORT_PROPNAME );
- }
String nodeName = fig.getNodeName();
if ( "default".equals( nodeName ) ) {
@@ -153,33 +142,5 @@ public class EsProvider {
}
- /**
- * Uses a project.properties file that Maven does substitution on to to replace the value of a property with the
- * path to the Maven build directory (a.k.a. target). It then uses this path to generate a random String which it
- * uses to append a path component to so a unique directory is selected. If already present it's deleted, then the
- * directory is created.
- *
- * @return a unique temporary directory
- *
- * @throws IOException if we cannot access the properties file
- */
- public static File getTempDirectory() throws IOException {
- File tmpdir;
- Properties props = new Properties();
- props.load( ClassLoader.getSystemResourceAsStream( "project.properties" ) );
- File basedir = new File( ( String ) props.get( "target.directory" ) );
- String comp = RandomStringUtils.randomAlphanumeric( 7 );
- tmpdir = new File( basedir, comp );
-
- if ( tmpdir.exists() ) {
- log.info( "Deleting directory: {}", tmpdir );
- FileUtils.forceDelete( tmpdir );
- }
- else {
- log.info( "Creating temporary directory: {}", tmpdir );
- FileUtils.forceMkdir( tmpdir );
- }
- return tmpdir;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
index f2aab2a..0d7b0d8 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
@@ -64,7 +64,7 @@ public class CorePerformanceIT extends BaseIT {
private static final Logger log = LoggerFactory.getLogger(CorePerformanceIT.class);
@ClassRule
- public static ElasticSearchRule es = new ElasticSearchRule();
+ public static ElasticSearchResource es = new ElasticSearchResource();
@ClassRule
public static CassandraRule cass = new CassandraRule();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
new file mode 100644
index 0000000..761f1ff
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchResource.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.impl;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.node.Node;
+import org.elasticsearch.node.NodeBuilder;
+import org.safehaus.guicyfig.Env;
+import org.safehaus.guicyfig.EnvironResource;
+import org.safehaus.guicyfig.GuicyFigModule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.RandomStringUtils;
+
+import org.apache.usergrid.persistence.core.util.AvailablePortFinder;
+import org.apache.usergrid.persistence.index.IndexFig;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+
+public class ElasticSearchResource extends EnvironResource {
+
+ private static final Logger log = LoggerFactory.getLogger( ElasticSearchResource.class );
+
+ private static Node node;
+
+
+
+ public ElasticSearchResource() {
+ super( Env.UNIT );
+ }
+
+
+ @Override
+ protected void before() throws Throwable {
+ startEs();
+ }
+
+
+ public synchronized ElasticSearchResource startEs(){
+ if ( node != null ) {
+ return this;
+ }
+
+
+ //override the system properties in the Archiaus env
+ int port = AvailablePortFinder.getNextAvailable( 9300 );
+
+ final String host = "127.0.0.1";
+ System.setProperty( IndexFig.ELASTICSEARCH_HOSTS, host );
+ System.setProperty( IndexFig.ELASTICSEARCH_PORT, port + "" );
+
+ //we have to create this AFTER we set our system properties, or they won't get picked upt
+ Injector injector = Guice.createInjector( new GuicyFigModule( IndexFig.class ) );
+ IndexFig indexFig = injector.getInstance( IndexFig.class );
+
+
+ final String clusterName = indexFig.getClusterName();
+
+ File tempDir;
+ try {
+ tempDir = getTempDirectory();
+ }
+ catch ( Exception ex ) {
+ throw new RuntimeException( "Fatal error unable to create temp dir, start embedded ElasticSearch", ex );
+ }
+
+
+ Settings settings = ImmutableSettings.settingsBuilder()
+ .put("cluster.name", clusterName)
+ .put("network.publish_host", host)
+ .put("transport.tcp.port", port)
+ .put("discovery.zen.ping.multicast.enabled", "false")
+ .put("node.http.enabled", false)
+ .put("path.logs", tempDir.toString())
+ .put("path.data", tempDir.toString())
+ .put("index.store.type", "memory")
+ .put("index.number_of_shards", 1)
+ .put("index.number_of_replicas", 1)
+ .build();
+
+
+ log.info( "-----------------------------------------------------------------------" );
+ log.info( "Starting ElasticSearch embedded server settings: \n" + settings.getAsMap() );
+ log.info( "-----------------------------------------------------------------------" );
+
+
+ node = NodeBuilder.nodeBuilder().settings( settings ).clusterName( indexFig.getClusterName() ).client( false ).data( true ).build().start();
+
+ Runtime.getRuntime().addShutdownHook( new Thread() {
+ @Override
+ public void run() {
+ shutdown();
+ }
+ } );
+
+ return this;
+ }
+
+
+ public static void shutdown() {
+ node.stop();
+ }
+
+
+ /**
+ * Uses a project.properties file that Maven does substitution on to to replace the value of a property with the
+ * path to the Maven build directory (a.k.a. target). It then uses this path to generate a random String which it
+ * uses to append a path component to so a unique directory is selected. If already present it's deleted, then the
+ * directory is created.
+ *
+ * @return a unique temporary directory
+ *
+ * @throws java.io.IOException if we cannot access the properties file
+ */
+ public static File getTempDirectory() throws IOException {
+ File tmpdir;
+ Properties props = new Properties();
+ props.load( ClassLoader.getSystemResourceAsStream( "project.properties" ) );
+ File basedir = new File( ( String ) props.get( "target.directory" ) );
+ String comp = RandomStringUtils.randomAlphanumeric( 7 );
+ tmpdir = new File( basedir, comp );
+
+ if ( tmpdir.exists() ) {
+ log.info( "Deleting directory: {}", tmpdir );
+ FileUtils.forceDelete( tmpdir );
+ }
+ else {
+ log.info( "Creating temporary directory: {}", tmpdir );
+ FileUtils.forceMkdir( tmpdir );
+ }
+
+ return tmpdir;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchRule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchRule.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchRule.java
deleted file mode 100644
index f1d1678..0000000
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/ElasticSearchRule.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-
-package org.apache.usergrid.persistence.index.impl;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.usergrid.persistence.index.IndexFig;
-import org.elasticsearch.client.Client;
-import org.safehaus.guicyfig.Env;
-import org.safehaus.guicyfig.EnvironResource;
-import org.safehaus.guicyfig.GuicyFigModule;
-
-
-public class ElasticSearchRule extends EnvironResource {
-
- private Client client;
-
- public ElasticSearchRule() {
- super( Env.UNIT );
- }
-
- @Override
- protected void before() throws Throwable {
- }
-
- public synchronized Client getClient() {
- if ( client == null ) {
- Injector injector = Guice.createInjector( new GuicyFigModule( IndexFig.class ) );
- IndexFig indexFig = injector.getInstance( IndexFig.class );
- client = new EsProvider(indexFig ).getClient( );
- }
- return client;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
index 31523bc..fada166 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
@@ -34,7 +34,6 @@ import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
import org.apache.usergrid.persistence.collection.util.EntityUtils;
import org.apache.usergrid.persistence.core.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.core.test.ITRunner;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.index.EntityIndex;
@@ -55,14 +54,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-@RunWith( ITRunner.class )
+@RunWith( EsRunner.class )
@UseModules( { TestIndexModule.class } )
public class EntityConnectionIndexImplTest extends BaseIT {
private static final Logger log = LoggerFactory.getLogger( EntityConnectionIndexImplTest.class );
@ClassRule
- public static ElasticSearchRule es = new ElasticSearchRule();
+ public static ElasticSearchResource es = new ElasticSearchResource();
@ClassRule
public static CassandraRule cass = new CassandraRule();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 00e1147..465c518 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -38,7 +38,6 @@ import org.apache.commons.lang3.time.StopWatch;
import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
import org.apache.usergrid.persistence.collection.util.EntityUtils;
import org.apache.usergrid.persistence.core.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.core.test.ITRunner;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.index.EntityIndex;
@@ -64,7 +63,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-@RunWith(ITRunner.class)
+@RunWith(EsRunner.class)
@UseModules({ TestIndexModule.class })
public class EntityIndexTest extends BaseIT {
@@ -74,7 +73,7 @@ public class EntityIndexTest extends BaseIT {
public static CassandraRule cass = new CassandraRule();
@Rule
- public ElasticSearchRule elasticSearchRule = new ElasticSearchRule();
+ public ElasticSearchResource elasticSearchResource = new ElasticSearchResource();
@Inject
@Rule
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
new file mode 100644
index 0000000..c972851
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsRunner.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one
+ * * or more contributor license agreements. See the NOTICE file
+ * * distributed with this work for additional information
+ * * regarding copyright ownership. The ASF licenses this file
+ * * to you under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance
+ * * with the License. You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing,
+ * * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * * KIND, either express or implied. See the License for the
+ * * specific language governing permissions and limitations
+ * * under the License.
+ *
+ */
+
+package org.apache.usergrid.persistence.index.impl;
+
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.junit.runners.model.InitializationError;
+
+import org.apache.usergrid.persistence.core.test.ITRunner;
+
+
+public class EsRunner extends ITRunner {
+
+
+ static {
+ ElasticSearchResource rule = new ElasticSearchResource();
+
+ try {
+ rule.before();
+ }
+ catch ( Throwable throwable ) {
+ throw new RuntimeException( "Unable to start ES", throwable );
+ }
+ }
+
+
+ public EsRunner( final Class<?> klass )
+ throws InitializationError, InvocationTargetException, InstantiationException, IllegalAccessException {
+ super( klass );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/corepersistence/queryindex/src/test/resources/usergrid-UNIT.properties
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/resources/usergrid-UNIT.properties b/stack/corepersistence/queryindex/src/test/resources/usergrid-UNIT.properties
index 79bf1c6..032d5c5 100644
--- a/stack/corepersistence/queryindex/src/test/resources/usergrid-UNIT.properties
+++ b/stack/corepersistence/queryindex/src/test/resources/usergrid-UNIT.properties
@@ -13,7 +13,7 @@ collections.keyspace.strategy.options=replication_factor:1
collections.keyspace.strategy.class=org.apache.cassandra.locator.SimpleStrategy
collection.stage.transient.timeout=6
-elasticsearch.startup=embedded
+elasticsearch.startup=forked
elasticsearch.cluster_name=usergrid
elasticsearch.index_prefix=usergrid
elasticsearch.hosts=127.0.0.1
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/test-utils/pom.xml
----------------------------------------------------------------------
diff --git a/stack/test-utils/pom.xml b/stack/test-utils/pom.xml
index 0e7d7be..f8e618d 100644
--- a/stack/test-utils/pom.xml
+++ b/stack/test-utils/pom.xml
@@ -74,6 +74,13 @@
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>queryindex</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+
<!-- Apache Dependencies -->
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchMain.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchMain.java b/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchMain.java
deleted file mode 100644
index 459acb8..0000000
--- a/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchMain.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.RandomStringUtils;
-import org.elasticsearch.common.settings.ImmutableSettings;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.node.Node;
-import org.elasticsearch.node.NodeBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Simple wrapper for starting "embedded" Tomcat as it's own process, for testing.
- */
-public class ElasticSearchMain {
-
- private static final Logger log = LoggerFactory.getLogger(ElasticSearchMain.class);
-
- public static void main(String[] args) throws Exception {
-
- String clusterName = args[0];
- String port = args[1];
-
- File tempDir;
- try {
- tempDir = getTempDirectory();
- } catch (Exception ex) {
- throw new RuntimeException(
- "Fatal error unable to create temp dir, start embedded ElasticSearch", ex);
- }
-
- Settings settings = ImmutableSettings.settingsBuilder()
- .put("cluster.name", clusterName)
- .put("network.publish_host", "127.0.0.1")
- .put("transport.tcp.port", port)
- .put("discovery.zen.ping.multicast.enabled", "false")
- .put("node.http.enabled", false)
- .put("path.logs", tempDir.toString())
- .put("path.data", tempDir.toString())
- .put("gateway.type", "none")
- .put("index.store.type", "memory")
- .put("index.number_of_shards", 1)
- .put("index.number_of_replicas", 1)
- .build();
-
- log.info("-----------------------------------------------------------------------");
- log.info("Starting forked ElasticSearch server with settings: \n" + settings.getAsMap());
- log.info("-----------------------------------------------------------------------");
-
- Node node = NodeBuilder.nodeBuilder().settings(settings)
- .clusterName(clusterName).node();
-
- while (true) {
- Thread.sleep(1000);
- }
- }
-
- /**
- * Uses a project.properties file that Maven does substitution on to to replace the value of a
- * property with the path to the Maven build directory (a.k.a. target). It then uses this path
- * to generate a random String which it uses to append a path component to so a unique directory
- * is selected. If already present it's deleted, then the directory is created.
- *
- * @return a unique temporary directory
- *
- * @throws IOException if we cannot access the properties file
- */
- public static File getTempDirectory() throws IOException {
- File tmpdir;
- Properties props = new Properties();
- props.load( ClassLoader.getSystemResourceAsStream( "project.properties" ) );
- File basedir = new File( ( String ) props.get( "target.directory" ) );
- String comp = RandomStringUtils.randomAlphanumeric( 7 );
- tmpdir = new File( basedir, comp );
-
- if ( tmpdir.exists() ) {
- log.info( "Deleting directory: {}", tmpdir );
- FileUtils.forceDelete( tmpdir );
- }
- else {
- log.info( "Creating temporary directory: {}", tmpdir );
- FileUtils.forceMkdir( tmpdir );
- }
-
- return tmpdir;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/278dfca2/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchResource.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchResource.java b/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchResource.java
deleted file mode 100644
index 250f5fe..0000000
--- a/stack/test-utils/src/main/java/org/apache/usergrid/ElasticSearchResource.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid;
-
-
-import org.junit.rules.ExternalResource;
-import org.apache.usergrid.cassandra.AvailablePortFinder;
-
-import org.apache.commons.lang.math.RandomUtils;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Map;
-import java.util.Properties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-
-/**
- * Startup ElasticSearch as a forked process (or not).
- */
-public class ElasticSearchResource extends ExternalResource {
- private static final Logger log = LoggerFactory.getLogger(ElasticSearchResource.class);
-
- public static final ElasticSearchResource instance = new ElasticSearchResource();
-
- private static final Object mutex = new Object();
- private int port;
- private boolean started = false;
- private Properties properties;
- private String startupType = "forked";
-
- Process process = null;
-
-
- protected ElasticSearchResource() {
- try {
- String[] locations = { "usergrid-properties-context.xml" };
- ConfigurableApplicationContext appContext =
- new ClassPathXmlApplicationContext( locations );
-
- properties = (Properties)appContext.getBean("properties");
-
- } catch (Exception ex) {
- throw new RuntimeException("Error getting properties", ex);
- }
-
- startupType = properties.getProperty("elasticsearch.startup");
- }
-
-
- @Override
- public void after() {
- log.info("Entering after");
-
- synchronized (mutex) {
-
- if ( process != null ) {
- log.info("----------------------------------------------------------------------");
- log.info("Destroying ElasticSearch running on port " + port);
- log.info("----------------------------------------------------------------------");
- process.destroy();
- started = false;
- }
- }
-
- log.info("Leaving after");
- }
-
-
- @Override
- public void before() throws Throwable {
- log.info("Entering before");
-
- if ( "forked".equals( startupType ) ) {
-
- synchronized (mutex) {
-
- if (started) {
- log.info("NOT starting ElasticSearch because it is already started");
- return;
- }
-
- process = startElasticSearchProcess();
- }
- }
-
- log.info("Leaving before");
- }
-
-
- private Process startElasticSearchProcess() throws IOException {
-
- port = AvailablePortFinder.getNextAvailable(4000 + RandomUtils.nextInt(10));
- System.setProperty( "EMBEDDED_ES_PORT", port+"" );
-
- String javaHome = (String)System.getenv("JAVA_HOME");
-
- String maxMemory = "-Xmx1000m";
-
- ProcessBuilder pb = new ProcessBuilder(javaHome + "/bin/java", maxMemory,
- "org.apache.usergrid.ElasticSearchMain",
- properties.getProperty("elasticsearch.cluster_name"), port + "");
-
- // ensure process gets same classpath we have
- String classpath = System.getProperty("java.class.path");
-// List<String> path = new ArrayList<String>();
-// String parts[] = classpath.split( File.pathSeparator );
-// for ( String part : parts ) {
-// path.add(part);
-// }
-// // plus our special properties directory
-// String newClasspath = StringUtils.join( path, File.pathSeparator );
-
- Map<String, String> env = pb.environment();
- StringBuilder sb = new StringBuilder();
- sb.append( classpath );
- env.put("CLASSPATH", sb.toString());
-
- //pb.directory(new File("."));
- pb.redirectErrorStream(true);
-
- final Process p = pb.start();
-
- //log.debug("Started ElasticSearch process with classpath = " + newClasspath );
-
- // use thread to log ElasticSearch output
- new Thread( new Runnable() {
- @Override
- public void run() {
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line = null;
- try {
- while ((line = br.readLine()) != null) {
- log.info(line);
- }
-
- } catch (Exception ex) {
- log.error("Error reading from ElasticSearch process", ex);
- return;
- }
- }
- }).start();
-
- started = true;
-
- Runtime.getRuntime().addShutdownHook( new Thread() {
- @Override
- public void run() {
- after();
- }
- } );
-
- return p;
- }
-
-
- public int getPort() {
- return port;
- }
-}