usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [1/2] usergrid git commit: delete collections via API, currently uses utility queue
Date Fri, 07 Jul 2017 15:04:30 GMT
Repository: usergrid
Updated Branches:
  refs/heads/collectionDelete [created] 7d3eb647d


http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Application.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Application.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Application.java
index 790b4d9..0a4360f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Application.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Application.java
@@ -48,6 +48,32 @@ public class Application extends TypedEntity implements Serializable {
 
     public static final String COLLECTION_ACTIVITIES = "activities";
 
+    public static final String COLLECTION_EVENTS = "events";
+
+    public static final String COLLECTION_FOLDERS = "folders";
+
+    public static final String COLLECTION_DEVICES = "devices";
+
+    public static final String COLLECTION_NOTIFICATIONS = "notifications";
+
+    public static final String COLLECTION_ROLES = "roles";
+
+    public static boolean isCustomCollectionName(String collectionName) {
+        switch (collectionName.toLowerCase()) {
+            case COLLECTION_USERS:
+            case COLLECTION_GROUPS:
+            case COLLECTION_ASSETS:
+            case COLLECTION_ACTIVITIES:
+            case COLLECTION_EVENTS:
+            case COLLECTION_FOLDERS:
+            case COLLECTION_DEVICES:
+            case COLLECTION_NOTIFICATIONS:
+            case COLLECTION_ROLES:
+                return false;
+        }
+        return true;
+    }
+
     @EntityProperty(indexed = true, fulltextIndexed = false, required = true, mutable = false,
aliasProperty = true,
             basic = true)
     protected String name;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/core/src/main/java/org/apache/usergrid/utils/InflectionUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/utils/InflectionUtils.java b/stack/core/src/main/java/org/apache/usergrid/utils/InflectionUtils.java
index 72b9207..dde2f4f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/utils/InflectionUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/utils/InflectionUtils.java
@@ -17,25 +17,59 @@
 package org.apache.usergrid.utils;
 
 
+import org.apache.usergrid.corepersistence.index.CollectionVersionUtil;
+import org.apache.usergrid.corepersistence.index.VersionedCollectionName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class InflectionUtils {
 
+    private static final Logger logger = LoggerFactory.getLogger(InflectionUtils.class );
+
+    private static VersionedCollectionName parseName(Object word) {
+        String name = word.toString().trim();
+        try {
+            return CollectionVersionUtil.parseVersionedName(name);
+        }
+        catch (Exception e) {
+            logger.error("parseName(): failed to parse the versioned name: {}", name);
+            return CollectionVersionUtil.createVersionedName(name, "");
+        }
+    }
+
+    private static String getVersionedName(String name, String version) {
+        try {
+            return CollectionVersionUtil.buildVersionedNameString(name, version, true);
+        }
+        catch (Exception e) {
+            // if versioned invalid, return name
+            return name;
+        }
+    }
+
     public static String pluralize( Object word ) {
-        return Inflector.INSTANCE.pluralize( word );
+        VersionedCollectionName name = parseName(word);
+        String pluralizedName = Inflector.INSTANCE.pluralize(name.getCollectionName());
+        return getVersionedName(pluralizedName, name.getCollectionVersion());
     }
 
 
     public static String singularize( Object word ) {
-        return Inflector.INSTANCE.singularize( word );
+        VersionedCollectionName name = parseName(word);
+        String singuralizedName = Inflector.INSTANCE.singularize(name.getCollectionName());
+        return getVersionedName(singuralizedName, name.getCollectionVersion());
     }
 
 
     public static boolean isPlural( Object word ) {
-        return Inflector.INSTANCE.isPlural( word );
+        VersionedCollectionName name = parseName(word);
+        return Inflector.INSTANCE.isPlural( name.getCollectionName() );
     }
 
 
     public static boolean isSingular( Object word ) {
-        return Inflector.INSTANCE.isSingular( word );
+        VersionedCollectionName name = parseName(word);
+        return Inflector.INSTANCE.isSingular( name.getCollectionName() );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
index 55ce26e..7a82513 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
@@ -29,6 +29,8 @@ import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.junit.Assert;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -37,8 +39,13 @@ import java.util.Map;
  * Classy class class.
  */
 public class AggregationServiceTest extends AbstractCoreIT {
+
+    private static final Logger logger = LoggerFactory.getLogger( AggregationServiceTest.class
);
+
+
     @Test
     public void testEntitySize() throws Exception {
+        logger.info("appId={}", this.app.getId());
         ApplicationScope applicationScope = CpNamingUtils.getApplicationScope(this.app.getId());
         Injector injector = SpringResource.getInstance().getBean(Injector.class);
         AggregationServiceFactory factory = injector.getInstance(AggregationServiceFactory.class);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncEventServiceImplTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncEventServiceImplTest.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncEventServiceImplTest.java
index 92b5983..c9bba02 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncEventServiceImplTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncEventServiceImplTest.java
@@ -26,6 +26,7 @@ import org.apache.usergrid.corepersistence.TestIndexModule;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventServiceImpl;
 import org.apache.usergrid.corepersistence.asyncevents.EventBuilder;
+import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
 import org.apache.usergrid.persistence.core.aws.NoAWSCredsRule;
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
 import org.apache.usergrid.persistence.core.rx.RxTaskScheduler;
@@ -84,9 +85,15 @@ public class AsyncEventServiceImplTest extends AsyncIndexServiceTest {
     @Inject
     public EntityIndexFactory entityIndexFactory;
 
+    @Inject
+    public CollectionVersionFig collectionVersionFig;
+
+    @Inject
+    public AllEntityIdsObservable allEntityIdsObservable;
+
     @Override
     protected AsyncEventService getAsyncEventService() {
-        return  new AsyncEventServiceImpl( queueManagerFactory, indexProcessorFig, indexProducer,
metricsFactory,  entityCollectionManagerFactory, indexLocationStrategyFactory, entityIndexFactory,
eventBuilder, mapManagerFactory, queueFig,  rxTaskScheduler );
+        return  new AsyncEventServiceImpl( queueManagerFactory, indexProcessorFig, indexProducer,
metricsFactory,  entityCollectionManagerFactory, indexLocationStrategyFactory, entityIndexFactory,
eventBuilder, mapManagerFactory, queueFig, collectionVersionFig, allEntityIdsObservable, rxTaskScheduler
);
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/CollectionVersionTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/CollectionVersionTest.java
b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/CollectionVersionTest.java
new file mode 100644
index 0000000..0278708
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/CollectionVersionTest.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.usergrid.corepersistence.index;
+
+public class CollectionVersionTest {
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/core/src/test/java/org/apache/usergrid/persistence/RebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/RebuildIndexTest.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/RebuildIndexTest.java
index a7759de..281f2af 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/RebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/RebuildIndexTest.java
@@ -178,7 +178,10 @@ public class RebuildIndexTest extends AbstractCoreIT {
         logger.info( "Started rebuildIndex()" );
 
         String rand = RandomStringUtils.randomAlphanumeric( 5 );
-        final UUID appId = setup.createApplication( "org_" + rand, "app_" + rand );
+        String orgName = "org_" + rand;
+        String appName = "app_" + rand;
+        final UUID appId = setup.createApplication(orgName,appName);
+        logger.info("orgName={} appName={} appId={}", orgName, appName, appId.toString());
 
         final EntityManager em = setup.getEmf().getEntityManager( appId );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
index b8c1caa..0ab0661 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
@@ -31,6 +31,9 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.usergrid.persistence.entities.Application;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
@@ -48,6 +51,8 @@ import org.apache.usergrid.services.ServicePayload;
 
 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
 
+import java.util.UUID;
+
 
 /**
  * A collection resource that stands before the Service Resource. If it cannot find
@@ -61,10 +66,63 @@ import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
 })
 public class CollectionResource extends ServiceResource {
 
+    private static final Logger logger = LoggerFactory.getLogger(CollectionResource.class);
+
+    public static final String CONFIRM_COLLECTION_NAME = "confirm_collection_name";
+
     public CollectionResource() {
     }
 
 
+    @POST
+    @Path("{itemName}/clear")
+    @Produces({MediaType.APPLICATION_JSON, "application/javascript"})
+    @RequireApplicationAccess
+    public ApiResponse executeClearCollection(
+        @Context UriInfo ui,
+        @PathParam("itemName") PathSegment itemName,
+        @QueryParam(CONFIRM_COLLECTION_NAME) String confirmCollectionName) throws Exception
{
+
+        if (logger.isTraceEnabled()){
+            logger.trace( "CollectionResource.executeDeleteOnCollection" );
+        }
+
+        if (!Application.isCustomCollectionName(itemName.toString())) {
+            throw new IllegalArgumentException(
+                "Cannot clear built-in collections (" + itemName + ")."
+            );
+        }
+
+        if (!itemName.toString().equals(confirmCollectionName)) {
+            throw new IllegalArgumentException(
+                "Cannot delete collection without supplying correct collection name in query
parameter " + CONFIRM_COLLECTION_NAME
+            );
+        }
+
+        addItemToServiceContext( ui, itemName );
+
+        UUID applicationId = getApplicationId();
+
+        emf.getEntityManager(applicationId).deleteCollection(itemName.toString());
+
+        if (logger.isTraceEnabled()) {
+            logger.trace("CollectionResource.executeDeleteOnCollection() deleted, appId={}
collection={}",
+                applicationId, itemName);
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction("delete");
+        response.setApplication(emf.getEntityManager( applicationId ).getApplication());
+        response.setParams(ui.getQueryParameters());
+
+        if (logger.isTraceEnabled()) {
+            logger.trace("CollectionResource.executeDeleteOnCollection() sending response");
+        }
+
+        return response;
+
+    }
+
     /**
      * POST settings for a collection.
      *

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
index 9373f5e..14ed54f 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
@@ -22,6 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
 import com.google.cloud.storage.StorageException;
 import org.apache.commons.lang.StringUtils;
+import org.apache.usergrid.corepersistence.index.CollectionVersionUtil;
+import org.apache.usergrid.corepersistence.index.VersionedCollectionName;
 import org.apache.usergrid.management.OrganizationConfig;
 import org.apache.usergrid.management.OrganizationConfigProps;
 import org.apache.usergrid.persistence.Entity;
@@ -415,6 +417,8 @@ public class ServiceResource extends AbstractContextResource {
                 response.setCount( results.size() );
             }
 
+            stripCollectionVersionsFromTypes(results);
+
             response.setResults( results );
         }
 
@@ -423,6 +427,17 @@ public class ServiceResource extends AbstractContextResource {
         return results;
     }
 
+    private void stripCollectionVersionsFromTypes(ServiceResults r) {
+        for (int i = 0; i < r.getEntities().size(); i++) {
+            Entity e = r.getEntity(i);
+            String oldType = e.getType();
+            VersionedCollectionName v = CollectionVersionUtil.parseVersionedName(oldType);
+            if (v.hasVersion()) {
+                e.setType(v.getCollectionName());
+                r.setEntity(i, e);
+            }
+        }
+    }
 
     @CheckPermissionsForPath
     @GET

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/CollectionDeleteTooSoonExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/CollectionDeleteTooSoonExceptionMapper.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/CollectionDeleteTooSoonExceptionMapper.java
new file mode 100644
index 0000000..3b247df
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/CollectionDeleteTooSoonExceptionMapper.java
@@ -0,0 +1,44 @@
+/*
+ * 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.rest.exceptions;
+
+
+import org.apache.usergrid.corepersistence.asyncevents.CollectionDeleteTooSoonException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+
+
+@Provider
+public class CollectionDeleteTooSoonExceptionMapper extends AbstractExceptionMapper<CollectionDeleteTooSoonException>
{
+
+    private static final Logger logger = LoggerFactory.getLogger(CollectionDeleteTooSoonExceptionMapper.class);
+
+    @Override
+    public Response toResponse( CollectionDeleteTooSoonException e ) {
+
+        if(logger.isTraceEnabled()) {
+            logger.trace("Tried to delete collection too soon after previous deletion", e.getMessage());
+        }
+
+        return toResponse( BAD_REQUEST, e );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/services/src/main/java/org/apache/usergrid/services/ServiceInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceInfo.java b/stack/services/src/main/java/org/apache/usergrid/services/ServiceInfo.java
index 4f6ce2f..2c5e527 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceInfo.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceInfo.java
@@ -83,6 +83,18 @@ public class ServiceInfo {
         hashCode = hasher.hash().asInt();
     }
 
+    // returns a copy of supplied ServiceInfo, with updated collectionName and itemType
+    public ServiceInfo( ServiceInfo info, String collectionName, String itemType ) {
+        this.name = info.name;
+        this.rootService = info.rootService;
+        this.rootType = info.rootType;
+        this.containerType = info.containerType;
+        this.collectionName = collectionName;
+        this.itemType = itemType;
+        this.patterns = new ArrayList<>(info.patterns);
+        this.collections = new ArrayList<>(info.collections);
+    }
+
 
     public static String normalizeServicePattern( String s ) {
         if ( s == null ) {
@@ -363,6 +375,11 @@ public class ServiceInfo {
         return info;
     }
 
+    public static ServiceInfo getVersionedServiceInfo( ServiceInfo origInfo, String collectionName,
String itemType ) {
+        // this is not cached
+        return new ServiceInfo(origInfo, collectionName, itemType);
+    }
+
 
     public String getClassName() {
         return getClassName( name );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
index 075278f..711a86c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManager.java
@@ -22,6 +22,10 @@ import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.usergrid.corepersistence.index.CollectionScopeImpl;
+import org.apache.usergrid.corepersistence.index.CollectionVersionManager;
+import org.apache.usergrid.corepersistence.index.CollectionVersionManagerFactory;
+import org.apache.usergrid.corepersistence.index.CollectionVersionUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
@@ -77,6 +81,8 @@ public class ServiceManager {
     private ServiceManagerFactory smf;
     private QueueManager qm;
 
+    private CollectionVersionManagerFactory cvmf;
+
     private Properties properties;
 
     // search for commercial packages first for SaaS version
@@ -89,11 +95,12 @@ public class ServiceManager {
     }
 
 
-    public ServiceManager init( ServiceManagerFactory smf, EntityManager em, Properties properties,
QueueManager qm ) {
+    public ServiceManager init( ServiceManagerFactory smf, EntityManager em, Properties properties,
QueueManager qm, CollectionVersionManagerFactory cvmf) {
         this.smf = smf;
         this.em = em;
         this.qm = qm;
         this.properties = properties;
+        this.cvmf = cvmf;
 
         // additional logging to help debug https://issues.apache.org/jira/browse/USERGRID-1291
         if ( em == null ) {
@@ -102,6 +109,9 @@ public class ServiceManager {
         if ( qm == null ) {
             logger.error("QueueManager is null");
         }
+        if ( cvmf == null ) {
+            logger.error("CollectionVersionManagerFactory is null");
+        }
 
         if ( em != null ) {
             try {
@@ -180,6 +190,9 @@ public class ServiceManager {
 
 
     public Entity importEntity( ServiceRequest request, Entity entity ) throws Exception
{
+        if (logger.isTraceEnabled()) {
+            logger.trace("importEntity: entity.type=", entity.getType());
+        }
         Service service = getEntityService( entity.getType() );
         if ( service != null ) {
             return service.importEntity( request, entity );
@@ -189,6 +202,9 @@ public class ServiceManager {
 
 
     public Entity writeEntity( ServiceRequest request, Entity entity ) throws Exception {
+        if (logger.isTraceEnabled()) {
+            logger.trace("writeEntity: entity.type=", entity.getType());
+        }
         Service service = getEntityService( entity.getType() );
         if ( service != null ) {
             return service.writeEntity( request, entity );
@@ -198,6 +214,9 @@ public class ServiceManager {
 
 
     public Entity updateEntity( ServiceRequest request, EntityRef ref, ServicePayload payload
) throws Exception {
+        if (logger.isTraceEnabled()) {
+            logger.trace("writeEntity: entity.type=", ref.getType());
+        }
         Service service = getEntityService( ref.getType() );
         if ( service != null ) {
             return service.updateEntity( request, ref, payload );
@@ -227,6 +246,34 @@ public class ServiceManager {
             return null;
         }
 
+        // use versionedCollectionName if appropriate
+        String versionedCollectionName = info.getCollectionName();
+        String unversionedCollectionName = CollectionVersionUtil.getBaseCollectionName(versionedCollectionName);
+        if (logger.isTraceEnabled()) {
+            logger.trace("getService: serviceType={} incoming collectionName={}", serviceType,
versionedCollectionName);
+        }
+
+        // if versioned collection name was passed in, use it, because it may be for an old
version
+        if (versionedCollectionName.equals(unversionedCollectionName)) {
+            // no version passed in
+            CollectionVersionManager collectionVersionManager = cvmf.getInstance(new CollectionScopeImpl(applicationId,
unversionedCollectionName));
+            // always bypass collection version cache for now
+            String currentCollectionVersion = collectionVersionManager.getCollectionVersion(true);
+
+            if (currentCollectionVersion != "") {
+                if (logger.isTraceEnabled()) {
+                    logger.trace("getService: currentCollectionVersion={}", currentCollectionVersion);
+                }
+                versionedCollectionName = CollectionVersionUtil.buildVersionedNameString(unversionedCollectionName,
currentCollectionVersion, false);
+                String versionedItemType = CollectionVersionUtil.buildVersionedNameString(info.getItemType(),
currentCollectionVersion, false);
+                if (logger.isTraceEnabled()) {
+                    logger.trace("getService() - using versioned collection name: collectionName={}
versionedCollectionName={} versionedItemType={}",
+                        unversionedCollectionName, versionedCollectionName, versionedItemType);
+                }
+                info = ServiceInfo.getVersionedServiceInfo(info, versionedCollectionName,
versionedItemType);
+            }
+        }
+
         Service service = getServiceInstance( info );
 
         if ( service != null ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
index 2425b95..1cc4751 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceManagerFactory.java
@@ -22,7 +22,7 @@ import java.util.Properties;
 import java.util.UUID;
 
 import com.google.inject.Injector;
-import org.apache.usergrid.locking.Lock;
+import org.apache.usergrid.corepersistence.index.CollectionVersionManagerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
@@ -46,6 +46,7 @@ public class ServiceManagerFactory implements ApplicationContextAware {
     private SchedulerService schedulerService;
     private LockManager lockManager;
     private QueueManagerFactory qmf;
+    private CollectionVersionManagerFactory cvmf;
 
     private List<ServiceExecutionEventListener> eventListeners;
     private List<ServiceCollectionEventListener> collectionListeners;
@@ -58,6 +59,7 @@ public class ServiceManagerFactory implements ApplicationContextAware {
         this.schedulerService = schedulerService;
         lockManager = injector.getInstance(LockManager.class);
         this.qmf = qmf;
+        this.cvmf = injector.getInstance(CollectionVersionManagerFactory.class);
     }
 
 
@@ -80,7 +82,7 @@ public class ServiceManagerFactory implements ApplicationContextAware {
             qm = qmf.getQueueManager( applicationId );
         }
         ServiceManager sm = new ServiceManager();
-        sm.init( this, em, properties, qm );
+        sm.init( this, em, properties, qm, cvmf);
         return sm;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/services/src/test/java/org/apache/usergrid/services/ActivitiesServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ActivitiesServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/ActivitiesServiceIT.java
index c4762f2..b654b5f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ActivitiesServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ActivitiesServiceIT.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.services;
 
 
+import net.jcip.annotations.NotThreadSafe;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -29,6 +30,7 @@ import static org.junit.Assert.assertNotNull;
 
 
 
+@NotThreadSafe
 public class ActivitiesServiceIT extends AbstractServiceIT {
     @SuppressWarnings("unused")
     private static final Logger LOG = LoggerFactory.getLogger( ActivitiesServiceIT.class
);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7d3eb647/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
index 62818c2..abc4897 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/CollectionServiceIT.java
@@ -28,6 +28,8 @@ import org.apache.usergrid.persistence.exceptions.UnexpectedEntityTypeException;
 import org.apache.usergrid.persistence.schema.CollectionInfo;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
 
+import java.util.UUID;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -244,7 +246,9 @@ public class CollectionServiceIT extends AbstractServiceIT {
 
         // TODO: This test cannot be supported with Core Persistence
         // try PUT on cats with a new UUID
-        final String catsUuid = "99999990-600c-11e2-b414-14109fd49581";
+        //final String catsUuid = "99999990-600c-11e2-b414-14109fd49581";
+        final String catsUuidStr = "99999990-600c-11e2-b414-14109fd49581";
+        final UUID catsUuid = UUID.fromString(catsUuidStr);
         ServiceResults results = app.testRequest( ServiceAction.PUT, 1, "cats", catsUuid
);
         Entity entity = results.getEntity();
         //Assert.assertEquals( entity.getUuid().toString(), catsUuid );


Mime
View raw message