usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject usergrid git commit: move delete call into resource
Date Thu, 03 Sep 2015 20:49:10 GMT
Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-938 10149d740 -> 657dad3ed


move delete call into resource


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/657dad3e
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/657dad3e
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/657dad3e

Branch: refs/heads/USERGRID-938
Commit: 657dad3ed5da8f185c939165d68083d7d14edc80
Parents: 10149d7
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Thu Sep 3 14:49:04 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Thu Sep 3 14:49:04 2015 -0600

----------------------------------------------------------------------
 .../service/ApplicationServiceImpl.java         | 17 +++-
 .../java/org/apache/usergrid/Application.java   |  7 ++
 .../org/apache/usergrid/CoreApplication.java    |  4 +
 .../java/org/apache/usergrid/CoreITSetup.java   |  3 +
 .../org/apache/usergrid/CoreITSetupImpl.java    |  6 ++
 .../persistence/ApplicationServiceIT.java       | 61 +++++++++++++
 .../usergrid/rest/ApplicationsResource.java     | 93 ++++++++++++++++++++
 .../apache/usergrid/rest/SystemResource.java    | 38 ++------
 8 files changed, 193 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
index 72dd677..07f7c13 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/ApplicationServiceImpl.java
@@ -19,10 +19,14 @@
  */
 package org.apache.usergrid.corepersistence.service;
 
+import com.google.inject.Inject;
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
 import org.apache.usergrid.corepersistence.asyncevents.EventBuilder;
 import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.model.entity.Id;
 import rx.Observable;
