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 2015/04/24 06:48:37 UTC
incubator-usergrid git commit: Initial wiring complete
Repository: incubator-usergrid
Updated Branches:
refs/heads/USERGRID-593 461613e4e -> c565ee17f
Initial wiring complete
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c565ee17
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c565ee17
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c565ee17
Branch: refs/heads/USERGRID-593
Commit: c565ee17f00d0958efd2b5cb4d0830e9cd8839d0
Parents: 461613e
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Apr 23 22:48:32 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Apr 23 22:48:32 2015 -0600
----------------------------------------------------------------------
.../corepersistence/CpRelationManager.java | 4 +-
.../corepersistence/command/CommandBuilder.java | 8 +-
.../command/read/CollectCommand.java | 2 +-
.../command/read/entity/EntityLoadCommand.java | 39 +++----
.../read/graph/ReadGraphCollectionCommand.java | 12 +-
.../results/AbstractGraphQueryExecutor.java | 45 ++++----
.../results/CollectionGraphQueryExecutor.java | 4 +-
.../results/ConnectionGraphQueryExecutor.java | 5 +-
.../results/GraphQueryExecutor.java | 115 -------------------
.../org/apache/usergrid/CoreApplication.java | 3 +
.../usergrid/persistence/index/query/Query.java | 2 +-
11 files changed, 63 insertions(+), 176 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 64708a2..edd352e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -944,7 +944,7 @@ public class CpRelationManager implements RelationManager {
* TODO refactor all of this away into commands
*/
if(query.isGraphQuery()){
- final QueryExecutor executor = new CollectionGraphQueryExecutor( this.entityCollectionManagerFactory,graphManagerFactory, applicationScope, headEntity, query.getCursor(), collName );
+ final QueryExecutor executor = new CollectionGraphQueryExecutor( this.entityCollectionManagerFactory,graphManagerFactory, applicationScope, headEntity, query.getCursor(), collName, query.getLimit() );
return executor.next();
}
@@ -1392,7 +1392,7 @@ public class CpRelationManager implements RelationManager {
* TODO refactor all of this away into commands
*/
if(query.isGraphQuery()){
- final QueryExecutor executor = new ConnectionGraphQueryExecutor( this.entityCollectionManagerFactory,graphManagerFactory, applicationScope, headEntity, query.getCursor(), connection );
+ final QueryExecutor executor = new ConnectionGraphQueryExecutor( this.entityCollectionManagerFactory,graphManagerFactory, applicationScope, headEntity, query.getCursor(), connection, query.getLimit() );
return executor.next();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/CommandBuilder.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/CommandBuilder.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/CommandBuilder.java
index 1d66d3a..de76f50 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/CommandBuilder.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/CommandBuilder.java
@@ -42,6 +42,7 @@ public class CommandBuilder {
private final ApplicationScope applicationScope;
private final RequestCursor requestCursor;
private final ResponseCursor responseCursor;
+ private final int limit;
private int count = 0;
@@ -53,9 +54,11 @@ public class CommandBuilder {
* traversal. Eventually as we untangle the existing Query service nightmare, the sourceId will be remove and should
* only be traversed from the root application
*/
- public CommandBuilder(final ApplicationScope applicationScope, final Id sourceId, final Optional<String> requestCursor ) {
+ public CommandBuilder( final ApplicationScope applicationScope, final Id sourceId,
+ final Optional<String> requestCursor, final int limit ) {
this.applicationScope = applicationScope;
+ this.limit = limit;
//set the request cursor
this.requestCursor = new RequestCursor( requestCursor );
@@ -87,6 +90,8 @@ public class CommandBuilder {
public <T> Observable<T> build( final CollectCommand<T> collectCommand ) {
setState( collectCommand );
+ collectCommand.setLimit( limit );
+
return currentObservable.compose( collectCommand );
}
@@ -101,5 +106,6 @@ public class CommandBuilder {
count++;
command.setCursorCaches( requestCursor, responseCursor );
+ command.setApplicationScope( applicationScope );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/CollectCommand.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/CollectCommand.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/CollectCommand.java
index 5e982b6..c2ad931 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/CollectCommand.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/CollectCommand.java
@@ -30,7 +30,7 @@ public interface CollectCommand<T> extends Command<T>{
* Set the prefered result size for the command
* @param resultSize
*/
- void setResultSize(final int resultSize);
+ void setLimit( final int resultSize );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/entity/EntityLoadCommand.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/entity/EntityLoadCommand.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/entity/EntityLoadCommand.java
index 4e292c5..f4de9e0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/entity/EntityLoadCommand.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/entity/EntityLoadCommand.java
@@ -111,17 +111,16 @@ public class EntityLoadCommand extends AbstractCommand<Results, Serializable> im
return stringIdGroupedObservable.toList()
.flatMap( new Func1<List<Id>, Observable<EntitySet>>() {
- @Override
- public Observable<EntitySet> call(
- final List<Id> ids ) {
-
- final EntityCollectionManager ecm =
- entityCollectionManagerFactory
- .createCollectionManager(
- collectionScope );
- return ecm.load( ids );
- }
- } );
+ @Override
+ public Observable<EntitySet> call(
+ final List<Id> ids ) {
+
+ final EntityCollectionManager ecm =
+ entityCollectionManagerFactory
+ .createCollectionManager( collectionScope );
+ return ecm.load( ids );
+ }
+ } );
}
} )
//emit our groups of entities as a stream of entities
@@ -149,14 +148,14 @@ public class EntityLoadCommand extends AbstractCommand<Results, Serializable> im
//convert them to a list, then map them into results
.toList().map( new Func1<List<org.apache.usergrid.persistence.Entity>, Results>() {
- @Override
- public Results call( final List<org.apache.usergrid.persistence.Entity> entities ) {
- final Results results = Results.fromEntities( entities );
- results.setCursor( generateCursor() );
-
- return results;
- }
- } );
+ @Override
+ public Results call( final List<org.apache.usergrid.persistence.Entity> entities ) {
+ final Results results = Results.fromEntities( entities );
+ results.setCursor( generateCursor() );
+
+ return results;
+ }
+ } );
}
} );
}
@@ -186,7 +185,7 @@ public class EntityLoadCommand extends AbstractCommand<Results, Serializable> im
@Override
- public void setResultSize( final int resultSize ) {
+ public void setLimit( final int resultSize ) {
this.resultSize = resultSize;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/graph/ReadGraphCollectionCommand.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/graph/ReadGraphCollectionCommand.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/graph/ReadGraphCollectionCommand.java
index d68a716..9ccb969 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/graph/ReadGraphCollectionCommand.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/command/read/graph/ReadGraphCollectionCommand.java
@@ -28,26 +28,22 @@ import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getCollecti
/**
* Command for reading graph edges on a collection
*/
-public class ReadGraphCollectionCommand extends AbstractReadGraphCommand{
+public class ReadGraphCollectionCommand extends AbstractReadGraphCommand {
private final String collectionName;
/**
* Create a new instance of our command
- * @param graphManagerFactory
- * @param collectionName
*/
- public ReadGraphCollectionCommand( final GraphManagerFactory graphManagerFactory, final String collectionName) {
- super(graphManagerFactory);
+ public ReadGraphCollectionCommand( final GraphManagerFactory graphManagerFactory, final String collectionName ) {
+ super( graphManagerFactory );
this.collectionName = collectionName;
}
-
-
@Override
protected String getEdgeTypeName() {
- return getCollectionScopeNameFromCollectionName(collectionName);
+ return getCollectionScopeNameFromCollectionName( collectionName );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/AbstractGraphQueryExecutor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/AbstractGraphQueryExecutor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/AbstractGraphQueryExecutor.java
index 7ae4e19..0bea013 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/AbstractGraphQueryExecutor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/AbstractGraphQueryExecutor.java
@@ -25,13 +25,10 @@ import java.util.NoSuchElementException;
import org.apache.usergrid.corepersistence.command.CommandBuilder;
import org.apache.usergrid.corepersistence.command.read.entity.EntityLoadCommand;
-import org.apache.usergrid.corepersistence.command.read.graph.ReadGraphConnectionCommand;
import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -47,33 +44,26 @@ import rx.Observable;
public abstract class AbstractGraphQueryExecutor implements QueryExecutor {
- private final Optional<String> requestCursor;
-
+ private final EntityCollectionManagerFactory entityCollectionManagerFactory;
+ private final ApplicationScope applicationScope;
+ private final Id sourceId;
+ private final int limit;
- //construct our results
- private final Observable<Results> resultsObservable;
+ private final Optional<String> requestCursor;
private Iterator<Results> observableIterator;
public AbstractGraphQueryExecutor( final EntityCollectionManagerFactory entityCollectionManagerFactory,
final ApplicationScope applicationScope, final EntityRef source,
- final String cursor ) {
+ final String cursor, final int limit ) {
- final Id sourceId = new SimpleId( source.getUuid(), source.getType() );
+ this.entityCollectionManagerFactory = entityCollectionManagerFactory;
+ this.applicationScope = applicationScope;
+ this.limit = limit;
+ this.sourceId = new SimpleId( source.getUuid(), source.getType() );
this.requestCursor = Optional.fromNullable( cursor );
-
- //set up our command builder
- final CommandBuilder commandBuilder = new CommandBuilder( applicationScope, sourceId, requestCursor );
-
-
-
- addTraverseCommand( commandBuilder );
-
- //construct our results to be observed later. This is a cold observable
- resultsObservable =
- commandBuilder.build( new EntityLoadCommand( entityCollectionManagerFactory, applicationScope ) );
}
@@ -90,6 +80,16 @@ public abstract class AbstractGraphQueryExecutor implements QueryExecutor {
if ( observableIterator == null ) {
//assign them to an interator. this now uses an internal buffer with backpressure, so we won't load all
// results
+ //set up our command builder
+ final CommandBuilder commandBuilder = new CommandBuilder( applicationScope, sourceId, requestCursor, limit );
+
+
+ addTraverseCommand( commandBuilder );
+
+ //construct our results to be observed later. This is a cold observable
+ final Observable<Results> resultsObservable =
+ commandBuilder.build( new EntityLoadCommand( entityCollectionManagerFactory, applicationScope ) );
+
this.observableIterator = resultsObservable.toBlocking().getIterator();
}
@@ -105,7 +105,7 @@ public abstract class AbstractGraphQueryExecutor implements QueryExecutor {
throw new NoSuchElementException( "No more results present" );
}
- final Results results = observableIterator.next();
+ final Results results = observableIterator.next();
//ugly and tight coupling, but we don't have a choice until we finish some refactoring
results.setQueryExecutor( this );
@@ -122,7 +122,6 @@ public abstract class AbstractGraphQueryExecutor implements QueryExecutor {
/**
* Add the traverse command to the graph
- * @param commandBuilder
*/
- protected abstract void addTraverseCommand(final CommandBuilder commandBuilder);
+ protected abstract void addTraverseCommand( final CommandBuilder commandBuilder );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/CollectionGraphQueryExecutor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/CollectionGraphQueryExecutor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/CollectionGraphQueryExecutor.java
index 022a096..651c27e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/CollectionGraphQueryExecutor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/CollectionGraphQueryExecutor.java
@@ -42,9 +42,9 @@ public class CollectionGraphQueryExecutor extends AbstractGraphQueryExecutor {
public CollectionGraphQueryExecutor( final EntityCollectionManagerFactory entityCollectionManagerFactory,
final GraphManagerFactory graphManagerFactory,
final ApplicationScope applicationScope, final EntityRef source,
- final String cursor, final String connectionName ) {
+ final String cursor, final String connectionName, final int limit ) {
- super( entityCollectionManagerFactory, applicationScope, source, cursor );
+ super( entityCollectionManagerFactory, applicationScope, source, cursor, limit );
this.graphManagerFactory = graphManagerFactory;
Preconditions.checkNotNull( connectionName, "connectionName is required on the query" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ConnectionGraphQueryExecutor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ConnectionGraphQueryExecutor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ConnectionGraphQueryExecutor.java
index 7e812e7..61726b7 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ConnectionGraphQueryExecutor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ConnectionGraphQueryExecutor.java
@@ -26,7 +26,6 @@ import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.graph.GraphManagerFactory;
-import org.apache.usergrid.persistence.index.query.Query;
import com.google.common.base.Preconditions;
@@ -40,9 +39,9 @@ public class ConnectionGraphQueryExecutor extends AbstractGraphQueryExecutor {
public ConnectionGraphQueryExecutor( final EntityCollectionManagerFactory entityCollectionManagerFactory,
final GraphManagerFactory graphManagerFactory,
final ApplicationScope applicationScope, final EntityRef source,
- final String cursor, final String connectionType ) {
+ final String cursor, final String connectionType, final int limit) {
- super( entityCollectionManagerFactory, applicationScope, source, cursor );
+ super( entityCollectionManagerFactory, applicationScope, source, cursor, limit );
this.graphManagerFactory = graphManagerFactory;
Preconditions.checkNotNull(connectionType, "connectionType is required on the query" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/GraphQueryExecutor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/GraphQueryExecutor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/GraphQueryExecutor.java
deleted file mode 100644
index 222880f..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/GraphQueryExecutor.java
+++ /dev/null
@@ -1,115 +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.corepersistence.results;
-
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import org.apache.usergrid.corepersistence.command.CommandBuilder;
-import org.apache.usergrid.corepersistence.command.read.entity.EntityLoadCommand;
-import org.apache.usergrid.corepersistence.command.read.graph.ReadGraphConnectionCommand;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
-import org.apache.usergrid.persistence.graph.GraphManagerFactory;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-
-import com.google.common.base.Optional;
-
-import rx.Observable;
-
-
-/**
- * This class is a nasty hack to bridge 2.0 observables into 1.0 iterators DO NOT use this as a model for moving
- * forward, pandas will die.
- */
-public class GraphQueryExecutor implements QueryExecutor {
-
-
- private final Optional<String> requestCursor;
-
-
- //construct our results
- private final Observable<Results> resultsObservable;
-
- private Iterator<Results> observableIterator;
-
-
- public GraphQueryExecutor( final GraphManagerFactory graphManagerFactory,
- final EntityCollectionManagerFactory entityCollectionManagerFactory,
- final CollectionScope collectionScope, final EntityRef source,
- final String connectionName, final String cursor ) {
- final Id sourceId = new SimpleId( source.getUuid(), source.getType() );
-
- this.requestCursor = Optional.fromNullable( cursor );
-
- //set up our command builder
- final CommandBuilder commandBuilder = new CommandBuilder( collectionScope, sourceId, requestCursor );
-
-
- //set the traverse command from the source Id to the connect name
- commandBuilder.withTraverseCommand( new ReadGraphConnectionCommand( graphManagerFactory, connectionName ) );
-
- //construct our results to be observed later. This is a cold observable
- resultsObservable =
- commandBuilder.build( new EntityLoadCommand( entityCollectionManagerFactory, collectionScope ) );
- }
-
-
- @Override
- public Iterator<Results> iterator() {
- return this;
- }
-
-
- @Override
- public boolean hasNext() {
-
- //hasn't been set up yet, run through our first setup
- if ( observableIterator == null ) {
- //assign them to an interator. this now uses an internal buffer with backpressure, so we won't load all
- // results
- this.observableIterator = resultsObservable.toBlocking().getIterator();
- }
-
-
- //see if our current results are not null
- return observableIterator.hasNext();
- }
-
-
- @Override
- public Results next() {
- if ( !hasNext() ) {
- throw new NoSuchElementException( "No more results present" );
- }
-
- return observableIterator.next();
- }
-
-
- @Override
- public void remove() {
- throw new RuntimeException( "Remove not implemented!!" );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index 99cfcf5..647424c 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -164,6 +164,9 @@ public class CoreApplication implements Application, TestRule {
LOG.info( "Created new application {} in organization {}", appName, orgName );
+// //wait for the index before proceeding
+// em.refreshIndex();
+
}
protected void before( Description description ) throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c565ee17/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
index ae89bfc..e77589d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/Query.java
@@ -848,7 +848,7 @@ public class Query {
* @return
*/
public boolean isGraphQuery(){
- return ql == null;
+ return rootOperand == null && ql == null;
}
@JsonIgnore