usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [08/14] incubator-usergrid git commit: adding async events
Date Tue, 14 Jul 2015 17:10:13 GMT
adding async 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/09873cec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/09873cec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/09873cec

Branch: refs/heads/observable-query-fix
Commit: 09873cec76ac5f11cef8e5cf39c870e823693619
Parents: a63c817
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Mon Jul 13 14:58:01 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Mon Jul 13 14:58:01 2015 -0600

----------------------------------------------------------------------
 .../asyncevents/AmazonAsyncEventService.java    |  11 +-
 .../asyncevents/AsyncEventService.java          |   1 +
 .../asyncevents/model/AsyncEvent.java           |  15 ++-
 .../model/InitializeApplicationIndexEvent.java  |   5 +-
 .../index/ReplicatedIndexLocationStrategy.java  | 103 +++++++++++++++++++
 5 files changed, 124 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09873cec/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
index 50000df..1390058 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
@@ -29,7 +29,7 @@ import com.codahale.metrics.Histogram;
 import com.google.common.base.Preconditions;
 import org.apache.usergrid.corepersistence.CpEntityManager;
 import org.apache.usergrid.corepersistence.asyncevents.model.*;
-import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory;
+import org.apache.usergrid.corepersistence.index.*;
 import org.apache.usergrid.corepersistence.rx.impl.EdgeScope;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