@@ -33,12 +37,15 @@ import rx.Observable;
 public class ApplicationServiceImpl  implements ApplicationService{
 
     private final AllEntityIdsObservable allEntityIdsObservable;
+    private final EntityCollectionManagerFactory entityCollectionManagerFactory;
     private final AsyncEventService asyncEventService;
     private final EventBuilder eventBuilder;
 
-    public ApplicationServiceImpl(AllEntityIdsObservable allEntityIdsObservable, AsyncEventService
asyncEventService, EventBuilder eventBuilder){
+    @Inject
+    public ApplicationServiceImpl(AllEntityIdsObservable allEntityIdsObservable, EntityCollectionManagerFactory
entityCollectionManagerFactory, AsyncEventService asyncEventService, EventBuilder eventBuilder){
 
         this.allEntityIdsObservable = allEntityIdsObservable;
+        this.entityCollectionManagerFactory = entityCollectionManagerFactory;
         this.asyncEventService = asyncEventService;
         this.eventBuilder = eventBuilder;
     }
@@ -50,12 +57,16 @@ public class ApplicationServiceImpl  implements ApplicationService{
 
         //EventBuilder eventBuilder = injector.getInstance(EventBuilder.class);
         Observable appObservable  = Observable.just(applicationScope);
+        EntityCollectionManager entityCollectionManager = entityCollectionManagerFactory.createCollectionManager(applicationScope);
 
 
         Observable<Id> countObservable = allEntityIdsObservable.getEntities(appObservable)
             //.map(entity -> eventBuilder.buildEntityDelete(applicationScope, entity.getId()).getEntitiesCompacted())
-            .doOnNext(entity -> asyncEventService.queueEntityDelete(applicationScope,
entity.getId()))
-            .map(entityIdScope -> entityIdScope.getId());
+            .map(entityIdScope -> ((EntityIdScope) entityIdScope).getId())
+            .doOnNext(id ->
+                    entityCollectionManager.mark((Id) id)
+                        .doOnNext(id2 -> asyncEventService.queueEntityDelete(applicationScope,
(Id) id2))
+            );
         return countObservable;
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/core/src/test/java/org/apache/usergrid/Application.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/Application.java b/stack/core/src/test/java/org/apache/usergrid/Application.java
index 56028bb..378a4f7 100644
--- a/stack/core/src/test/java/org/apache/usergrid/Application.java
+++ b/stack/core/src/test/java/org/apache/usergrid/Application.java
@@ -20,6 +20,7 @@ package org.apache.usergrid;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.usergrid.corepersistence.service.ApplicationService;
 import org.junit.rules.TestRule;
 
 import org.apache.usergrid.persistence.Entity;
@@ -158,4 +159,10 @@ public interface Application extends TestRule {
      * @return
      */
     public EntityManager getEntityManager();
+
+    /**
+     * get application service
+     * @return
+     */
+    ApplicationService getApplicationService();
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index 465d238..f152389 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ExecutionException;
 
 import com.google.inject.Injector;
 import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory;
+import org.apache.usergrid.corepersistence.service.ApplicationService;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.index.*;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -244,4 +245,7 @@ public class CoreApplication implements Application, TestRule {
     public EntityManager getEntityManager() {
         return em;
     }
+
+    @Override
+    public ApplicationService getApplicationService(){ return setup.getApplicationService();}
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
index 6da0515..7a0ebae 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
@@ -20,6 +20,7 @@ package org.apache.usergrid;
 import java.util.UUID;
 
 import com.google.inject.Injector;
+import org.apache.usergrid.corepersistence.service.ApplicationService;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.junit.rules.TestRule;
 
@@ -44,4 +45,6 @@ public interface CoreITSetup extends TestRule {
     Injector getInjector();
 
     TestEntityIndex getEntityIndex();
+
+    ApplicationService getApplicationService();
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
index 30e8b35..d2129a4 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@ -19,6 +19,7 @@ package org.apache.usergrid;
 
 import com.google.inject.Injector;
 import org.apache.usergrid.cassandra.SpringResource;
+import org.apache.usergrid.corepersistence.service.ApplicationService;
 import org.apache.usergrid.mq.QueueManagerFactory;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityManagerFactory;
@@ -113,6 +114,11 @@ public class CoreITSetupImpl implements CoreITSetup, TestEntityIndex
{
          return qmf;
     }
 
+    @Override
+    public ApplicationService getApplicationService(){
+        return injector.getInstance(ApplicationService.class);
+    }
+
 
     @Override
     public CassandraService getCassSvc() {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
new file mode 100644
index 0000000..5274987
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/ApplicationServiceIT.java
@@ -0,0 +1,61 @@
+/*
+ *
+ *  * 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.persistence;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * testy test
+ */
+public class ApplicationServiceIT extends AbstractCoreIT {
+    private static final Logger LOG = LoggerFactory.getLogger(ApplicationServiceIT.class);
+
+
+    public ApplicationServiceIT() {
+        super();
+    }
+
+    @Test
+    public void testDeletes() throws Exception{
+        EntityManager entityManager = this.app.getEntityManager();
+        Map<String,Object> map = new HashMap<>();
+        Entity entity = entityManager.create("tests", map);
+        this.app.refreshIndex();
+        Thread.sleep(500);
+        Observable<Id> ids =
+            this.app.getApplicationService().deleteAllEntities(CpNamingUtils.getApplicationScope(entityManager.getApplicationId()));
+        ids.toBlocking().last();
+        this.app.refreshIndex();
+        Thread.sleep(500);
+        entity = entityManager.get(entity);
+        Assert.assertNull(entity);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java
new file mode 100644
index 0000000..4504387
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/ApplicationsResource.java
@@ -0,0 +1,93 @@
+/*
+ *
+ *  * 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.rest;
+
+import com.sun.jersey.api.json.JSONWithPadding;
+import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Classy class class.
+ */
+@Component
+@Scope( "singleton" )
+@Produces( {
+    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
+    "application/ecmascript", "text/jscript"
+} )
+public class ApplicationsResource extends AbstractContextResource {
+
+    private static final Logger logger = LoggerFactory.getLogger(ApplicationsResource.class);
+
+
+    public ApplicationsResource() {
+
+        logger.info( "ApplicationsResource initialized" );
+    } {
+
+    }
+
+    @RequireSystemAccess
+    @DELETE
+    @Path( "{applicationId}" )
+    public JSONWithPadding clearApplication( @Context UriInfo ui,
+                                             @PathParam("applicationId") UUID applicationId,
+                                             @QueryParam( "confirmApplicationId" ) UUID confirmApplicationId,
+                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
+
+        if(confirmApplicationId == null || !confirmApplicationId.equals(applicationId)){
+            throw new IllegalArgumentException("please make confirmApplicationId equal to
applicationId");
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "clear application" );
+
+        logger.info( "clearing up application" );
+        AtomicInteger itemsDeleted = new AtomicInteger(0);
+        try {
+            management.deleteAllEntities(applicationId)
+                .count()
+                .doOnNext(count -> itemsDeleted.set(count))
+                .toBlocking().lastOrDefault(0);
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to delete all items, deleted: " + itemsDeleted.get(), e
);
+        }
+        Map<String,Object> data = new HashMap<>();
+        data.put("count",itemsDeleted.get());
+        response.setData(data);
+        response.setSuccess();
+        return new JSONWithPadding( response, callback );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/657dad3e/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
index 20f0fa4..f266441 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
@@ -79,39 +79,6 @@ public class SystemResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
-    @RequireSystemAccess
-    @DELETE
-    @Path( "applications/{applicationId}" )
-    public JSONWithPadding clearApplication( @Context UriInfo ui,
-                                               @PathParam("applicationId") UUID applicationId,
-                                               @QueryParam( "confirmApplicationId" ) UUID
confirmApplicationId,
-                                              @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-        throws Exception {
-
-        if(confirmApplicationId == null || !confirmApplicationId.equals(applicationId)){
-            throw new IllegalArgumentException("please make confirmApplicationId equal to
applicationId");
-        }
-
-        ApiResponse response = createApiResponse();
-        response.setAction( "clear application" );
-
-        logger.info( "clearing up application" );
-        AtomicInteger itemsDeleted = new AtomicInteger(0);
-        try {
-             management.deleteAllEntities(applicationId)
-             .count()
-             .doOnNext(count -> itemsDeleted.set(count))
-             .toBlocking().lastOrDefault(0);
-        }
-        catch ( Exception e ) {
-            logger.error( "Unable to delete all items, deleted: " + itemsDeleted.get(), e
);
-        }
-        Map<String,Object> data = new HashMap<>();
-        data.put("count",itemsDeleted.get());
-        response.setData(data);
-        response.setSuccess();
-        return new JSONWithPadding( response, callback );
-    }
 
 
     @Path( "migrate" )
@@ -128,4 +95,9 @@ public class SystemResource extends AbstractContextResource {
     public DatabaseResource database() {
         return getSubResource( DatabaseResource.class );
     }
+
+    @Path( "applications" )
+    public ApplicationsResource applications() {
+        return getSubResource( ApplicationsResource.class );
+    }
 }


Mime
View raw message