From eb20781dc0d9be42556476b7a8fd73444e2d5b5a Mon Sep 17 00:00:00 2001 From: Dave Johnson Date: Tue, 29 Jul 2014 09:59:59 -0400 Subject: [PATCH 1/2] Bug fixes and cleanups in awscluster scripts, mostly around ElasticSearch installation and configuration. --- .../dist/init_instance/create_keyspaces.sh | 5 +- .../main/dist/init_instance/init_db_server.sh | 6 +- .../init_instance/init_graphite_server.sh | 9 +- .../dist/init_instance/init_rest_server.sh | 8 +- .../init_instance/install_elasticsearch.sh | 14 +- .../dist/init_instance/install_yourkit.sh | 28 +- .../src/main/groovy/NodeRegistry.groovy | 20 +- .../groovy/configure_elasticsearch.groovy | 12 +- .../src/main/groovy/configure_usergrid.groovy | 17 +- .../src/main/groovy/registry_register.groovy | 3 +- .../src/main/groovy/wait_for_instances.groovy | 11 +- stack/awscluster/ugcluster-cf.json | 1028 ++++++++++++----- .../resources/corepersistence-UNIT.properties | 17 - .../test/resources/usergrid-CHOP.properties | 17 - 14 files changed, 816 insertions(+), 379 deletions(-) delete mode 100644 stack/core/src/test/resources/corepersistence-UNIT.properties delete mode 100644 stack/core/src/test/resources/usergrid-CHOP.properties diff --git a/stack/awscluster/src/main/dist/init_instance/create_keyspaces.sh b/stack/awscluster/src/main/dist/init_instance/create_keyspaces.sh index 9aa1fe7f29..811fce23c4 100644 --- a/stack/awscluster/src/main/dist/init_instance/create_keyspaces.sh +++ b/stack/awscluster/src/main/dist/init_instance/create_keyspaces.sh @@ -21,9 +21,8 @@ pushd /etc/apt/sources.list.d - -#Run the cassandra cql to create the keyspaces. Note this only works for the us-east region for the replication factor -#on the keyspaces +# Run the cassandra cql to create the keyspaces. Note this only works for +# the us-east region for the replication factor on the keyspaces cd /usr/share/usergrid/scripts FIRSTHOST="$(groovy get_first_instance.groovy cassandra)" diff --git a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh index 197dd5713b..b9c4f56714 100644 --- a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh +++ b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh @@ -49,9 +49,6 @@ cp /usr/share/aws-java-sdk-*/lib/* /home/ubuntu/.groovy/lib rm /home/ubuntu/.groovy/lib/stax* ln -s /home/ubuntu/.groovy /root/.groovy -cd /usr/share/usergrid/scripts -groovy tag_instance.groovy - cd /usr/share/usergrid/init_instance ./install_oraclejdk.sh @@ -70,3 +67,6 @@ cd /usr/share/usergrid/init_instance cd /usr/share/usergrid/init_instance ./create_keyspaces.sh +# tag last so we can see in the console that the script ran to completion +cd /usr/share/usergrid/scripts +groovy tag_instance.groovy diff --git a/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh b/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh index 91b1601e4a..a9d74c01de 100644 --- a/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh +++ b/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh @@ -49,15 +49,12 @@ cp /usr/share/aws-java-sdk-*/lib/* /home/ubuntu/.groovy/lib rm /home/ubuntu/.groovy/lib/stax* ln -s /home/ubuntu/.groovy /root/.groovy -cd /usr/share/usergrid/scripts -groovy tag_instance.groovy - cd /usr/share/usergrid/init_instance ./install_oraclejdk.sh - cd /usr/share/usergrid/scripts groovy registry_register.groovy graphite - - +# tag last so we can see in the console that the script ran to completion +cd /usr/share/usergrid/scripts +groovy tag_instance.groovy diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh index 6ace352c86..11ce5976f7 100644 --- a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh +++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh @@ -28,6 +28,7 @@ dpkg-reconfigure -f noninteractive tzdata PKGS="openjdk-7-jdk tomcat7 s3cmd ntp unzip groovy" apt-get update apt-get -y --force-yes install ${PKGS} +/etc/init.d/tomcat7 stop # Install AWS Java SDK and get it into the Groovy classpath curl http://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip > /tmp/aws-sdk-java.zip @@ -67,11 +68,12 @@ rm -rf /var/lib/tomcat7/webapps/* cp -r /usr/share/usergrid/webapps/* /var/lib/tomcat7/webapps groovy configure_portal_new.groovy >> /var/lib/tomcat7/webapps/portal/config.js - - - cd /usr/share/usergrid/init_instance ./install_yourkit.sh # Go /etc/init.d/tomcat7 start + +# tag last so we can see in the console that the script ran to completion +cd /usr/share/usergrid/scripts +groovy tag_instance.groovy diff --git a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh index 460588c1fb..f7b5f3c378 100644 --- a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh +++ b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh @@ -21,8 +21,6 @@ pushd /etc/apt/sources.list.d -groovy ./registry_register.groovy elasticsearch - # Install and stop ElasticSearch cat >> elasticsearch.sources.list << EOF deb http://packages.elasticsearch.org/elasticsearch/1.2/debian stable main @@ -38,16 +36,20 @@ mkdir -p /mnt/log/elasticsearch chown elasticsearch /mnt/log/elasticsearch # Configure ElasticSearch +cd /usr/share/usergrid/scripts + +# No need to do this, elasticsearch nodes are also cassandra nodes +#groovy registry_register.groovy elasticsearch +#groovy wait_for_instances.groovy elasticsearch ${CASSANDRA_NUM_SERVERS} + cat >> /etc/default/elasticsearch << EOF JAVA_HOME=/usr/lib/jvm/jdk1.7.0 EOF -update-rc.d elasticsearch defaults 95 10 -cd /usr/share/usergrid/scripts - - groovy ./configure_elasticsearch.groovy > /etc/elasticsearch/elasticsearch.yml +update-rc.d elasticsearch defaults 95 10 + # Go! /etc/init.d/elasticsearch start diff --git a/stack/awscluster/src/main/dist/init_instance/install_yourkit.sh b/stack/awscluster/src/main/dist/init_instance/install_yourkit.sh index 37936cd66e..b1e29a3cd6 100644 --- a/stack/awscluster/src/main/dist/init_instance/install_yourkit.sh +++ b/stack/awscluster/src/main/dist/init_instance/install_yourkit.sh @@ -1,9 +1,27 @@ +#!/bin/bash + +# +# 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. +# + -##### # Optional, install yourkit remote profiler -##### -if [ $YOURKIT = "true" ]; then +if [[ $YOURKIT = "true" ]]; then mkdir -p /tmp/yourkit cd /tmp/yourkit @@ -19,7 +37,3 @@ JAVA_OPTS="${JAVA_OPTS} -agentpath:/tmp/yourkit/yjp-2013-build-13088/bin/linux-x EOF fi - -###### -# End yourkit installation -###### diff --git a/stack/awscluster/src/main/groovy/NodeRegistry.groovy b/stack/awscluster/src/main/groovy/NodeRegistry.groovy index 38c44be145..2f955ba9c5 100644 --- a/stack/awscluster/src/main/groovy/NodeRegistry.groovy +++ b/stack/awscluster/src/main/groovy/NodeRegistry.groovy @@ -74,16 +74,24 @@ class NodeRegistry { * Add the node to the database if it doesn't exist */ def addNode(def nodeType) { + def gar = new GetAttributesRequest(domain, hostName); def response = sdbClient.getAttributes(gar); - if (response.getAttributes().size() == 1) { - println "Already registered" + + if (response.getAttributes().size() > 0) { def attrs = response.getAttributes() for (att in attrs) { - println("${hostName} -> ${att.getName()} : ${att.getValue()}") } + } - return false; + if (response.getAttributes().size() > 1) { + def attrs = response.getAttributes() + for (att in attrs) { + if ( att.getValue().equals(nodeType)) { + println "Already registered" + return false; + } + } } else { println "Registering..." @@ -92,11 +100,9 @@ class NodeRegistry { attrs.add(stackAtt) def par = new PutAttributesRequest(domain, hostName, attrs) sdbClient.putAttributes(par); - println "Registraition done." + println "Registration done." return true; } - - } def deleteRegistry(){ diff --git a/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy b/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy index 79dfa53b0d..ce8e3c580a 100644 --- a/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy +++ b/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy @@ -24,27 +24,29 @@ // Emits Cassandra config file based on environment and Cassandra node // registry in SimpleDB // + import com.amazonaws.auth.* import com.amazonaws.services.simpledb.* import com.amazonaws.services.simpledb.model.* String hostName = (String)System.getenv().get("PUBLIC_HOSTNAME") - +def clusterName = (String)System.getenv().get("CASSANDRA_CLUSTER_NAME") NodeRegistry registry = new NodeRegistry(); // build seed list by listing all Cassandra nodes found in SimpleDB domain with our stackName -def selectResult = registry.searchNode('elasticsearch') -def seeds = "" +// works because cassandra nodes are also elasticsearch nodes +def selectResult = registry.searchNode('cassandra') +def esnodes = "" def sep = "" for (hostname in selectResult) { - seeds = "${seeds}${sep}\"${hostname}\"" + esnodes = "${esnodes}${sep}\"${hostname}\"" sep = "," } def elasticSearchConfig = """ cluster.name: ${clusterName} -discovery.zen.ping.multicast.enabled: true +discovery.zen.ping.multicast.enabled: false discovery.zen.ping.unicast.hosts: [${esnodes}] node: name: ${hostName} diff --git a/stack/awscluster/src/main/groovy/configure_usergrid.groovy b/stack/awscluster/src/main/groovy/configure_usergrid.groovy index 124a323681..f85b2cbd46 100644 --- a/stack/awscluster/src/main/groovy/configure_usergrid.groovy +++ b/stack/awscluster/src/main/groovy/configure_usergrid.groovy @@ -51,34 +51,31 @@ def sep = "" for (item in selectResult) { cassandras = "${cassandras}${sep}${item}:9160" sep = "," - } -//TODO T.N Make this the graphite url +// TODO T.N Make this the graphite url selectResult = registry.searchNode('graphite') def graphite = "" sep = "" for (item in selectResult) { graphite = "${graphite}${sep}${item}" sep = "," - } +// cassandra nodes are also our elasticsearch nodes +selectResult = registry.searchNode('cassandra') def esnodes = "" sep = "" -for (item in selectResult.getItems()) { - def att = item.getAttributes().get(0) - if (att.getValue().equals(stackName)) { - esnodes = "${esnodes}${sep}${item.getName()}" - sep = "," - } +for (item in selectResult) { + esnodes = "${esnodes}${sep}${item}" + sep = "," } def usergridConfig = """ ###################################################### # Minimal Usergrid configuration properties for local Tomcat and Cassandra -cassandra.url=${seeds} +cassandra.url=${cassandras} cassandra.cluster=${clusterName} cassandra.keyspace.strategy=org.apache.cassandra.locator.SimpleStrategy cassandra.keyspace.replication=${replFactor} diff --git a/stack/awscluster/src/main/groovy/registry_register.groovy b/stack/awscluster/src/main/groovy/registry_register.groovy index a5282c38b8..144b18b44f 100644 --- a/stack/awscluster/src/main/groovy/registry_register.groovy +++ b/stack/awscluster/src/main/groovy/registry_register.groovy @@ -28,8 +28,7 @@ import com.amazonaws.services.simpledb.model.* if (args.size() != 1 ) { - println "this script expects one argument. registry_register.groovy nodetype" - // You can even print the usage here. + println "This script expects one argument. registry_register.groovy nodetype" return 1; } diff --git a/stack/awscluster/src/main/groovy/wait_for_instances.groovy b/stack/awscluster/src/main/groovy/wait_for_instances.groovy index 98ddc3b04a..9aec033377 100644 --- a/stack/awscluster/src/main/groovy/wait_for_instances.groovy +++ b/stack/awscluster/src/main/groovy/wait_for_instances.groovy @@ -16,18 +16,16 @@ * directory of this distribution. */ - // // wait_for_instances.groovy // // Wait for enough Cassandra servers are up before proceding, // Enough means count greater than or equal to replication factor. -// + import com.amazonaws.auth.* import com.amazonaws.services.simpledb.* import com.amazonaws.services.simpledb.model.* - if (args.size() !=2 ) { println "this script expects two arguments. wait_for_instances.groovy nodetype numberOfServers" // You can even print the usage here. @@ -37,7 +35,6 @@ if (args.size() !=2 ) { String nodetype = args[0] int numberOfServers = args[1].toInteger() - NodeRegistry registry = new NodeRegistry(); println "Waiting for ${numberOfServers} nodes of type ${nodetype} to register..." @@ -46,20 +43,16 @@ def count = 0 while (true) { try { - - - def selectResult = registry.searchNode(nodetype) - count = selectResult.size(); if (count >= numberOfServers) { println("count = ${count}, total number of servers is ${numberOfServers}. Breaking") break } - println("Found ${count} nodes but need at least ${numberOfServers}. Waiting...") + } catch (Exception e) { println "ERROR waiting for Casasndra ${e.getMessage()}, will continue waiting" } diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json index 66f326b4be..dcd32217fc 100644 --- a/stack/awscluster/ugcluster-cf.json +++ b/stack/awscluster/ugcluster-cf.json @@ -20,7 +20,7 @@ "RestMinServers": { "Description": "Minimum number of REST servers.", "Type": "Number", - "Default": "3", + "Default": "1", "MinValue": "1" }, "RestMaxServers": { @@ -32,8 +32,16 @@ "RestInstanceType": { "Description": "Instance type for REST servers", "Type": "String", - "Default": "m1.large", - "AllowedValues": ["m1.small", "m1.medium", "m1.large", "m1.xlarge", "m3.xlarge", "m3.large", "c3.4xlarge"], + "Default": "m3.large", + "AllowedValues": [ + "m1.small", + "m1.medium", + "m1.large", + "m1.xlarge", + "m3.xlarge", + "m3.large", + "c3.4xlarge" + ], "ConstraintDescription": "must be valid instance type." }, "KeyPair": { @@ -55,8 +63,16 @@ "CassInstanceType": { "Description": "Instance type for Cass servers", "Type": "String", - "Default": "m1.xlarge", - "AllowedValues": ["m1.small", "m1.medium", "m1.large", "m1.xlarge", "m3.xlarge", "m3.2xlarge", "c3.4xlarge"], + "Default": "c3.4xlarge", + "AllowedValues": [ + "m1.small", + "m1.medium", + "m1.large", + "m1.xlarge", + "m3.xlarge", + "m3.2xlarge", + "c3.4xlarge" + ], "ConstraintDescription": "must be valid instance type." }, "CassReplicationFactor": { @@ -79,145 +95,417 @@ "Description": "Email for notifications", "Type": "String", "Default": "dmjohnson+super@apigee.com" + }, + "GraphiteInstanceType": { + "Description": "Instance type for Graphite server", + "Type": "String", + "Default": "m3.large", + "AllowedValues": [ + "t1.micro", + "m1.small", + "m1.medium", + "m1.large", + "m3.large", + "m1.xlarge", + "m3.xlarge", + "m3.2xlarge", + "c3.4xlarge" + ], + "ConstraintDescription": "must be valid instance type." + }, + "GraphiteNumServers": { + "Description": "Minimum number of graphite servers. There should only be one", + "Type": "Number", + "Default": "1", + "MinValue": "1" + }, + "InstallYourkit": { + "Description": "Install the yourkit remote profiling agent into tomcat. Valid values are 'true' or 'false'", + "Type": "String", + "Default": "false" } }, "Mappings": { "AWSInstanceType2Arch": { - "m1.small": {"Arch": "64"}, - "m1.medium": {"Arch": "64"}, - "m1.large": {"Arch": "64"}, - "m1.xlarge": {"Arch": "64"}, - "m3.large": {"Arch": "64"}, - "c3.4xlarge": {"Arch": "64"} + "t1.micro": { + "Arch": "64" + }, + "m1.small": { + "Arch": "64" + }, + "m1.medium": { + "Arch": "64" + }, + "m1.large": { + "Arch": "64" + }, + "m1.xlarge": { + "Arch": "64" + }, + "m3.large": { + "Arch": "64" + }, + "m3.xlarge": { + "Arch": "64" + }, + "c3.2xlarge": { + "Arch": "64" + }, + "c3.4xlarge": { + "Arch": "64" + } }, "AWSRegionArch2AMI": { - "ap-southeast-2": {"64": "ami-5993f663"}, - "us-east-1": {"64": "ami-7cbd4f14"}, - "us-west-2": {"64": "ami-2598ea15"} + "ap-southeast-2": { + "64": "ami-5993f663" + }, + "us-east-1": { + "64": "ami-7cbd4f14" + }, + "us-west-2": { + "64": "ami-2598ea15" + } }, "TwoAZs": { - "ap-southeast-2": {"AZ1": "ap-southeast-2a", "AZ2": "ap-southeast-2b"}, - "us-east-1": {"AZ1": "us-east-1b", "AZ2": "us-east-1c"}, - "us-west-2": {"AZ1": "us-west-2a", "AZ2": "us-west-2b"} + "ap-southeast-2": { + "AZ1": "ap-southeast-2a", + "AZ2": "ap-southeast-2b" + }, + "us-east-1": { + "AZ1": "us-east-1b", + "AZ2": "us-east-1c" + }, + "us-west-2": { + "AZ1": "us-west-2a", + "AZ2": "us-west-2b" + } } }, "Resources": { - "RestUser": { + "GraphiteUser": { "Type": "AWS::IAM::User", "Properties": { "Path": "/", - "Policies": [{ + "Policies": [ + { "PolicyName": "root", - "PolicyDocument": {"Statement": [{ + "PolicyDocument": { + "Statement": [ + { "Effect": "Allow", "Action": "*", "Resource": "*" - }]} - }] + + } + ] + } + } + ] + } + }, + "GraphiteKey": { + "Type": "AWS::IAM::AccessKey", + "Properties": { + "UserName": { + "Ref": "GraphiteUser" + } + } + }, + "GraphiteAutoScalingLaunchConfiguration":{ + "Type":"AWS::AutoScaling::LaunchConfiguration", + "Properties":{ + "UserData":{ + "Fn::Base64":{ + "Fn::Join":[ + "", + [ + "#!/bin/bash -x\n", + "sudo git clone https://github.com/hopsoft/docker-graphite-statsd.git \n", + "sudo ./docker-graphite-statsd/bin/start \n", + "sudo git clone https://github.com/dotcloud/collectd-graphite.git \n", + "sudo collectd-graphite/docker build -t collectd-graphite . \n", + + "#!/bin/bash -ex\n", + "# REST SERVER STARTUP \n", + "exec >/var/log/usergrid-bootstrap.log 2>&1\n", + "\n", + "mkdir -p /usr/share/usergrid\n", + "\n", + "# create script that sets our environment variables\n", + "cat >/etc/profile.d/usergrid-env.sh </etc/profile.d/aws-credentials.sh </etc/s3cfg </var/log/usergrid-bootstrap.log 2>&1\n", - "\n", - "mkdir -p /usr/share/usergrid\n", - "\n", - - "# create script that sets our environment variables\n", - "cat >/etc/profile.d/usergrid-env.sh </etc/profile.d/aws-credentials.sh </etc/s3cfg </var/log/usergrid-bootstrap.log 2>&1\n", + "\n", + "mkdir -p /usr/share/usergrid\n", + "\n", + "# create script that sets our environment variables\n", + "cat >/etc/profile.d/usergrid-env.sh </etc/profile.d/aws-credentials.sh </etc/awscredential.properties </etc/s3cfg </var/log/usergrid-bootstrap.log 2>&1\n", - - "\n", - "mkdir -p /usr/share/usergrid\n", - "\n", - - "# create script that sets our environment variables\n", - "cat >/etc/profile.d/usergrid-env.sh </etc/profile.d/aws-credentials.sh </etc/s3cfg </var/log/usergrid-bootstrap.log 2>&1\n", + "\n", + "mkdir -p /usr/share/usergrid\n", + "\n", + "# create script that sets our environment variables\n", + "cat >/etc/profile.d/usergrid-env.sh </etc/profile.d/aws-credentials.sh </etc/s3cfg < Date: Tue, 29 Jul 2014 10:04:01 -0400 Subject: [PATCH 2/2] Fixes to allow Tomcat, Cassanrda and ElasticSearch to work properly in REST tests. --- .../test/resources/usergrid-test.properties | 3 +++ .../usergrid/corepersistence/CpSetup.java | 7 ++++++ .../persistence/index/impl/EsProvider.java | 23 +++++++++++++++---- stack/pom.xml | 8 +++---- .../apache/usergrid/rest/TomcatResource.java | 15 +++++------- .../collection/activities/AndOrQueryTest.java | 12 ++++++++++ .../rest/src/test/resources/log4j.properties | 11 +++++---- .../cassandra/ManagementServiceImpl.java | 2 +- .../java/org/apache/usergrid/TomcatMain.java | 1 + 9 files changed, 58 insertions(+), 24 deletions(-) diff --git a/stack/config/src/test/resources/usergrid-test.properties b/stack/config/src/test/resources/usergrid-test.properties index b820e5cb0f..8388e52926 100644 --- a/stack/config/src/test/resources/usergrid-test.properties +++ b/stack/config/src/test/resources/usergrid-test.properties @@ -44,6 +44,9 @@ cassandra.writecl=QUORUM #Keyspace to use for locking cassandra.lock.keyspace=Locks +elasticsearch.embedded=true +elasticsearch.cluster_name=test_cluster + #Properties to control the number of buckets in the index. usergrid.index.defaultbucketsize=20 usergrid.counter.skipAggregate=false diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java index f3cc87c836..a940e0a5ae 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java @@ -120,6 +120,13 @@ public void init() throws Exception { cpProps.put("cassandra.port", hosts[0].getPort()); cpProps.put("cassandra.cluster_name", cass.getProperties().get("cassandra.cluster")); + String cassRemoteString = (String)cass.getProperties().get("cassandra.use_remote"); + if ( cassRemoteString != null && cassRemoteString.equals("false")) { + cpProps.put("cassandra.embedded", "true"); + } else { + cpProps.put("cassandra.embedded", "false"); + } + cpProps.put("collections.keyspace.strategy.class", cass.getProperties().get("cassandra.keyspace.strategy")); 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 678aae2f01..58446e4ee0 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 @@ -79,10 +79,17 @@ public static synchronized Client getClient(IndexFig fig) { } Settings settings = ImmutableSettings.settingsBuilder() - .put("node.http.enabled", true) + + .put("cluster.name", fig.getClusterName()) + + .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) @@ -90,7 +97,7 @@ public static synchronized Client getClient(IndexFig fig) { .build(); log.info("-----------------------------------------------------------------------"); - log.info("Starting ElasticSearch embedded with settings: \n" + settings.getAsMap() ); + log.info("Starting ElasticSearch embedded server with settings: \n" + settings.getAsMap() ); log.info("-----------------------------------------------------------------------"); Node node = NodeBuilder.nodeBuilder().settings(settings) @@ -109,17 +116,23 @@ public static synchronized Client getClient(IndexFig fig) { } Settings settings = ImmutableSettings.settingsBuilder() - .put("client.transport.ping_timeout", 2000) // milliseconds - .put("client.transport.nodes_sampler_interval", 100) + .put("cluster.name", fig.getClusterName()) - .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", allHosts) + .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) + .build(); + log.info("-----------------------------------------------------------------------"); log.info("Creating ElasticSearch client with settings: " + settings.getAsMap()); + log.info("-----------------------------------------------------------------------"); Node node = NodeBuilder.nodeBuilder().settings(settings) .client(true).node(); diff --git a/stack/pom.xml b/stack/pom.xml index 4e4eee2b9b..4c03904bed 100644 --- a/stack/pom.xml +++ b/stack/pom.xml @@ -190,13 +190,13 @@ core services tools + mongo-emulator + websocket rest - test-utils - build-tools launcher + test-utils query-validator - mongo-emulator - websocket + build-tools diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java index d7fd7f36c4..0da3701b1e 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/TomcatResource.java @@ -121,7 +121,10 @@ private Process startTomcatProcess( String propDirPath ) throws IOException { String javaHome = (String)System.getenv("JAVA_HOME"); - ProcessBuilder pb = new ProcessBuilder(javaHome + "/bin/java", + String logConfig = "-Dlog4j.configuration=file:./src/test/resources/log4j.properties"; + String maxMemory = "-Xmx5000m"; + + ProcessBuilder pb = new ProcessBuilder(javaHome + "/bin/java", maxMemory, logConfig, "org.apache.usergrid.TomcatMain", "src/main/webapp", port + ""); // ensure Tomcat gets same classpath we have @@ -184,14 +187,7 @@ private void createPropertyFiles( String propDirPath ) throws IOException { pw.println("usergrid.sysadmin.login.email=superuser@usergrid.com"); pw.println("usergrid.sysadmin.login.password=superpassword"); pw.println("usergrid.sysadmin.login.allowed=true"); - pw.flush(); - pw.close(); - pw = new PrintWriter( - new FileWriter( propDirPath + File.separator + "corepersistence.properties")); - - pw.println("cassandra.hosts=127.0.0.1"); - pw.println("cassandra.port=" + cassPort); pw.println("cassandra.version=1.2"); pw.println("cassandra.cluster_name=Usergrid"); pw.println("cassandra.connections=20"); @@ -204,10 +200,11 @@ private void createPropertyFiles( String propDirPath ) throws IOException { pw.println("elasticsearch.hosts=127.0.0.1"); pw.println("elasticsearch.port=" + esPort); - pw.println("elasticsearch.cluster_name=usergrid_test"); + pw.println("elasticsearch.cluster_name=test_cluster"); pw.println("elasticsearch.index_prefix=usergrid"); pw.println("index.query.limit.default=1000"); + pw.flush(); pw.close(); } diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java index bf90d4d11b..5dbce3b3a3 100644 --- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java +++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/activities/AndOrQueryTest.java @@ -74,6 +74,8 @@ public void queriesWithAndPastLimit() throws IOException { } } + this.reindex( context.getAppUuid() ); + String errorQuery = "select * where created >= " + created + "AND madeup = true"; JsonNode incorrectNode = activities.withQuery( errorQuery ).get(); @@ -104,6 +106,8 @@ public void displayFullQueriesInLimit() throws IOException { JsonNode activity = activities.create( props ); } + this.reindex( context.getAppUuid() ); + String query = "select * where not verb = 'go'"; JsonNode incorrectNode = activities.query( query, "limit", Integer.toString( 10 ) ); @@ -133,6 +137,8 @@ public void queryReturnCount() throws Exception { JsonNode[] correctValues = activities.createEntitiesWithOrdinal( props, numValuesTested ); + this.reindex( context.getAppUuid() ); + String inCorrectQuery = "select * where verb = 'go' and ordinal >= 10 "; activities.verificationOfQueryResults( correctValues, true, inCorrectQuery ); @@ -148,6 +154,8 @@ public void queryCheckAsc() throws Exception { JsonNode[] correctValues; correctValues = madeupStuff.createEntitiesWithOrdinal( character, 1000 ); + this.reindex( context.getAppUuid() ); + String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou eq 'Ruff' ORDER BY " + "Ordinal asc"; @@ -166,6 +174,8 @@ public void queryReturnCheck() throws Exception { JsonNode[] correctValues = madeupStuff.createEntitiesWithOrdinal( character, numOfEntities ); + this.reindex( context.getAppUuid() ); + String inquisitiveQuery = "select * where Ordinal >= 0 and Ordinal <= 2000 or WhoHelpedYou = 'Ruff'"; int totalEntitiesContained = madeupStuff.verificationOfQueryResults( correctValues, true, inquisitiveQuery ); @@ -181,6 +191,8 @@ public void queryReturnCheckWithShortHand() throws IOException { madeupStuff.createEntitiesWithOrdinal( character, 1000 ); + this.reindex( context.getAppUuid() ); + String inquisitiveQuery = "select * where Ordinal gte 0 and Ordinal lte 2000 or WhoHelpedYou eq 'Ruff'"; int totalEntitiesContained = madeupStuff.countEntities( inquisitiveQuery ); diff --git a/stack/rest/src/test/resources/log4j.properties b/stack/rest/src/test/resources/log4j.properties index bea288b251..a6ab96a3c3 100644 --- a/stack/rest/src/test/resources/log4j.properties +++ b/stack/rest/src/test/resources/log4j.properties @@ -41,20 +41,21 @@ log4j.logger.org.apache.usergrid.rest.security.AllowAjaxFilter=WARN, stdout log4j.logger.me.prettyprint.hector.api.beans.AbstractComposite=ERROR, stdout log4j.logger.org.apache.usergrid.locking.singlenode.SingleNodeLockManagerImpl=DEBUG, stdout -#log4j.logger.org.apache.usergrid=WARN -log4j.logger.org.apache.usergrid.corepersistence=DEBUG +log4j.logger.org.apache.usergrid=WARN +log4j.logger.org.apache.usergrid.corepersistence=INFO #log4j.logger.org.apache.usergrid.corepersistence.CpEntityManagerFactory=DEBUG #log4j.logger.org.apache.usergrid.corepersistence.CpSetup=DEBUG #log4j.logger.com.netflix.hystrix=DEBUG #log4j.logger.org.antlr=DEBUG #log4j.logger.org.apache.usergrid.persistence.CollectionIT=DEBUG -log4j.logger.org.apache.usergrid.persistence.index=DEBUG #log4j.logger.org.apache.usergrid.persistence.index.impl=INFO -#log4j.logger.org.apache.usergrid.persistence.collection=INFO +log4j.logger.org.apache.usergrid.persistence.index=INFO +log4j.logger.org.apache.usergrid.persistence.collection=INFO #log4j.logger.org.elasticsearch=DEBUG #log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout -log4j.logger.org.apache.usergrid.rest=INFO +log4j.logger.org.apache.usergrid.rest=WARN +log4j.logger.org.apache.usergrid.rest.TomcatResource=INFO #log4j.logger.org.usergrid.rest.management=DEBUG diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java index b30c99e41a..4cc5761578 100644 --- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java +++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java @@ -2864,7 +2864,7 @@ private void writeCreds( UUID appId, EntityRef owner, CredentialsInfo creds, Str private CredentialsInfo readCreds( UUID appId, UUID ownerId, String ownerType, String key ) throws Exception { EntityManager em = emf.getEntityManager( appId ); - Entity owner = em.get( new SimpleEntityRef( ownerType, ownerId ) ); + Entity owner = em.get( ownerId ); return ( CredentialsInfo ) em.getDictionaryElementValue( owner, DICTIONARY_CREDENTIALS, key ); } diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java b/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java index 2cf353ce98..371cae9485 100644 --- a/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java +++ b/stack/test-utils/src/main/java/org/apache/usergrid/TomcatMain.java @@ -40,6 +40,7 @@ public static void main(String[] args) throws Exception { Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(dataDir.getAbsolutePath()); tomcat.setPort(port); + tomcat.getConnector().setAttribute("maxThreads", "600"); tomcat.addWebapp("/", new File(webappsPath).getAbsolutePath()); log.info("-----------------------------------------------------------------");