You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/11/12 20:05:25 UTC
usergrid git commit: fix alias issues
Repository: usergrid
Updated Branches:
refs/heads/USERGRID-1104 [created] fec6520eb
fix alias issues
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/fec6520e
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/fec6520e
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/fec6520e
Branch: refs/heads/USERGRID-1104
Commit: fec6520eb47fa6fe7bc1d8d7fad6a729874f3475
Parents: 204bf04
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Nov 12 11:07:29 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Nov 12 11:47:08 2015 -0700
----------------------------------------------------------------------
.../asyncevents/AmazonAsyncEventService.java | 15 ++++++++
.../index/impl/DeIndexOperation.java | 4 +--
.../persistence/index/impl/IndexingUtils.java | 21 ++++++++++++
.../index/impl/IndexingUtilsTest.java | 36 ++++++++++++++++++++
4 files changed, 74 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/fec6520e/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 16e119c..77777c2 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
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.usergrid.persistence.index.impl.IndexingUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -550,6 +551,7 @@ public class AmazonAsyncEventService implements AsyncEventService {
indexOperationMessage = ObjectJsonSerializer.INSTANCE.fromString( message, IndexOperationMessage.class );
}
+ checkInitialize(indexOperationMessage);
//NOTE that we intentionally do NOT delete from the map. We can't know when all regions have consumed the message
//so we'll let compaction on column expiration handle deletion
@@ -565,6 +567,19 @@ public class AmazonAsyncEventService implements AsyncEventService {
}
+ private void checkInitialize(final IndexOperationMessage indexOperationMessage) {
+ indexOperationMessage.getIndexRequests().stream().forEach(req -> {
+ UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId);
+ ApplicationScope appScope = CpNamingUtils.getApplicationScope(appId);
+ entityIndexFactory.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(appScope));
+ });
+
+ indexOperationMessage.getDeIndexRequests().stream().forEach(req -> {
+ UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId);
+ ApplicationScope appScope = CpNamingUtils.getApplicationScope(appId);
+ entityIndexFactory.createEntityIndex(indexLocationStrategyFactory.getIndexLocationStrategy(appScope));
+ });
+ }
@Override
http://git-wip-us.apache.org/repos/asf/usergrid/blob/fec6520e/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexOperation.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexOperation.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexOperation.java
index dbecf8a..aefceda 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexOperation.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/DeIndexOperation.java
@@ -44,10 +44,10 @@ import static org.apache.usergrid.persistence.index.impl.IndexingUtils.createInd
public class DeIndexOperation implements BatchOperation {
@JsonProperty
- private String[] indexes;
+ public String[] indexes;
@JsonProperty
- private String documentId;
+ public String documentId;
public DeIndexOperation() {
http://git-wip-us.apache.org/repos/asf/usergrid/blob/fec6520e/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
index 18cb928..179b3c4 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
@@ -244,6 +244,23 @@ public class IndexingUtils {
return new CandidateResult( entityId, UUID.fromString( versionUUID ), documentId );
}
+ /**
+ * Parse the document id into a candidate result
+ */
+ public static UUID parseAppIdFromIndexDocId( final String documentId) {
+
+ final Matcher matcher = DOCUMENT_PATTERN.matcher(documentId);
+
+ Preconditions.checkArgument(matcher.matches(), "Pattern for document id did not match expected format");
+ Preconditions.checkArgument(matcher.groupCount() == 9, "9 groups expected in the pattern");
+
+ //Other fields can be parsed using groups. The groups start at value 1, group 0 is the entire match
+ final String appUUID = matcher.group(1);
+
+ return UUID.fromString(appUUID);
+
+ }
+
/**
* Get the entity type
@@ -262,4 +279,8 @@ public class IndexingUtils {
sb.append( ENTITY_TYPE_NAME).append("(" ).append( type ).append( ")" );
return sb.toString();
}
+
+ public static UUID getApplicationIdFromIndexDocId(String documentId) {
+ return parseAppIdFromIndexDocId(documentId);
+ }
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/fec6520e/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexingUtilsTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexingUtilsTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexingUtilsTest.java
index 97389b2..d93f8a3 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexingUtilsTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexingUtilsTest.java
@@ -31,6 +31,7 @@ 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 static org.apache.usergrid.persistence.index.impl.IndexingUtils.parseAppIdFromIndexDocId;
import static org.apache.usergrid.persistence.index.impl.IndexingUtils.parseIndexDocId;
import static org.junit.Assert.assertEquals;
@@ -91,6 +92,41 @@ public class IndexingUtilsTest {
@Test
+ public void testAppIdFromDocumentId() {
+
+ final ApplicationScopeImpl applicationScope = new ApplicationScopeImpl( new SimpleId( "application" ) );
+
+ final Id id = new SimpleId( "id" );
+ final UUID version = UUIDGenerator.newTimeUUID();
+
+ final SearchEdgeImpl searchEdge =
+ new SearchEdgeImpl( new SimpleId( "source" ), "users", SearchEdge.NodeType.TARGET );
+
+ final String output = IndexingUtils.createIndexDocId( applicationScope, id, version, searchEdge );
+
+
+ final String expected =
+ "appId(" + applicationScope.getApplication().getUuid() + ",application).entityId(" + id.getUuid() + "," + id
+ .getType() + ").version(" + version + ").nodeId(" + searchEdge.getNodeId().getUuid() + "," + searchEdge
+ .getNodeId().getType() + ").edgeName(users).nodeType(TARGET)";
+
+
+ assertEquals( output, expected );
+
+
+ //now parse it
+
+ final CandidateResult parsedId = parseIndexDocId( output );
+
+ assertEquals(version, parsedId.getVersion());
+ assertEquals(id, parsedId.getId());
+
+ final UUID appId = parseAppIdFromIndexDocId(output);
+ assertEquals(appId,applicationScope.getApplication().getUuid());
+ }
+
+
+ @Test
public void testDocumentIdPipes() {
final ApplicationScopeImpl applicationScope = new ApplicationScopeImpl( new SimpleId( "application" ) );