You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/30 14:50:06 UTC
[01/12] git commit: apns null reference issue
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o-events 9153eb9d8 -> ec0d69aa3
apns null reference issue
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/77b8c593
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/77b8c593
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/77b8c593
Branch: refs/heads/two-dot-o-events
Commit: 77b8c59325c7cfbd0c04be2a66dfce3ce55ab1bd
Parents: 610eb2d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Oct 29 13:12:20 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Oct 29 13:12:20 2014 -0600
----------------------------------------------------------------------
.../notifications/apns/APNsAdapter.java | 37 ++++++++++----------
.../notifications/apns/EntityPushManager.java | 5 +--
2 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/77b8c593/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
index 79a3b9e..a943bf5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -64,6 +64,7 @@ public class APNsAdapter implements ProviderAdapter {
private EntityManager entityManager;
private EntityPushManager pushManager;
+ private LinkedBlockingQueue<SimpleApnsPushNotification> queue;
public APNsAdapter(EntityManager entityManager, Notifier notifier){
this.entityManager = entityManager;
@@ -76,13 +77,12 @@ public class APNsAdapter implements ProviderAdapter {
try {
CountDownLatch latch = new CountDownLatch(1);
notification.setLatch(latch);
- EntityPushManager pushManager = getPushManager(notifier);
- addToQueue(pushManager, notification);
- latch.await(10000,TimeUnit.MILLISECONDS);
- if(notification.hasFailed()){
- // this is expected with a bad certificate (w/message: comes from failedconnectionlistener
- throw new ConnectionException("Bad certificate. Double-check your environment.",notification.getCause() != null ? notification.getCause() : new Exception("Bad certificate."));
- }
+ addToQueue(notification);
+ latch.await(10000, TimeUnit.MILLISECONDS);
+ if (notification.hasFailed()) {
+ // this is expected with a bad certificate (w/message: comes from failedconnectionlistener
+ throw new ConnectionException("Bad certificate. Double-check your environment.", notification.getCause() != null ? notification.getCause() : new Exception("Bad certificate."));
+ }
notification.finished();
} catch (Exception e) {
notification.finished();
@@ -97,8 +97,8 @@ public class APNsAdapter implements ProviderAdapter {
}
}
- private BlockingQueue<SimpleApnsPushNotification> addToQueue(PushManager<SimpleApnsPushNotification> pushManager, SimpleApnsPushNotification notification) throws InterruptedException {
- BlockingQueue<SimpleApnsPushNotification> queue = pushManager.getQueue();
+ private BlockingQueue<SimpleApnsPushNotification> addToQueue(SimpleApnsPushNotification notification) throws Exception {
+ BlockingQueue<SimpleApnsPushNotification> queue = getPushManager(notifier).getQueue();
queue.offer(notification,2500,TimeUnit.MILLISECONDS);
return queue;
}
@@ -107,9 +107,8 @@ public class APNsAdapter implements ProviderAdapter {
public void sendNotification(String providerId, Object payload, Notification notification, TaskTracker tracker)
throws Exception {
APNsNotification apnsNotification = APNsNotification.create(providerId, payload.toString(), notification, tracker);
- PushManager<SimpleApnsPushNotification> pushManager = getPushManager(notifier);
try {
- addToQueue(pushManager, apnsNotification);
+ addToQueue( apnsNotification);
apnsNotification.messageSent();
}catch (InterruptedException ie){
apnsNotification.messageSendFailed(ie);
@@ -129,10 +128,12 @@ public class APNsAdapter implements ProviderAdapter {
}
private EntityPushManager getPushManager(Notifier notifier) throws ExecutionException {
- if(pushManager != null && !pushManager.isStarted() && pushManager.isShutDown()){
+ if (pushManager == null || !pushManager.isStarted() || pushManager.isShutDown()) {
PushManagerConfiguration config = new PushManagerConfiguration();
config.setConcurrentConnectionCount(Runtime.getRuntime().availableProcessors() * 2);
- EntityPushManager pushManager = new EntityPushManager(notifier,entityManager, config);
+ queue = new LinkedBlockingQueue<SimpleApnsPushNotification>();
+
+ pushManager = new EntityPushManager(notifier, entityManager, queue, config);
//only tested when a message is sent
pushManager.registerRejectedNotificationListener(new RejectedAPNsListener());
//this will get tested when start is called
@@ -144,10 +145,9 @@ public class APNsAdapter implements ProviderAdapter {
if (!pushManager.isStarted()) { //ensure manager is started
pushManager.start();
}
- }catch(IllegalStateException ise){
- logger.debug("failed to start",ise);//could have failed because its started
+ } catch (IllegalStateException ise) {
+ logger.debug("failed to start", ise);//could have failed because its started
}
- return pushManager;
}
return pushManager;
}
@@ -189,8 +189,9 @@ public class APNsAdapter implements ProviderAdapter {
@Override
public void stop() {
try {
- if (!pushManager.isShutDown()) {
- List<SimpleApnsPushNotification> notifications = pushManager.shutdown(3000);
+ EntityPushManager entityPushManager = getPushManager(notifier);
+ if (!entityPushManager.isShutDown()) {
+ List<SimpleApnsPushNotification> notifications = entityPushManager.shutdown(3000);
for (SimpleApnsPushNotification notification1 : notifications) {
try {
((APNsNotification) notification1).messageSendFailed(new Exception("Cache Expired: Shutting down sender"));
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/77b8c593/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
index d675081..c3790b8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/EntityPushManager.java
@@ -32,6 +32,7 @@ import javax.net.ssl.SSLContext;
import java.io.InputStream;
import java.security.KeyStore;
import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.LinkedBlockingQueue;
/**
* Store notifier within PushManager so it can be retrieved later. Need this for the async token listener
@@ -40,8 +41,8 @@ public class EntityPushManager extends PushManager<SimpleApnsPushNotification> {
private final Notifier notifier;
private final EntityManager entityManager;
- public EntityPushManager( Notifier notifier, EntityManager entityManager, PushManagerConfiguration configuration) {
- super(getApnsEnvironment(notifier), getSSLContext(notifier), null, null, new LinkedBlockingDeque<SimpleApnsPushNotification>(), configuration, notifier.getName());
+ public EntityPushManager( Notifier notifier, EntityManager entityManager, LinkedBlockingQueue<SimpleApnsPushNotification> queue, PushManagerConfiguration configuration) {
+ super(getApnsEnvironment(notifier), getSSLContext(notifier), null, null, queue, configuration, notifier.getName());
this.notifier = notifier;
this.entityManager = entityManager;
}
[08/12] git commit: Contains code that helps make it easier to mock.
Posted by sn...@apache.org.
Contains code that helps make it easier to mock.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/da38f0bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/da38f0bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/da38f0bf
Branch: refs/heads/two-dot-o-events
Commit: da38f0bfebe87d1e0fb7fcff85a55f2576762302
Parents: f5df7b7
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 16:33:00 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 16:33:00 2014 -0700
----------------------------------------------------------------------
.../persistence/collection/impl/EntityVersionCreatedTask.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/da38f0bf/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
index b78b09c..fdfb551 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
@@ -122,7 +122,10 @@ public class EntityVersionCreatedTask implements Task<Void> {
}
if ( listenerSize == 1 ) {
- listeners.iterator().next().versionCreated( collectionScope,entity );
+ EntityVersionCreated entityVersionCreated = listeners.iterator().next();
+
+ entityVersionCreated.versionCreated( collectionScope,entity );
+
return;
}
[04/12] git commit: Cleaned up extra lines.
Posted by sn...@apache.org.
Cleaned up extra lines.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/67f74225
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/67f74225
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/67f74225
Branch: refs/heads/two-dot-o-events
Commit: 67f742256eb36a97e612f3e6b6ca9b5a7026be93
Parents: 0537e10
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 14:01:51 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 14:01:51 2014 -0700
----------------------------------------------------------------------
.../events/EntityVersionCreatedImpl.java | 3 ---
.../persistence/collection/guice/CollectionModule.java | 13 -------------
.../collection/impl/EntityCollectionManagerImpl.java | 11 -----------
.../persistence/index/impl/EsEntityIndexBatchImpl.java | 4 ----
4 files changed, 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/67f74225/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
index 738183c..c7aada7 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
@@ -39,9 +39,6 @@ public class EntityVersionCreatedImpl implements EntityVersionCreated{
HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
-// CpEntityManagerFactory emf = (CpEntityManagerFactory)
-// CpSetup.getInjector().getInstance( EntityManagerFactory.class );
-
final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
EntityIndexBatch batch = ei.createBatch();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/67f74225/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
index de99078..4c96303 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
@@ -93,19 +93,6 @@ public class CollectionModule extends AbstractModule {
}
-
- @Provides
- public List<EntityVersionDeleted> emptyEntityVersionDeletedInitialization(){
- return Collections.EMPTY_LIST;
-
- }
-
- @Provides
- public List<EntityDeleted> emptyEntityDeletedInitialization(){
- return Collections.EMPTY_LIST;
-
- }
-
@Provides
@Singleton
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/67f74225/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 3d33a52..5b6265c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -159,7 +159,6 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
ValidationUtils.verifyIdentity(entityId);
-
// create our observable and start the write
final CollectionIoEvent<Entity> writeData =
new CollectionIoEvent<Entity>(collectionScope, entity);
@@ -174,20 +173,10 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
observable.map(writeCommit).doOnNext(new Action1<Entity>() {
@Override
public void call(final Entity entity) {
-//<<<<<<< Updated upstream
-//
-// // TODO fire a task here
-//
-// taskExecutor.submit(entityVersionCleanupFactory.getTask(
-// collectionScope, entityId, entity.getVersion() ));
-//
-// // post-processing to come later. leave it empty for now.
-//=======
//TODO fire the created task first then the entityVersioncleanup
taskExecutor.submit(entityVersionCreatedFactory.getTask(collectionScope,entity));
taskExecutor.submit(entityVersionCleanupFactory.getTask(collectionScope, entityId,entity.getVersion()));
//post-processing to come later. leave it empty for now.
-//>>>>>>> Stashed changes
}
}).doOnError(rollback);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/67f74225/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 1fca845..ca7f666 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -222,10 +222,6 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
( STRING_PREFIX + ENTITYID_FIELDNAME,entity.getId().getUuid().toString().toLowerCase() ),
FilterBuilders.rangeFilter("version").lt( entity.getId().getUuid().timestamp() ));
-
-
- //QueryBuilders.rangeQuery( )
-
DeleteByQueryResponse response = client.prepareDeleteByQuery("test")
.setQuery( fqb ).execute().actionGet();
[11/12] git commit: Merge branch 'pr/91' into two-dot-o-events
Posted by sn...@apache.org.
Merge branch 'pr/91' into two-dot-o-events
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f8131365
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f8131365
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f8131365
Branch: refs/heads/two-dot-o-events
Commit: f8131365e23fc6896dd0d6b5c00c4183e4878beb
Parents: bd2b127 389bee7
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Oct 30 09:38:25 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Oct 30 09:38:25 2014 -0400
----------------------------------------------------------------------
.../events/EntityVersionCreatedImpl.java | 49 ++++
.../collection/EntityVersionCreatedFactory.java | 31 +++
.../collection/guice/CollectionModule.java | 16 +-
.../impl/EntityCollectionManagerImpl.java | 20 +-
.../impl/EntityVersionCreatedTask.java | 150 +++++++++++
.../impl/EntityVersionCreatedTaskTest.java | 270 +++++++++++++++++++
.../persistence/index/EntityIndexBatch.java | 12 +-
.../index/impl/EsEntityIndexBatchImpl.java | 22 ++
8 files changed, 546 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
[10/12] git commit: Merge branch 'two-dot-o' into two-dot-o-events
Posted by sn...@apache.org.
Merge branch 'two-dot-o' into two-dot-o-events
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/bd2b1271
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/bd2b1271
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/bd2b1271
Branch: refs/heads/two-dot-o-events
Commit: bd2b127188b1140b3d9a4d3e30c4df90ad92285b
Parents: 9153eb9 97ee70f
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Oct 30 09:38:15 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Oct 30 09:38:15 2014 -0400
----------------------------------------------------------------------
.../notifications/apns/APNsAdapter.java | 37 ++++++++++----------
.../notifications/apns/EntityPushManager.java | 5 +--
2 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
[05/12] git commit: Created extra step to help mock out the test.
Created new test to check to see how one listener is handled
Posted by sn...@apache.org.
Created extra step to help mock out the test.
Created new test to check to see how one listener is handled
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e6760f25
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e6760f25
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e6760f25
Branch: refs/heads/two-dot-o-events
Commit: e6760f2569a9b1fb10ba5155120d59ecf5f4b733
Parents: 67f7422
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 16:25:41 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 16:25:41 2014 -0700
----------------------------------------------------------------------
.../persistence/collection/impl/EntityVersionCreatedTask.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e6760f25/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
index b78b09c..cef4248 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
@@ -122,7 +122,9 @@ public class EntityVersionCreatedTask implements Task<Void> {
}
if ( listenerSize == 1 ) {
- listeners.iterator().next().versionCreated( collectionScope,entity );
+ EntityVersionCreated entityVersionCreated = listeners.iterator().next();
+
+ entityVersionCreated.versionCreated( collectionScope,entity );
return;
}
[06/12] git commit: Revert "Created extra step to help mock out the
test."
Posted by sn...@apache.org.
Revert "Created extra step to help mock out the test."
This reverts commit e6760f2569a9b1fb10ba5155120d59ecf5f4b733.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/839fc2b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/839fc2b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/839fc2b5
Branch: refs/heads/two-dot-o-events
Commit: 839fc2b5d62212ce3cffc4de47addba51ba9b9fd
Parents: e6760f2
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 16:30:59 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 16:30:59 2014 -0700
----------------------------------------------------------------------
.../persistence/collection/impl/EntityVersionCreatedTask.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/839fc2b5/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
index cef4248..b78b09c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
@@ -122,9 +122,7 @@ public class EntityVersionCreatedTask implements Task<Void> {
}
if ( listenerSize == 1 ) {
- EntityVersionCreated entityVersionCreated = listeners.iterator().next();
-
- entityVersionCreated.versionCreated( collectionScope,entity );
+ listeners.iterator().next().versionCreated( collectionScope,entity );
return;
}
[07/12] git commit: This contains the extra test.
Posted by sn...@apache.org.
This contains the extra test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f5df7b7b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f5df7b7b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f5df7b7b
Branch: refs/heads/two-dot-o-events
Commit: f5df7b7b0eb9741abfe204c61136d12e7f7ae77c
Parents: 839fc2b
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 16:32:11 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 16:32:11 2014 -0700
----------------------------------------------------------------------
.../impl/EntityVersionCreatedTaskTest.java | 135 +++++++++++++++++++
1 file changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f5df7b7b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
index 4f1abca..9f8d77f 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
@@ -3,11 +3,13 @@ package org.apache.usergrid.persistence.collection.impl;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Semaphore;
import org.junit.AfterClass;
import org.junit.Test;
@@ -132,4 +134,137 @@ public class EntityVersionCreatedTaskTest {
}
+ @Test//(timeout=10000)
+ public void oneListener()//why does it matter if it has a version or not without a listener
+ throws ExecutionException, InterruptedException, ConnectionException {
+
+
+ final SerializationFig serializationFig = mock( SerializationFig.class );
+
+ when( serializationFig.getBufferSize() ).thenReturn( 10 );
+
+ final MvccEntitySerializationStrategy ess =
+ mock( MvccEntitySerializationStrategy.class );
+
+ final MvccLogEntrySerializationStrategy less =
+ mock( MvccLogEntrySerializationStrategy.class );
+
+ final Keyspace keyspace = mock( Keyspace.class );
+
+ final MutationBatch entityBatch = mock( MutationBatch.class );
+
+ final MutationBatch logBatch = mock( MutationBatch.class );
+
+ final EntityVersionCreatedFactory entityVersionCreatedFactory = mock(EntityVersionCreatedFactory.class);
+
+ when( keyspace.prepareMutationBatch() )
+ .thenReturn( mock( MutationBatch.class ) ) // don't care what happens to this one
+ .thenReturn( entityBatch )
+ .thenReturn( logBatch );
+
+ // intentionally no events
+
+ //create a latch for the event listener, and add it to the list of events
+ final int sizeToReturn = 1;
+
+ final CountDownLatch latch = new CountDownLatch( sizeToReturn );
+
+ final EntityVersionCreatedTest eventListener = new EntityVersionCreatedTest(latch);
+
+ final Set<EntityVersionCreated> listeners = mock( Set.class );//new HashSet<EntityVersionCreated>();
+
+ final Iterator<EntityVersionCreated> helper = mock(Iterator.class);
+
+
+ when ( listeners.size()).thenReturn( 1 );
+ when ( listeners.iterator()).thenReturn( helper );
+ when ( helper.next() ).thenReturn( eventListener );
+
+ final Id applicationId = new SimpleId( "application" );
+
+ final CollectionScope appScope = new CollectionScopeImpl(
+ applicationId, applicationId, "users" );
+
+ final Id entityId = new SimpleId( "user" );
+
+ final Entity entity = new Entity( entityId );
+
+ final MvccEntity mvccEntity = new MvccEntityImpl( entityId, UUIDGenerator.newTimeUUID(),
+ MvccEntity.Status.COMPLETE,entity );
+
+
+ // mock up a single log entry for our first test
+ final LogEntryMock logEntryMock =
+ LogEntryMock.createLogEntryMock(less, appScope, entityId, 2 );
+
+ final UUID version = logEntryMock.getEntries().iterator().next().getVersion();
+
+ final UniqueValueSerializationStrategy uvss =
+ mock( UniqueValueSerializationStrategy.class );
+
+ //when ( listeners.iterator().next().versionCreated(appScope,entity));
+
+
+ EntityVersionCreatedTask entityVersionCreatedTask =
+ new EntityVersionCreatedTask(entityVersionCreatedFactory,
+ serializationFig,
+ less,
+ ess,
+ uvss,
+ keyspace,
+ appScope,
+ listeners,
+ entity);
+
+ // start the task
+ ListenableFuture<Void> future = taskExecutor.submit( entityVersionCreatedTask );
+
+ // wait for the task
+ future.get();
+
+ //mocked listener makes sure that the task is called
+ verify( listeners ).size();
+ verify( listeners ).iterator();
+ verify( helper ).next();
+
+ }
+
+ private static class EntityVersionCreatedTest implements EntityVersionCreated {
+ final CountDownLatch invocationLatch;
+
+ private EntityVersionCreatedTest( final CountDownLatch invocationLatch) {
+ this.invocationLatch = invocationLatch;
+ }
+
+ @Override
+ public void versionCreated( final CollectionScope scope, final Entity entity ) {
+ invocationLatch.countDown();
+ }
+ }
+
+
+// private static class SlowListener extends EntityVersionCreatedTest {
+// final Semaphore blockLatch;
+//
+// private SlowListener( final CountDownLatch invocationLatch, final Semaphore blockLatch ) {
+// super( invocationLatch );
+// this.blockLatch = blockLatch;
+// }
+//
+//
+// @Override
+// public void versionDeleted( final CollectionScope scope, final Id entityId,
+// final List<MvccEntity> entityVersion ) {
+//
+// //wait for unblock to happen before counting down invocation latches
+// try {
+// blockLatch.acquire();
+// }
+// catch ( InterruptedException e ) {
+// throw new RuntimeException( e );
+// }
+// super.versionDeleted( scope, entityId, entityVersion );
+// }
+// }
+
}
[02/12] git commit: Merge branch 'two-dot-o' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Posted by sn...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/97ee70fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/97ee70fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/97ee70fe
Branch: refs/heads/two-dot-o-events
Commit: 97ee70fe8b38366eb0790877154c961cf2773a9d
Parents: 707c9b9 77b8c59
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 15:22:01 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 15:22:01 2014 -0400
----------------------------------------------------------------------
.../notifications/apns/APNsAdapter.java | 37 ++++++++++----------
.../notifications/apns/EntityPushManager.java | 5 +--
2 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
[09/12] git commit: Re-added in the timeout and removed the previous
code that added complexity.
Posted by sn...@apache.org.
Re-added in the timeout and removed the previous code that added complexity.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/389bee72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/389bee72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/389bee72
Branch: refs/heads/two-dot-o-events
Commit: 389bee7282f3c60c77e8998d1ec9ea5807f316d2
Parents: da38f0b
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 16:46:29 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 16:46:29 2014 -0700
----------------------------------------------------------------------
.../persistence/collection/impl/EntityVersionCreatedTask.java | 5 +----
.../collection/impl/EntityVersionCreatedTaskTest.java | 4 ++--
2 files changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/389bee72/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
index fdfb551..256e65f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
@@ -122,10 +122,7 @@ public class EntityVersionCreatedTask implements Task<Void> {
}
if ( listenerSize == 1 ) {
- EntityVersionCreated entityVersionCreated = listeners.iterator().next();
-
- entityVersionCreated.versionCreated( collectionScope,entity );
-
+ listeners.iterator().next().versionCreated( collectionScope, entity );
return;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/389bee72/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
index 9f8d77f..21895ba 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
@@ -134,8 +134,8 @@ public class EntityVersionCreatedTaskTest {
}
- @Test//(timeout=10000)
- public void oneListener()//why does it matter if it has a version or not without a listener
+ @Test(timeout=10000)
+ public void oneListener()
throws ExecutionException, InterruptedException, ConnectionException {
[03/12] git commit: EntityVersionCreated implementation.
Posted by sn...@apache.org.
EntityVersionCreated implementation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0537e100
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0537e100
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0537e100
Branch: refs/heads/two-dot-o-events
Commit: 0537e1006339d6741fb45f988d95da74c01cfb30
Parents: 9153eb9
Author: grey <gr...@apigee.com>
Authored: Wed Oct 29 12:59:00 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Oct 29 12:59:00 2014 -0700
----------------------------------------------------------------------
.../events/EntityVersionCreatedImpl.java | 52 +++++++
.../collection/EntityVersionCreatedFactory.java | 31 ++++
.../collection/guice/CollectionModule.java | 3 +
.../impl/EntityCollectionManagerImpl.java | 29 +++-
.../impl/EntityVersionCreatedTask.java | 150 +++++++++++++++++++
.../impl/EntityVersionCreatedTaskTest.java | 135 +++++++++++++++++
.../persistence/index/EntityIndexBatch.java | 12 +-
.../index/impl/EsEntityIndexBatchImpl.java | 26 ++++
8 files changed, 428 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
new file mode 100644
index 0000000..738183c
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
@@ -0,0 +1,52 @@
+package org.apache.usergrid.corepersistence.events;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.corepersistence.CpEntityManager;
+import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
+import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.index.EntityIndexBatch;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+
+/**
+ * Created by ApigeeCorporation on 10/24/14.
+ */
+public class EntityVersionCreatedImpl implements EntityVersionCreated{
+
+ private static final Logger logger = LoggerFactory.getLogger( EntityVersionCreatedImpl.class );
+
+ public EntityVersionCreatedImpl() {
+ logger.debug("EntityVersionCreated");
+ }
+
+ @Override
+ public void versionCreated( final CollectionScope scope, final Entity entity ) {
+ logger.debug("Entering deleted for entity {}:{} v {} "
+ + "scope\n name: {}\n owner: {}\n app: {}",
+ new Object[] { entity.getId().getType(), entity.getId().getUuid(), entity.getVersion(),
+ scope.getName(), scope.getOwner(), scope.getApplication()});
+
+ HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
+ CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
+
+// CpEntityManagerFactory emf = (CpEntityManagerFactory)
+// CpSetup.getInjector().getInstance( EntityManagerFactory.class );
+
+ final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
+
+ EntityIndexBatch batch = ei.createBatch();
+
+ batch.deindexPreviousVersions( entity );
+ batch.execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCreatedFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCreatedFactory.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCreatedFactory.java
new file mode 100644
index 0000000..4248d42
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCreatedFactory.java
@@ -0,0 +1,31 @@
+/*
+ * 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.collection;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.impl.EntityVersionCreatedTask;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+public interface EntityVersionCreatedFactory {
+ public EntityVersionCreatedTask getTask( final CollectionScope scope, final Entity entity);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
index 3532fe0..de99078 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
@@ -27,6 +27,7 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory
import org.apache.usergrid.persistence.collection.EntityCollectionManagerSync;
import org.apache.usergrid.persistence.collection.EntityDeletedFactory;
import org.apache.usergrid.persistence.collection.EntityVersionCleanupFactory;
+import org.apache.usergrid.persistence.collection.EntityVersionCreatedFactory;
import org.apache.usergrid.persistence.collection.event.EntityDeleted;
import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
import org.apache.usergrid.persistence.collection.impl.EntityCollectionManagerImpl;
@@ -72,9 +73,11 @@ public class CollectionModule extends AbstractModule {
install ( new FactoryModuleBuilder().build( EntityVersionCleanupFactory.class ));
install ( new FactoryModuleBuilder().build( EntityDeletedFactory.class));
+ install ( new FactoryModuleBuilder().build( EntityVersionCreatedFactory.class ));
// users of this module can add their own implemementations
// for more information: https://github.com/google/guice/wiki/Multibindings
+
Multibinder.newSetBinder( binder(), EntityVersionDeleted.class );
Multibinder.newSetBinder( binder(), EntityVersionCreated.class );
Multibinder.newSetBinder( binder(), EntityDeleted.class );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index b1d6b2f..3d33a52 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -91,7 +91,10 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
private final MarkCommit markCommit;
private final TaskExecutor taskExecutor;
- private final EntityVersionCleanupFactory entityVersionCleanupFactory;
+
+ private EntityVersionCleanupFactory entityVersionCleanupFactory;
+ private EntityVersionCreatedFactory entityVersionCreatedFactory;
+
private final MvccLogEntrySerializationStrategy mvccLogEntrySerializationStrategy;
private final MvccEntitySerializationStrategy entitySerializationStrategy;
private final EntityDeletedFactory entityDeletedFactory;
@@ -110,16 +113,19 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
final MarkStart markStart,
final MarkCommit markCommit,
final EntityVersionCleanupFactory entityVersionCleanupFactory,
+ final EntityVersionCreatedFactory entityVersionCreatedFactory,
final MvccEntitySerializationStrategy entitySerializationStrategy,
final UniqueValueSerializationStrategy uniqueValueSerializationStrategy,
final MvccLogEntrySerializationStrategy mvccLogEntrySerializationStrategy,
final EntityDeletedFactory entityDeletedFactory,
@CollectionTaskExecutor final TaskExecutor taskExecutor,
@Assisted final CollectionScope collectionScope
+
) {
this.uniqueValueSerializationStrategy = uniqueValueSerializationStrategy;
this.entitySerializationStrategy = entitySerializationStrategy;
this.entityDeletedFactory = entityDeletedFactory;
+ this.entityVersionCreatedFactory = entityVersionCreatedFactory;
Preconditions.checkNotNull(uuidService, "uuidService must be defined");
@@ -168,13 +174,20 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
observable.map(writeCommit).doOnNext(new Action1<Entity>() {
@Override
public void call(final Entity entity) {
-
- // TODO fire a task here
-
- taskExecutor.submit(entityVersionCleanupFactory.getTask(
- collectionScope, entityId, entity.getVersion() ));
-
- // post-processing to come later. leave it empty for now.
+//<<<<<<< Updated upstream
+//
+// // TODO fire a task here
+//
+// taskExecutor.submit(entityVersionCleanupFactory.getTask(
+// collectionScope, entityId, entity.getVersion() ));
+//
+// // post-processing to come later. leave it empty for now.
+//=======
+ //TODO fire the created task first then the entityVersioncleanup
+ taskExecutor.submit(entityVersionCreatedFactory.getTask(collectionScope,entity));
+ taskExecutor.submit(entityVersionCleanupFactory.getTask(collectionScope, entityId,entity.getVersion()));
+ //post-processing to come later. leave it empty for now.
+//>>>>>>> Stashed changes
}
}).doOnError(rollback);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
new file mode 100644
index 0000000..b78b09c
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTask.java
@@ -0,0 +1,150 @@
+package org.apache.usergrid.persistence.collection.impl;
+
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityVersionCreatedFactory;
+import org.apache.usergrid.persistence.collection.MvccEntity;
+import org.apache.usergrid.persistence.collection.event.EntityDeleted;
+import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
+import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
+import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.impl.UniqueValueImpl;
+import org.apache.usergrid.persistence.core.rx.ObservableIterator;
+import org.apache.usergrid.persistence.core.task.Task;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.field.Field;
+
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
+import rx.Observable;
+import rx.functions.Action1;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+
+/**
+ * Created by ApigeeCorporation on 10/24/14.
+ */
+public class EntityVersionCreatedTask implements Task<Void> {
+ private static final Logger LOG = LoggerFactory.getLogger( EntityVersionCleanupTask.class );
+
+
+ private final Set<EntityVersionCreated> listeners;
+
+ private final MvccLogEntrySerializationStrategy logEntrySerializationStrategy;
+ private final MvccEntitySerializationStrategy entitySerializationStrategy;
+ private UniqueValueSerializationStrategy uniqueValueSerializationStrategy;
+ private final Keyspace keyspace;
+
+ private final SerializationFig serializationFig;
+
+ private final CollectionScope collectionScope;
+ private final Entity entity;
+
+ private EntityVersionCreatedFactory entityVersionCreatedFactory;
+
+
+
+ @Inject
+ public EntityVersionCreatedTask( EntityVersionCreatedFactory entityVersionCreatedFactory,
+ final SerializationFig serializationFig,
+ final MvccLogEntrySerializationStrategy logEntrySerializationStrategy,
+ final MvccEntitySerializationStrategy entitySerializationStrategy,
+ final UniqueValueSerializationStrategy uniqueValueSerializationStrategy,
+ final Keyspace keyspace,
+ @Assisted final CollectionScope collectionScope,
+ final Set<EntityVersionCreated> listeners,
+ @Assisted final Entity entity ) {
+
+ this.entityVersionCreatedFactory = entityVersionCreatedFactory;
+ this.serializationFig = serializationFig;
+ this.logEntrySerializationStrategy = logEntrySerializationStrategy;
+ this.entitySerializationStrategy = entitySerializationStrategy;
+ this.uniqueValueSerializationStrategy = uniqueValueSerializationStrategy;
+ this.keyspace = keyspace;
+ this.listeners = listeners;
+ this.collectionScope = collectionScope;
+ this.entity = entity;
+
+ }
+
+
+ @Override
+ public void exceptionThrown( final Throwable throwable ) {
+ LOG.error( "Unable to run update task for collection {} with entity {} and version {}",
+ new Object[] { collectionScope, entity}, throwable );
+ }
+
+
+ @Override
+ public Void rejected() {
+ //Our task was rejected meaning our queue was full. We need this operation to run,
+ // so we'll run it in our current thread
+ try {
+ call();
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Exception thrown in call task", e );
+ }
+
+ return null;
+ }
+
+ @Override
+ public Void call() throws Exception {
+
+ fireEvents();
+ return null;
+ }
+
+ private void fireEvents() {
+ final int listenerSize = listeners.size();
+
+ if ( listenerSize == 0 ) {
+ return;
+ }
+
+ if ( listenerSize == 1 ) {
+ listeners.iterator().next().versionCreated( collectionScope,entity );
+ return;
+ }
+
+ LOG.debug( "Started firing {} listeners", listenerSize );
+ //if we have more than 1, run them on the rx scheduler for a max of 8 operations at a time
+ Observable.from(listeners)
+ .parallel( new Func1<Observable<EntityVersionCreated
+ >, Observable<EntityVersionCreated>>() {
+
+ @Override
+ public Observable<EntityVersionCreated> call(
+ final Observable<EntityVersionCreated> entityVersionCreatedObservable ) {
+
+ return entityVersionCreatedObservable.doOnNext( new Action1<EntityVersionCreated>() {
+ @Override
+ public void call( final EntityVersionCreated listener ) {
+ listener.versionCreated(collectionScope,entity);
+ }
+ } );
+ }
+ }, Schedulers.io() ).toBlocking().last();
+
+ LOG.debug( "Finished firing {} listeners", listenerSize );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
new file mode 100644
index 0000000..4f1abca
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCreatedTaskTest.java
@@ -0,0 +1,135 @@
+package org.apache.usergrid.persistence.collection.impl;
+
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityVersionCreatedFactory;
+import org.apache.usergrid.persistence.collection.MvccEntity;
+import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
+import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
+import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
+import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.util.LogEntryMock;
+import org.apache.usergrid.persistence.core.task.NamedTaskExecutorImpl;
+import org.apache.usergrid.persistence.core.task.TaskExecutor;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.netflix.astyanax.Keyspace;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
+/**
+ * Created task tests.
+ */
+public class EntityVersionCreatedTaskTest {
+
+ private static final TaskExecutor taskExecutor = new NamedTaskExecutorImpl( "test", 4, 0 );
+
+ @AfterClass
+ public static void shutdown() {
+ taskExecutor.shutdown();
+ }
+
+ @Test(timeout=10000)
+ public void noListener()//why does it matter if it has a version or not without a listener
+ throws ExecutionException, InterruptedException, ConnectionException {
+
+
+ final SerializationFig serializationFig = mock( SerializationFig.class );
+
+ when( serializationFig.getBufferSize() ).thenReturn( 10 );
+
+ final MvccEntitySerializationStrategy ess =
+ mock( MvccEntitySerializationStrategy.class );
+
+ final MvccLogEntrySerializationStrategy less =
+ mock( MvccLogEntrySerializationStrategy.class );
+
+ final Keyspace keyspace = mock( Keyspace.class );
+
+ final MutationBatch entityBatch = mock( MutationBatch.class );
+
+ final MutationBatch logBatch = mock( MutationBatch.class );
+
+ final EntityVersionCreatedFactory entityVersionCreatedFactory = mock(EntityVersionCreatedFactory.class);
+
+ when( keyspace.prepareMutationBatch() )
+ .thenReturn( mock( MutationBatch.class ) ) // don't care what happens to this one
+ .thenReturn( entityBatch )
+ .thenReturn( logBatch );
+
+ // intentionally no events
+ final Set<EntityVersionCreated> listeners = mock( Set.class );//new HashSet<EntityVersionCreated>();
+
+ when ( listeners.size()).thenReturn( 0 );
+
+ final Id applicationId = new SimpleId( "application" );
+
+ final CollectionScope appScope = new CollectionScopeImpl(
+ applicationId, applicationId, "users" );
+
+ final Id entityId = new SimpleId( "user" );
+
+ final Entity entity = new Entity( entityId );
+
+ final MvccEntity mvccEntity = new MvccEntityImpl( entityId, UUIDGenerator.newTimeUUID(),
+ MvccEntity.Status.COMPLETE,entity );
+
+
+ // mock up a single log entry for our first test
+ final LogEntryMock logEntryMock =
+ LogEntryMock.createLogEntryMock(less, appScope, entityId, 2 );
+
+ final UUID version = logEntryMock.getEntries().iterator().next().getVersion();
+
+ final UniqueValueSerializationStrategy uvss =
+ mock( UniqueValueSerializationStrategy.class );
+
+ EntityVersionCreatedTask entityVersionCreatedTask =
+ new EntityVersionCreatedTask(entityVersionCreatedFactory,
+ serializationFig,
+ less,
+ ess,
+ uvss,
+ keyspace,
+ appScope,
+ listeners,
+ entity);
+
+ // start the task
+ ListenableFuture<Void> future = taskExecutor.submit( entityVersionCreatedTask );
+
+ // wait for the task
+ future.get();
+
+ //mocked listener makes sure that the task is called
+ verify( listeners ).size();
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
index 04992e1..bd1ee40 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
@@ -60,11 +60,19 @@ public interface EntityIndexBatch {
* Create a delete method that deletes by Id. This will delete all documents from ES with
* the same entity Id, effectively removing all versions of an entity from all index scopes.
*/
- public EntityIndexBatch deleteEntity( Id entityId );
+ public EntityIndexBatch deleteEntity( Id entityId );
/**
- * Execute the batch
+ * Takes all the previous versions of the current entity and deindexs all previous versions
+ * @param entity
+ * @return
*/
+ public EntityIndexBatch deindexPreviousVersions(Entity entity);
+
+
+ /**
+ * Execute the batch
+ */
public void execute();
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0537e100/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 6b9f481..1fca845 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -30,6 +30,9 @@ import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.client.Client;
+import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.FilteredQueryBuilder;
+import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -211,6 +214,29 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
return this;
}
+ @Override
+ public EntityIndexBatch deindexPreviousVersions(Entity entity){
+
+ FilteredQueryBuilder fqb = QueryBuilders.filteredQuery
+ (QueryBuilders.termQuery
+ ( STRING_PREFIX + ENTITYID_FIELDNAME,entity.getId().getUuid().toString().toLowerCase() ),
+ FilterBuilders.rangeFilter("version").lt( entity.getId().getUuid().timestamp() ));
+
+
+
+ //QueryBuilders.rangeQuery( )
+
+ DeleteByQueryResponse response = client.prepareDeleteByQuery("test")
+ .setQuery( fqb ).execute().actionGet();
+
+ logger.debug("Deleted entity {}:{} from all index scopes with response status = {}",
+ new Object[] { entity.getId().getType(), entity.getId().getUuid(), response.status().toString() });
+
+ maybeFlush();
+
+ return this;
+ }
+
@Override
public void execute() {
[12/12] git commit: Minor refactoring,
renamed our event handlers to use suffix "Handler", fixed some headers,
imports, etc.
Posted by sn...@apache.org.
Minor refactoring, renamed our event handlers to use suffix "Handler", fixed some headers, imports, etc.
This closes #91
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ec0d69aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ec0d69aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ec0d69aa
Branch: refs/heads/two-dot-o-events
Commit: ec0d69aa32d952c80a9152b22fe9f3de2bade08c
Parents: f813136
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Oct 30 09:49:51 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Oct 30 09:49:51 2014 -0400
----------------------------------------------------------------------
.../usergrid/corepersistence/GuiceModule.java | 8 +-
.../events/EntityDeletedHandler.java | 63 +++++++++++++++
.../events/EntityDeletedImpl.java | 64 ---------------
.../events/EntityVersionCreatedHandler.java | 62 +++++++++++++++
.../events/EntityVersionCreatedImpl.java | 49 ------------
.../events/EntityVersionDeletedHandler.java | 84 ++++++++++++++++++++
.../events/EntityVersionDeletedImpl.java | 83 -------------------
.../corepersistence/StaleIndexCleanupTest.java | 14 ++--
.../impl/EntityVersionCleanupTask.java | 2 +-
9 files changed, 222 insertions(+), 207 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
index a11fe8b..21eba41 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
@@ -17,8 +17,8 @@ package org.apache.usergrid.corepersistence;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
-import org.apache.usergrid.corepersistence.events.EntityDeletedImpl;
-import org.apache.usergrid.corepersistence.events.EntityVersionDeletedImpl;
+import org.apache.usergrid.corepersistence.events.EntityDeletedHandler;
+import org.apache.usergrid.corepersistence.events.EntityVersionDeletedHandler;
import org.apache.usergrid.persistence.collection.event.EntityDeleted;
import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
import org.apache.usergrid.persistence.collection.guice.CollectionModule;
@@ -50,11 +50,11 @@ public class GuiceModule extends AbstractModule {
Multibinder<EntityDeleted> entityBinder
= Multibinder.newSetBinder(binder(), EntityDeleted.class);
- entityBinder.addBinding().to(EntityDeletedImpl.class);
+ entityBinder.addBinding().to(EntityDeletedHandler.class);
Multibinder<EntityVersionDeleted> versionBinder
= Multibinder.newSetBinder(binder(), EntityVersionDeleted.class);
- versionBinder.addBinding().to(EntityVersionDeletedImpl.class);
+ versionBinder.addBinding().to(EntityVersionDeletedHandler.class);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
new file mode 100644
index 0000000..b5cb1ff
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
@@ -0,0 +1,63 @@
+/*
+ * 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.corepersistence.events;
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.event.EntityDeleted;
+import org.apache.usergrid.persistence.index.EntityIndexBatch;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import java.util.UUID;
+import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Delete all Query Index indexes associated with an Entity that has just been deleted.
+ */
+public class EntityDeletedHandler implements EntityDeleted {
+ private static final Logger logger = LoggerFactory.getLogger(EntityDeletedHandler.class );
+
+
+ public EntityDeletedHandler() {
+ logger.debug("Created");
+ }
+
+ @Override
+ public void deleted(CollectionScope scope, Id entityId, UUID version) {
+
+ logger.debug("Entering deleted for entity {}:{} v {} "
+ + "scope\n name: {}\n owner: {}\n app: {}",
+ new Object[] { entityId.getType(), entityId.getUuid(), version,
+ scope.getName(), scope.getOwner(), scope.getApplication()});
+
+ HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
+ CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
+
+ final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
+
+ EntityIndexBatch batch = ei.createBatch();
+
+ batch.deleteEntity( entityId );
+ batch.execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
deleted file mode 100644
index 925e01d..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
+++ /dev/null
@@ -1,64 +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.corepersistence.events;
-
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.event.EntityDeleted;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-import java.util.UUID;
-import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
-import org.apache.usergrid.corepersistence.CpSetup;
-import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Delete all Query Index indexes associated with an Entity that has just been deleted.
- */
-public class EntityDeletedImpl implements EntityDeleted {
- private static final Logger logger = LoggerFactory.getLogger( EntityDeletedImpl.class );
-
-
- public EntityDeletedImpl() {
- logger.debug("Created");
- }
-
- @Override
- public void deleted(CollectionScope scope, Id entityId, UUID version) {
-
- logger.debug("Entering deleted for entity {}:{} v {} "
- + "scope\n name: {}\n owner: {}\n app: {}",
- new Object[] { entityId.getType(), entityId.getUuid(), version,
- scope.getName(), scope.getOwner(), scope.getApplication()});
-
- HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
- CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
-
- final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
-
- EntityIndexBatch batch = ei.createBatch();
-
- batch.deleteEntity( entityId );
- batch.execute();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java
new file mode 100644
index 0000000..64d1125
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java
@@ -0,0 +1,62 @@
+/*
+ * 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.corepersistence.events;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.index.EntityIndexBatch;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+
+/**
+ * Clean up stale entity indexes when new version of Entity created. Called when an Entity is
+ * updated by the Collections module and we react by calling the Query Index module and removing
+ * any indexes that exist for previous versions of the the Entity.
+ */
+public class EntityVersionCreatedHandler implements EntityVersionCreated {
+
+ private static final Logger logger = LoggerFactory.getLogger(EntityVersionCreatedHandler.class );
+
+ public EntityVersionCreatedHandler() {
+ logger.debug("EntityVersionCreated");
+ }
+
+ @Override
+ public void versionCreated( final CollectionScope scope, final Entity entity ) {
+ logger.debug("Entering deleted for entity {}:{} v {} "
+ + "scope\n name: {}\n owner: {}\n app: {}",
+ new Object[] { entity.getId().getType(), entity.getId().getUuid(), entity.getVersion(),
+ scope.getName(), scope.getOwner(), scope.getApplication()});
+
+ HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
+ CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
+
+ final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
+
+ EntityIndexBatch batch = ei.createBatch();
+
+ batch.deindexPreviousVersions( entity );
+ batch.execute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
deleted file mode 100644
index c7aada7..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedImpl.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.apache.usergrid.corepersistence.events;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.corepersistence.CpEntityManager;
-import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
-import org.apache.usergrid.corepersistence.CpSetup;
-import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
-import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.model.entity.Entity;
-
-
-/**
- * Created by ApigeeCorporation on 10/24/14.
- */
-public class EntityVersionCreatedImpl implements EntityVersionCreated{
-
- private static final Logger logger = LoggerFactory.getLogger( EntityVersionCreatedImpl.class );
-
- public EntityVersionCreatedImpl() {
- logger.debug("EntityVersionCreated");
- }
-
- @Override
- public void versionCreated( final CollectionScope scope, final Entity entity ) {
- logger.debug("Entering deleted for entity {}:{} v {} "
- + "scope\n name: {}\n owner: {}\n app: {}",
- new Object[] { entity.getId().getType(), entity.getId().getUuid(), entity.getVersion(),
- scope.getName(), scope.getOwner(), scope.getApplication()});
-
- HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
- CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
-
- final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
-
- EntityIndexBatch batch = ei.createBatch();
-
- batch.deindexPreviousVersions( entity );
- batch.execute();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
new file mode 100644
index 0000000..046e9c2
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
@@ -0,0 +1,84 @@
+/*
+ * 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.corepersistence.events;
+
+import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.MvccEntity;
+import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
+import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.index.EntityIndexBatch;
+import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+import java.util.List;
+
+import com.google.inject.Inject;
+import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
+
+
+/**
+ * Remove Entity index when specific version of Entity is deleted.
+ * TODO: do we need this? Don't our version-created and entity-deleted handlers take care of this?
+ * If we do need it then it should be wired in via GuiceModule in the corepersistence package.
+ */
+public class EntityVersionDeletedHandler implements EntityVersionDeleted {
+
+ private final SerializationFig serializationFig;
+
+ @Inject
+ public EntityVersionDeletedHandler(SerializationFig fig) {
+ this.serializationFig = fig;
+ }
+
+ @Override
+ public void versionDeleted(
+ final CollectionScope scope, final Id entityId, final List<MvccEntity> entityVersions) {
+
+ HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
+ CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
+
+ final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
+
+ final EntityIndexBatch eibatch = ei.createBatch();
+
+ final IndexScope indexScope = new IndexScopeImpl(
+ new SimpleId(scope.getOwner().getUuid(), scope.getOwner().getType()),
+ scope.getName()
+ );
+ rx.Observable.from(entityVersions)
+ .subscribeOn(Schedulers.io())
+ .buffer(serializationFig.getBufferSize())
+ .map(new Func1<List<MvccEntity>, List<MvccEntity>>() {
+ @Override
+ public List<MvccEntity> call(List<MvccEntity> entityList) {
+ for (MvccEntity entity : entityList) {
+ eibatch.deindex(indexScope, entityId, entity.getVersion());
+ }
+ eibatch.execute();
+ return entityList;
+ }
+ }).toBlocking().last();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedImpl.java
deleted file mode 100644
index fb52573..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedImpl.java
+++ /dev/null
@@ -1,83 +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.corepersistence.events;
-
-import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
-import org.apache.usergrid.corepersistence.CpSetup;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.MvccEntity;
-import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
-import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import rx.functions.Func1;
-import rx.schedulers.Schedulers;
-
-import java.util.List;
-
-import com.google.inject.Inject;
-import org.apache.usergrid.corepersistence.HybridEntityManagerFactory;
-
-
-/**
- * Purge old entity versions
- */
-public class EntityVersionDeletedImpl implements EntityVersionDeleted {
-
- private final SerializationFig serializationFig;
-
- @Inject
- public EntityVersionDeletedImpl(SerializationFig fig) {
- this.serializationFig = fig;
- }
-
- @Override
- public void versionDeleted(
- final CollectionScope scope, final Id entityId, final List<MvccEntity> entityVersions) {
-
- HybridEntityManagerFactory hemf = (HybridEntityManagerFactory)CpSetup.getEntityManagerFactory();
- CpEntityManagerFactory cpemf = (CpEntityManagerFactory)hemf.getImplementation();
-
- final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope);
-
- final EntityIndexBatch eibatch = ei.createBatch();
-
- final IndexScope indexScope = new IndexScopeImpl(
- new SimpleId(scope.getOwner().getUuid(), scope.getOwner().getType()),
- scope.getName()
- );
- rx.Observable.from(entityVersions)
- .subscribeOn(Schedulers.io())
- .buffer(serializationFig.getBufferSize())
- .map(new Func1<List<MvccEntity>, List<MvccEntity>>() {
- @Override
- public List<MvccEntity> call(List<MvccEntity> entityList) {
- for (MvccEntity entity : entityList) {
- eibatch.deindex(indexScope, entityId, entity.getVersion());
- }
- eibatch.execute();
- return entityList;
- }
- }).toBlocking().last();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
index c4b362d..d828733 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
@@ -1,17 +1,19 @@
/*
- * 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.
+ * 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
+ * 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.
+ * 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.corepersistence;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec0d69aa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupTask.java
index d45eeb9..d4bf6e6 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupTask.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupTask.java
@@ -1,6 +1,6 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. The ASF licenses this file to You
+ * 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