@@ -38,9 +38,6 @@ import org.apache.usergrid.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.usergrid.corepersistence.index.EntityIndexOperation;
-import org.apache.usergrid.corepersistence.index.IndexProcessorFig;
-import org.apache.usergrid.corepersistence.index.IndexService;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
@@ -255,7 +252,8 @@ public class AmazonAsyncEventService implements AsyncEventService {
 
     @Override
     public void queueInitializeApplicationIndex( final ApplicationScope applicationScope)
{
-        offer(new InitializeApplicationIndexEvent(applicationScope));
+        IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
+        offer(new InitializeApplicationIndexEvent(new ReplicatedIndexLocationStrategy(indexLocationStrategy)));
     }
 
 
@@ -379,8 +377,7 @@ public class AmazonAsyncEventService implements AsyncEventService {
         Preconditions.checkNotNull(message, "QueueMessage Body cannot be null for handleInitializeApplicationIndex");
         Preconditions.checkArgument(event.getEventType() == AsyncEvent.EventType.APPLICATION_INDEX,
String.format("Event Type for handleInitializeApplicationIndex must be APPLICATION_INDEX,
got %s", event.getEventType()));
 
-        final ApplicationScope applicationScope = event.getApplicationScope();
-        final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
+        final IndexLocationStrategy indexLocationStrategy = event.getIndexLocationStrategy();
         final EntityIndex index = entityIndexFactory.createEntityIndex(indexLocationStrategy);
         index.initialize();
         ack(message);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09873cec/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AsyncEventService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AsyncEventService.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AsyncEventService.java
index a36a9ae..1a5e865 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AsyncEventService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AsyncEventService.java
@@ -22,6 +22,7 @@ package org.apache.usergrid.corepersistence.asyncevents;
 
 import org.apache.usergrid.corepersistence.index.ReIndexAction;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.index.IndexLocationStrategy;
 import org.apache.usergrid.persistence.model.entity.Entity;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09873cec/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/AsyncEvent.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/AsyncEvent.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/AsyncEvent.java
index 9278e0f..3fabc1c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/AsyncEvent.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/AsyncEvent.java
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
 import org.apache.usergrid.persistence.model.entity.Id;
 
 import java.io.Serializable;
@@ -37,6 +38,9 @@ import java.io.Serializable;
 public class AsyncEvent implements Serializable {
 
     @JsonProperty
+    protected IndexLocationStrategy indexLocationStrategy;
+
+    @JsonProperty
     protected EventType eventType;
 
     @JsonProperty
@@ -75,9 +79,9 @@ public class AsyncEvent implements Serializable {
         this.creationTime = System.currentTimeMillis();
     }
 
-    public AsyncEvent(EventType eventType, ApplicationScope applicationScope) {
+    public AsyncEvent(EventType eventType, IndexLocationStrategy indexLocationStrategy) {
         this.eventType = eventType;
-        this.applicationScope = applicationScope;
+        this.indexLocationStrategy = indexLocationStrategy;
         this.creationTime = System.currentTimeMillis();
     }
 
@@ -132,6 +136,13 @@ public class AsyncEvent implements Serializable {
         this.applicationScope = applicationScope;
     }
 
+    @JsonSerialize
+    public IndexLocationStrategy getIndexLocationStrategy() { return indexLocationStrategy;
}
+
+    public void setIndexLocationStrategy( IndexLocationStrategy indexLocationStrategy ){
+        this.indexLocationStrategy = indexLocationStrategy;
+    }
+
     @JsonSerialize()
     public Edge getEdge() {
         return edge;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09873cec/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/InitializeApplicationIndexEvent.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/InitializeApplicationIndexEvent.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/InitializeApplicationIndexEvent.java
index 656d820..8b20651 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/InitializeApplicationIndexEvent.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/model/InitializeApplicationIndexEvent.java
@@ -21,6 +21,7 @@ package org.apache.usergrid.corepersistence.asyncevents.model;
 
 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
 
 /**
  * event to init app index
@@ -30,8 +31,8 @@ public class InitializeApplicationIndexEvent extends AsyncEvent {
     public InitializeApplicationIndexEvent() {
         super(EventType.APPLICATION_INDEX);
     }
-    public InitializeApplicationIndexEvent(final ApplicationScope applicationScope) {
-        super(EventType.APPLICATION_INDEX, applicationScope);
+    public InitializeApplicationIndexEvent(final IndexLocationStrategy indexLocationStrategy)
{
+        super(EventType.APPLICATION_INDEX, indexLocationStrategy);
 
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09873cec/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReplicatedIndexLocationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReplicatedIndexLocationStrategy.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReplicatedIndexLocationStrategy.java
new file mode 100644
index 0000000..b404a78
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReplicatedIndexLocationStrategy.java
@@ -0,0 +1,103 @@
+/*
+ *
+ *  * 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.index;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.index.IndexAlias;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
+
+/**
+ * Classy class class.
+ */
+public class ReplicatedIndexLocationStrategy implements IndexLocationStrategy {
+
+    private ReplicatedIndexAlias alias;
+    private String rootName;
+    private String indexInitialName;
+    private ApplicationScope applicationScope;
+    private int numberShards;
+    private int numberReplicas;
+
+    public ReplicatedIndexLocationStrategy(){
+
+    }
+
+    public ReplicatedIndexLocationStrategy(IndexLocationStrategy indexLocationStrategy){
+        alias = new ReplicatedIndexAlias( indexLocationStrategy.getAlias() );
+        rootName = indexLocationStrategy.getIndexRootName();
+        indexInitialName = indexLocationStrategy.getIndexInitialName();
+        applicationScope = indexLocationStrategy.getApplicationScope();
+        numberShards = indexLocationStrategy.getNumberOfShards();
+        numberReplicas = indexLocationStrategy.getNumberOfReplicas();
+    }
+
+    @Override
+    public IndexAlias getAlias() {
+        return alias;
+    }
+
+    @Override
+    public String getIndexRootName() {
+        return rootName;
+    }
+
+    @Override
+    public String getIndexInitialName() {
+        return indexInitialName;
+    }
+
+    @Override
+    public ApplicationScope getApplicationScope() {
+        return applicationScope;
+    }
+
+    @Override
+    public int getNumberOfShards() {
+        return numberShards;
+    }
+
+    @Override
+    public int getNumberOfReplicas() {
+        return numberReplicas;
+    }
+
+    public static class ReplicatedIndexAlias implements IndexAlias{
+
+        private String readAlias;
+        private String writeAlias;
+
+        public ReplicatedIndexAlias(){
+
+        }
+        public ReplicatedIndexAlias(IndexAlias alias){
+            this.readAlias = alias.getReadAlias();
+            this.writeAlias = alias.getWriteAlias();
+        }
+        @Override
+        public String getReadAlias() {
+            return readAlias;
+        }
+
+        @Override
+        public String getWriteAlias() {
+            return writeAlias;
+        }
+    }
+}


Mime
View raw message