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/04/08 22:40:33 UTC
[1/8] incubator-usergrid git commit: fixed migration logic
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o-dev 38ff124b2 -> 0fcdd2794
fixed migration logic
fixed migration logic
fixed migration logic
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a62091df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a62091df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a62091df
Branch: refs/heads/two-dot-o-dev
Commit: a62091dfb0e17ca535b93a48bbe2e32fb28e4f0a
Parents: 15db4e8
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 09:30:48 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 10:11:12 2015 -0600
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 139 +++++-----
.../migration/AppInfoMigrationPlugin.java | 252 ++++++++-----------
.../persistence/EntityManagerFactory.java | 71 ++++--
.../cassandra/EntityManagerFactoryImpl.java | 12 +
.../migration/AppInfoMigrationPluginTest.java | 11 +-
5 files changed, 235 insertions(+), 250 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a62091df/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 3700003..ce036f5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -24,14 +24,12 @@ import com.google.inject.TypeLiteral;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.usergrid.persistence.graph.impl.SimpleEdge;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
@@ -68,16 +66,9 @@ 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 org.apache.usergrid.utils.UUIDUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
import rx.Observable;
-import rx.observables.BlockingObservable;
import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static org.apache.usergrid.persistence.Schema.*;
@@ -245,7 +236,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// Ensure our management system exists before creating our application
init();
- EntityManager managementEm = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ EntityManager managementEm = getEntityManager( getManagementAppId() );
final String appName = buildAppName( organizationName, name );
@@ -303,41 +294,66 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public void deleteApplication(UUID applicationId) throws Exception {
// find application_info for application to delete
+ String collectionFromName = CpNamingUtils.APPLICATION_INFO;
+ String collectionToName = CpNamingUtils.DELETED_APPLICATION_INFO;
+ migrateAppInfo(applicationId, collectionFromName, collectionToName).toBlocking()
+ .lastOrDefault(null);
+ }
+ @Override
+ public Entity restoreApplication(UUID applicationId) throws Exception {
+
+ // get the deleted_application_info for the deleted app
+
+ final EntityManager managementEm = getEntityManager(getManagementAppId());
+
+ migrateAppInfo(applicationId,CpNamingUtils.DELETED_APPLICATION_INFO,CpNamingUtils.APPLICATION_INFO)
+ .toBlocking().lastOrDefault(null);
+
+ this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
+ @Override
+ public void onProgress(EntityRef entity) {
+ logger.info("Restored entity {}:{}", entity.getType(), entity.getUuid());
+ }
+ });
+
+ return managementEm.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO,applicationId));
+ }
+
+ @Override
+ public Observable migrateAppInfo(UUID applicationUUID, String collectionFromName, String collectionToName) throws Exception {
+
+ final ApplicationScope managementAppScope = CpNamingUtils.getApplicationScope(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
final EntityManager managementEm = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- final Application app = managementEm.getApplication();
- final Id managementAppId = new SimpleId(app.getUuid(), app.getType());
- final ApplicationScope managementAppScope = new ApplicationScopeImpl(managementAppId);
- final GraphManager managementGraphManager = managerCache.getGraphManager(managementAppScope);
- final Id deletedAppId = new SimpleId(applicationId, CpNamingUtils.APPLICATION_INFO);
- final ApplicationScope deletedAppScope = new ApplicationScopeImpl(deletedAppId);
- Entity appInfoToDelete = managementEm.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+ final Id applicationId = new SimpleId(applicationUUID, collectionFromName);
+ final ApplicationScope applicationScope = new ApplicationScopeImpl(applicationId);
+
+ Entity oldAppEntity = managementEm.get(new SimpleEntityRef(collectionFromName, applicationUUID));
Observable copyConnections = Observable.empty();
- if(appInfoToDelete!=null) {
+ if(oldAppEntity!=null) {
// ensure that there is not already a deleted app with the same name
- final EntityRef alias = managementEm.getAlias(
- CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName());
+ final EntityRef alias = managementEm.getAlias(collectionToName, oldAppEntity.getName());
if (alias != null) {
throw new ConflictException("Cannot delete app with same name as already deleted app");
}
// make a copy of the app to delete application_info entity
// and put it in a deleted_application_info collection
- final Entity deletedApp = managementEm.create(new SimpleId(appInfoToDelete.getUuid(),
- CpNamingUtils.DELETED_APPLICATION_INFO), appInfoToDelete.getProperties());
+ final Entity newAppEntity = managementEm.create(new SimpleId(applicationUUID,
+ collectionToName), oldAppEntity.getProperties());
// copy its connections too
- final Set<String> connectionTypes = managementEm.getConnectionTypes(appInfoToDelete);
+ final Set<String> connectionTypes = managementEm.getConnectionTypes(oldAppEntity);
copyConnections = Observable.from(connectionTypes).doOnNext(connType -> {
try {
final Results connResults =
- managementEm.getConnectedEntities(appInfoToDelete, connType, null, Query.Level.ALL_PROPERTIES);
+ managementEm.getConnectedEntities(oldAppEntity, connType, null, Query.Level.ALL_PROPERTIES);
connResults.getEntities().forEach(entity -> {
try {
- managementEm.createConnection(deletedApp, connType, entity);
+ managementEm.createConnection(newAppEntity, connType, entity);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -347,67 +363,23 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
});
}
- final ApplicationEntityIndex aei = entityIndexFactory.createApplicationEntityIndex(deletedAppScope);
- final Observable deleteNodeGraph = managementGraphManager.deleteNode(deletedAppId, Long.MAX_VALUE);
+ final ApplicationEntityIndex aei = entityIndexFactory.createApplicationEntityIndex(applicationScope);
+ final GraphManager managementGraphManager = managerCache.getGraphManager(managementAppScope);
+ final Observable deleteNodeGraph = managementGraphManager.deleteNode(applicationId, Long.MAX_VALUE);
final Observable deleteAppFromIndex = aei.deleteApplication();
- Observable.concat(copyConnections, deleteNodeGraph, deleteAppFromIndex)
+ return Observable.concat(copyConnections, deleteNodeGraph, deleteAppFromIndex)
.doOnCompleted(() -> {
try {
- managementEm.delete(appInfoToDelete);
- applicationIdCache.evictAppId(appInfoToDelete.getName());
+ if (oldAppEntity != null) {
+ managementEm.delete(oldAppEntity);
+ applicationIdCache.evictAppId(oldAppEntity.getName());
+ entityIndex.refresh();
+ }
} catch (Exception e) {
throw new RuntimeException(e);
}
- }).toBlocking().lastOrDefault(null);
-
- }
-
-
- @Override
- public Entity restoreApplication(UUID applicationId) throws Exception {
-
- // get the deleted_application_info for the deleted app
-
- final EntityManager managementEm = getEntityManager(getManagementAppId());
-
- final Entity deletedAppInfo = managementEm.get(new SimpleEntityRef(CpNamingUtils.DELETED_APPLICATION_INFO,applicationId));
-
- if ( deletedAppInfo == null ) {
- throw new EntityNotFoundException("Cannot restore. Deleted Application not found: " + applicationId );
- }
-
-
- // create application_info for restored app
-
- Entity restoredAppInfo = managementEm.create(new SimpleId( deletedAppInfo.getUuid(),CpNamingUtils.APPLICATION_INFO)
- , deletedAppInfo.getProperties());
-
- // copy connections from deleted app entity
-
- final Set<String> connectionTypes = managementEm.getConnectionTypes(deletedAppInfo);
- for ( String connType : connectionTypes ) {
- final Results connResults =
- managementEm.getConnectedEntities(deletedAppInfo, connType, null, Query.Level.ALL_PROPERTIES);
- for ( Entity entity : connResults.getEntities() ) {
- managementEm.createConnection( restoredAppInfo, connType, entity );
- }
- }
-
- // delete the deleted app entity rebuild the app index
- managementEm.delete(deletedAppInfo);
-
- entityIndex.refresh();
-
- this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
- @Override
- public void onProgress(EntityRef entity) {
- logger.info("Restored entity {}:{}", entity.getType(), entity.getUuid());
- }
- });
- applicationIdCache.evictAppId(restoredAppInfo.getName());
-
- return restoredAppInfo;
+ });
}
@@ -536,7 +508,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public boolean updateServiceProperties(Map<String, String> properties) {
EntityManager em = getEntityManager(getManagementAppId());
- Query q = Query.fromQL( "select *");
+ Query q = Query.fromQL("select *");
Results results = null;
try {
results = em.searchCollection( em.getApplicationRef(), "propertymaps", q);
@@ -558,7 +530,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// intentionally going only one-level deep into fields and treating all
// values as strings because that is all we need for service properties
for ( String key : properties.keySet() ) {
- propsEntity.setProperty( key, properties.get(key).toString() );
+ propsEntity.setProperty(key, properties.get(key).toString());
}
try {
@@ -647,6 +619,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
return CpNamingUtils.MANAGEMENT_APPLICATION_ID;
}
+ @Override
+ public EntityManager getManagementEntityManager() {
+ return getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ }
+
/**
* Gets the setup.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a62091df/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
index 53ffe79..92c8895 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
@@ -36,7 +36,6 @@ import org.apache.usergrid.persistence.graph.GraphManager;
import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.graph.SearchByEdgeType;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
-import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.model.entity.*;
import org.apache.usergrid.utils.UUIDUtils;
import org.slf4j.Logger;
@@ -45,7 +44,6 @@ import rx.Observable;
import rx.functions.Func1;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
@@ -99,7 +97,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
@Override
public int getMaxVersion() {
- return 1; // standalone plugin, happens once
+ return 2; // standalone plugin, happens once
}
@@ -112,153 +110,123 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
@Override
public void run(ProgressObserver observer) {
- final int version = migrationInfoSerialization.getVersion( getName() );
+ final int version = migrationInfoSerialization.getVersion(getName());
- if ( version == getMaxVersion() ) {
+ if (version == getMaxVersion()) {
logger.debug("Skipping Migration Plugin: " + getName());
return;
}
-
observer.start();
-
- // Get appinfos from the Graph, we don't expect many so use iterator
-
- final Iterator<org.apache.usergrid.persistence.model.entity.Entity> iterator =
- getOldAppInfos().toBlocking().getIterator();
-
- if ( iterator.hasNext() ) {
-
- // we found appinfos, now migrate them to application_infos in the Management App
-
- final EntityManager em = emf.getEntityManager( emf.getManagementAppId());
-
- String currentAppName = null;
- try {
- logger.info("Migrating old appinfos");
-
- while ( iterator.hasNext() ) {
-
- Map oldAppInfo = CpEntityMapUtils.toMap( iterator.next() );
- currentAppName = (String)oldAppInfo.get( PROPERTY_NAME );
-
- migragrateOneAppInfo(em, oldAppInfo, observer);
+ //get old app infos to migrate
+ final Observable<org.apache.usergrid.persistence.model.entity.Entity> oldAppInfos = getOldAppInfos();
+ oldAppInfos
+ .doOnNext(oldAppInfoEntity -> {
+ try {
+ migrateAppInfo( oldAppInfoEntity, observer);
+ }catch (Exception e){
+ logger.error("Failed to migrate app info"+oldAppInfoEntity.getId().getUuid(),e);
+ throw new RuntimeException(e);
}
- // note that the old appinfos are not deleted
+ })
+ .doOnCompleted(() -> {
+ migrationInfoSerialization.setVersion(getName(), getMaxVersion());
+ observer.complete();
+ }).toBlocking().lastOrDefault(null);
- migrationInfoSerialization.setVersion( getName(), getMaxVersion() );
-
- } catch (Exception e) {
+ }
- // stop on any exception and return failure
- String msg = "Exception writing application_info for " + currentAppName;
- logger.error(msg, e);
- observer.failed( getMaxVersion(), msg);
+ private void migrateAppInfo( org.apache.usergrid.persistence.model.entity.Entity oldAppInfoEntity, ProgressObserver observer) {
+ // Get appinfos from the Graph, we don't expect many so use iterator
+ final EntityManager managementEm = emf.getManagementEntityManager();
+
+ Map oldAppInfoMap = CpEntityMapUtils.toMap(oldAppInfoEntity);
+
+ final String name = (String) oldAppInfoMap.get(PROPERTY_NAME);
+
+ try {
+ final String orgName = name.split("/")[0];
+ final String appName = name.split("/")[1];
+ UUID applicationId = getUuid(oldAppInfoMap,"applicationUuid");
+ UUID originalUuid = getUuid(oldAppInfoMap,"uuid");
+
+ //get app info from graph to see if it has been migrated already
+ Entity appInfo = getApplicationInfo(applicationId);
+ if (appInfo == null) {
+ // create and connect new APPLICATION_INFO oldAppInfo to Organization
+ appInfo = createNewAppInfo(managementEm, name, applicationId);
+ deleteOldAppInfo(originalUuid);
+ observer.update(getMaxVersion(), "Created application_info for " + appName);
+ // create org->app connections, but not for apps in dummy "usergrid" internal organization
+ if (!orgName.equals("usergrid")) {
+ EntityRef orgRef = managementEm.getAlias(Group.ENTITY_TYPE, orgName);
+ managementEm.createConnection(orgRef, "owns", appInfo);
+ }
+ } else {
+ //already migrated don't do anything
+ observer.update(getMaxVersion(), "Received existing application_info for " + appName + " don't do anything");
}
- } else {
- logger.info("No old appinfos found, no need for migration");
+ } catch (Exception e) {
+ String msg = "Exception writing application_info for " + name;
+ logger.error(msg, e);
+ observer.failed(getMaxVersion(), msg);
+ throw new RuntimeException(e);
}
- observer.complete();
-
}
-
- private void migragrateOneAppInfo(
- EntityManager em, Map oldAppInfo, ProgressObserver observer) throws Exception {
-
- final String name = (String)oldAppInfo.get( PROPERTY_NAME );
- final String orgName = name.split("/")[0];
- final String appName = name.split("/")[1];
-
+ private UUID getUuid(Map oldAppInfoMap, String key) {
UUID applicationId;
-
- Object uuidObject = oldAppInfo.get("applicationUuid");
+ Object uuidObject = oldAppInfoMap.get(key);
if (uuidObject instanceof UUID) {
applicationId = (UUID) uuidObject;
} else {
applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
}
+ return applicationId;
+ }
- // create and connect new APPLICATION_INFO oldAppInfo to Organization
-
- final UUID appId = applicationId;
-
- Entity appInfo = getApplicationInfo( emf, appId );
- if ( appInfo == null ) {
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put(PROPERTY_NAME, name);
- put(PROPERTY_APPLICATION_ID, appId);
- }};
- appInfo = em.create(appId, CpNamingUtils.APPLICATION_INFO, appInfoMap);
- observer.update( getMaxVersion(), "Created application_info for " + appName);
-
- } else {
- appInfo.setProperty(PROPERTY_APPLICATION_ID, appId);
- em.update(appInfo);
- observer.update( getMaxVersion(), "Updated existing application_info for " + appName);
- }
-
- // create org->app connections, but not for apps in dummy "usergrid" internal organization
+ private Entity createNewAppInfo(EntityManager managementEm, final String name, final UUID applicationId) throws Exception {
+ Entity appInfo;Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
+ put(PROPERTY_NAME, name);
+ put(PROPERTY_APPLICATION_ID, applicationId);
+ }};
+ appInfo = managementEm.create(new SimpleId(applicationId, CpNamingUtils.APPLICATION_INFO), appInfoMap);
+ return appInfo;
+ }
- if ( !orgName.equals("usergrid") ) {
- EntityRef orgRef = em.getAlias(Group.ENTITY_TYPE, orgName );
- em.createConnection(orgRef, "owns", appInfo);
- }
+ private void deleteOldAppInfo(UUID uuid) {
+ final ApplicationScope systemAppScope = getApplicationScope(CpNamingUtils.SYSTEM_APP_ID );
+ final EntityCollectionManager systemCollectionManager =
+ entityCollectionManagerFactory.createCollectionManager( systemAppScope );
+ systemCollectionManager.delete(new SimpleId(uuid, "appinfos")).toBlocking().last();
}
/**
* TODO: Use Graph to get application_info for an specified Application.
*/
- private Entity getApplicationInfo( final EntityManagerFactory emf, final UUID appId ) throws Exception {
-
- final ApplicationScope appScope = getApplicationScope( emf.getManagementAppId() );
-
- final EntityCollectionManager collectionManager =
- entityCollectionManagerFactory.createCollectionManager( appScope );
-
- final GraphManager gm = graphManagerFactory.createEdgeManager(appScope);
-
- String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS );
+ private Entity getApplicationInfo( final UUID appId ) throws Exception {
- Id rootAppId = appScope.getApplication();
-
- final SimpleSearchByEdgeType simpleSearchByEdgeType = new SimpleSearchByEdgeType(
- rootAppId, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null);
-
- // TODO: is there a better way?
+ final ApplicationScope managementAppScope = getApplicationScope(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ final EntityCollectionManager managementCollectionManager = entityCollectionManagerFactory.createCollectionManager(managementAppScope);
+ Observable<Edge> edgesObservable = getApplicationInfoEdges();
+ //get the graph for all app infos
Observable<org.apache.usergrid.persistence.model.entity.Entity> entityObs =
- gm.loadEdgesFromSource( simpleSearchByEdgeType )
- .flatMap(new Func1<Edge, Observable<org.apache.usergrid.persistence.model.entity.Entity>>() {
-
- @Override
- public Observable<org.apache.usergrid.persistence.model.entity.Entity> call(final Edge edge) {
-
- final Id appInfoId = edge.getTargetNode();
-
- return collectionManager.load(appInfoId)
- .filter(new Func1<org.apache.usergrid.persistence.model.entity.Entity, Boolean>() {
- @Override
- public Boolean call(final org.apache.usergrid.persistence.model.entity.Entity entity) {
- if (entity == null) {
- logger.warn("Encountered a null application info for id {}", appInfoId);
- return false;
- }
- if ( entity.getId().getUuid().equals( appId )) {
- return true;
- }
- return false;
- }
- });
- }
+ edgesObservable.flatMap(edge -> {
+ final Id appInfoId = edge.getTargetNode();
+ return managementCollectionManager
+ .load(appInfoId)
+ .filter( entity ->{
+ //check for app id
+ return entity != null ? entity.getId().getUuid().equals(appId) : false;
+ });
});
// don't expect many applications, so we block
-
org.apache.usergrid.persistence.model.entity.Entity applicationInfo =
entityObs.toBlocking().lastOrDefault(null);
@@ -275,14 +243,6 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
return entity;
-// UUID mgmtAppId = emf.getManagementAppId();
-// EntityManager rootEm = emf.getEntityManager( mgmtAppId );
-//
-// final Results applicationInfoResults = rootEm.searchCollection(
-// new SimpleEntityRef("application", mgmtAppId), "application_infos",
-// Query.fromQL("select * where applicationId=" + appId.toString()));
-//
-// return applicationInfoResults.getEntity();
}
@@ -291,43 +251,43 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
*/
public Observable<org.apache.usergrid.persistence.model.entity.Entity> getOldAppInfos( ) {
- final ApplicationScope appScope = getApplicationScope( CpNamingUtils.SYSTEM_APP_ID );
+ final ApplicationScope systemAppScope = getApplicationScope(CpNamingUtils.SYSTEM_APP_ID);
- final EntityCollectionManager collectionManager =
- entityCollectionManagerFactory.createCollectionManager( appScope );
+ final EntityCollectionManager systemCollectionManager =
+ entityCollectionManagerFactory.createCollectionManager(systemAppScope);
- final GraphManager gm = graphManagerFactory.createEdgeManager(appScope);
+ final GraphManager gm = graphManagerFactory.createEdgeManager(systemAppScope);
- String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( "appinfos" );
+ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName("appinfos");
- Id rootAppId = appScope.getApplication();
+ Id rootAppId = systemAppScope.getApplication();
final SimpleSearchByEdgeType simpleSearchByEdgeType = new SimpleSearchByEdgeType(
rootAppId, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null);
Observable<org.apache.usergrid.persistence.model.entity.Entity> entityObs =
gm.loadEdgesFromSource( simpleSearchByEdgeType )
- .flatMap(new Func1<Edge, Observable<org.apache.usergrid.persistence.model.entity.Entity>>() {
+ .flatMap(edge -> {
+ final Id appInfoId = edge.getTargetNode();
- @Override
- public Observable<org.apache.usergrid.persistence.model.entity.Entity> call(final Edge edge) {
-
- final Id appInfoId = edge.getTargetNode();
-
- return collectionManager.load(appInfoId)
- .filter(new Func1<org.apache.usergrid.persistence.model.entity.Entity, Boolean>() {
- @Override
- public Boolean call(final org.apache.usergrid.persistence.model.entity.Entity entity) {
- if (entity == null) {
- logger.warn("Encountered a null application info for id {}", appInfoId);
- return false;
- }
- return true;
- }
- });
- }
+ return systemCollectionManager.load(appInfoId)
+ .filter(entity -> (entity != null));
});
return entityObs;
}
+
+ Observable<Edge> edgesObservable;
+ public Observable<Edge> getApplicationInfoEdges() {
+ final ApplicationScope managementAppScope = getApplicationScope(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ final GraphManager gm = graphManagerFactory.createEdgeManager(managementAppScope);
+
+ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.APPLICATION_INFOS);
+
+
+ final SimpleSearchByEdgeType simpleSearchByEdgeType = new SimpleSearchByEdgeType(
+ CpNamingUtils.generateApplicationId(CpNamingUtils.MANAGEMENT_APPLICATION_ID), edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null);
+ edgesObservable = edgesObservable !=null ? edgesObservable : gm.loadEdgesFromSource( simpleSearchByEdgeType );
+ return edgesObservable;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a62091df/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 4182732..445cef4 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.UUID;
import org.apache.usergrid.persistence.core.util.Health;
+import rx.Observable;
/**
@@ -39,21 +40,28 @@ public interface EntityManagerFactory {
*
* @return EntityDao for the specified parameters
*/
- public abstract EntityManager getEntityManager( UUID applicationId );
+ EntityManager getEntityManager( UUID applicationId );
/**
- * Creates a new application.
- *
- * @param name a unique application name.
- *
- * @return Entity of type application_info that represents the newly created Application
- *
- * @throws Exception the exception
+ * get management app em
+ * @return
*/
- public abstract Entity createApplicationV2( String organizationName, String name ) throws Exception;
+ EntityManager getManagementEntityManager();
+
+
+ /**
+ * Creates a new application.
+ *
+ * @param name a unique application name.
+ *
+ * @return Entity of type application_info that represents the newly created Application
+ *
+ * @throws Exception the exception
+ */
+ Entity createApplicationV2( String organizationName, String name ) throws Exception;
@Deprecated
- public abstract UUID createApplication( String organizationName, String name ) throws Exception;
+ UUID createApplication( String organizationName, String name ) throws Exception;
/**
* Creates a Application entity. All entities except for applications must be attached to a
@@ -66,11 +74,11 @@ public interface EntityManagerFactory {
*
* @throws Exception the exception
*/
- public abstract Entity createApplicationV2(
+ Entity createApplicationV2(
String organizationName, String name, Map<String, Object> properties ) throws Exception;
@Deprecated
- public abstract UUID createApplication(
+ UUID createApplication(
String organizationName, String name, Map<String, Object> properties ) throws Exception;
/**
@@ -78,14 +86,33 @@ public interface EntityManagerFactory {
*
* @param applicationId UUID of Application to be deleted.
*/
- public abstract void deleteApplication( UUID applicationId ) throws Exception;
+ void deleteApplication( UUID applicationId ) throws Exception;
+
+ /**
+ *
+ * @param applicationUUID
+ * @param collectionFromName
+ * @param collectionToName
+ * @return
+ * @throws Exception
+ */
+ Observable migrateAppInfo( UUID applicationUUID, String collectionFromName, String collectionToName) throws Exception;
/**
* Restore deleted application.
*/
- public Entity restoreApplication( UUID applicationId) throws Exception;
+ Entity restoreApplication( UUID applicationId) throws Exception;
- public abstract UUID importApplication( String organization, UUID applicationId, String name,
+ /**
+ *
+ * @param organization
+ * @param applicationId
+ * @param name
+ * @param properties
+ * @return
+ * @throws Exception
+ */
+ UUID importApplication( String organization, UUID applicationId, String name,
Map<String, Object> properties ) throws Exception;
/**
@@ -97,7 +124,7 @@ public interface EntityManagerFactory {
*
* @throws Exception the exception
*/
- public abstract UUID lookupApplication( String name ) throws Exception;
+ UUID lookupApplication( String name ) throws Exception;
/**
* Returns all the applications in the system.
@@ -106,19 +133,19 @@ public interface EntityManagerFactory {
*
* @throws Exception the exception
*/
- public abstract Map<String, UUID> getApplications() throws Exception;
+ Map<String, UUID> getApplications() throws Exception;
public Map<String, UUID> getDeletedApplications() throws Exception;
- public abstract void setup() throws Exception;
+ void setup() throws Exception;
- public abstract Map<String, String> getServiceProperties();
+ Map<String, String> getServiceProperties();
- public abstract boolean updateServiceProperties( Map<String, String> properties );
+ boolean updateServiceProperties( Map<String, String> properties );
- public abstract boolean setServiceProperty( String name, String value );
+ boolean setServiceProperty( String name, String value );
- public abstract boolean deleteServiceProperty( String name );
+ boolean deleteServiceProperty( String name );
/**
* @return Entity of type application_info that represents the newly created application.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a62091df/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
index 882e7d9..91d7524 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
+import org.apache.usergrid.exception.NotImplementedException;
import org.apache.usergrid.persistence.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,6 +69,7 @@ import static org.apache.usergrid.persistence.cassandra.CassandraService.RETRY_C
import static org.apache.usergrid.utils.ConversionUtils.uuid;
import static org.apache.usergrid.persistence.cassandra.Serializers.*;
import org.apache.usergrid.persistence.core.util.Health;
+import rx.Observable;
/**
@@ -133,6 +135,11 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
return _getEntityManager( applicationId );
}
+ @Override
+ public EntityManager getManagementEntityManager() {
+ throw new NotImplementedException();
+ }
+
private EntityManager _getEntityManager( UUID applicationId ) {
EntityManagerImpl em = new EntityManagerImpl();
@@ -214,6 +221,11 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
throw new UnsupportedOperationException("Not supported.");
}
+ @Override
+ public Observable migrateAppInfo(UUID applicationUUID, String collectionFromName, String collectionToName) throws Exception {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
private String buildAppName( String organizationName, String name ) {
return StringUtils.lowerCase( name.contains( "/" ) ? name : organizationName + "/" + name );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a62091df/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
index 9cb99be..5c36876 100644
--- a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
@@ -27,8 +27,11 @@ import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.management.OrganizationOwnerInfo;
import org.apache.usergrid.persistence.*;
import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.index.query.Query;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -65,6 +68,12 @@ public class AppInfoMigrationPluginTest {
@Test
public void testRun() throws Exception {
+ MigrationInfoSerialization serialization = Mockito.mock(MigrationInfoSerialization.class);
+ Mockito.when(serialization.getVersion(Mockito.any())).thenReturn(0);
+ EntityCollectionManagerFactory ecmf = setup.getInjector().getInstance(EntityCollectionManagerFactory.class);
+ GraphManagerFactory gmf = setup.getInjector().getInstance(GraphManagerFactory.class);
+
+ AppInfoMigrationPlugin appInfoMigrationPlugin = new AppInfoMigrationPlugin(setup.getEmf(),serialization,ecmf,gmf);
// create 10 applications, each with 10 entities
@@ -148,7 +157,7 @@ public class AppInfoMigrationPluginTest {
logger.debug("\n\nRun the migration\n");
ProgressObserver po = Mockito.mock(ProgressObserver.class);
- setup.getAppInfoMigrationPlugin().run(po);
+ appInfoMigrationPlugin.run(po);
logger.debug("\n\nVerify migration results\n");
[2/8] incubator-usergrid git commit: Merge branch 'two-dot-o-dev' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-550
Posted by sf...@apache.org.
Merge branch 'two-dot-o-dev' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-550
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0a3f9dba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0a3f9dba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0a3f9dba
Branch: refs/heads/two-dot-o-dev
Commit: 0a3f9dbae4449cec88fdf29e9c744d166ddfe9a3
Parents: a62091d 38ff124
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 10:18:05 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 10:18:05 2015 -0600
----------------------------------------------------------------------
.../rest/applications/ApplicationCreateIT.java | 135 +++++++
.../applications/ApplicationCreateTest.java | 135 -------
.../rest/applications/ApplicationDeleteIT.java | 389 +++++++++++++++++++
.../applications/ApplicationDeleteTest.java | 389 -------------------
4 files changed, 524 insertions(+), 524 deletions(-)
----------------------------------------------------------------------
[5/8] incubator-usergrid git commit: add cache fig
Posted by sf...@apache.org.
add cache fig
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3c504f1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3c504f1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3c504f1c
Branch: refs/heads/two-dot-o-dev
Commit: 3c504f1cd9482fb8669ce8a447ae0d95f729ba37
Parents: a509c0d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 11:28:43 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 11:28:43 2015 -0600
----------------------------------------------------------------------
.../apache/usergrid/corepersistence/ApplicationIdCacheFig.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c504f1c/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
index 3815381..f4181ac 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
@@ -19,16 +19,13 @@
*/
package org.apache.usergrid.corepersistence;
-/**
- * Application id cache fig
- */
import org.safehaus.guicyfig.Default;
import org.safehaus.guicyfig.GuicyFig;
import org.safehaus.guicyfig.Key;
/**
- * The config for the entity cache
+ * Application id cache fig
*/
public interface ApplicationIdCacheFig extends GuicyFig {
[7/8] incubator-usergrid git commit: remove circular refs
Posted by sf...@apache.org.
remove circular refs
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5cc3bf6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5cc3bf6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5cc3bf6e
Branch: refs/heads/two-dot-o-dev
Commit: 5cc3bf6e51bacee599f3ceae671edde1a95435ca
Parents: 7b229d4
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 13:46:38 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 13:46:38 2015 -0600
----------------------------------------------------------------------
.../ApplicationIdCacheFactory.java | 43 ++++++++++++++++++++
.../corepersistence/ApplicationIdCacheImpl.java | 17 ++++----
.../usergrid/corepersistence/CoreModule.java | 2 +-
.../corepersistence/CpEntityManagerFactory.java | 2 +-
4 files changed, 52 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cc3bf6e/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFactory.java
new file mode 100644
index 0000000..ac8b43b
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFactory.java
@@ -0,0 +1,43 @@
+/*
+ *
+ * * 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;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.usergrid.persistence.EntityManager;
+
+/**
+ * returns instances of cache.
+ */
+@Singleton
+public class ApplicationIdCacheFactory {
+ private final ApplicationIdCacheFig fig;
+ private final ManagerCache cache;
+
+ @Inject
+ public ApplicationIdCacheFactory(ApplicationIdCacheFig fig,ManagerCache cache){
+
+ this.fig = fig;
+ this.cache = cache;
+ }
+ public ApplicationIdCache getInstance(EntityManager managementEntityManager){
+ return new ApplicationIdCacheImpl(managementEntityManager,cache,fig);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cc3bf6e/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 2063fb1..ec98e23 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -51,7 +51,6 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
* Implements the org app cache for faster runtime lookups. These values are immutable, so this LRU cache can stay
* full for the duration of the execution
*/
-@Singleton
public class ApplicationIdCacheImpl implements ApplicationIdCache {
private static final Logger logger = LoggerFactory.getLogger(ApplicationIdCacheImpl.class);
@@ -59,17 +58,15 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
/**
* Cache the pointer to our root entity manager for reference
*/
- private final EntityManager rootEm;
- private final CpEntityManagerFactory emf;
private final LoadingCache<String, Optional<UUID>> appCache;
+ private final EntityManager managementEnityManager;
+ private final ManagerCache managerCache;
-
- @Inject
- public ApplicationIdCacheImpl(final EntityManagerFactory emf, ApplicationIdCacheFig fig) {
- this.emf = (CpEntityManagerFactory)emf;
- this.rootEm = emf.getEntityManager(emf.getManagementAppId());
+ public ApplicationIdCacheImpl(final EntityManager managementEnityManager, ManagerCache managerCache, ApplicationIdCacheFig fig) {
+ this.managementEnityManager = managementEnityManager;
+ this.managerCache = managerCache;
appCache = CacheBuilder.newBuilder()
.maximumSize(fig.getCacheSize())
.expireAfterWrite(fig.getCacheTimeout(), TimeUnit.MILLISECONDS)
@@ -101,12 +98,12 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
UUID value = null;
- EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
+ EntityCollectionManager ecm = managerCache.getEntityCollectionManager(
new ApplicationScopeImpl(
new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );
try {
- if ( rootEm.getApplication() == null ) {
+ if ( managementEnityManager.getApplication() == null ) {
return Optional.empty();
}
} catch ( Exception e ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cc3bf6e/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 8a8a1e0..7859ffc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -110,6 +110,7 @@ public class CoreModule extends AbstractModule {
// install(new QueueModule());
bind(ManagerCache.class).to( CpManagerCache.class );
+ bind(ApplicationIdCacheFactory.class);
Multibinder<EntityDeleted> entityBinder =
Multibinder.newSetBinder(binder(), EntityDeleted.class);
@@ -143,7 +144,6 @@ public class CoreModule extends AbstractModule {
bind(AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);
install(new GuicyFigModule(ApplicationIdCacheFig.class));
- bind(ApplicationIdCache.class).to(ApplicationIdCacheImpl.class);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5cc3bf6e/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index f5ae1c6..642d555 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -118,7 +118,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
- this.applicationIdCache = injector.getInstance(ApplicationIdCache.class);
+ this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(getManagementEntityManager());
}
[3/8] incubator-usergrid git commit: add cache fig
Posted by sf...@apache.org.
add cache fig
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/803941cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/803941cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/803941cb
Branch: refs/heads/two-dot-o-dev
Commit: 803941cbd05352b54aabbe231f977fe5f193dbd5
Parents: 0a3f9db
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 11:26:20 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 11:26:20 2015 -0600
----------------------------------------------------------------------
.../corepersistence/ApplicationIdCacheFig.java | 46 ++++++++++++++++++++
.../corepersistence/ApplicationIdCacheImpl.java | 34 +++++++++------
.../usergrid/corepersistence/CoreModule.java | 6 ++-
3 files changed, 71 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/803941cb/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
new file mode 100644
index 0000000..7b7cec0
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * * 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;
+
+/**
+ * Classy class class.
+ */
+
+import org.safehaus.guicyfig.Default;
+import org.safehaus.guicyfig.GuicyFig;
+import org.safehaus.guicyfig.Key;
+
+/**
+ * The config for the entity cache
+ */
+public interface ApplicationIdCacheFig extends GuicyFig {
+
+
+ @Key( "usergrid.applicationid_cache_size" )
+ @Default( "10000" )
+ int getCacheSize();
+
+ @Key( "usergrid.applicationid_cache_timeout_ms" )
+ @Default( "1000" )
+ int getCacheTimeout();
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/803941cb/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 8fb4f6b..2bf8ed1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -38,7 +38,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.Observable;
+import java.util.Optional;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
@@ -57,26 +59,30 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
private final EntityManager rootEm;
private final CpEntityManagerFactory emf;
- private final LoadingCache<String, UUID> appCache =
- CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, UUID>() {
- @Override
- public UUID load( final String key ) throws Exception {
- return fetchApplicationId( key );
- }
- } );
+ private final LoadingCache<String, Optional<UUID>> appCache;
+
- public ApplicationIdCacheImpl(final EntityManagerFactory emf) {
+ public ApplicationIdCacheImpl(final EntityManagerFactory emf, ApplicationIdCacheFig fig) {
this.emf = (CpEntityManagerFactory)emf;
- this.rootEm = emf.getEntityManager( emf.getManagementAppId());
+ this.rootEm = emf.getEntityManager(emf.getManagementAppId());
+ appCache = CacheBuilder.newBuilder()
+ .maximumSize(fig.getCacheSize())
+ .expireAfterWrite(fig.getCacheTimeout(), TimeUnit.MILLISECONDS)
+ .build(new CacheLoader<String, Optional<UUID>>() {
+ @Override
+ public Optional<UUID> load(final String key) throws Exception {
+ return fetchApplicationId(key);
+ }
+ });
}
@Override
public UUID getApplicationId( final String applicationName ) {
try {
- UUID optionalUuid = appCache.get( applicationName.toLowerCase() );
+ Optional<UUID> optionalUuid = appCache.get( applicationName.toLowerCase() );
logger.debug("Returning for key {} value {}", applicationName, optionalUuid );
- return optionalUuid;
+ return optionalUuid.get();
} catch (Exception e) {
logger.debug("Returning for key {} value null", applicationName );
return null;
@@ -87,7 +93,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
/**
* Fetch our application id
*/
- private UUID fetchApplicationId( final String applicationName ) {
+ private Optional<UUID> fetchApplicationId( final String applicationName ) {
UUID value = null;
@@ -97,7 +103,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
try {
if ( rootEm.getApplication() == null ) {
- return null;
+ return Optional.empty();
}
} catch ( Exception e ) {
logger.error("Error looking up management app", e);
@@ -116,7 +122,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
}else{
logger.debug("Could not load value for key {} ", applicationName );
}
- return value;
+ return value == null ? Optional.<UUID>empty() : Optional.of(value);
}
catch ( Exception e ) {
throw new RuntimeException( "Unable to retrieve application id", e );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/803941cb/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 62f2d1b..63abed9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.corepersistence;
import org.apache.usergrid.corepersistence.migration.*;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.safehaus.guicyfig.GuicyFigModule;
import org.springframework.context.ApplicationContext;
import org.apache.usergrid.corepersistence.events.EntityDeletedHandler;
@@ -139,7 +140,10 @@ public class CoreModule extends AbstractModule {
plugins.addBinding().to( AppInfoMigrationPlugin.class );
plugins.addBinding().to( MigrationModuleVersionPlugin.class );
- bind( AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);
+ bind(AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);
+
+ install(new GuicyFigModule(ApplicationIdCacheFig.class));
+
}
[8/8] incubator-usergrid git commit: Merge branch 'USERGRID-550' into
two-dot-o-dev
Posted by sf...@apache.org.
Merge branch 'USERGRID-550' into two-dot-o-dev
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0fcdd279
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0fcdd279
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0fcdd279
Branch: refs/heads/two-dot-o-dev
Commit: 0fcdd2794d2fb287a444c49c32b7754db591d091
Parents: 15db4e8 5cc3bf6
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 13:52:33 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 13:52:33 2015 -0600
----------------------------------------------------------------------
.../ApplicationIdCacheFactory.java | 43 ++
.../corepersistence/ApplicationIdCacheFig.java | 43 ++
.../corepersistence/ApplicationIdCacheImpl.java | 49 ++-
.../usergrid/corepersistence/CoreModule.java | 7 +-
.../corepersistence/CpEntityManagerFactory.java | 141 +++----
.../migration/AppInfoMigrationPlugin.java | 252 +++++-------
.../persistence/EntityManagerFactory.java | 71 ++--
.../cassandra/EntityManagerFactoryImpl.java | 12 +
.../rest/applications/ApplicationCreateIT.java | 135 +++++++
.../applications/ApplicationCreateTest.java | 135 -------
.../rest/applications/ApplicationDeleteIT.java | 389 +++++++++++++++++++
.../applications/ApplicationDeleteTest.java | 389 -------------------
.../migration/AppInfoMigrationPluginTest.java | 11 +-
13 files changed, 880 insertions(+), 797 deletions(-)
----------------------------------------------------------------------
[6/8] incubator-usergrid git commit: change to guice instance
Posted by sf...@apache.org.
change to guice instance
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/7b229d48
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/7b229d48
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/7b229d48
Branch: refs/heads/two-dot-o-dev
Commit: 7b229d48824806cb0aebe9d86457b45ad8d3d5e2
Parents: 3c504f1
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 13:28:18 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 13:28:18 2015 -0600
----------------------------------------------------------------------
.../apache/usergrid/corepersistence/ApplicationIdCacheImpl.java | 4 ++++
.../java/org/apache/usergrid/corepersistence/CoreModule.java | 1 +
.../apache/usergrid/corepersistence/CpEntityManagerFactory.java | 2 +-
3 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b229d48/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 2bf8ed1..2063fb1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -23,6 +23,8 @@ package org.apache.usergrid.corepersistence;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityManagerFactory;
@@ -49,6 +51,7 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
* Implements the org app cache for faster runtime lookups. These values are immutable, so this LRU cache can stay
* full for the duration of the execution
*/
+@Singleton
public class ApplicationIdCacheImpl implements ApplicationIdCache {
private static final Logger logger = LoggerFactory.getLogger(ApplicationIdCacheImpl.class);
@@ -63,6 +66,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
+ @Inject
public ApplicationIdCacheImpl(final EntityManagerFactory emf, ApplicationIdCacheFig fig) {
this.emf = (CpEntityManagerFactory)emf;
this.rootEm = emf.getEntityManager(emf.getManagementAppId());
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b229d48/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index 63abed9..8a8a1e0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -143,6 +143,7 @@ public class CoreModule extends AbstractModule {
bind(AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);
install(new GuicyFigModule(ApplicationIdCacheFig.class));
+ bind(ApplicationIdCache.class).to(ApplicationIdCacheImpl.class);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b229d48/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index ce036f5..f5ae1c6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -118,7 +118,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
- this.applicationIdCache = new ApplicationIdCacheImpl( this );
+ this.applicationIdCache = injector.getInstance(ApplicationIdCache.class);
}
[4/8] incubator-usergrid git commit: add cache fig
Posted by sf...@apache.org.
add cache fig
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a509c0d3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a509c0d3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a509c0d3
Branch: refs/heads/two-dot-o-dev
Commit: a509c0d3fb7089b7d14a287a39191eaa1fbad119
Parents: 803941c
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Apr 8 11:27:29 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Apr 8 11:27:29 2015 -0600
----------------------------------------------------------------------
.../apache/usergrid/corepersistence/ApplicationIdCacheFig.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a509c0d3/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
index 7b7cec0..3815381 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheFig.java
@@ -20,7 +20,7 @@
package org.apache.usergrid.corepersistence;
/**
- * Classy class class.
+ * Application id cache fig
*/
import org.safehaus.guicyfig.Default;
@@ -38,7 +38,7 @@ public interface ApplicationIdCacheFig extends GuicyFig {
int getCacheSize();
@Key( "usergrid.applicationid_cache_timeout_ms" )
- @Default( "1000" )
+ @Default( "60000" )
int getCacheTimeout();