You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/03/30 21:58:05 UTC
[01/50] incubator-usergrid git commit: Merge branch 'two-dot-o' into
USERGRID-361-appdeletetest
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o-dev 07cb9dfd6 -> 217e7dc13
Merge branch 'two-dot-o' into USERGRID-361-appdeletetest
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3b91da08
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3b91da08
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3b91da08
Branch: refs/heads/two-dot-o-dev
Commit: 3b91da08e9199356c3c62be54f47936ef8bb8ab5
Parents: 592c730 ebf6e13
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 3 16:46:26 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 3 16:46:26 2015 -0500
----------------------------------------------------------------------
stack/rest/catalina_base/bin/setenv.sh | 8 -
stack/rest/catalina_base/conf/server.xml | 144 -
stack/rest/catalina_base/conf/tomcat-users.xml | 36 -
stack/rest/catalina_base/conf/web.xml | 4614 ------------------
.../lib/usergrid-deployment.properties | 113 -
.../webapps/host-manager/META-INF/context.xml | 27 -
.../webapps/host-manager/WEB-INF/jsp/401.jsp | 70 -
.../webapps/host-manager/WEB-INF/jsp/403.jsp | 84 -
.../webapps/host-manager/WEB-INF/jsp/404.jsp | 61 -
.../webapps/host-manager/WEB-INF/web.xml | 144 -
.../webapps/host-manager/images/add.gif | Bin 1037 -> 0 bytes
.../webapps/host-manager/images/asf-logo.gif | Bin 7279 -> 0 bytes
.../webapps/host-manager/images/code.gif | Bin 394 -> 0 bytes
.../webapps/host-manager/images/design.gif | Bin 608 -> 0 bytes
.../webapps/host-manager/images/docs.gif | Bin 261 -> 0 bytes
.../webapps/host-manager/images/fix.gif | Bin 345 -> 0 bytes
.../webapps/host-manager/images/tomcat.gif | Bin 1934 -> 0 bytes
.../webapps/host-manager/images/update.gif | Bin 627 -> 0 bytes
.../webapps/host-manager/images/void.gif | Bin 43 -> 0 bytes
.../webapps/host-manager/index.jsp | 18 -
.../webapps/host-manager/manager.xml | 26 -
.../webapps/manager/META-INF/context.xml | 27 -
.../webapps/manager/WEB-INF/jsp/401.jsp | 79 -
.../webapps/manager/WEB-INF/jsp/403.jsp | 94 -
.../webapps/manager/WEB-INF/jsp/404.jsp | 62 -
.../manager/WEB-INF/jsp/sessionDetail.jsp | 197 -
.../manager/WEB-INF/jsp/sessionsList.jsp | 172 -
.../webapps/manager/WEB-INF/web.xml | 209 -
.../webapps/manager/images/add.gif | Bin 1037 -> 0 bytes
.../webapps/manager/images/asf-logo.gif | Bin 7279 -> 0 bytes
.../webapps/manager/images/code.gif | Bin 394 -> 0 bytes
.../webapps/manager/images/design.gif | Bin 608 -> 0 bytes
.../webapps/manager/images/docs.gif | Bin 261 -> 0 bytes
.../webapps/manager/images/fix.gif | Bin 345 -> 0 bytes
.../webapps/manager/images/tomcat.gif | Bin 2066 -> 0 bytes
.../webapps/manager/images/update.gif | Bin 627 -> 0 bytes
.../webapps/manager/images/void.gif | Bin 43 -> 0 bytes
.../catalina_base/webapps/manager/index.jsp | 18 -
.../catalina_base/webapps/manager/status.xsd | 84 -
.../catalina_base/webapps/manager/xform.xsl | 125 -
stack/rest/catalina_base/webapps/portal | 1 -
.../manager/org/apache/jsp/index_jsp.java | 83 -
.../usergrid/rest/test/PropertiesResource.java | 2 +-
.../usergrid/rest/management/AdminUsersIT.java | 967 ++--
.../rest/test/resource2point0/ClientSetup.java | 14 +-
.../rest/test/resource2point0/RestClient.java | 4 +-
.../resource2point0/TestPropertiesResource.java | 47 +
.../endpoints/mgmt/ConfirmResource.java | 46 +
.../endpoints/mgmt/OrgResource.java | 12 +-
.../endpoints/mgmt/ReactivateResource.java | 46 +
.../endpoints/mgmt/ResetResource.java | 42 +
.../endpoints/mgmt/TokenResource.java | 4 +-
.../endpoints/mgmt/UserResource.java | 25 +
.../endpoints/mgmt/UsersResource.java | 7 +
.../resources/usergrid-custom-test.properties | 6 -
55 files changed, 655 insertions(+), 7063 deletions(-)
----------------------------------------------------------------------
[18/50] incubator-usergrid git commit: Switch back to giving each
application_info entity it's own UUID instead of using the same UUID as the
application itself.
Posted by sn...@apache.org.
Switch back to giving each application_info entity it's own UUID instead of using the same UUID as the application itself.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/60785263
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/60785263
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/60785263
Branch: refs/heads/two-dot-o-dev
Commit: 607852637b7ae95bc8ef315d79787c6ca2fa44a9
Parents: 9eeb2b5
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 12 11:53:36 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 12 11:53:36 2015 -0400
----------------------------------------------------------------------
.../corepersistence/ApplicationIdCache.java | 2 +-
.../corepersistence/ApplicationIdCacheImpl.java | 67 ++++++---
.../corepersistence/CpEntityManagerFactory.java | 138 ++++++++++++-------
.../usergrid/corepersistence/CpSetup.java | 2 +-
.../migration/AppInfoMigrationPlugin.java | 55 ++++++--
.../usergrid/exception/ConflictException.java | 36 +++++
.../persistence/EntityManagerFactory.java | 22 ++-
.../org/apache/usergrid/persistence/Schema.java | 5 +-
.../cassandra/EntityManagerFactoryImpl.java | 21 ++-
.../index/impl/EsEntityIndexImpl.java | 9 +-
.../rest/applications/ApplicationResource.java | 9 +-
.../rest/applications/ServiceResource.java | 8 +-
.../exceptions/ConflictExceptionMapper.java | 2 +-
.../organizations/OrganizationResource.java | 12 +-
.../applications/ApplicationDeleteTest.java | 50 +++++--
.../endpoints/OrganizationResource.java | 6 +-
stack/rest/src/test/resources/log4j.properties | 7 +-
.../usergrid/management/ApplicationInfo.java | 4 +
.../usergrid/management/ManagementService.java | 4 +-
.../cassandra/ManagementServiceImpl.java | 95 +++++--------
.../exceptions/ConflictException.java | 36 -----
.../migration/AppInfoMigrationPluginTest.java | 111 ++++++++++++---
.../cassandra/ApplicationCreatorIT.java | 1 +
23 files changed, 466 insertions(+), 236 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
index 71637bd..4aa1113 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
@@ -36,7 +36,7 @@ public interface ApplicationIdCache {
/**
* Evict the application by name
*/
- public Optional<UUID> getApplicationId(final String applicationName);
+ public UUID getApplicationId(final String applicationName);
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 202e68d..b03f422 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
@@ -24,15 +24,16 @@ import java.util.UUID;
import java.util.concurrent.ExecutionException;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.*;
import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.utils.UUIDUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -40,6 +41,7 @@ import com.google.common.cache.LoadingCache;
* full for the duration of the execution
*/
public class ApplicationIdCacheImpl implements ApplicationIdCache {
+ private static final Logger logger = LoggerFactory.getLogger(ApplicationIdCacheImpl.class);
/**
@@ -47,10 +49,10 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
*/
private final EntityManager rootEm;
- private final LoadingCache<String, Optional<UUID>> appCache =
- CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, Optional<UUID>>() {
+ private final LoadingCache<String, UUID> appCache =
+ CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, UUID>() {
@Override
- public Optional<UUID> load( final String key ) throws Exception {
+ public UUID load( final String key ) throws Exception {
return fetchApplicationId( key );
}
} );
@@ -61,12 +63,15 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
}
@Override
- public Optional<UUID> getApplicationId( final String applicationName ) {
+ public UUID getApplicationId( final String applicationName ) {
try {
- return appCache.get( applicationName );
+ UUID optionalUuid = appCache.get( applicationName.toLowerCase() );
+ logger.debug("Returning for key {} value {}", applicationName, optionalUuid );
+ return optionalUuid;
}
- catch ( ExecutionException e ) {
- throw new RuntimeException( "Unable to load app cache", e );
+ catch ( Exception e ) {
+ logger.debug("Returning for key {} value null", applicationName );
+ return null;
}
}
@@ -74,18 +79,40 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
/**
* Fetch our application id
*/
- private Optional<UUID> fetchApplicationId( final String applicationName ) {
+ private UUID fetchApplicationId( final String applicationName ) {
+
+ UUID value = null;
+
+ try {
+ if ( rootEm.getApplication() == null ) {
+ return null;
+ }
+ } catch ( Exception e ) {
+ logger.error("Error looking up app", e);
+ }
try {
- UUID applicationId = null;
+ Query q = Query.fromQL( Schema.PROPERTY_NAME + " = '" + applicationName.toLowerCase() + "'" );
+
+ Results results = rootEm.searchCollection(
+ rootEm.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS, q);
+
+ if ( !results.isEmpty() ) {
+
+ Entity entity = results.iterator().next();
+ Object uuidObject = entity.getProperty(Schema.PROPERTY_APPLICATION_ID);
+
+ if (uuidObject instanceof UUID) {
+ value = (UUID) uuidObject;
+ } else {
+ value = UUIDUtils.tryExtractUUID(
+ entity.getProperty(Schema.PROPERTY_APPLICATION_ID).toString());
+ }
- final EntityRef alias = rootEm.getAlias( CpNamingUtils.APPLICATION_INFO, applicationName );
- if ( alias != null ) {
- Entity entity = rootEm.get(alias);
- applicationId = (UUID) entity.getProperty("uuid");
}
- return Optional.fromNullable( applicationId );
+ logger.debug("Loaded for key {} value {}", applicationName, value );
+ return value;
}
catch ( Exception e ) {
throw new RuntimeException( "Unable to retrieve application id", e );
@@ -95,12 +122,14 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
@Override
public void evictAppId( final String applicationName ) {
- appCache.invalidate( applicationName );
+ appCache.invalidate( applicationName.toLowerCase() );
+ logger.debug("Invalidated key {}", applicationName.toLowerCase());
}
@Override
public void evictAll() {
appCache.invalidateAll();
+ logger.debug("Invalidated all keys");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 1fb8a7b..8e432e8 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
@@ -25,6 +25,7 @@ import com.google.inject.TypeLiteral;
import com.yammer.metrics.annotation.Metered;
import org.apache.commons.lang.StringUtils;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.exception.ConflictException;
import org.apache.usergrid.persistence.*;
import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.cassandra.CounterUtils;
@@ -81,10 +82,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
/** Have we already initialized the index for the management app? */
private AtomicBoolean indexInitialized = new AtomicBoolean( );
- /** Keep track of applications that already have indexes to avoid redundant re-creation. */
- private static final Set<UUID> applicationIndexesCreated = new HashSet<UUID>();
-
-
// cache of already instantiated entity managers
private LoadingCache<UUID, EntityManager> entityManagers
= CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<UUID, EntityManager>() {
@@ -93,14 +90,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
});
- private final ApplicationIdCache orgApplicationCache;
-
+ private final ApplicationIdCache applicationIdCache;
private ManagerCache managerCache;
-
-
-
private CassandraService cassandraService;
private CounterUtils counterUtils;
private Injector injector;
@@ -114,7 +107,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.injector = injector;
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
- this.orgApplicationCache = new ApplicationIdCacheImpl( this );
+ this.applicationIdCache = new ApplicationIdCacheImpl( this );
}
@@ -189,21 +182,21 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
@Override
- public UUID createApplication(String organizationName, String name) throws Exception {
- return createApplication( organizationName, name, null );
+ public Entity createApplicationV2(String organizationName, String name) throws Exception {
+ return createApplicationV2(organizationName, name, null);
}
@Override
- public UUID createApplication(
+ public Entity createApplicationV2(
String orgName, String name, Map<String, Object> properties) throws Exception {
String appName = buildAppName( orgName, name );
- final Optional<UUID> appId = orgApplicationCache.getApplicationId( appName );
+ final UUID appId = applicationIdCache.getApplicationId( appName );
- if ( appId.isPresent() ) {
+ if ( appId != null ) {
throw new ApplicationAlreadyExistsException( name );
}
@@ -212,18 +205,21 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
logger.debug( "New application orgName {} orgAppName {} id {} ",
new Object[] { orgName, name, applicationId.toString() } );
- initializeApplication( orgName, applicationId, appName, properties );
- return applicationId;
+ return initializeApplicationV2(orgName, applicationId, appName, properties);
}
+
private String buildAppName( String organizationName, String name ) {
return StringUtils.lowerCase( name.contains( "/" ) ? name : organizationName + "/" + name );
}
+ /**
+ * @return UUID of newly created Entity of type application_info
+ */
@Override
- public UUID initializeApplication( String organizationName, UUID applicationId, String name,
+ public Entity initializeApplicationV2( String organizationName, final UUID applicationId, String name,
Map<String, Object> properties ) throws Exception {
EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
@@ -241,7 +237,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
getSetup().setupApplicationKeyspace( applicationId, appName );
if ( properties == null ) {
- properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
+ properties = new TreeMap<>( CASE_INSENSITIVE_ORDER );
}
properties.put( PROPERTY_NAME, appName );
EntityManager appEm = getEntityManager( applicationId );
@@ -252,27 +248,28 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// create application info entity in the management app
- final UUID appId = applicationId;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
- put( PROPERTY_UUID, appId );
+ put( PROPERTY_APPLICATION_ID, applicationId );
}};
+ Entity appInfo;
try {
- em.create( appId, CpNamingUtils.APPLICATION_INFO, appInfoMap );
+ appInfo = em.create(CpNamingUtils.APPLICATION_INFO, appInfoMap);
} catch (DuplicateUniquePropertyExistsException e) {
throw new ApplicationAlreadyExistsException(appName);
}
em.refreshIndex();
- //evict app Id from cache
- orgApplicationCache.evictAppId( appName );
+ // evict app Id from cache
+ applicationIdCache.evictAppId(appName);
logger.info("Initialized application {}", appName);
- return applicationId;
+ return appInfo;
}
+
/**
* Delete Application.
*
@@ -286,77 +283,96 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void deleteApplication(UUID applicationId) throws Exception {
- // make a copy of the app to delete application_info entity
+ // find application_info for application to delete
+
+ EntityManager em = getEntityManager(getManagementAppId());
+
+ final Results results = em.searchCollection(em.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS,
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+ Entity appInfoToDelete = results.getEntity();
- EntityManager em = getEntityManager( this.getManagementAppId() );
- Entity appToDelete = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+ // ensure that there is not already a deleted app with the same name
+ final EntityRef alias = em.getAlias(
+ CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.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
Entity deletedApp = em.create(
- applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, appToDelete.getProperties());
+ CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getProperties());
// copy its connections too
- final Set<String> connectionTypes = em.getConnectionTypes(appToDelete);
+ final Set<String> connectionTypes = em.getConnectionTypes(appInfoToDelete);
for ( String connType : connectionTypes ) {
- final Results results =
- em.getConnectedEntities(appToDelete, connType, null, Query.Level.ALL_PROPERTIES);
- for ( Entity entity : results.getEntities() ) {
+ final Results connResults =
+ em.getConnectedEntities(appInfoToDelete, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : connResults.getEntities() ) {
em.createConnection( deletedApp, connType, entity );
}
}
// delete the app from the application_info collection and delete its index
- em.delete(appToDelete);
+ em.delete(appInfoToDelete);
em.refreshIndex();
final EntityIndex entityIndex = managerCache.getEntityIndex(
new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
+
+ applicationIdCache.evictAppId(appInfoToDelete.getName());
+
entityIndex.deleteIndex();
}
@Override
- public void restoreApplication(UUID applicationId) throws Exception {
+ public Entity restoreApplication(UUID applicationId) throws Exception {
// get the deleted_application_info for the deleted app
- EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- Entity deletedApp = em.get(
- new SimpleEntityRef(CpNamingUtils.DELETED_APPLICATION_INFO, applicationId));
+ EntityManager em = getEntityManager(getManagementAppId());
+
+ final Results results = em.searchCollection(em.getApplicationRef(), CpNamingUtils.DELETED_APPLICATION_INFOS,
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+ Entity deletedAppInfo = results.getEntity();
- if ( deletedApp == null ) {
+ if ( deletedAppInfo == null ) {
throw new EntityNotFoundException("Cannot restore. Deleted Application not found: " + applicationId );
}
// create application_info for restored app
- Entity restoredApp = em.create(
- deletedApp.getUuid(), CpNamingUtils.APPLICATION_INFO, deletedApp.getProperties());
+ Entity restoredAppInfo = em.create(
+ deletedAppInfo.getUuid(), CpNamingUtils.APPLICATION_INFO, deletedAppInfo.getProperties());
// copy connections from deleted app entity
- final Set<String> connectionTypes = em.getConnectionTypes(deletedApp);
+ final Set<String> connectionTypes = em.getConnectionTypes(deletedAppInfo);
for ( String connType : connectionTypes ) {
- final Results results =
- em.getConnectedEntities(deletedApp, connType, null, Query.Level.ALL_PROPERTIES);
- for ( Entity entity : results.getEntities() ) {
- em.createConnection( restoredApp, connType, entity );
+ final Results connResults =
+ em.getConnectedEntities(deletedAppInfo, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : connResults.getEntities() ) {
+ em.createConnection( restoredAppInfo, connType, entity );
}
}
// delete the deleted app entity rebuild the app index
- em.delete(deletedApp);
+ em.delete(deletedAppInfo);
this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@Override
public void onProgress(EntityRef entity) {
- logger.info( "Restored entity {}:{}", entity.getType(), entity.getUuid() );
+ logger.info( "Restored entity {}:{}", entity.getType(), entity.getUuid() );
}
});
+
+ return restoredAppInfo;
}
@@ -370,7 +386,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public UUID lookupApplication( String orgAppName ) throws Exception {
- return orgApplicationCache.getApplicationId( orgAppName ).orNull();
+ return applicationIdCache.getApplicationId( orgAppName );
}
@@ -690,8 +706,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void flushEntityManagerCaches() {
+
managerCache.invalidate();
- orgApplicationCache.evictAll();
+
+ applicationIdCache.evictAll();
+
Map<UUID, EntityManager> entityManagersMap = entityManagers.asMap();
for ( UUID appUuid : entityManagersMap.keySet() ) {
EntityManager em = entityManagersMap.get(appUuid);
@@ -735,4 +754,23 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
return ecm.getHealth();
}
+
+ @Override
+ public UUID createApplication(String organizationName, String name) throws Exception {
+ throw new UnsupportedOperationException("Not supported in v2");
+ }
+
+
+ @Override
+ public UUID createApplication(
+ String organizationName, String name, Map<String, Object> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported in v2");
+ }
+
+ @Override
+ public UUID initializeApplication(
+ String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception {
+ throw new UnsupportedOperationException("Not supported in v2");
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index 8dd4a12..c5c792b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -100,7 +100,7 @@ public class CpSetup implements Setup {
logger.info( "Setting up management app" );
try {
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
+ emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
}
catch ( ApplicationAlreadyExistsException ex ) {
logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 1a456c8..1c38615 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
@@ -34,6 +34,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
@@ -49,9 +50,8 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
public static String PLUGIN_NAME = "appinfo-migration";
- // protected for test purposes only
@Inject
- protected EntityManagerFactory emf;
+ protected EntityManagerFactory emf; // protected for test purposes only
@Override
public String getName() {
@@ -77,13 +77,15 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
if ( !results.isEmpty() ) {
// applications still found in old appinfos collection, migrate them.
- logger.info("Migrating old appinfos");
+
+ String currentAppName = null;
try {
+ logger.info("Migrating old appinfos");
for (Entity oldAppInfo : results.getEntities()) {
- final String appName = oldAppInfo.getName();
+ final String appName = currentAppName = oldAppInfo.getName();
UUID applicationId;
UUID organizationId;
@@ -104,23 +106,37 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
// create and connect new APPLICATION_INFO oldAppInfo to Organization
final UUID appId = applicationId;
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put(PROPERTY_NAME, appName);
- put(PROPERTY_UUID, appId);
- }};
- final Entity appInfo;
- appInfo = em.create(appId, CpNamingUtils.APPLICATION_INFO, appInfoMap);
- em.createConnection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "owns", appInfo);
- em.delete(oldAppInfo);
+ Entity appInfo = getApplicationInfo( emf, appId );
+ if ( appInfo == null ) {
+ Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
+ put(PROPERTY_NAME, appName);
+ put(PROPERTY_APPLICATION_ID, appId);
+ }};
+ appInfo = em.create(appId, CpNamingUtils.APPLICATION_INFO, appInfoMap);
+ observer.update( getMaxVersion(), "Created application_info for " + appName);
- observer.update( getMaxVersion(), "Updated application " + appName);
+ } else {
+ appInfo.setProperty(PROPERTY_APPLICATION_ID, appId);
+ em.update(appInfo);
+ observer.update( getMaxVersion(), "Updated existing application_info for " + appName);
+ }
+ em.createConnection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "owns", appInfo);
}
em.refreshIndex();
+ // after we've successfully created all of the application_infos, we delete the old appoinfos
+
+ for (Entity oldAppInfo : results.getEntities()) {
+ em.delete(oldAppInfo);
+ }
+
} catch (Exception e) {
- String msg = "Exception writing new application_info collection";
+
+ // stop on any exception and return failure
+
+ String msg = "Exception writing application_info for " + currentAppName;
logger.error(msg, e);
observer.failed( getMaxVersion(), msg);
}
@@ -130,7 +146,18 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
}
observer.complete();
+ }
+
+ private Entity getApplicationInfo( EntityManagerFactory emf, UUID appId ) throws Exception {
+
+ 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();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/core/src/main/java/org/apache/usergrid/exception/ConflictException.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/exception/ConflictException.java b/stack/core/src/main/java/org/apache/usergrid/exception/ConflictException.java
new file mode 100644
index 0000000..bbebbaa
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/exception/ConflictException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.exception;
+
+public class ConflictException extends Exception {
+
+ public ConflictException() {
+ super();
+ }
+
+ public ConflictException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+ public ConflictException(String arg0) {
+ super(arg0);
+ }
+
+ public ConflictException(Throwable arg0) {
+ super(arg0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 cd71cf9..df1615a 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
@@ -49,10 +49,13 @@ public interface EntityManagerFactory {
*
* @param name a unique application name.
*
- * @return the newly created application id.
+ * @return Entity of type application_info that represents the newly created Application
*
* @throws Exception the exception
*/
+ public abstract Entity createApplicationV2( String organizationName, String name ) throws Exception;
+
+ @Deprecated
public abstract UUID createApplication( String organizationName, String name ) throws Exception;
/**
@@ -62,12 +65,16 @@ public interface EntityManagerFactory {
* @param name the name of the application to create.
* @param properties property values to create in the new entity or null.
*
- * @return the newly created application id.
+ * @return Entity of type application_info that represents the newly created Application
*
* @throws Exception the exception
*/
+ public abstract Entity createApplicationV2(
+ String organizationName, String name, Map<String, Object> properties ) throws Exception;
+
+ @Deprecated
public abstract UUID createApplication(
- String organizationName, String name, Map<String, Object> properties ) throws Exception;
+ String organizationName, String name, Map<String, Object> properties ) throws Exception;
/**
* Delete Application.
@@ -79,7 +86,7 @@ public interface EntityManagerFactory {
/**
* Restore deleted application.
*/
- public void restoreApplication( UUID applicationId) throws Exception;
+ public Entity restoreApplication( UUID applicationId) throws Exception;
public abstract UUID importApplication( String organization, UUID applicationId, String name,
Map<String, Object> properties ) throws Exception;
@@ -117,6 +124,13 @@ public interface EntityManagerFactory {
public abstract boolean deleteServiceProperty( String name );
+ /**
+ * @return Entity of type application_info that represents the newly created application.
+ */
+ public Entity initializeApplicationV2(
+ String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception;
+
+ @Deprecated
public UUID initializeApplication(
String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/core/src/main/java/org/apache/usergrid/persistence/Schema.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Schema.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Schema.java
index f44fffa..1e3826d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Schema.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Schema.java
@@ -108,6 +108,7 @@ public class Schema {
public static final String TYPE_MEMBER = "member";
public static final String PROPERTY_ACTIVATED = "activated";
+ public static final String PROPERTY_APPLICATION_ID = "applicationId";
public static final String PROPERTY_COLLECTION_NAME = "collectionName";
public static final String PROPERTY_CREATED = "created";
public static final String PROPERTY_CONFIRMED = "confirmed";
@@ -1420,10 +1421,10 @@ public class Schema {
/*
* public Entity toEntity(Reader reader) { Entity entity =
* mapper.convertValue(reader, Entity.class); return entity; }
- *
+ *
* public Entity toEntity(InputStream input) { Entity entity =
* mapper.convertValue(input, Entity.class); return entity; }
- *
+ *
* public Entity toEntity(String string) { Entity entity =
* mapper.convertValue(string, Entity.class); return entity; }
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 4f3dabc..135424d 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.persistence.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
@@ -356,6 +357,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
}
+
@Override
public boolean updateServiceProperties( Map<String, String> properties ) {
try {
@@ -437,7 +439,6 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
throw new UnsupportedOperationException("Not supported.");
}
-
@Override
public void addIndex(UUID appId, String suffix,final int shards,final int replicas,final String consistency) {
throw new UnsupportedOperationException("Not supported in v1");
@@ -449,7 +450,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
}
@Override
- public void restoreApplication(UUID applicationId) throws Exception {
+ public Entity restoreApplication(UUID applicationId) throws Exception {
throw new UnsupportedOperationException("Not supported in v1");
}
@@ -458,4 +459,20 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
throw new UnsupportedOperationException("Not supported in v1");
}
+ public Entity createApplicationV2( String organizationName, String name ) throws Exception {
+ throw new UnsupportedOperationException("Not supported in v1");
+ }
+
+ @Override
+ public Entity initializeApplicationV2(
+ String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception {
+ throw new UnsupportedOperationException("Not supported in v1");
+ }
+
+ @Override
+ public Entity createApplicationV2(
+ String organizationName, String name, Map<String, Object> properties) throws Exception {
+ throw new UnsupportedOperationException("Not supported in v1");
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 18b006d..88f02ab 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -682,9 +682,8 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
@Override
public void onResponse( DeleteByQueryResponse response) {
timeDeleteAllVersions.stop();
- logger
- .debug( "Deleted entity {}:{} from all index scopes with response status = {}", entityId.getType(),
- entityId.getUuid(), response.status().toString() );
+ logger.debug( "Deleted entity {}:{} from all index scopes with response status = {}",
+ entityId.getType(), entityId.getUuid(), response.status().toString() );
checkDeleteByQueryResponse(tqb, response);
}
@@ -693,8 +692,8 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
@Override
public void onFailure( Throwable e ) {
timeDeleteAllVersions.stop();
- logger.error( "Deleted entity {}:{} from all index scopes with error {}", entityId.getType(),
- entityId.getUuid(), e);
+ logger.error( "Failed to delete entity {}:{} from all index scopes with error {}",
+ entityId.getType(), entityId.getUuid(), e);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index 5726466..a35532d 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -30,6 +30,7 @@ import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.StringUtils;
import org.apache.usergrid.rest.ApiResponse;
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
import org.slf4j.Logger;
@@ -515,7 +516,13 @@ public class ApplicationResource extends ServiceResource {
@RequireOrganizationAccess
@Override
public JSONWithPadding executeDelete( @Context UriInfo ui,
- @QueryParam("callback") @DefaultValue("callback") String callback ) throws Exception {
+ @QueryParam("callback") @DefaultValue("callback") String callback,
+ @QueryParam("app_delete_confirm") String confirmDelete) throws Exception {
+
+ if (!"confirm_delete_of_application_and_data".equals( confirmDelete ) ) {
+ throw new IllegalArgumentException(
+ "Cannot delete application without app_delete_confirm parameter");
+ }
Properties props = management.getProperties();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 bb02f8b..eaa2531 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
@@ -423,9 +423,11 @@ public class ServiceResource extends AbstractContextResource {
@DELETE
@RequireApplicationAccess
- public JSONWithPadding executeDelete( @Context UriInfo ui,
- @QueryParam("callback") @DefaultValue("callback") String callback )
- throws Exception {
+ public JSONWithPadding executeDelete(
+ @Context UriInfo ui,
+ @QueryParam("callback") @DefaultValue("callback") String callback,
+ @QueryParam("app_delete_confirm") String confirmAppDelete )
+ throws Exception {
LOG.debug( "ServiceResource.executeDelete" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
index 34a813d..51a38e3 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
@@ -17,7 +17,7 @@
package org.apache.usergrid.rest.exceptions;
-import org.apache.usergrid.management.exceptions.ConflictException;
+import org.apache.usergrid.exception.ConflictException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
index 695becc..ff26ba2 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.rest.organizations;
import com.google.common.collect.BiMap;
import com.sun.jersey.api.json.JSONWithPadding;
import java.util.UUID;
+import java.util.regex.Pattern;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.Path;
@@ -32,6 +33,7 @@ import javax.ws.rs.core.UriInfo;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.usergrid.exception.NotImplementedException;
import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.persistence.index.query.Identifier;
import org.apache.usergrid.rest.AbstractContextResource;
import org.apache.usergrid.rest.RootResource;
import org.apache.usergrid.rest.applications.ApplicationResource;
@@ -40,6 +42,7 @@ import org.apache.usergrid.rest.exceptions.OrganizationApplicationNotFoundExcept
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
import org.apache.usergrid.rest.utils.PathingUtils;
import org.apache.usergrid.security.shiro.utils.SubjectUtils;
+import org.apache.usergrid.utils.UUIDUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
@@ -140,8 +143,15 @@ public class OrganizationResource extends AbstractContextResource {
String orgAppName = PathingUtils.assembleAppName( organizationName, applicationName );
UUID applicationId = emf.lookupApplication( orgAppName );
+
if ( applicationId == null ) {
- throw new OrganizationApplicationNotFoundException( orgAppName, uriInfo, properties );
+
+ // TODO: fix this hacky work-around for apparent Jersey issue
+ applicationId = UUIDUtils.tryExtractUUID( applicationName );
+
+ if ( applicationId == null ) {
+ throw new OrganizationApplicationNotFoundException( orgAppName, uriInfo, properties );
+ }
}
return appResourceFor( applicationId );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
index 1826d59..0eaf566 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
@@ -20,6 +20,9 @@ package org.apache.usergrid.rest.applications;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.usergrid.corepersistence.ApplicationIdCacheImpl;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.EntityManagerFactory;
import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResponse;
import org.apache.usergrid.rest.test.resource2point0.model.*;
@@ -30,6 +33,9 @@ import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MediaType;
import java.io.StringReader;
import java.util.*;
+import java.util.regex.Pattern;
+
+import static org.junit.Assert.fail;
public class ApplicationDeleteTest extends AbstractRestIT {
@@ -61,9 +67,22 @@ public class ApplicationDeleteTest extends AbstractRestIT {
// delete the app
+ try {
+ clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteId.toString()).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .delete();
+
+ fail("Delete must fail without app_delete_confirm parameter");
+
+ } catch ( Exception e ) {
+ logger.error("Error", e);
+ }
+
clientSetup.getRestClient()
.org(orgName).app(appToDeleteId.toString() ).getResource()
.queryParam("access_token", orgAdminToken.getAccessToken() )
+ .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
.delete();
// test that we can no longer get the app
@@ -75,7 +94,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
.type(MediaType.APPLICATION_JSON)
.get(ApiResponse.class);
- Assert.fail("Must not be able to get deleted app");
+ fail("Must not be able to get deleted app");
} catch ( UniformInterfaceException expected ) {
Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
@@ -92,7 +111,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
.type(MediaType.APPLICATION_JSON )
.get(ApiResponse.class);
- Assert.fail("Must not be able to get deleted app's collection");
+ fail("Must not be able to get deleted app's collection");
} catch ( UniformInterfaceException expected ) {
Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
@@ -110,7 +129,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
.type( MediaType.APPLICATION_JSON)
.get(ApiResponse.class);
- Assert.fail("Must not be able to get deleted app entity");
+ fail("Must not be able to get deleted app entity");
} catch ( UniformInterfaceException expected ) {
// TODO: why not a 404?
@@ -129,7 +148,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
for ( String appName : orgAppResponse.getData().keySet() ) {
if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
- Assert.fail("Deleted app must not be included in list of org apps");
+ fail("Deleted app must not be included in list of org apps");
}
}
@@ -185,21 +204,29 @@ public class ApplicationDeleteTest extends AbstractRestIT {
// delete the app
+ logger.debug("\n\nDeleting app\n");
+
clientSetup.getRestClient()
- .org(orgName).app(appToDeleteId.toString() ).getResource()
+ .org(orgName).app( appToDeleteName ).getResource()
.queryParam("access_token", orgAdminToken.getAccessToken() )
+ .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
.delete();
+ Thread.sleep(1000);
+
// restore the app
+ logger.debug("\n\nRestoring app\n");
+
clientSetup.getRestClient()
- .org(orgName).app(appToDeleteId.toString() ).getResource()
+ .org(orgName).app( appToDeleteId.toString() ).getResource()
.queryParam("access_token", orgAdminToken.getAccessToken() )
.put();
-
// test that we can see the application in the list of applications
+ logger.debug("\n\nGetting app list from management end-point\n");
+
ManagementResponse orgAppResponse = clientSetup.getRestClient()
.management().orgs().organization( orgName ).apps().getOrganizationApplications();
@@ -215,6 +242,8 @@ public class ApplicationDeleteTest extends AbstractRestIT {
// test that we can get an app entity
+ logger.debug("\n\nGetting entities from app\n");
+
UUID entityId = entities.get(0).getUuid();
ApiResponse entityResponse = clientSetup.getRestClient()
.org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
@@ -255,6 +284,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
clientSetup.getRestClient()
.org( orgName ).app(appToDeleteId.toString() ).getResource()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
.delete();
// create new app with same name
@@ -270,7 +300,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
.queryParam("access_token", orgAdminToken.getAccessToken())
.put();
- Assert.fail("Must fail to restore app with same name as existing app");
+ fail("Must fail to restore app with same name as existing app");
} catch ( UniformInterfaceException e ) {
Assert.assertEquals(409, e.getResponse().getStatus());
@@ -300,6 +330,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
clientSetup.getRestClient()
.org( orgName ).app(appToDeleteId.toString() ).getResource()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
.delete();
// create new app with same name
@@ -313,9 +344,10 @@ public class ApplicationDeleteTest extends AbstractRestIT {
clientSetup.getRestClient()
.org(orgName).app( newAppId.toString() ).getResource()
.queryParam("access_token", orgAdminToken.getAccessToken())
+ .queryParam("app_delete_confirm", "confirm_delete_of_application_and_data")
.delete();
- Assert.fail("Must fail to delete app with same name as deleted app");
+ fail("Must fail to delete app with same name as deleted app");
} catch ( UniformInterfaceException e ) {
Assert.assertEquals( 409, e.getResponse().getStatus() );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
index 253de6e..cf774d0 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/OrganizationResource.java
@@ -18,6 +18,7 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints;
import java.util.Map;
+import java.util.UUID;
import javax.ws.rs.core.MediaType;
@@ -38,11 +39,10 @@ public class OrganizationResource extends NamedResource {
super( name, context, parent );
}
- public ApplicationsResource app(final String app){
- return new ApplicationsResource( app, context ,this );
+ public ApplicationsResource app(final String name){
+ return new ApplicationsResource( name, context ,this );
}
-
public void post(Map<String,String> organization) {
getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON )
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/rest/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/log4j.properties b/stack/rest/src/test/resources/log4j.properties
index 4c9c709..27e35c8 100644
--- a/stack/rest/src/test/resources/log4j.properties
+++ b/stack/rest/src/test/resources/log4j.properties
@@ -47,7 +47,6 @@ log4j.logger.org.apache.usergrid.rest.filters.MeteringFilter=ERROR
#log4j.logger.org.apache.usergrid.corepersistence.CpRelationManager=DEBUG
#log4j.logger.org.apache.usergrid.corepersistence.CpEntityManager=DEBUG
#log4j.logger.org.apache.usergrid.corepersistence.CpEntityManagerFactory=DEBUG
-#log4j.logger.org.apache.usergrid.corepersistence.CpSetup=INFO
#log4j.logger.org.apache.usergrid.persistence.index=DEBUG
#log4j.logger.org.apache.usergrid.persistence.index.impl=DEBUG
@@ -67,16 +66,16 @@ log4j.logger.org.apache.usergrid.rest.filters.MeteringFilter=ERROR
#log4j.logger.org.apache.usergrid.services.notifiers=DEBUG
#log4j.logger.org.apache.usergrid.services.groups.users.devices=DEBUG
+log4j.logger.org.apache.usergrid.rest=INFO
+log4j.logger.org.apache.usergrid.rest.exceptions=DEBUG
#log4j.logger.org.apache.usergrid.rest.NotificationsIT=DEBUG
#log4j.logger.org.apache.usergrid.cassandra.CassandraResource=DEBUG
#log4j.logger.org.apache.usergrid.rest.TomcatResource=INFO
-#log4j.logger.org.apache.usergrid.rest=INFO
-log4j.logger.org.apache.usergrid.rest.management=DEBUG
+#log4j.logger.org.apache.usergrid.rest.management=DEBUG
#log4j.logger.org.apache.usergrid.rest.management.users=DEBUG
#log4j.logger.org.apache.usergrid.rest.organizations.users=DEBUG
#log4j.logger.org.apache.usergrid.rest.applications.users.UsersResource=DEBUG
#log4j.logger.org.apache.usergrid.rest.applications.ServiceResource=DEBUG
-
#log4j.logger.org.apache.usergrid.rest.security=DEBUG
#log4j.logger.org.apache.usergrid.security=DEBUG
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
index 30c494f..d11cf9a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
@@ -34,6 +34,10 @@ public class ApplicationInfo {
private final String name;
+ /**
+ * @param id The application ID (not the same as the ID of the application_info).
+ * @param name The application name in orgname/appname format.
+ */
public ApplicationInfo( UUID id, String name ) {
this.id = id;
this.name = name;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 8ed15f2..b83c46b 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -46,8 +46,6 @@ public interface ManagementService {
public void addAdminUserToOrganization( UserInfo user, OrganizationInfo organization, boolean email )
throws Exception;
- public UUID addApplicationToOrganization( UUID organizationId, UUID applicationId, Entity appInfo ) throws Exception;
-
public AccessInfo authorizeClient( String clientId, String clientSecret, long ttl ) throws Exception;
public ActivationState handleConfirmationTokenForAdminUser( UUID userId, String token ) throws Exception;
@@ -95,6 +93,8 @@ public interface ManagementService {
public void deactivateOrganization( UUID organizationId ) throws Exception;
+ public UUID addApplicationToOrganization(UUID organizationId, Entity appInfo) throws Exception;
+
public void deleteOrganizationApplication( UUID organizationId, UUID applicationId ) throws Exception;
public void disableAdminUser( UUID userId ) throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 84f5d13..2874ffc 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -29,7 +29,10 @@ import java.util.Set;
import java.util.UUID;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.exception.ConflictException;
import org.apache.usergrid.management.exceptions.*;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.index.query.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,16 +48,8 @@ import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
import org.apache.usergrid.management.UserInfo;
-import org.apache.usergrid.persistence.CredentialsInfo;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
import org.apache.usergrid.persistence.index.query.Identifier;
-import org.apache.usergrid.persistence.PagingResultsIterator;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.entities.User;
@@ -647,24 +642,8 @@ public class ManagementServiceImpl implements ManagementService {
@Override
- public UUID importApplication( UUID organizationId, Application application ) throws Exception {
- // TODO organizationName
- OrganizationInfo organization = getOrganizationByUuid( organizationId );
- UUID applicationId =
- emf.importApplication( organization.getName(), application.getUuid(), application.getName(),
- application.getProperties() );
-
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- properties.setProperty( "name", buildAppName( application.getName(), organization ) );
- properties.setProperty( PROPERTY_PATH, organization.getName() );
- Entity appInfo = em.create(
- applicationId, CpNamingUtils.APPLICATION_INFO, application.getProperties() );
-
- writeUserToken( smf.getManagementAppId(), appInfo, encryptionService
- .plainTextCredentials( generateOAuthSecretKey( AuthPrincipalType.APPLICATION ), null, applicationId ) );
-
- addApplicationToOrganization( organizationId, applicationId, appInfo );
- return applicationId;
+ public UUID importApplication( UUID organizationId, final Application application ) throws Exception {
+ throw new UnsupportedOperationException("Import application not supported");
}
@@ -1550,14 +1529,14 @@ public class ManagementServiceImpl implements ManagementService {
@Override
public Map<String, Object> getOrganizationData( OrganizationInfo organization ) throws Exception {
- Map<String, Object> jsonOrganization = new HashMap<String, Object>();
+ Map<String, Object> jsonOrganization = new HashMap<>();
jsonOrganization.putAll( JsonUtils.toJsonMap( organization ) );
BiMap<UUID, String> applications = getApplicationsForOrganization( organization.getUuid() );
jsonOrganization.put( "applications", applications.inverse() );
List<UserInfo> users = getAdminUsersForOrganization( organization.getUuid() );
- Map<String, Object> jsonUsers = new HashMap<String, Object>();
+ Map<String, Object> jsonUsers = new HashMap<>();
for ( UserInfo u : users ) {
jsonUsers.put( u.getUsername(), u );
}
@@ -1631,20 +1610,17 @@ public class ManagementServiceImpl implements ManagementService {
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
- UUID applicationId = emf.createApplication(
- organizationInfo.getName(), applicationName, properties );
+ Entity appInfo = emf.createApplicationV2(
+ organizationInfo.getName(), applicationName, properties);
em.refreshIndex();
- Entity appInfo = em.get(
- new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
-
writeUserToken( smf.getManagementAppId(), appInfo,
encryptionService.plainTextCredentials(
generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
null,
smf.getManagementAppId() ) );
- addApplicationToOrganization( organizationId, applicationId, appInfo );
+ UUID applicationId = addApplicationToOrganization( organizationId, appInfo );
UserInfo user = null;
try {
@@ -1668,20 +1644,6 @@ public class ManagementServiceImpl implements ManagementService {
@Override
public void deleteApplication(UUID applicationId) throws Exception {
-
- // make sure there is not already a delete app with the same name
-
- EntityManager em = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- Entity appToDelete = em.get(
- new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
-
- final EntityRef alias = em.getAlias(
- CpNamingUtils.DELETED_APPLICATION_INFO, appToDelete.getName() );
-
- if ( alias != null ) {
- throw new ConflictException("Cannot delete app with same name as already deleted app");
- }
-
emf.deleteApplication( applicationId );
}
@@ -1701,13 +1663,10 @@ public class ManagementServiceImpl implements ManagementService {
// restore application_info entity
EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
- emf.restoreApplication(applicationId);
+ Entity appInfo = emf.restoreApplication(applicationId);
// restore token
- Entity appInfo = em.get(
- new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
-
writeUserToken( smf.getManagementAppId(), appInfo,
encryptionService.plainTextCredentials(
generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
@@ -1718,7 +1677,7 @@ public class ManagementServiceImpl implements ManagementService {
EntityRef alias = em.getAlias( Group.ENTITY_TYPE, orgName );
Entity orgEntity = em.get( alias );
- addApplicationToOrganization( orgEntity.getUuid(), applicationId, appInfo );
+ addApplicationToOrganization( orgEntity.getUuid(), appInfo );
// create activity
@@ -1773,6 +1732,7 @@ public class ManagementServiceImpl implements ManagementService {
final BiMap<UUID, String> applications = HashBiMap.create();
final EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+ // query for application_info entities
final Results results = em.getConnectedEntities(
new SimpleEntityRef(Group.ENTITY_TYPE, organizationGroupId),
"owns", CpNamingUtils.APPLICATION_INFO, Level.ALL_PROPERTIES );
@@ -1791,7 +1751,11 @@ public class ManagementServiceImpl implements ManagementService {
entityName = entityName.toLowerCase();
}
- applications.put( entity.getUuid(), entityName );
+ // make sure we return applicationId and not the application_info UUID
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ entity.getProperty( PROPERTY_APPLICATION_ID ).toString() );
+
+ applications.put( applicationId, entityName );
}
@@ -1813,8 +1777,14 @@ public class ManagementServiceImpl implements ManagementService {
}
+ /**
+ * @return UUID of the application itself (NOT the application_info entity).
+ */
@Override
- public UUID addApplicationToOrganization( UUID organizationId, UUID applicationId, Entity appInfo ) throws Exception {
+ public UUID addApplicationToOrganization(UUID organizationId, Entity appInfo) throws Exception {
+
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
if ( ( organizationId == null ) || ( applicationId == null ) ) {
return null;
@@ -1860,7 +1830,12 @@ public class ManagementServiceImpl implements ManagementService {
return null;
}
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- Entity entity = em.get( new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
+ EntityRef mgmtAppRef = new SimpleEntityRef( Schema.TYPE_APPLICATION, smf.getManagementAppId() );
+
+ final Results results = em.searchCollection(mgmtAppRef, CpNamingUtils.APPLICATION_INFOS,
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+
+ Entity entity = results.getEntity();
if ( entity != null ) {
return new ApplicationInfo( applicationId, entity.getName() );
@@ -1875,8 +1850,12 @@ public class ManagementServiceImpl implements ManagementService {
return null;
}
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- Entity entity = em.get( new SimpleEntityRef(
- CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ));
+ EntityRef mgmtAppRef = new SimpleEntityRef( Schema.TYPE_APPLICATION, smf.getManagementAppId() );
+
+ final Results results = em.searchCollection(mgmtAppRef, CpNamingUtils.DELETED_APPLICATION_INFOS,
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+
+ Entity entity = results.getEntity();
if ( entity != null ) {
return new ApplicationInfo( applicationId, entity.getName() );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java b/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java
deleted file mode 100644
index 2ec14c8..0000000
--- a/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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.management.exceptions;
-
-public class ConflictException extends ManagementException {
-
- public ConflictException() {
- super();
- }
-
- public ConflictException(String arg0, Throwable arg1) {
- super(arg0, arg1);
- }
-
- public ConflictException(String arg0) {
- super(arg0);
- }
-
- public ConflictException(Throwable arg0) {
- super(arg0);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/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 c117c49..30b7a3c 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
@@ -24,16 +24,16 @@ import org.apache.usergrid.ServiceITSetup;
import org.apache.usergrid.ServiceITSetupImpl;
import org.apache.usergrid.cassandra.ClearShiroSubject;
import org.apache.usergrid.management.OrganizationOwnerInfo;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.*;
import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.persistence.index.query.Query;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.*;
@@ -48,6 +48,7 @@ import static org.junit.Assert.*;
* ManagementService's application and organization logic.
*/
public class AppInfoMigrationPluginTest {
+ private static final Logger logger = LoggerFactory.getLogger(AppInfoMigrationPluginTest.class);
@Rule
public ClearShiroSubject clearShiroSubject = new ClearShiroSubject();
@@ -62,9 +63,11 @@ public class AppInfoMigrationPluginTest {
@Test
public void testRun() throws Exception {
- // create 10 applications, each with 10 entities
+ // create 10 applications, each with 10 entities
- final String orgName = uniqueOrg();
+ logger.debug("\n\nCreate 10 apps each with 10 entities");
+
+ final String orgName = uniqueOrg();
OrganizationOwnerInfo organization = orgAppRule.createOwnerAndOrganization(
orgName, uniqueUsername(), uniqueEmail(),"Ed Anuff", "test" );
@@ -85,46 +88,66 @@ public class AppInfoMigrationPluginTest {
}
}
- assertNotNull("Should be able to get application",
- setup.getEmf().lookupApplication(orgName + "/application0"));
+ UUID mgmtAppId = setup.getEmf().getManagementAppId();
+ EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId );
+
+ checkApplicationsOk( orgName );
// create corresponding 10 appinfo entities in Management app
// and delete the application_info entities from the Management app
- UUID mgmtAppId = setup.getEmf().getManagementAppId();
- EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId );
+ logger.debug("\n\nCreate old-style appinfo entities to be migrated\n");
+ List<Entity> deletedApps = new ArrayList<>();
+
+ int count = 0;
for ( UUID appId : appIds ) {
+
+ final Entity applicationInfo = getApplicationInfo( appId );
+
+ final String appName = applicationInfo.getName();
final String finalOrgId = organization.getOrganization().getUuid().toString();
- final String finalAppId = appId.toString();
+ final String finalAppId = applicationInfo.getProperty( Schema.PROPERTY_APPLICATION_ID ).toString();
rootEm.create("appinfo", new HashMap<String, Object>() {{
+ put("name", appName );
put("organizationUuid", finalOrgId );
put("applicationUuid", finalAppId );
}});
- rootEm.delete( new SimpleEntityRef("application_info", appId ));
+
+ // delete some but not all of the application_info entities
+ // so that we cover both create and update cases
+
+ if ( count++ % 2 == 0 ) {
+ rootEm.delete( applicationInfo );
+ deletedApps.add( applicationInfo );
+ }
}
+ setup.getEmf().refreshIndex();
setup.getEmf().flushEntityManagerCaches();
- // test that applications are now borked
+ Thread.sleep(1000);
+
+ // test that applications are now broken
- assertNull("Should not be able to get application",
- setup.getEmf().lookupApplication(orgName + "/application0"));
+ checkApplicationsBroken( orgName, deletedApps );
// run the migration, which should restore the application_info entities
+ logger.debug("\n\nRun the migration\n");
+
ProgressObserver po = Mockito.mock(ProgressObserver.class);
AppInfoMigrationPlugin plugin = new AppInfoMigrationPlugin();
plugin.emf = setup.getEmf();
plugin.run( po );
+ logger.debug("\n\nVerify migration results\n");
+
// test that expected calls were made the to progress observer (use mock library)
Mockito.verify( po, Mockito.times(10) ).update( Mockito.anyInt(), Mockito.anyString() );
setup.getEmf().refreshIndex();
- // test that 10 appinfo entities have been removed
-
final Results appInfoResults = rootEm.searchCollection(
new SimpleEntityRef("application", mgmtAppId), "appinfos", Query.fromQL("select *"));
assertEquals( 0, appInfoResults.size() );
@@ -133,9 +156,57 @@ public class AppInfoMigrationPluginTest {
new SimpleEntityRef("application", mgmtAppId), "application_infos", Query.fromQL("select *"));
assertEquals( 10, applicationInfoResults.size() );
- // test that 10 applications are no longer borked
+ // test that 10 applications are no longer broken
+
+ checkApplicationsOk( orgName );
+ }
+
+ private void checkApplicationsBroken( String orgName, List<Entity> deletedApps ) throws Exception {
+
+ logger.debug("\n\nChecking applications broken\n");
+
+
+ for ( Entity applicationInfo : deletedApps ) {
+
+ String appName = applicationInfo.getName();
+ UUID uuid = setup.getEmf().lookupApplication( appName );
+
+ // missing application_info does not completely break applications, but we...
+ assertNull("Should not be able to lookup deleted application by name" + appName, uuid);
+ }
+ }
+
+ private void checkApplicationsOk( String orgName) throws Exception {
+
+ logger.debug("\n\nChecking applications OK\n");
+
+ for (int i=0; i<10; i++) {
+
+ String appName = orgName + "/application" + i;
+
+ UUID uuid = setup.getEmf().lookupApplication( appName );
+ assertNotNull("Should be able to get application", uuid );
+
+ EntityManager em = setup.getEmf().getEntityManager( uuid );
+
+ Application app = em.getApplication();
+ assertEquals( appName, app.getName() );
+
+ Results results = em.searchCollection(
+ em.getApplicationRef(), "things", Query.fromQL("select *"));
+ assertEquals( "Should have 10 entities", 10, results.size() );
+ }
+ }
+
+ private Entity getApplicationInfo( UUID appId ) throws Exception {
+
+ UUID mgmtAppId = setup.getEmf().getManagementAppId();
+ EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId );
+
+ final Results applicationInfoResults = rootEm.searchCollection(
+ new SimpleEntityRef("application", mgmtAppId), "application_infos",
+ Query.fromQL("select * where applicationId=" + appId.toString()));
- assertNotNull("Should be able to get application",
- setup.getEmf().lookupApplication(orgName + "/application0"));
+ return applicationInfoResults.getEntity();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60785263/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
index 20b2e17..6e0f37e 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.management.cassandra;
import java.util.Set;
+import org.apache.usergrid.corepersistence.ApplicationIdCacheImpl;
import org.junit.Rule;
import org.junit.Test;
[47/50] incubator-usergrid git commit: Add wait to lookupApplication()
Posted by sn...@apache.org.
Add wait to lookupApplication()
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e6117930
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e6117930
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e6117930
Branch: refs/heads/two-dot-o-dev
Commit: e61179305c98a58168bfd672ea46ee789d0fe32a
Parents: 2eca36f
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 30 09:50:23 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 30 09:50:23 2015 -0400
----------------------------------------------------------------------
.../cassandra/EntityManagerFactoryImplIT.java | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e6117930/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index d52f3f6..b64f0b5 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -166,7 +166,15 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
// attempt to get entities in application's collections in various ways should all fail
- assertNull( setup.getEmf().lookupApplication( orgName + "/" + appName ));
+ for ( int i=0; i<maxRetries; i++ ) {
+ found = ( setup.getEmf().lookupApplication( orgName + "/" + appName ) != null );
+ if ( found ) {
+ Thread.sleep( 500 );
+ } else {
+ break;
+ }
+ }
+ assertFalse( "Lookup of deleted app must fail", found );
// app must not be found in apps collection
@@ -182,6 +190,8 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
// restore the app
+ emf.refreshIndex();
+
emf.restoreApplication( deletedAppId );
emf.rebuildAllIndexes(new EntityManagerFactory.ProgressObserver() {
[44/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/efb7d6f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/efb7d6f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/efb7d6f5
Branch: refs/heads/two-dot-o-dev
Commit: efb7d6f553f24ede9fb8f27459e9d59e5156f430
Parents: f007f47 e4466e1
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 24 14:40:02 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 24 14:40:02 2015 -0400
----------------------------------------------------------------------
.../usergrid/security/providers/PingIdentityProvider.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------
[50/50] incubator-usergrid git commit: Merge branch 'two-dot-o-dev'
of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into
two-dot-o-dev
Posted by sn...@apache.org.
Merge branch 'two-dot-o-dev' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-dev
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/217e7dc1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/217e7dc1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/217e7dc1
Branch: refs/heads/two-dot-o-dev
Commit: 217e7dc13297e81e84eafdc6297fbcc1d2eb9bf3
Parents: d2be54b 07cb9df
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 30 15:57:45 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 30 15:57:45 2015 -0400
----------------------------------------------------------------------
.../AllApplicationsObservable.java | 8 +-
.../usergrid/corepersistence/CoreModule.java | 9 +-
.../corepersistence/CpEntityManager.java | 122 +++++-----
.../corepersistence/CpEntityManagerFactory.java | 14 +-
.../rx/impl/AbstractGraphVisitorImpl.java | 2 +-
.../rx/impl/AllApplicationsObservableImpl.java | 2 +-
.../rx/ApplicationObservableTestIT.java | 2 +-
.../core/metrics/MetricsFactory.java | 2 +-
.../data/DataMigrationManagerImpl.java | 9 +-
.../impl/migration/EdgeDataMigrationImpl.java | 2 +-
.../index/ApplicationEntityIndex.java | 20 +-
.../usergrid/persistence/index/EntityIndex.java | 12 +-
.../usergrid/persistence/index/IndexAlias.java | 38 ++++
.../persistence/index/IndexBufferConsumer.java | 2 +-
.../persistence/index/IndexBufferProducer.java | 2 +-
.../usergrid/persistence/index/IndexCache.java | 39 ++++
.../persistence/index/IndexIdentifier.java | 57 +----
.../usergrid/persistence/index/SearchType.java | 12 +-
.../usergrid/persistence/index/SearchTypes.java | 3 +-
.../persistence/index/guice/IndexModule.java | 45 +++-
.../persistence/index/impl/DeIndexRequest.java | 42 ++--
.../index/impl/EntityToMapConverter.java | 173 ++++++++++++++
.../impl/EsApplicationEntityIndexImpl.java | 228 +++++++------------
.../index/impl/EsEntityIndexBatchImpl.java | 219 +-----------------
.../index/impl/EsEntityIndexFactoryImpl.java | 4 +-
.../index/impl/EsEntityIndexImpl.java | 32 ++-
.../persistence/index/impl/EsIndexCache.java | 142 ------------
.../index/impl/EsIndexCacheImpl.java | 141 ++++++++++++
.../index/impl/IndexIdentifierImpl.java | 68 ++++++
.../persistence/index/impl/IndexRequest.java | 24 +-
.../persistence/index/impl/IndexingUtils.java | 10 +-
.../impl/SearchRequestBuilderStrategy.java | 195 ++++++++++++++++
.../migration/EsIndexDataMigrationImpl.java | 105 +++++++++
.../index/migration/EsIndexMigrationPlugin.java | 46 ++++
.../index/migration/IndexDataVersions.java | 39 ++++
.../index/migration/IndexMigration.java | 35 +++
.../index/migration/LegacyIndexIdentifier.java | 78 +++++++
.../index/query/CandidateResults.java | 24 +-
.../usergrid/persistence/index/query/Query.java | 36 +--
.../index/guice/TestIndexModule.java | 51 ++++-
.../index/impl/BufferQueueSQSImplTest.java | 20 +-
.../persistence/index/impl/EntityIndexTest.java | 60 +++--
.../index/impl/IndexLoadTestsIT.java | 4 -
.../index/impl/IndexMigrationTest.java | 106 +++++++++
.../persistence/query/tree/GrammarTreeTest.java | 10 +-
.../org/apache/usergrid/rest/RootResource.java | 2 +-
46 files changed, 1513 insertions(+), 783 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/217e7dc1/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index b62cdf8,d994419..62f2d1b
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@@ -16,7 -16,7 +16,8 @@@
package org.apache.usergrid.corepersistence;
+import org.apache.usergrid.corepersistence.migration.*;
+ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.springframework.context.ApplicationContext;
import org.apache.usergrid.corepersistence.events.EntityDeletedHandler;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/217e7dc1/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index baac821,99204a8..c613e44
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -156,11 -164,10 +156,9 @@@ public class CpEntityManagerFactory imp
em.getApplication();
}
- ApplicationScope appScope = new ApplicationScopeImpl(new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ) );
- ApplicationEntityIndex applicationEntityIndex = entityIndexFactory.createApplicationEntityIndex(appScope);
- applicationEntityIndex.initializeIndex();
+ entityIndex.initialize();
entityIndex.refresh();
-
} catch (Exception ex) {
throw new RuntimeException("Fatal error creating system application", ex);
}
@@@ -259,14 -263,59 +257,10 @@@
throw new ApplicationAlreadyExistsException( appName );
}
- ApplicationScope applicationScope = new ApplicationScopeImpl(new SimpleId( applicationId,"application"));
- ApplicationEntityIndex applicationEntityIndex = entityIndexFactory.createApplicationEntityIndex(applicationScope);
- applicationEntityIndex.initializeIndex();
-
getSetup().setupApplicationKeyspace( applicationId, appName );
- final Optional<UUID> cachedValue = orgApplicationCache.getOrganizationId( organizationName );
-
-
- UUID orgUuid;
-
- if ( !cachedValue.isPresent() ) {
-
-
- // create new org because the specified one does not exist
- final String orgName = organizationName;
-
-
-
- try {
- final Entity orgInfo = em.create( "organization", new HashMap<String, Object>() {{
- put( PROPERTY_NAME, orgName );
- }} );
- orgUuid = orgInfo.getUuid();
- //evit so it's re-loaded later
- orgApplicationCache.evictOrgId( name );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- //swallow, if it exists, just get it
- orgApplicationCache.evictOrgId( organizationName );
- orgUuid = orgApplicationCache.getOrganizationId( organizationName ).get();
- }
-
- } else{
- orgUuid = cachedValue.get();
- }
-
- // create appinfo entry in the system app
- final UUID appId = applicationId;
- final UUID orgId = orgUuid;
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put( PROPERTY_NAME, appName );
- put( "applicationUuid", appId );
- put( "organizationUuid", orgId );
- }};
-
- try {
- em.create( "appinfo", appInfoMap );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- throw new ApplicationAlreadyExistsException( appName );
- }
- entityIndex.refresh();
-
- // create application entity
if ( properties == null ) {
- properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
+ properties = new TreeMap<>( CASE_INSENSITIVE_ORDER );
}
properties.put( PROPERTY_NAME, appName );
EntityManager appEm = getEntityManager( applicationId);
@@@ -722,15 -724,9 +716,9 @@@
public void rebuildApplicationIndexes( UUID appId, ProgressObserver po ) throws Exception {
EntityManager em = getEntityManager( appId );
- ApplicationScope applicationScope = new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ));
- //explicitly invoke create index, we don't know if it exists or not in ES during a rebuild.
- ApplicationEntityIndex applicationEntityIndex = entityIndexFactory.createApplicationEntityIndex(applicationScope);
- applicationEntityIndex.initializeIndex();
- em.reindex(po);
-
em.reindex( po );
- logger.info("\n\nRebuilt index for applicationId {} \n", appId );
+ logger.info("\n\nRebuilt index for applicationId {} \n", appId);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/217e7dc1/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
index 8dbea19,b57f088..d872b71
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
@@@ -71,20 -69,21 +71,20 @@@ public class AllApplicationsObservableI
@Override
- public Observable<ApplicationScope> getAllApplications() {
+ public Observable<ApplicationScope> getData() {
- //emit our 3 hard coded applications that are used the manage the system first.
+ //emit our hard coded applications that are used the manage the system first.
//this way consumers can perform whatever work they need to on the root system first
- final Observable<ApplicationScope> systemIds = Observable.from( Arrays
- .asList( getApplicationScope( CpNamingUtils.DEFAULT_APPLICATION_ID ),
+ final Observable<ApplicationScope> systemIds = Observable.from(
+ Arrays.asList(
getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID ),
- getApplicationScope( CpNamingUtils.SYSTEM_APP_ID ) ) );
+ getApplicationScope( CpNamingUtils.SYSTEM_APP_ID ))); // still need deprecated system app here
-
- final ApplicationScope appScope = getApplicationScope( CpNamingUtils.SYSTEM_APP_ID );
+ final ApplicationScope appScope = getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
final CollectionScope appInfoCollectionScope =
- new CollectionScopeImpl( appScope.getApplication(), appScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPINFOS ) );
+ new CollectionScopeImpl( appScope.getApplication(), appScope.getApplication(),
+ CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPLICATION_INFOS) );
final EntityCollectionManager collectionManager =
entityCollectionManagerFactory.createCollectionManager( appInfoCollectionScope );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/217e7dc1/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/217e7dc1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 98640c3,ee28939..6b3a11d
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@@ -29,8 -30,12 +30,9 @@@ import org.apache.usergrid.persistence.
import org.apache.usergrid.persistence.core.util.Health;
import org.apache.usergrid.persistence.index.*;
import org.apache.usergrid.persistence.index.exceptions.IndexException;
-
+ import org.apache.usergrid.persistence.index.migration.IndexDataVersions;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
import org.elasticsearch.action.ActionFuture;
-
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
[29/50] incubator-usergrid git commit: Run tests with 1 fork and 1
thread until we figure out how to make tests run concurrently again.
Posted by sn...@apache.org.
Run tests with 1 fork and 1 thread until we figure out how to make tests run concurrently again.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f1bf0354
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f1bf0354
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f1bf0354
Branch: refs/heads/two-dot-o-dev
Commit: f1bf0354b3f2326cd610f7d8b63563459b8b6f4f
Parents: 8ea46ba
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 19 16:47:08 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 19 16:47:08 2015 -0400
----------------------------------------------------------------------
stack/pom.xml | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f1bf0354/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index f24917a..da8e696 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -121,8 +121,10 @@
<!-- only use half the cores on the machine for testing -->
<usergrid.it.parallel>methods</usergrid.it.parallel>
<usergrid.it.reuseForks>true</usergrid.it.reuseForks>
- <usergrid.it.forkCount>4</usergrid.it.forkCount>
- <usergrid.it.threads>8</usergrid.it.threads>
+
+ <!-- run with 1 fork and 1 thread until we figure out how to make tests run concurrently again -->
+ <usergrid.it.forkCount>1</usergrid.it.forkCount>
+ <usergrid.it.threads>1</usergrid.it.threads>
<metrics.version>3.0.0</metrics.version>
<rx.version>0.19.6</rx.version>
[20/50] incubator-usergrid git commit: Apparently,
we need both data and regular migrations.
Posted by sn...@apache.org.
Apparently, we need both data and regular migrations.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/01d22ec1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/01d22ec1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/01d22ec1
Branch: refs/heads/two-dot-o-dev
Commit: 01d22ec13cb3e05ab280e7a63be95c774c07ce25
Parents: 44b5690
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 12 18:16:37 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 12 18:16:37 2015 -0400
----------------------------------------------------------------------
.../apache/usergrid/rest/MigrateResource.java | 50 +++++++++++++-------
1 file changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/01d22ec1/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
index f249512..27055f3 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
@@ -52,23 +52,24 @@ import com.sun.jersey.api.json.JSONWithPadding;
@Component
@Scope( "singleton" )
@Produces( {
- MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
- "application/ecmascript", "text/jscript"
+ MediaType.APPLICATION_JSON,
+ "application/javascript",
+ "application/x-javascript",
+ "text/ecmascript",
+ "application/ecmascript",
+ "text/jscript"
} )
public class MigrateResource extends AbstractContextResource {
private static final Logger logger = LoggerFactory.getLogger( MigrateResource.class );
-
public MigrateResource() {
logger.info( "SystemResource initialized" );
}
-
@Autowired
private Injector guiceInjector;
-
@RequireSystemAccess
@PUT
@Path( "run" )
@@ -85,7 +86,17 @@ public class MigrateResource extends AbstractContextResource {
@Override
public void run() {
- logger.info( "Migrating Data " );
+
+ logger.info( "Migrating Schema" );
+
+ try {
+ getMigrationManager().migrate();
+ }
+ catch ( Exception e ) {
+ logger.error( "Unable to migrate data", e );
+ }
+
+ logger.info( "Migrating Data" );
try {
getDataMigrationManager().migrate();
@@ -100,7 +111,6 @@ public class MigrateResource extends AbstractContextResource {
migrate.setDaemon( true );
migrate.start();
-
response.setSuccess();
return new JSONWithPadding( response, callback );
@@ -110,15 +120,14 @@ public class MigrateResource extends AbstractContextResource {
@RequireSystemAccess
@PUT
@Path( "set" )
- public JSONWithPadding setMigrationVersion( @Context UriInfo ui, Map<String, Object> json,
- @QueryParam( "callback" ) @DefaultValue( "" ) String callback )
+ public JSONWithPadding setMigrationVersion(
+ @Context UriInfo ui, Map<String, Object> json,
+ @QueryParam( "callback" ) @DefaultValue( "" ) String callback )
throws Exception {
logger.debug( "setMigrationVersion" );
Preconditions.checkNotNull( json, "You must provide a json body" );
-
-
Preconditions.checkArgument( json.keySet().size() > 0, "You must specify at least one module and version" );
/**
@@ -144,8 +153,9 @@ public class MigrateResource extends AbstractContextResource {
@RequireSystemAccess
@GET
@Path( "status" )
- public JSONWithPadding migrateStatus( @Context UriInfo ui,
- @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
+ public JSONWithPadding migrateStatus(
+ @Context UriInfo ui,
+ @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
throws Exception {
ApiResponse response = createApiResponse();
@@ -172,8 +182,9 @@ public class MigrateResource extends AbstractContextResource {
@RequireSystemAccess
@GET
@Path( "count" )
- public JSONWithPadding migrateCount( @Context UriInfo ui,
- @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
+ public JSONWithPadding migrateCount(
+ @Context UriInfo ui,
+ @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
throws Exception {
ApiResponse response = createApiResponse();
@@ -188,7 +199,14 @@ public class MigrateResource extends AbstractContextResource {
/**
- * Get the Data migraiton manager
+ * Get the schema migration manager
+ */
+ private MigrationManager getMigrationManager() {
+ return guiceInjector.getInstance( MigrationManager.class );
+ }
+
+ /**
+ * Get the Data migration manager
*/
private DataMigrationManager getDataMigrationManager() {
return guiceInjector.getInstance( DataMigrationManager.class );
[03/50] incubator-usergrid git commit: Changes to merge appinfo and
application_info collections into one application_info collection. Also: -
Removed unnecessary system and default applications - Now use seek rather
than search to load application info
Posted by sn...@apache.org.
Changes to merge appinfo and application_info collections into one application_info collection. Also:
- Removed unnecessary system and default applications
- Now use seek rather than search to load application info entities
- Uncommented the parts of ApplicationDeleteTest that did not work before the appinfo fix
- Will migrate old appinfo collection to application_info on startup, but can be configured to skip that
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c0d50394
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c0d50394
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c0d50394
Branch: refs/heads/two-dot-o-dev
Commit: c0d50394e0e4f3b3669fcfd582b78ce49a86a542
Parents: 4d8678c
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 4 13:34:11 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 4 13:34:11 2015 -0500
----------------------------------------------------------------------
.../main/resources/usergrid-default.properties | 2 +
.../corepersistence/CpEntityManagerFactory.java | 220 +++++++++++++------
.../usergrid/corepersistence/CpSetup.java | 12 +-
.../rx/ApplicationObservable.java | 14 +-
.../corepersistence/util/CpNamingUtils.java | 12 +-
.../persistence/EntityManagerFactory.java | 2 -
.../cassandra/EntityManagerFactoryImpl.java | 4 -
.../persistence/cassandra/SetupImpl.java | 2 -
.../java/org/apache/usergrid/CoreITSetup.java | 2 -
.../org/apache/usergrid/CoreITSetupImpl.java | 6 -
.../rx/ApplicationObservableTestIT.java | 1 -
.../cassandra/EntityManagerFactoryImplIT.java | 2 +-
.../exceptions/NotFoundExceptionMapper.java | 35 +++
.../applications/ApplicationDeleteTest.java | 71 +++---
.../endpoints/mgmt/ManagementResponse.java | 9 +
.../cassandra/ManagementServiceImpl.java | 5 +-
.../services/ServiceManagerFactory.java | 4 -
.../usergrid/services/ServiceRequestIT.java | 9 +-
18 files changed, 249 insertions(+), 163 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/config/src/main/resources/usergrid-default.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/main/resources/usergrid-default.properties b/stack/config/src/main/resources/usergrid-default.properties
index d42d12c..ffc7628 100644
--- a/stack/config/src/main/resources/usergrid-default.properties
+++ b/stack/config/src/main/resources/usergrid-default.properties
@@ -67,6 +67,8 @@ index.query.limit.default=1000
usergrid.entity_cache_size=200
usergrid.entity_cache_timeout_ms=500
+# Once you've run once with migration true, it is safe to disable this
+usergrid.twodoto.appinfo.migration=true
###############################################################################
#
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/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 39243d2..99e07a5 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
@@ -29,13 +29,8 @@ import org.apache.commons.lang.StringUtils;
import org.apache.usergrid.corepersistence.rx.AllEntitiesInSystemObservable;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.AbstractEntity;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityFactory;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.persistence.*;
+
import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
@@ -50,7 +45,7 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.core.util.Health;
import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
@@ -92,7 +87,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private static final Set<UUID> applicationIndexesCreated = new HashSet<UUID>();
- // cache of already instantiated entity managers
+ // cache of already instantiated oldAppInfo managers
private LoadingCache<UUID, EntityManager> entityManagers
= CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<UUID, EntityManager>() {
public EntityManager load(UUID appId) { // no checked exception
@@ -118,7 +113,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.managerCache = injector.getInstance( ManagerCache.class );
this.dataMigrationManager = injector.getInstance( DataMigrationManager.class );
-
+ // can be removed after everybody moves to Usergrid 2.0, default is true
+ Properties configProps = cassandraService.getProperties();
+ if ( configProps.getProperty("usergrid.twodoto.appinfo.migration", "true").equals("true")) {
+ migrateOldAppInfos();
+ }
}
@@ -164,7 +163,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
return entityManagers.get( applicationId );
}
catch ( Exception ex ) {
- logger.error("Error getting entity manager", ex);
+ logger.error("Error getting oldAppInfo manager", ex);
}
return _getEntityManager( applicationId );
}
@@ -254,13 +253,12 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
em.refreshIndex();
}
- // create appinfo entry in the system app
+ // create appinfo entry in the management app
final UUID appId = applicationId;
final UUID orgId = orgUuid;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
put( PROPERTY_UUID, appId );
- put( "organizationUuid", orgId );
}};
try {
@@ -270,7 +268,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
em.refreshIndex();
- // create application entity
+ // create application oldAppInfo
if ( properties == null ) {
properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
}
@@ -299,21 +297,19 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void deleteApplication(UUID applicationId) throws Exception {
- // remove old appinfo Entity, which is in the System App's appinfos collection
+ // remove old appinfo Entity, which is in the Management App's appinfos collection
EntityManager em = getEntityManager( this.getManagementAppId() );
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection( em.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS, q );
- Entity appToDelete = results.getEntity();
- em.delete( appToDelete );
+ Entity applicationInfo = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+ em.delete( applicationInfo );
// create new Entity in deleted_appinfos collection, with same UUID and properties as deleted appinfo
- em.create( CpNamingUtils.DELETED_APPINFO, appToDelete.getProperties() );
+ em.create( applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, applicationInfo.getProperties() );
em.refreshIndex();
// delete the application's index
- EntityIndex ei = managerCache.getEntityIndex(new ApplicationScopeImpl(
- new SimpleId(applicationId, TYPE_APPLICATION)));
+ EntityIndex ei = managerCache.getEntityIndex(
+ new ApplicationScopeImpl( new SimpleId(applicationId, TYPE_APPLICATION)) );
ei.deleteIndex();
}
@@ -323,9 +319,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// remove old delete_appinfos Entity
EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection(em.getApplicationRef(), CpNamingUtils.DELETED_APPINFOS, q);
- Entity appToRestore = results.getEntity();
+ Entity appToRestore = em.get( new SimpleEntityRef( CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ));
if ( appToRestore == null ) {
throw new EntityNotFoundException("Cannot restore. Deleted Application not found: " + applicationId );
@@ -333,18 +327,15 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
em.delete( appToRestore );
- // restore entity in appinfo collection
- Map<String, Object> appProps = appToRestore.getProperties();
- appProps.remove("uuid");
- Entity restoredApp = em.create(CpNamingUtils.APPLICATION_INFO, appToRestore.getProperties());
-
+ // restore oldAppInfo in appinfo collection
+ em.create( appToRestore.getUuid(), CpNamingUtils.APPLICATION_INFO, appToRestore.getProperties());
em.refreshIndex();
// rebuild the apps index
this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@Override
public void onProgress(EntityRef entity) {
- logger.info("Restored entity {}:{}", entity.getType(), entity.getUuid());
+ logger.info("Restored oldAppInfo {}:{}", entity.getType(), entity.getUuid());
}
});
@@ -383,20 +374,67 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
- public UUID lookupApplication( String name ) throws Exception {
+ public UUID lookupApplication( final String name ) throws Exception {
init();
+ // attempt to look up APPLICATION_INFO oldAppInfo by name
+
+ UUID applicationId = null;
EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
final EntityRef alias = em.getAlias( CpNamingUtils.APPLICATION_INFO, name );
- if ( alias == null ) {
- return null;
- }
- final Entity entity = em.get( alias );
- if ( entity == null ) {
- return null;
- }
- final UUID property = ( UUID ) entity.getProperty( "uuid" );
- return property;
+ if ( alias != null ) {
+ Entity entity = em.get(alias);
+ applicationId = (UUID) entity.getProperty("uuid");
+ }
+
+ // below is not necessary if migrateOldAppInfos() has already run
+
+// if ( applicationId == null ) {
+//
+// // maybe there is a record in the old and deprecated "appinfos" collection
+//
+// UUID organizationId = null;
+//
+// Query q = Query.fromQL( PROPERTY_NAME + " = '" + name + "'");
+// Results results = em.searchCollection( em.getApplicationRef(), "appinfos" , q);
+// if ( !results.isEmpty() ) {
+// Entity entity = results.iterator().next();
+// Object uuidObject = entity.getProperty("applicationUuid");
+// if (uuidObject instanceof UUID) {
+// applicationId = (UUID)uuidObject;
+// } else {
+// applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+// }
+// uuidObject = entity.getProperty("organizationUuid");
+// if (uuidObject instanceof UUID) {
+// organizationId = (UUID)uuidObject;
+// } else {
+// organizationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+// }
+// }
+//
+// if ( applicationId != null ) {
+//
+// // copy application information into new APPLICATION_INFO collection
+//
+// final UUID appId = applicationId;
+// Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
+// put( PROPERTY_NAME, name );
+// put( PROPERTY_UUID, appId );
+// }};
+//
+// final Entity appInfo;
+// try {
+// appInfo = em.create( appId, CpNamingUtils.APPLICATION_INFO, appInfoMap );
+// } catch (DuplicateUniquePropertyExistsException e) {
+// throw new ApplicationAlreadyExistsException(name);
+// }
+// em.createConnection( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId ), "owns", appInfo );
+// em.refreshIndex();
+// }
+// }
+
+ return applicationId;
}
@@ -429,8 +467,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
final String scopeName;
final String edgeType;
if ( deleted ) {
- edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.DELETED_APPINFOS);
- scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(CpNamingUtils.DELETED_APPINFOS);
+ edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.DELETED_APPLICATION_INFOS);
+ scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(CpNamingUtils.DELETED_APPLICATION_INFOS);
} else {
edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.APPLICATION_INFOS );
scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(CpNamingUtils.APPLICATION_INFOS);
@@ -464,19 +502,82 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
.toBlockingObservable().lastOrDefault(null);
if ( e == null ) {
- logger.warn("Applicaion {} in index but not found in collections", targetId );
+ logger.warn("Application {} in index but not found in collections", targetId );
continue;
}
- appMap.put(
- (String)e.getField( PROPERTY_NAME ).getValue(),
- (UUID)e.getField( "applicationUuid" ).getValue());
+ appMap.put( (String)e.getField( PROPERTY_NAME ).getValue(), e.getId().getUuid());
}
return appMap;
}
+ private void migrateOldAppInfos() {
+
+ EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+
+ Query q = Query.fromQL("select *");
+ Results results = null;
+ try {
+ results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
+ } catch (Exception e) {
+ logger.error("Error reading old appinfos collection, not migrating", e);
+ return;
+ }
+
+ if ( !results.isEmpty() ) {
+
+ // applications still found in old appinfos collection, migrate them.
+ logger.info("Migrating old appinfos");
+
+ for ( Entity oldAppInfo : results.getEntities() ) {
+
+ final String appName = oldAppInfo.getName();
+
+ UUID applicationId = null, organizationId = null;
+ Object uuidObject = oldAppInfo.getProperty("applicationUuid");
+ if (uuidObject instanceof UUID) {
+ applicationId = (UUID) uuidObject;
+ } else {
+ applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+ }
+ uuidObject = oldAppInfo.getProperty("organizationUuid");
+ if (uuidObject instanceof UUID) {
+ organizationId = (UUID) uuidObject;
+ } else {
+ organizationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+ }
+
+ // create and connect new APPLICATION_INFO oldAppInfo to Organization
+
+ final UUID appId = applicationId;
+ Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
+ put(PROPERTY_NAME, appName);
+ put(PROPERTY_UUID, appId);
+ }};
+
+ final Entity appInfo;
+ try {
+ appInfo = em.create(appId, CpNamingUtils.APPLICATION_INFO, appInfoMap);
+ em.createConnection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "owns", appInfo);
+ em.delete( oldAppInfo );
+ logger.info("Migrated old appinfo for app {}", appName);
+
+ } catch (Exception e) {
+ logger.error("Error migration application " + appName + " continuing ", e);
+ }
+ }
+
+ em.refreshIndex();
+
+ } else {
+ logger.info("No old appinfos found, no need for migration");
+ }
+
+ }
+
+
@Override
public void setup() throws Exception {
getSetup().init();
@@ -628,14 +729,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
- @Override
- public UUID getDefaultAppId() {
- return CpNamingUtils.DEFAULT_APPLICATION_ID;
- }
-
-
-
-
/**
* Gets the setup.
* @return Setup helper
@@ -678,14 +771,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private List<EntityIndex> getManagementIndexes() {
return Arrays.asList(
-
- // management app
- managerCache
- .getEntityIndex( new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) ),
-
- // default app TODO: do we need this in two-dot-o
- managerCache
- .getEntityIndex( new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) ) );
+ managerCache.getEntityIndex( // management app
+ new ApplicationScopeImpl(new SimpleId(getManagementAppId(), "application"))));
}
@@ -700,7 +787,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
logger.info("About to rebuild indexes for {} applications", appMap.keySet().size());
for ( UUID appUuid : appMap.values() ) {
- rebuildApplicationIndexes( appUuid, po );
+ try {
+ rebuildApplicationIndexes(appUuid, po);
+ } catch ( Exception e) {
+ logger.error("Error rebuilding index for app " + appUuid + " continuing...", e );
+ }
}
}
@@ -708,7 +799,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void rebuildInternalIndexes( ProgressObserver po ) throws Exception {
rebuildApplicationIndexes( CpNamingUtils.MANAGEMENT_APPLICATION_ID, po );
- rebuildApplicationIndexes( CpNamingUtils.DEFAULT_APPLICATION_ID, po );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index d70c16c..066a5eb 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -99,17 +99,7 @@ public class CpSetup implements Setup {
injector.getInstance( DataMigrationManager.class ).migrate();
- logger.info( "Setting up default applications" );
-
- try {
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getDefaultAppId(), DEFAULT_APPLICATION, null );
- }
- catch ( ApplicationAlreadyExistsException ex ) {
- logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, DEFAULT_APPLICATION );
- }
- catch ( OrganizationAlreadyExistsException oaee ) {
- logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
- }
+ logger.info( "Setting up management app" );
try {
emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
index 65022e6..bc8882f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
@@ -58,14 +58,10 @@ public class ApplicationObservable {
*/
public static Observable<Id> getAllApplicationIds( final ManagerCache managerCache ) {
- //emit our 3 hard coded applications that are used the manage the system first.
- //this way consumers can perform whatever work they need to on the root system first
-
-
- final Observable<Id> systemIds = Observable.from( Arrays
- .asList( generateApplicationId( CpNamingUtils.DEFAULT_APPLICATION_ID ),
- generateApplicationId( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ) );
-
+ // emit internal hard-coded applications first (currently there is only one)
+ // this way consumers can perform whatever work they need to on the root system first
+ final Observable<Id> systemIds = Observable.from(
+ Arrays.asList( generateApplicationId( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ) );
final ApplicationScope appScope = getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
@@ -114,7 +110,7 @@ public class ApplicationObservable {
@Override
public Id call( final org.apache.usergrid.persistence.model.entity.Entity entity ) {
- final UUID uuid = ( UUID ) entity.getField( "applicationUuid" ).getValue();
+ final UUID uuid = entity.getId().getUuid();
return CpNamingUtils.generateApplicationId( uuid );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 8c8f1c7..8f3327d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -51,20 +51,14 @@ public class CpNamingUtils {
public static final UUID MANAGEMENT_APPLICATION_ID =
UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
- /** TODO Do we need this in two-dot-o? */
- public static final UUID DEFAULT_APPLICATION_ID =
- UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
-
/**
- * The app infos entity object type. This holds the app name, appId, and org name
+ * Information about applications is stored in the management app using these types
*/
public static final String APPLICATION_INFO = "application_info";
-
public static final String APPLICATION_INFOS = "application_infos";
- public static final String DELETED_APPINFO = "deleted_application_info";
-
- public static final String DELETED_APPINFOS = "deleted_application_infos";
+ public static final String DELETED_APPLICATION_INFO = "deleted_application_info";
+ public static final String DELETED_APPLICATION_INFOS = "deleted_application_infos";
/**
* The name of the map that holds our entity id->type mapping
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/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 b668e24..3420b7f 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
@@ -117,8 +117,6 @@ public interface EntityManagerFactory {
public UUID getManagementAppId();
- public UUID getDefaultAppId();
-
public void refreshIndex();
public void rebuildAllIndexes( ProgressObserver po ) throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/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 9a90e59..54eefa4 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
@@ -406,10 +406,6 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
return MANAGEMENT_APPLICATION_ID;
}
- @Override
- public UUID getDefaultAppId() {
- return DEFAULT_APPLICATION_ID;
- }
@Override
public void refreshIndex() {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
index 23c0489..778f2d0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
@@ -63,8 +63,6 @@ public class SetupImpl implements Setup {
public void createDefaultApplications() throws Exception {
// TODO unique check?
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getDefaultAppId(), DEFAULT_APPLICATION, null );
-
emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/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 201a0c5..27475af 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
@@ -29,8 +29,6 @@ import org.apache.usergrid.persistence.cassandra.CassandraService;
public interface CoreITSetup extends TestRule {
- boolean USE_DEFAULT_APPLICATION = false;
-
EntityManagerFactory getEmf();
QueueManagerFactory getQmf();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/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 d403a1e..6557b02 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@ -129,15 +129,9 @@ public class CoreITSetupImpl implements CoreITSetup {
@Override
public UUID createApplication( String organizationName, String applicationName ) throws Exception {
-
- if ( USE_DEFAULT_APPLICATION ) {
- return emf.getDefaultAppId();
- }
-
return emf.createApplication( organizationName, applicationName );
}
-
@Override
public void dump( String name, Object obj ) {
if ( obj != null && LOG.isInfoEnabled() ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
index f21ca94..b564366 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
@@ -54,7 +54,6 @@ public class ApplicationObservableTestIT extends AbstractCoreIT {
//now our get all apps we expect. There may be more, but we don't care about those.
final Set<UUID> applicationIds = new HashSet<UUID>() {{
- add( CpNamingUtils.DEFAULT_APPLICATION_ID );
add( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
add( createdApplication.getUuid() );
}};
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index c3bc020..2f29735 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -132,7 +132,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
}
}
- assertTrue("Deleted app not found in deleted apps collection", found );
+ assertTrue( "Deleted app must be found in in deleted apps collection", found );
// attempt to get entities in application's collections in various ways should all fail
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotFoundExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotFoundExceptionMapper.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotFoundExceptionMapper.java
new file mode 100644
index 0000000..165a8d3
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/NotFoundExceptionMapper.java
@@ -0,0 +1,35 @@
+/*
+ * 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 com.sun.jersey.api.NotFoundException;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+
+
+@Provider
+public class NotFoundExceptionMapper extends AbstractExceptionMapper<NotFoundException> {
+
+ @Override
+ public Response toResponse( NotFoundException e ) {
+ return toResponse( NOT_FOUND, e );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
index 82ec478..8ac449a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
@@ -28,6 +28,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MediaType;
+import java.io.StringReader;
import java.util.*;
@@ -41,14 +42,14 @@ public class ApplicationDeleteTest extends AbstractRestIT {
// create app with a collection of "things"
String orgName = clientSetup.getOrganization().getName();
- String appToDelete = clientSetup.getAppName() + "_appToDelete";
+ String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
ApiResponse appCreateResponse = clientSetup.getRestClient()
.management().orgs().organization( orgName ).app().getResource()
.queryParam( "access_token", orgAdminToken.getAccessToken() )
.type( MediaType.APPLICATION_JSON )
- .post( ApiResponse.class, new Application( appToDelete ) );
+ .post( ApiResponse.class, new Application( appToDeleteName ) );
UUID appToDeleteId = appCreateResponse.getEntities().get(0).getUuid();
List<Entity> entities = new ArrayList<>();
@@ -61,7 +62,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
}});
ApiResponse createResponse = clientSetup.getRestClient()
- .org(orgName).app( appToDelete ).collection("things").getResource()
+ .org(orgName).app( appToDeleteName ).collection("things").getResource()
.queryParam("access_token", orgAdminToken.getAccessToken())
.type(MediaType.APPLICATION_JSON)
.post( ApiResponse.class, entity );
@@ -80,7 +81,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
try {
clientSetup.getRestClient()
- .org(orgName).app(appToDelete).getResource()
+ .org(orgName).app(appToDeleteName).getResource()
.queryParam("access_token", orgAdminToken.getAccessToken())
.type(MediaType.APPLICATION_JSON)
.get(ApiResponse.class);
@@ -97,7 +98,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
try {
clientSetup.getRestClient()
- .org(orgName).app(appToDelete).collection("things").getResource()
+ .org(orgName).app(appToDeleteName).collection("things").getResource()
.queryParam("access_token", orgAdminToken.getAccessToken() )
.type(MediaType.APPLICATION_JSON )
.get(ApiResponse.class);
@@ -115,7 +116,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
try {
UUID entityId = entities.get(0).getUuid();
clientSetup.getRestClient()
- .org(orgName).app(appToDelete).collection("things").entity( entityId ).getResource()
+ .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
.queryParam( "access_token", orgAdminToken.getAccessToken())
.type( MediaType.APPLICATION_JSON)
.get(ApiResponse.class);
@@ -123,6 +124,7 @@ public class ApplicationDeleteTest extends AbstractRestIT {
Assert.fail("Must not be able to get deleted app entity");
} catch ( UniformInterfaceException expected ) {
+ // TODO: why not a 404?
Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
@@ -132,43 +134,40 @@ public class ApplicationDeleteTest extends AbstractRestIT {
refreshIndex();
+ ManagementResponse orgAppResponse = clientSetup.getRestClient()
+ .management().orgs().organization( orgName ).apps().getOrganizationApplications();
- // TODO: uncomment this when USERGRID-448 (redundant appinfos) is fixed
-// ManagementResponse orgAppResponse = clientSetup.getRestClient()
-// .management().orgs().organization( orgName ).apps().getOrganizationApplications();
-//
-// for ( String appName : orgAppResponse.getData().keySet() ) {
-// if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
-// Assert.fail("Deleted app must not be included in list of org apps");
-// }
-// }
+ for ( String appName : orgAppResponse.getData().keySet() ) {
+ if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
+ Assert.fail("Deleted app must not be included in list of org apps");
+ }
+ }
// test that we cannot delete the application a second time
- // TODO: uncomment this when USERGRID-448 (redundant appinfos) is fixed
-// try {
-// clientSetup.getRestClient()
-// .org(orgName).app(appToDeleteId.toString()).getResource()
-// .queryParam("access_token", orgAdminToken.getAccessToken())
-// .delete();
-//
-// } catch ( UniformInterfaceException expected ) {
-// Assert.assertEquals("Error must be 400", 400, expected.getResponse().getStatus() );
-// JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
-// Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
-// }
+ try {
+ clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteId.toString()).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .delete();
+
+ } catch ( UniformInterfaceException expected ) {
+ Assert.assertEquals("Error must be 404", 404, expected.getResponse().getStatus() );
+ JsonNode node = mapper.readTree( expected.getResponse().getEntity( String.class ));
+ Assert.assertEquals("not_found", node.get("error").textValue());
+ }
// test that we can create a new application with the same name
- // TODO: uncomment this when USERGRID-448 (redundant appinfos) is fixed
-// ApiResponse appCreateAgainResponse = clientSetup.getRestClient()
-// .management().orgs().organization( orgName ).app().getResource()
-// .queryParam( "access_token", orgAdminToken.getAccessToken() )
-// .type( MediaType.APPLICATION_JSON )
-// .post( ApiResponse.class, new Application( appToDelete ) );
-//
-// Assert.assertEquals("Must be able to create app with same name as deleted app",
-// "CREATED", appCreateAgainResponse.getStatus().toUpperCase());
+ ApiResponse appCreateAgainResponse = clientSetup.getRestClient()
+ .management().orgs().organization( orgName ).app().getResource()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .type( MediaType.APPLICATION_JSON )
+ .post( ApiResponse.class, new Application( appToDeleteName ) );
+
+ Assert.assertEquals("Must be able to create app with same name as deleted app",
+ (orgName + "/" + appToDeleteName).toLowerCase(),
+ appCreateAgainResponse.getEntities().get(0).get("name"));
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResponse.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResponse.java
index 74240dc..b5cd751 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResponse.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ManagementResponse.java
@@ -28,6 +28,7 @@ public class ManagementResponse {
private Map<String, Object> data;
private long timestamp;
private long duration;
+ private String uri;
public long getDuration() {
return duration;
@@ -60,4 +61,12 @@ public class ManagementResponse {
public void setAction(String action) {
this.action = action;
}
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index a128b4e..39af2eb 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -1639,10 +1639,7 @@ public class ManagementServiceImpl implements ManagementService {
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
em.refreshIndex();
- // already done by EMF
-// properties.put( "name", buildAppName( applicationName, organizationInfo ) );
-// properties.put( "appUuid", applicationId );
-// Entity appInfo = em.create(applicationId, CpNamingUtils.APPLICATION_INFO, properties);
+ // TODO: move this logic into the EntityManagerFactory implementation
String appName = buildAppName( applicationName, organizationInfo );
Query q = Query.fromQL(PROPERTY_NAME + " = '" + appName + "'");
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/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 9a55aa8..abab195 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
@@ -134,8 +134,4 @@ public class ServiceManagerFactory implements ApplicationContextAware {
return emf.getManagementAppId();
}
- public UUID getDefaultAppId() {
- return emf.getDefaultAppId();
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0d50394/stack/services/src/test/java/org/apache/usergrid/services/ServiceRequestIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ServiceRequestIT.java b/stack/services/src/test/java/org/apache/usergrid/services/ServiceRequestIT.java
index c581611..e80bb06 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ServiceRequestIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ServiceRequestIT.java
@@ -41,7 +41,7 @@ import static org.apache.usergrid.services.ServiceParameter.parameters;
-public class ServiceRequestIT {
+public class ServiceRequestIT extends AbstractServiceIT {
private static final Logger logger = LoggerFactory.getLogger( ServiceRequestIT.class );
@@ -49,16 +49,11 @@ public class ServiceRequestIT {
@Rule
public ClearShiroSubject clearShiroSubject = new ClearShiroSubject();
- @Rule
- public ServiceITSetup setup = new ServiceITSetupImpl( );
-
-
@Test
public void testPaths() throws Exception {
- UUID applicationId = setup.getEmf().getDefaultAppId();
- ServiceManager services = setup.getSmf().getServiceManager( applicationId );
+ ServiceManager services = setup.getSmf().getServiceManager( app.getId() );
ServiceRequest path = services.newRequest( ServiceAction.GET, parameters( "users", "bob" ), null );
// path = path.addSegment("users", "bob");
[15/50] incubator-usergrid git commit: First pass at migration
framework-based migration for appinfo to application_info, plus a test.
Posted by sn...@apache.org.
First pass at migration framework-based migration for appinfo to application_info, plus a test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2190a5ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2190a5ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2190a5ae
Branch: refs/heads/two-dot-o-dev
Commit: 2190a5aebb74c0971dcef9d76262211dfccf9b21
Parents: ae111da
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 11 09:43:40 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 11 09:43:40 2015 -0400
----------------------------------------------------------------------
.../corepersistence/ApplicationIdCacheImpl.java | 4 +-
.../usergrid/corepersistence/CoreModule.java | 8 +-
.../corepersistence/CpEntityManagerFactory.java | 31 ++--
.../usergrid/corepersistence/CpSetup.java | 4 +-
.../migration/AppInfoMigrationPlugin.java | 145 +++++++++++++++++++
.../migration/AppInfoVersions.java | 40 +++++
.../migration/CoreDataVersions.java | 8 +-
.../migration/MigrationModuleVersionPlugin.java | 7 +
.../migration/AppInfoMigrationPluginTest.java | 141 ++++++++++++++++++
9 files changed, 361 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/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 d415259..202e68d 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
@@ -66,7 +66,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
return appCache.get( applicationName );
}
catch ( ExecutionException e ) {
- throw new RuntimeException( "Unable to load org cache", e );
+ throw new RuntimeException( "Unable to load app cache", e );
}
}
@@ -85,7 +85,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
applicationId = (UUID) entity.getProperty("uuid");
}
- return Optional.of( applicationId );
+ return Optional.fromNullable( applicationId );
}
catch ( Exception e ) {
throw new RuntimeException( "Unable to retrieve application id", e );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/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 cf927ce..adbc499 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
@@ -16,15 +16,12 @@
package org.apache.usergrid.corepersistence;
+import org.apache.usergrid.corepersistence.migration.*;
import org.springframework.context.ApplicationContext;
import org.apache.usergrid.corepersistence.events.EntityDeletedHandler;
import org.apache.usergrid.corepersistence.events.EntityVersionCreatedHandler;
import org.apache.usergrid.corepersistence.events.EntityVersionDeletedHandler;
-import org.apache.usergrid.corepersistence.migration.CoreMigration;
-import org.apache.usergrid.corepersistence.migration.CoreMigrationPlugin;
-import org.apache.usergrid.corepersistence.migration.EntityTypeMappingMigration;
-import org.apache.usergrid.corepersistence.migration.MigrationModuleVersionPlugin;
import org.apache.usergrid.corepersistence.rx.impl.AllEntitiesInSystemImpl;
import org.apache.usergrid.corepersistence.rx.impl.AllNodesInGraphImpl;
import org.apache.usergrid.corepersistence.rx.impl.AllApplicationsObservableImpl;
@@ -132,7 +129,8 @@ public class CoreModule extends AbstractModule {
//wire up the collection migration plugin
final Multibinder<MigrationPlugin> plugins = Multibinder.newSetBinder( binder(), MigrationPlugin.class );
plugins.addBinding().to( CoreMigrationPlugin.class );
- plugins.addBinding().to(MigrationModuleVersionPlugin.class );
+ plugins.addBinding().to( AppInfoMigrationPlugin.class );
+ plugins.addBinding().to( MigrationModuleVersionPlugin.class );
bind( AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/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 e435cb2..1fb8a7b 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
@@ -236,10 +236,22 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
throw new ApplicationAlreadyExistsException( appName );
}
- // create application info entity in the management app
+ // create application info entity
getSetup().setupApplicationKeyspace( applicationId, appName );
+ if ( properties == null ) {
+ properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
+ }
+ properties.put( PROPERTY_NAME, appName );
+ EntityManager appEm = getEntityManager( applicationId );
+ appEm.create( applicationId, TYPE_APPLICATION, properties );
+ appEm.createIndex();
+ appEm.resetRoles();
+ appEm.refreshIndex();
+
+ // create application info entity in the management app
+
final UUID appId = applicationId;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
@@ -253,23 +265,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
em.refreshIndex();
- // create application info entity
-
- if ( properties == null ) {
- properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
- }
- properties.put( PROPERTY_NAME, appName );
- EntityManager appEm = getEntityManager( applicationId );
- appEm.create( applicationId, TYPE_APPLICATION, properties );
- appEm.createIndex();
- appEm.resetRoles();
- appEm.refreshIndex();
-
- logger.info("Initialized application {}", appName);
-
//evict app Id from cache
orgApplicationCache.evictAppId( appName );
+ logger.info("Initialized application {}", appName);
return applicationId;
}
@@ -691,6 +690,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void flushEntityManagerCaches() {
+ managerCache.invalidate();
+ orgApplicationCache.evictAll();
Map<UUID, EntityManager> entityManagersMap = entityManagers.asMap();
for ( UUID appUuid : entityManagersMap.keySet() ) {
EntityManager em = entityManagersMap.get(appUuid);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index 066a5eb..8dd4a12 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -97,8 +97,6 @@ public class CpSetup implements Setup {
//force the EMF creation of indexes before creating the default applications
emf.refreshIndex();
- injector.getInstance( DataMigrationManager.class ).migrate();
-
logger.info( "Setting up management app" );
try {
@@ -110,6 +108,8 @@ public class CpSetup implements Setup {
catch ( OrganizationAlreadyExistsException oaee ) {
logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
}
+
+ injector.getInstance( DataMigrationManager.class ).migrate();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/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
new file mode 100644
index 0000000..1a456c8
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
@@ -0,0 +1,145 @@
+/*
+ * 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.migration;
+
+import com.google.inject.Inject;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.core.migration.data.MigrationPlugin;
+import org.apache.usergrid.persistence.core.migration.data.PluginPhase;
+import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.entities.Group;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.utils.UUIDUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
+
+
+/**
+ * Migration of appinfos collection to application_info collection.
+ *
+ * Part of USERGRID-448 "Remove redundant appinfos collections in ManagementServiceImpl"
+ * https://issues.apache.org/jira/browse/USERGRID-448
+ */
+public class AppInfoMigrationPlugin implements MigrationPlugin {
+ private static final Logger logger = LoggerFactory.getLogger(AppInfoMigrationPlugin.class);
+
+ public static String PLUGIN_NAME = "appinfo-migration";
+
+ // protected for test purposes only
+ @Inject
+ protected EntityManagerFactory emf;
+
+ @Override
+ public String getName() {
+ return PLUGIN_NAME;
+ }
+
+ @Override
+ public void run(ProgressObserver observer) {
+
+ observer.start();
+
+ EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+
+ Query q = Query.fromQL("select *");
+ Results results;
+ try {
+ results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
+ } catch (Exception e) {
+ logger.error("Error reading old appinfos collection, not migrating", e);
+ return;
+ }
+
+ if ( !results.isEmpty() ) {
+
+ // applications still found in old appinfos collection, migrate them.
+ logger.info("Migrating old appinfos");
+
+ try {
+
+ for (Entity oldAppInfo : results.getEntities()) {
+
+ final String appName = oldAppInfo.getName();
+
+ UUID applicationId;
+ UUID organizationId;
+
+ Object uuidObject = oldAppInfo.getProperty("applicationUuid");
+ if (uuidObject instanceof UUID) {
+ applicationId = (UUID) uuidObject;
+ } else {
+ applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+ }
+ uuidObject = oldAppInfo.getProperty("organizationUuid");
+ if (uuidObject instanceof UUID) {
+ organizationId = (UUID) uuidObject;
+ } else {
+ organizationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+ }
+
+ // create and connect new APPLICATION_INFO oldAppInfo to Organization
+
+ final UUID appId = applicationId;
+ Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
+ put(PROPERTY_NAME, appName);
+ put(PROPERTY_UUID, appId);
+ }};
+
+ final Entity appInfo;
+ appInfo = em.create(appId, CpNamingUtils.APPLICATION_INFO, appInfoMap);
+ em.createConnection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "owns", appInfo);
+ em.delete(oldAppInfo);
+
+ observer.update( getMaxVersion(), "Updated application " + appName);
+ }
+
+ em.refreshIndex();
+
+ } catch (Exception e) {
+ String msg = "Exception writing new application_info collection";
+ logger.error(msg, e);
+ observer.failed( getMaxVersion(), msg);
+ }
+
+ } else {
+ logger.info("No old appinfos found, no need for migration");
+ }
+
+ observer.complete();
+
+ }
+
+ @Override
+ public int getMaxVersion() {
+ return CoreDataVersions.APPINFO_FIX.getVersion();
+ }
+
+ @Override
+ public PluginPhase getPhase() {
+ return PluginPhase.MIGRATE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoVersions.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoVersions.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoVersions.java
new file mode 100644
index 0000000..00787b6
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoVersions.java
@@ -0,0 +1,40 @@
+/*
+ * 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.migration;
+
+
+/**
+ * Enumeration of versions for the application and organization data stored by the system.
+ * Specifically by the CpEntityManagerImpl and MangementSystemImpl classes.
+ */
+public enum AppInfoVersions {
+
+ INITIAL(0),
+ APPINFO_FIX(1); // Migration of appinfo to application_info
+
+ private final int version;
+
+
+ private AppInfoVersions( final int version ) {this.version = version;}
+
+
+ public int getVersion() {
+ return version;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/CoreDataVersions.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/CoreDataVersions.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/CoreDataVersions.java
index 94ff88c..6c80de6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/CoreDataVersions.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/CoreDataVersions.java
@@ -24,11 +24,13 @@ package org.apache.usergrid.corepersistence.migration;
* Versions of data as they exist across our system
*/
public enum CoreDataVersions {
- //even though this didn't really come first in time, we need to run this first in order to bring our system
- //up to date so that our new migration module can proceed.
+
+ // even though this didn't really come first in time, we need to run this first
+ // in order to bring our system up to date so that our new migration module can proceed.
INITIAL(0),
- ID_MAP_FIX(1);
+ ID_MAP_FIX(1),
+ APPINFO_FIX(2);
private final int version;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
index 00e7f11..c979ed5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
@@ -56,6 +56,11 @@ public class MigrationModuleVersionPlugin implements MigrationPlugin{
*/
private static final int ENTITY_V2_MIGRATION = 3;
+ /**
+ * Appinfo to application_info migration.
+ */
+ private static final int APPINFO_MIGRATION = 4;
+
/**
* Get versions directly from impls so we know they're accurate
@@ -102,6 +107,8 @@ public class MigrationModuleVersionPlugin implements MigrationPlugin{
migrationInfoSerialization.setVersion( GraphMigrationPlugin.PLUGIN_NAME, edgeMetadataSerializationV2.getImplementationVersion() );
case ID_MIGRATION:
migrationInfoSerialization.setVersion( CoreMigrationPlugin.PLUGIN_NAME, CoreDataVersions.ID_MAP_FIX.getVersion() );
+ case APPINFO_MIGRATION:
+ migrationInfoSerialization.setVersion( AppInfoMigrationPlugin.PLUGIN_NAME, AppInfoVersions.APPINFO_FIX.getVersion() );
}
//save the version
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2190a5ae/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
new file mode 100644
index 0000000..c117c49
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.migration;
+
+import org.apache.usergrid.NewOrgAppAdminRule;
+import org.apache.usergrid.ServiceITSetup;
+import org.apache.usergrid.ServiceITSetupImpl;
+import org.apache.usergrid.cassandra.ClearShiroSubject;
+import org.apache.usergrid.management.OrganizationOwnerInfo;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.*;
+
+import static org.apache.usergrid.TestHelper.uniqueEmail;
+import static org.apache.usergrid.TestHelper.uniqueOrg;
+import static org.apache.usergrid.TestHelper.uniqueUsername;
+import static org.junit.Assert.*;
+
+
+/**
+ * Really a Core module test but it needs to be here so that it can use
+ * ManagementService's application and organization logic.
+ */
+public class AppInfoMigrationPluginTest {
+
+ @Rule
+ public ClearShiroSubject clearShiroSubject = new ClearShiroSubject();
+
+ @ClassRule
+ public static ServiceITSetup setup = new ServiceITSetupImpl();
+
+ @Rule
+ public NewOrgAppAdminRule orgAppRule = new NewOrgAppAdminRule( setup );
+
+
+ @Test
+ public void testRun() throws Exception {
+
+ // create 10 applications, each with 10 entities
+
+ final String orgName = uniqueOrg();
+ OrganizationOwnerInfo organization = orgAppRule.createOwnerAndOrganization(
+ orgName, uniqueUsername(), uniqueEmail(),"Ed Anuff", "test" );
+
+ List<UUID> appIds = new ArrayList<>();
+
+ for ( int i=0; i<10; i++ ) {
+
+ UUID appId = setup.getMgmtSvc().createApplication(
+ organization.getOrganization().getUuid(), "application" + i ).getId();
+ appIds.add( appId );
+
+ EntityManager em = setup.getEmf().getEntityManager( appId );
+ for ( int j=0; j<10; j++ ) {
+ final String entityName = "thing" + j;
+ em.create("thing", new HashMap<String, Object>() {{
+ put("name", entityName );
+ }});
+ }
+ }
+
+ assertNotNull("Should be able to get application",
+ setup.getEmf().lookupApplication(orgName + "/application0"));
+
+ // create corresponding 10 appinfo entities in Management app
+ // and delete the application_info entities from the Management app
+
+ UUID mgmtAppId = setup.getEmf().getManagementAppId();
+ EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId );
+
+ for ( UUID appId : appIds ) {
+ final String finalOrgId = organization.getOrganization().getUuid().toString();
+ final String finalAppId = appId.toString();
+ rootEm.create("appinfo", new HashMap<String, Object>() {{
+ put("organizationUuid", finalOrgId );
+ put("applicationUuid", finalAppId );
+ }});
+ rootEm.delete( new SimpleEntityRef("application_info", appId ));
+ }
+
+ setup.getEmf().flushEntityManagerCaches();
+
+ // test that applications are now borked
+
+ assertNull("Should not be able to get application",
+ setup.getEmf().lookupApplication(orgName + "/application0"));
+
+ // run the migration, which should restore the application_info entities
+
+ ProgressObserver po = Mockito.mock(ProgressObserver.class);
+ AppInfoMigrationPlugin plugin = new AppInfoMigrationPlugin();
+ plugin.emf = setup.getEmf();
+ plugin.run( po );
+
+ // test that expected calls were made the to progress observer (use mock library)
+
+ Mockito.verify( po, Mockito.times(10) ).update( Mockito.anyInt(), Mockito.anyString() );
+ setup.getEmf().refreshIndex();
+
+ // test that 10 appinfo entities have been removed
+
+ final Results appInfoResults = rootEm.searchCollection(
+ new SimpleEntityRef("application", mgmtAppId), "appinfos", Query.fromQL("select *"));
+ assertEquals( 0, appInfoResults.size() );
+
+ final Results applicationInfoResults = rootEm.searchCollection(
+ new SimpleEntityRef("application", mgmtAppId), "application_infos", Query.fromQL("select *"));
+ assertEquals( 10, applicationInfoResults.size() );
+
+ // test that 10 applications are no longer borked
+
+ assertNotNull("Should be able to get application",
+ setup.getEmf().lookupApplication(orgName + "/application0"));
+ }
+}
[05/50] incubator-usergrid git commit: Fix for changes that broke the
JobSchedulerService by changing the way that MetricsFactory is instantiated.
Posted by sn...@apache.org.
Fix for changes that broke the JobSchedulerService by changing the way that MetricsFactory is instantiated.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c298a457
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c298a457
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c298a457
Branch: refs/heads/two-dot-o-dev
Commit: c298a457f93b2e1cd11827835a11aa9aa697cc8f
Parents: 54ce892
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 5 13:02:50 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 5 13:02:50 2015 -0500
----------------------------------------------------------------------
.../batch/service/JobSchedulerService.java | 28 +++++++++++++++-----
.../main/resources/usergrid-core-context.xml | 3 ++-
2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c298a457/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java b/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
index 5d57ab7..dfd852d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
@@ -25,6 +25,8 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
+import com.google.inject.Injector;
+import org.apache.usergrid.corepersistence.CpSetup;
import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,6 +77,8 @@ public class JobSchedulerService extends AbstractScheduledService {
private Counter successCounter;
private Counter failCounter;
+ private Injector injector;
+
//TODO Add meters for throughput of start and stop
@@ -86,6 +90,13 @@ public class JobSchedulerService extends AbstractScheduledService {
@Override
protected void runOneIteration() throws Exception {
+ MetricsFactory metricsFactory = injector.getInstance( MetricsFactory.class );
+
+ jobTimer = metricsFactory.getTimer( JobSchedulerService.class, "job_execution_timer" );
+ runCounter = metricsFactory.getCounter( JobSchedulerService.class, "running_workers" );
+ successCounter = metricsFactory.getCounter( JobSchedulerService.class, "successful_jobs" );
+ failCounter = metricsFactory.getCounter( JobSchedulerService.class, "failed_jobs" );
+
try {
LOG.info( "Running one check iteration ..." );
List<JobDescriptor> activeJobs;
@@ -338,12 +349,13 @@ public class JobSchedulerService extends AbstractScheduledService {
/**
* Set the metrics factory
*/
- public void setMetricsFactory( MetricsFactory metricsFactory ) {
- jobTimer = metricsFactory.getTimer( JobSchedulerService.class, "job_execution_timer" );
- runCounter = metricsFactory.getCounter( JobSchedulerService.class, "running_workers" );
- successCounter = metricsFactory.getCounter( JobSchedulerService.class, "successful_jobs" );
- failCounter = metricsFactory.getCounter( JobSchedulerService.class, "failed_jobs" );
- }
+// public void setMetricsFactory( MetricsFactory metricsFactory ) {
+//
+// jobTimer = metricsFactory.getTimer( JobSchedulerService.class, "job_execution_timer" );
+// runCounter = metricsFactory.getCounter( JobSchedulerService.class, "running_workers" );
+// successCounter = metricsFactory.getCounter( JobSchedulerService.class, "successful_jobs" );
+// failCounter = metricsFactory.getCounter( JobSchedulerService.class, "failed_jobs" );
+// }
/*
@@ -404,6 +416,10 @@ public class JobSchedulerService extends AbstractScheduledService {
return jobListener;
}
+ public void setInjector(Injector injector) {
+ this.injector = injector;
+ }
+
/**
* Simple factory for labeling job worker threads for easier debugging
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c298a457/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml
index c8ce0d8..bb5d114 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -188,6 +188,7 @@
<property name="workerSize" value="${usergrid.scheduler.job.workers}" />
<property name="interval" value="${usergrid.scheduler.job.interval}" />
<property name="maxFailCount" value="${usergrid.scheduler.job.maxfail}" />
+ <property name="injector" ref="injector" />
</bean>
<bean id="schedulerService" class="org.apache.usergrid.batch.service.SchedulerServiceImpl">
@@ -196,7 +197,7 @@
</bean>
<bean id="jobFactory" class="org.apache.usergrid.batch.UsergridJobFactory" />
-
+
<context:component-scan base-package="org.apache.usergrid.batch.job" />
<context:annotation-config />
[45/50] incubator-usergrid git commit: Fixes issue with throwable not
being caught in onSubscribe function
Posted by sn...@apache.org.
Fixes issue with throwable not being caught in onSubscribe function
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2d1c8b8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2d1c8b8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2d1c8b8a
Branch: refs/heads/two-dot-o-dev
Commit: 2d1c8b8ac7b20b63a11d83adca56839d8b409cca
Parents: beb2a2a
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Mar 26 09:47:58 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Mar 26 09:47:58 2015 -0600
----------------------------------------------------------------------
.../index/impl/EsIndexBufferConsumerImpl.java | 39 +++++++-------------
1 file changed, 14 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2d1c8b8a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index 7e64de3..d064b97 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@ -153,12 +153,16 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
//name our thread so it's easy to see
Thread.currentThread().setName( "QueueConsumer_" + counter.incrementAndGet() );
- List<IndexOperationMessage> drainList;
+
+ List<IndexOperationMessage> drainList = null;
+
do {
- try {
+ Timer.Context timer = produceTimer.time();
+
+
+ try {
- Timer.Context timer = produceTimer.time();
drainList = bufferQueue
.take( config.getIndexBufferSize(), config.getIndexBufferTimeout(),
@@ -174,10 +178,15 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
timer.stop();
}
- catch ( Exception e ) {
+ catch ( Throwable t ) {
final long sleepTime = config.getFailureRetryTime();
- log.error( "Failed to dequeue. Sleeping for {} milliseconds", sleepTime, e );
+ log.error( "Failed to dequeue. Sleeping for {} milliseconds", sleepTime, t );
+
+ if ( drainList != null ) {
+ inFlight.addAndGet( -1 * drainList.size() );
+ }
+
try {
Thread.sleep( sleepTime );
@@ -216,26 +225,6 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
inFlight.addAndGet( -1 * indexOperationMessages.size() );
}
} )
- //catch an unexpected error, then emit an empty list to ensure our subscriber doesn't die
- .onErrorReturn( new Func1<Throwable, List<IndexOperationMessage>>() {
- @Override
- public List<IndexOperationMessage> call( final Throwable throwable ) {
- final long sleepTime = config.getFailureRetryTime();
-
- log.error( "Failed to dequeue. Sleeping for {} milliseconds", sleepTime, throwable );
-
- try {
- Thread.sleep( sleepTime );
- }
- catch ( InterruptedException ie ) {
- //swallow
- }
-
- indexErrorCounter.inc();
-
- return Collections.EMPTY_LIST;
- }
- } )
.subscribeOn( Schedulers.newThread() );
[09/50] incubator-usergrid git commit: Many fixes to application
delete and restore logic, ApplicationDeleteTests now complete and all passing.
Posted by sn...@apache.org.
Many fixes to application delete and restore logic, ApplicationDeleteTests now complete and all passing.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/14f45ed1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/14f45ed1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/14f45ed1
Branch: refs/heads/two-dot-o-dev
Commit: 14f45ed1455abea62b534da8662f246dcbb8d6e9
Parents: b7e41f2
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 6 16:35:52 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 6 16:35:52 2015 -0500
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 124 +++++------
.../corepersistence/util/CpNamingUtils.java | 3 -
.../persistence/EntityManagerFactory.java | 7 +-
.../rest/applications/ApplicationResource.java | 21 +-
.../exceptions/ConflictExceptionMapper.java | 35 +++
.../applications/ApplicationsResource.java | 34 +--
.../organizations/OrganizationResource.java | 11 +-
.../applications/ApplicationDeleteTest.java | 214 ++++++++++++++++---
.../endpoints/mgmt/ApplicationResource.java | 46 +++-
.../usergrid/management/ManagementService.java | 6 +
.../cassandra/ManagementServiceImpl.java | 110 ++++++++--
.../exceptions/ConflictException.java | 36 ++++
12 files changed, 492 insertions(+), 155 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/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 0144ea8..e1a7c60 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
@@ -31,6 +31,7 @@ import org.apache.usergrid.corepersistence.rx.AllEntitiesInSystemObservable;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.*;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_PATH;
import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
@@ -221,41 +222,20 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public UUID initializeApplication( String organizationName, UUID applicationId, String name,
Map<String, Object> properties ) throws Exception {
-
EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
final String appName = buildAppName( organizationName, name );
// check for pre-existing application
+
if ( lookupApplication( appName ) != null ) {
throw new ApplicationAlreadyExistsException( appName );
}
- getSetup().setupApplicationKeyspace( applicationId, appName );
-
- UUID orgUuid = lookupOrganization( organizationName );
- if ( orgUuid == null ) {
-
- // create new org because the specified one does not exist
- final String orgName = organizationName;
-
- final Entity orgInfo;
+ // create application info entity in the management app
- try {
- orgInfo = em.create( "organization", new HashMap<String, Object>() {{
- put( PROPERTY_NAME, orgName );
- }} );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- throw new OrganizationAlreadyExistsException( orgName );
- }
-
- em.refreshIndex();
- }
-
- // create appinfo entry in the management app
+ getSetup().setupApplicationKeyspace( applicationId, appName );
final UUID appId = applicationId;
- final UUID orgId = orgUuid;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
put( PROPERTY_UUID, appId );
@@ -268,13 +248,13 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
em.refreshIndex();
- // create application oldAppInfo
+ // create application info entity
+
if ( properties == null ) {
properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
}
properties.put( PROPERTY_NAME, appName );
EntityManager appEm = getEntityManager( applicationId );
-
appEm.create( applicationId, TYPE_APPLICATION, properties );
appEm.resetRoles();
appEm.refreshIndex();
@@ -297,46 +277,76 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void deleteApplication(UUID applicationId) throws Exception {
- // remove old application info Entity, which is in the Management App's application infos collection
+ // make a copy of the app to delete application_info entity
+
EntityManager em = getEntityManager( this.getManagementAppId() );
- Entity applicationInfo = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
- em.delete( applicationInfo );
+ Entity appToDelete = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+
+ // and put it in a deleted_application_info collection
+
+ Entity deletedApp = em.create(
+ applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, appToDelete.getProperties() );
+
+ // copy its connections too
+
+ final Set<String> connectionTypes = em.getConnectionTypes(appToDelete);
+ for ( String connType : connectionTypes ) {
+ final Results results =
+ em.getConnectedEntities(appToDelete, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : results.getEntities() ) {
+ em.createConnection( deletedApp, connType, entity );
+ }
+ }
- // create new Entity in deleted_application_infos collection,
- // with same UUID and properties as deleted application info
- em.create( applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, applicationInfo.getProperties() );
+ // delete the app from the application_info collection and delete its index
+ em.delete( appToDelete);
em.refreshIndex();
- // delete the application's index
- managerCache.getEntityIndex( new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
+ final EntityIndex entityIndex = managerCache.getEntityIndex(
+ new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
+ entityIndex.deleteIndex();
}
@Override
public void restoreApplication(UUID applicationId) throws Exception {
- // remove old delete_appinfos Entity
+ // get the deleted_application_info for the deleted app
+
EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- Entity appToRestore = em.get( new SimpleEntityRef( CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ));
+ Entity deletedApp = em.get(
+ new SimpleEntityRef( CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ));
- if ( appToRestore == null ) {
+ if ( deletedApp == null ) {
throw new EntityNotFoundException("Cannot restore. Deleted Application not found: " + applicationId );
}
- em.delete( appToRestore );
+ // create application_info for restored app
- // restore oldAppInfo in appinfo collection
- em.create( appToRestore.getUuid(), CpNamingUtils.APPLICATION_INFO, appToRestore.getProperties());
- em.refreshIndex();
+ Entity restoredApp = em.create(
+ deletedApp.getUuid(), CpNamingUtils.APPLICATION_INFO, deletedApp.getProperties());
+
+ // copy connections from deleted app entity
+
+ final Set<String> connectionTypes = em.getConnectionTypes(deletedApp);
+ for ( String connType : connectionTypes ) {
+ final Results results =
+ em.getConnectedEntities(deletedApp, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : results.getEntities() ) {
+ em.createConnection( restoredApp, connType, entity );
+ }
+ }
+
+ // delete the deleted app entity rebuild the app index
+
+ em.delete( deletedApp );
- // rebuild the apps index
this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@Override
public void onProgress(EntityRef entity) {
- logger.info("Restored oldAppInfo {}:{}", entity.getType(), entity.getUuid());
+ logger.debug("Restored oldAppInfo {}:{}", entity.getType(), entity.getUuid());
}
-
});
}
@@ -350,33 +360,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
- public UUID lookupOrganization( String name ) throws Exception {
- init();
-
- // Query q = Query.fromQL(PROPERTY_NAME + " = '" + name + "'");
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
-
- final EntityRef alias = em.getAlias( "organizations", name );
-
- if ( alias == null ) {
- return null;
- }
-
- final Entity entity = em.get( alias );
-
- if ( entity == null ) {
- return null;
- }
-
- return entity.getUuid();
- }
-
-
@Override
public UUID lookupApplication( final String name ) throws Exception {
init();
- // attempt to look up APPLICATION_INFO oldAppInfo by name
+ // attempt to look up APPLICATION_INFO by name
UUID applicationId = null;
EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
@@ -440,7 +428,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
@Metered(group = "core", name = "EntityManagerFactory_getApplication")
public Map<String, UUID> getApplications() throws Exception {
- return getApplications( false );
+ return getApplications(false);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 8f3327d..0adf9d7 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -38,9 +38,6 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
*/
public class CpNamingUtils {
- // TODO: Why do we have three internal apps? Can we merge this into a single management app?
- // It would make administration much easier and cleaner on the ES side
-
/** Edge types for collection suffix */
public static final String EDGE_COLL_SUFFIX = "zzzcollzzz";
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/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 a077ea0..42caf02 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
@@ -76,6 +76,11 @@ public interface EntityManagerFactory {
*/
public abstract void deleteApplication( UUID applicationId ) throws Exception;
+ /**
+ * Restore deleted application.
+ */
+ public void restoreApplication( UUID applicationId) throws Exception;
+
public abstract UUID importApplication( String organization, UUID applicationId, String name,
Map<String, Object> properties ) throws Exception;
@@ -169,8 +174,6 @@ public interface EntityManagerFactory {
public Health getEntityStoreHealth();
- void restoreApplication(UUID applicationId) throws Exception;
-
public interface ProgressObserver {
public void onProgress( EntityRef entity);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index 4f8002b..e62a9cb 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -30,6 +30,7 @@ import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import com.sun.jersey.api.ConflictException;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
import org.apache.usergrid.rest.ApiResponse;
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
@@ -488,6 +489,9 @@ public class ApplicationResource extends ServiceResource {
}
+ /**
+ * Put on application URL will restore application if it was deleted.
+ */
@PUT
@RequireOrganizationAccess
@Override
@@ -498,12 +502,7 @@ public class ApplicationResource extends ServiceResource {
throw new IllegalArgumentException("Application ID not specified in request");
}
- ApplicationInfo app = management.getApplicationInfo( applicationId );
- if ( app == null ) {
- throw new EntityNotFoundException("Application ID " + applicationId + " not found");
- }
-
- emf.restoreApplication( applicationId );
+ management.restoreApplication( applicationId );
ApiResponse response = createApiResponse();
response.setAction( "restore" );
@@ -532,15 +531,9 @@ public class ApplicationResource extends ServiceResource {
throw new IllegalArgumentException("Application ID not specified in request");
}
- ApplicationInfo app = management.getApplicationInfo( applicationId );
- if ( app == null ) {
- throw new EntityNotFoundException("Application ID " + applicationId + " not found");
- }
-
- emf.deleteApplication( applicationId );
+ management.deleteApplication( applicationId );
- LOG.debug( "ApplicationResource.delete() deleted appId = {} appName = {}",
- applicationId, app.getName() );
+ LOG.debug( "ApplicationResource.delete() deleted appId = {}", applicationId);
ApiResponse response = createApiResponse();
response.setAction( "delete" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
new file mode 100644
index 0000000..34a813d
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/exceptions/ConflictExceptionMapper.java
@@ -0,0 +1,35 @@
+/*
+ * 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.management.exceptions.ConflictException;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+import static javax.ws.rs.core.Response.Status.CONFLICT;
+
+
+@Provider
+public class ConflictExceptionMapper extends AbstractExceptionMapper<ConflictException> {
+
+ @Override
+ public Response toResponse( ConflictException e ) {
+ return toResponse( CONFLICT, e );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
index 1fe9745..5691e2e 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
@@ -132,31 +132,31 @@ public class ApplicationsResource extends AbstractContextResource {
@RequireOrganizationAccess
@Path(RootResource.APPLICATION_ID_PATH)
- public ApplicationResource applicationFromOrganizationByApplicationId( @Context UriInfo ui,
- @PathParam( "applicationId" )
- String applicationIdStr ) throws Exception {
+ public ApplicationResource applicationFromOrganizationByApplicationId(
+ @Context UriInfo ui, @PathParam( "applicationId" ) String applicationIdStr ) throws Exception {
- return getSubResource( ApplicationResource.class ).init( organization, UUID.fromString( applicationIdStr ) );
+ return getSubResource( ApplicationResource.class )
+ .init( organization, UUID.fromString( applicationIdStr ) );
}
-// @RequireOrganizationAccess
-// @Path(RootResource.APPLICATION_ID_PATH)
-// @PUT
-// public ApplicationResource restoreApplicationFromOrganizationByApplicationId(
-// @Context UriInfo ui,
-// @PathParam( "applicationId" )
-// String applicationIdStr ) throws Exception {
-//
-// return getSubResource( ApplicationResource.class ).init( organization, UUID.fromString( applicationIdStr ) );
-// }
+ @RequireOrganizationAccess
+ @Path(RootResource.APPLICATION_ID_PATH)
+ @PUT
+ public ApplicationResource restoreApplicationFromOrganizationByApplicationId(
+ @Context UriInfo ui,
+ @PathParam( "applicationId" )
+ String applicationIdStr ) throws Exception {
+
+ return getSubResource( ApplicationResource.class )
+ .init( organization, UUID.fromString( applicationIdStr ) );
+ }
@RequireOrganizationAccess
@Path( "{applicationName}" )
- public ApplicationResource applicationFromOrganizationByApplicationName( @Context UriInfo ui,
- @PathParam( "applicationName" )
- String applicationName ) throws Exception {
+ public ApplicationResource applicationFromOrganizationByApplicationName(
+ @Context UriInfo ui, @PathParam( "applicationName" ) String applicationName ) throws Exception {
String appName =
applicationName.contains( "/" ) ? applicationName : organization.getName() + "/" + applicationName;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
index 8aee185..695becc 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/organizations/OrganizationResource.java
@@ -100,9 +100,14 @@ public class OrganizationResource extends AbstractContextResource {
if (organizationId == null) {
return null;
}
- BiMap<UUID, String> apps = management.getApplicationsForOrganization( organizationId );
- if ( apps.get( applicationId ) == null ) {
- return null;
+
+ // don't look up app if request is a PUT because a PUT can be used to restore a deleted app
+ if ( !hc.getRequest().getMethod().equalsIgnoreCase("PUT") ) {
+
+ BiMap<UUID, String> apps = management.getApplicationsForOrganization(organizationId);
+ if (apps.get(applicationId) == null) {
+ return null;
+ }
}
return appResourceFor( applicationId );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
index 8ac449a..1826d59 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationDeleteTest.java
@@ -36,6 +36,16 @@ public class ApplicationDeleteTest extends AbstractRestIT {
private static final Logger logger = LoggerFactory.getLogger(ApplicationDeleteTest.class);
+ /**
+ * Test most common use cases.
+ * <pre>
+ * - create app with collection of things
+ * - delete the app
+ * - test that attempts to get the app, its collections and entities throw 400 with message
+ * - test that we cannot delete the app a second time
+ * - test that we can create a new app with the same name as the deleted app
+ * </pre>
+ */
@Test
public void testBasicOperation() throws Exception {
@@ -45,30 +55,9 @@ public class ApplicationDeleteTest extends AbstractRestIT {
String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
- ApiResponse appCreateResponse = clientSetup.getRestClient()
- .management().orgs().organization( orgName ).app().getResource()
- .queryParam( "access_token", orgAdminToken.getAccessToken() )
- .type( MediaType.APPLICATION_JSON )
- .post( ApiResponse.class, new Application( appToDeleteName ) );
- UUID appToDeleteId = appCreateResponse.getEntities().get(0).getUuid();
-
List<Entity> entities = new ArrayList<>();
- for ( int i=0; i<10; i++ ) {
- final String entityName = "entity" + i;
- Entity entity = new Entity();
- entity.setProperties(new HashMap<String, Object>() {{
- put("name", entityName );
- }});
-
- ApiResponse createResponse = clientSetup.getRestClient()
- .org(orgName).app( appToDeleteName ).collection("things").getResource()
- .queryParam("access_token", orgAdminToken.getAccessToken())
- .type(MediaType.APPLICATION_JSON)
- .post( ApiResponse.class, entity );
-
- entities.add( createResponse.getEntities().get(0) );
- }
+ UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
// delete the app
@@ -130,7 +119,8 @@ public class ApplicationDeleteTest extends AbstractRestIT {
Assert.assertEquals("organization_application_not_found", node.get("error").textValue());
}
- // test that we cannot see the application in the list of applications
+ // test that we cannot see the application in the list of applications returned
+ // by the management resource's get organization's applications end-point
refreshIndex();
@@ -171,33 +161,195 @@ public class ApplicationDeleteTest extends AbstractRestIT {
}
+ /**
+ * Test restore of deleted app.
+ * <pre>
+ * - create app with collection of things
+ * - delete the app
+ * - restore the app
+ * - test that we can get the app, its collections and an entity
+ * </pre>
+ */
@Test
public void testAppRestore() throws Exception {
- // create and delete app
+ // create app with a collection of "things"
+
+ String orgName = clientSetup.getOrganization().getName();
+ String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+ Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+ List<Entity> entities = new ArrayList<>();
+
+ UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+ // delete the app
+
+ clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteId.toString() ).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken() )
+ .delete();
// restore the app
- // test that app appears in list of apps
+ clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteId.toString() ).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken() )
+ .put();
+
- // test that application's collection exists
- }
+ // test that we can see the application in the list of applications
+
+ ManagementResponse orgAppResponse = clientSetup.getRestClient()
+ .management().orgs().organization( orgName ).apps().getOrganizationApplications();
+
+ boolean found = false;
+ for ( String appName : orgAppResponse.getData().keySet() ) {
+ if ( orgAppResponse.getData().get( appName ).equals( appToDeleteId.toString() )) {
+ found = true;
+ break;
+ }
+ }
+
+ Assert.assertTrue( found );
+ // test that we can get an app entity
+ UUID entityId = entities.get(0).getUuid();
+ ApiResponse entityResponse = clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteName).collection("things").entity( entityId ).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .type(MediaType.APPLICATION_JSON)
+ .get(ApiResponse.class);
+ Assert.assertEquals( entityId, entityResponse.getEntities().get(0).getUuid() );
+ // test that we can get deleted app's collection
+
+ ApiResponse collectionReponse = clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteName).collection("things").getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .type(MediaType.APPLICATION_JSON)
+ .get(ApiResponse.class);
+ Assert.assertEquals( entities.size(), collectionReponse.getEntityCount() );
+ }
+
+
+ /**
+ * Test that we cannot restore deleted app with same name as
+ */
@Test
public void testAppRestoreConflict() throws Exception {
- // create and delete app
+ // create app with a collection of "things"
+
+ String orgName = clientSetup.getOrganization().getName();
+ String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+ Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+ List<Entity> entities = new ArrayList<>();
+
+ UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+ // delete the app
+
+ clientSetup.getRestClient()
+ .org( orgName ).app(appToDeleteId.toString() ).getResource()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .delete();
+
+ // create new app with same name
+
+ createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+ // attempt to restore original app, should get 409
+
+ try {
+
+ clientSetup.getRestClient()
+ .org(orgName).app(appToDeleteId.toString()).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .put();
+
+ Assert.fail("Must fail to restore app with same name as existing app");
+
+ } catch ( UniformInterfaceException e ) {
+ Assert.assertEquals(409, e.getResponse().getStatus());
+ }
+ }
+
+
+ /**
+ * Test that we cannot delete an app with same name as an app that is already deleted.
+ * TODO: investigate way to support this, there should be no such restriction.
+ */
+ @Test
+ public void testAppDeleteConflict() throws Exception {
+
+ // create app with a collection of "things"
+
+ String orgName = clientSetup.getOrganization().getName();
+ String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
+ Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+
+ List<Entity> entities = new ArrayList<>();
+
+ UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+ // delete the app
+
+ clientSetup.getRestClient()
+ .org( orgName ).app(appToDeleteId.toString() ).getResource()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .delete();
// create new app with same name
- // attempt to restore original app
+ UUID newAppId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+
+ // attempt to delete new app, it should fail
+
+ try {
+
+ clientSetup.getRestClient()
+ .org(orgName).app( newAppId.toString() ).getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .delete();
+
+ Assert.fail("Must fail to delete app with same name as deleted app");
+
+ } catch ( UniformInterfaceException e ) {
+ Assert.assertEquals( 409, e.getResponse().getStatus() );
+ }
+ }
+
+
+ private UUID createAppWithCollection(
+ String orgName, String appName, Token orgAdminToken, List<Entity> entities) {
+
+ ApiResponse appCreateResponse = clientSetup.getRestClient()
+ .management().orgs().organization( orgName ).app().getResource()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .type( MediaType.APPLICATION_JSON )
+ .post( ApiResponse.class, new Application( appName ) );
+ UUID appId = appCreateResponse.getEntities().get(0).getUuid();
+
+ for ( int i=0; i<10; i++ ) {
- // test that HTTP 409 CONFLICT and informative error message is received
+ final String entityName = "entity" + i;
+ Entity entity = new Entity();
+ entity.setProperties(new HashMap<String, Object>() {{
+ put("name", entityName );
+ }});
- // create a collection with two entities
+ ApiResponse createResponse = clientSetup.getRestClient()
+ .org(orgName).app( appName ).collection("things").getResource()
+ .queryParam("access_token", orgAdminToken.getAccessToken())
+ .type(MediaType.APPLICATION_JSON)
+ .post( ApiResponse.class, entity );
+ entities.add( createResponse.getEntities().get(0) );
+ }
+ return appId;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
index 6b7742f..034c302 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
@@ -22,17 +22,28 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
import javax.ws.rs.core.MediaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
import org.apache.usergrid.rest.test.resource2point0.model.Application;
import org.apache.usergrid.rest.test.resource2point0.model.*;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.StringReader;
/**
* Classy class class.
*/
public class ApplicationResource extends NamedResource {
+
+ private static final Logger logger = LoggerFactory.getLogger(ApplicationResource.class);
+
+ ObjectMapper mapper = new ObjectMapper();
+
public ApplicationResource(ClientContext context, UrlResource parent) {
super("applications", context, parent);
}
@@ -51,16 +62,41 @@ public class ApplicationResource extends NamedResource {
.accept(MediaType.APPLICATION_JSON).post(application);
}
- public Entity post(Entity payload){
- ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
- .post(ApiResponse.class, payload);
+ public Entity post(Entity payload) {
+
+ String responseString = getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(MediaType.APPLICATION_JSON)
+ .post(String.class, payload);
+
+ logger.debug("Response from post: " + responseString);
+
+ ApiResponse response;
+ try {
+ response = mapper.readValue(new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
return new Entity(response);
}
public Entity get() {
- ApiResponse response = getResource(true).type(MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
- .get(ApiResponse.class);
+
+ String responseString = getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(MediaType.APPLICATION_JSON)
+ .get(String.class);
+
+ logger.debug("Response from post: " + responseString);
+
+ ApiResponse response;
+ try {
+ response = mapper.readValue(new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
return new Entity(response);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 97d23c2..aff9e15 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -149,6 +149,8 @@ public interface ManagementService {
public ApplicationInfo getApplicationInfo( UUID applicationId ) throws Exception;
+ ApplicationInfo getDeletedApplicationInfo(UUID applicationId) throws Exception;
+
public ApplicationInfo getApplicationInfo( Identifier id ) throws Exception;
public ApplicationInfo getApplicationInfoFromAccessToken( String token ) throws Exception;
@@ -318,4 +320,8 @@ public interface ManagementService {
/** For testing purposes only */
public Properties getProperties();
+
+ public void deleteApplication(UUID applicationId) throws Exception;
+
+ public ApplicationInfo restoreApplication(UUID applicationId) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index d8fc0f5..a33c324 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -29,7 +29,10 @@ import java.util.Set;
import java.util.UUID;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.management.exceptions.*;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,15 +48,6 @@ import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
import org.apache.usergrid.management.UserInfo;
-import org.apache.usergrid.management.exceptions.DisabledAdminUserException;
-import org.apache.usergrid.management.exceptions.DisabledAppUserException;
-import org.apache.usergrid.management.exceptions.IncorrectPasswordException;
-import org.apache.usergrid.management.exceptions.ManagementException;
-import org.apache.usergrid.management.exceptions.RecentlyUsedPasswordException;
-import org.apache.usergrid.management.exceptions.UnableToLeaveOrganizationException;
-import org.apache.usergrid.management.exceptions.UnactivatedAdminUserException;
-import org.apache.usergrid.management.exceptions.UnactivatedAppUserException;
-import org.apache.usergrid.management.exceptions.UnconfirmedAdminUserException;
import org.apache.usergrid.persistence.CredentialsInfo;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
@@ -250,8 +244,7 @@ public class ManagementServiceImpl implements ManagementService {
return properties.properties;
}
-
- @Autowired
+ @Autowired
public void setTokenService( TokenService tokens ) {
this.tokens = tokens;
}
@@ -1662,7 +1655,7 @@ public class ManagementServiceImpl implements ManagementService {
}
catch ( UnavailableSecurityManagerException e ) {
// occurs in the rare case that this is called before the full stack is initialized
- logger.warn("Error getting user, organization created activity will not be created", e);
+ logger.warn("Error getting user, application created activity will not be created", e);
}
if ( ( user != null ) && user.isAdminUser() ) {
postOrganizationActivity( organizationId, user, "create", appInfo, "Application", applicationName,
@@ -1677,6 +1670,82 @@ public class ManagementServiceImpl implements ManagementService {
@Override
+ public void deleteApplication(UUID applicationId) throws Exception {
+
+ // make sure there is not already a delete app with the same name
+
+ EntityManager em = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ Entity appToDelete = em.get(
+ new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
+
+ final EntityRef alias = em.getAlias(
+ CpNamingUtils.DELETED_APPLICATION_INFO, appToDelete.getName() );
+
+ if ( alias != null ) {
+ throw new ConflictException("Cannot delete app with same name as already deleted app");
+ }
+
+ emf.deleteApplication( applicationId );
+ }
+
+
+ @Override
+ public ApplicationInfo restoreApplication(UUID applicationId) throws Exception {
+
+ ApplicationInfo app = getDeletedApplicationInfo( applicationId );
+ if ( app == null ) {
+ throw new EntityNotFoundException("Deleted application ID " + applicationId + " not found");
+ }
+
+ if ( emf.lookupApplication( app.getName() ) != null ) {
+ throw new ConflictException("Cannot restore application, one with that name already exists.");
+ }
+
+ // restore application_info entity
+
+ EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ emf.restoreApplication(applicationId);
+
+ // restore token
+
+ Entity appInfo = em.get(
+ new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
+
+ writeUserToken( smf.getManagementAppId(), appInfo,
+ encryptionService.plainTextCredentials(
+ generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
+ null,
+ smf.getManagementAppId() ) );
+
+ String orgName = appInfo.getName().split("/")[0];
+ EntityRef alias = em.getAlias( Group.ENTITY_TYPE, orgName );
+ Entity orgEntity = em.get( alias );
+
+ addApplicationToOrganization( orgEntity.getUuid(), applicationId, appInfo );
+
+ // create activity
+
+ UserInfo user = null;
+ try {
+ user = SubjectUtils.getUser();
+ }
+ catch ( UnavailableSecurityManagerException e ) {
+ // occurs in the rare case that this is called before the full stack is initialized
+ logger.warn("Error getting user, application restored created activity will not be created", e);
+ }
+ if ( ( user != null ) && user.isAdminUser() ) {
+ postOrganizationActivity( orgEntity.getUuid(), user, "restore", appInfo, "Application", appInfo.getName(),
+ "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
+ + ")</a> restored an application named " + appInfo.getName(), null );
+ }
+
+ em.refreshIndex();
+
+ return new ApplicationInfo( applicationId, appInfo.getName() );
+ }
+
+
+ @Override
public OrganizationInfo getOrganizationForApplication( UUID applicationInfoId ) throws Exception {
if ( applicationInfoId == null ) {
@@ -1804,6 +1873,22 @@ public class ManagementServiceImpl implements ManagementService {
@Override
+ public ApplicationInfo getDeletedApplicationInfo(UUID applicationId) throws Exception {
+ if ( applicationId == null ) {
+ return null;
+ }
+ EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+ Entity entity = em.get( new SimpleEntityRef(
+ CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ));
+
+ if ( entity != null ) {
+ return new ApplicationInfo( applicationId, entity.getName() );
+ }
+ return null;
+ }
+
+
+ @Override
public ApplicationInfo getApplicationInfo( Identifier id ) throws Exception {
if ( id == null ) {
return null;
@@ -2979,4 +3064,5 @@ public class ManagementServiceImpl implements ManagementService {
else
return Boolean.parseBoolean(obj);
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/14f45ed1/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java b/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java
new file mode 100644
index 0000000..2ec14c8
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/management/exceptions/ConflictException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed 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.management.exceptions;
+
+public class ConflictException extends ManagementException {
+
+ public ConflictException() {
+ super();
+ }
+
+ public ConflictException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+ public ConflictException(String arg0) {
+ super(arg0);
+ }
+
+ public ConflictException(Throwable arg0) {
+ super(arg0);
+ }
+}
[13/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/07f1f62a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/07f1f62a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/07f1f62a
Branch: refs/heads/two-dot-o-dev
Commit: 07f1f62afe1b4869395710c29328d73cdbd4bc3c
Parents: a4bdc1f 1eca271
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 10 09:40:50 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 10 09:40:50 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 34 +-------
.../persistence/EntityManagerFactory.java | 20 -----
.../cassandra/EntityManagerFactoryImpl.java | 23 -----
.../data/DataMigrationManagerImplTest.java | 34 ++++++--
.../apache/usergrid/rest/MigrateResource.java | 90 ++++++++++++++------
5 files changed, 95 insertions(+), 106 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/07f1f62a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 4e22b12,c58cd5e..78f2095
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -115,14 -131,8 +115,13 @@@ public class CpEntityManagerFactory imp
this.counterUtils = counterUtils;
this.injector = injector;
this.managerCache = injector.getInstance( ManagerCache.class );
- this.dataMigrationManager = injector.getInstance( DataMigrationManager.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
+ // can be removed after everybody moves to Usergrid 2.0, default is true
+ Properties configProps = cassandraService.getProperties();
+ if ( configProps.getProperty("usergrid.twodoto.appinfo.migration", "true").equals("true")) {
+ migrateOldAppInfos();
+ }
this.orgApplicationCache = new OrgApplicationCacheImpl( this );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/07f1f62a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/07f1f62a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
[49/50] incubator-usergrid git commit: Merge branch 'two-dot-o-dev'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'two-dot-o-dev' into USERGRID-448-appinfofix
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/d2be54be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/d2be54be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/d2be54be
Branch: refs/heads/two-dot-o-dev
Commit: d2be54be4e57004c55f8be372feb1b9d3974a157
Parents: e611793 a099d0f
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 30 10:19:22 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 30 10:19:22 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 30 +-
.../corepersistence/CpRelationManager.java | 304 +++------
.../usergrid/corepersistence/CpSetup.java | 14 +-
.../results/CollectionRefsVerifier.java | 44 ++
.../CollectionResultsLoaderFactoryImpl.java | 60 ++
.../results/ConnectionRefsVerifier.java | 61 ++
.../ConnectionResultsLoaderFactoryImpl.java | 65 ++
.../results/ElasticSearchQueryExecutor.java | 212 ++++++
.../corepersistence/results/QueryExecutor.java | 37 ++
.../corepersistence/results/RefsVerifier.java | 42 --
.../results/ResultsLoaderFactory.java | 3 +-
.../results/ResultsLoaderFactoryImpl.java | 62 --
.../persistence/MultiQueryIterator.java | 6 +-
.../apache/usergrid/persistence/Results.java | 26 +-
.../cassandra/QueryProcessorImpl.java | 12 +-
.../usergrid/persistence/PathQueryIT.java | 46 +-
.../persistence/query/IteratingQueryIT.java | 38 +-
stack/core/src/test/resources/log4j.properties | 2 +
.../persistence/graph/GraphManagerIT.java | 2 +-
.../index/ApplicationEntityIndex.java | 5 +
.../usergrid/persistence/index/EntityIndex.java | 6 +-
.../usergrid/persistence/index/IndexFig.java | 16 +-
.../index/impl/BufferQueueInMemoryImpl.java | 10 +-
.../impl/EsApplicationEntityIndexImpl.java | 12 +
.../index/impl/EsEntityIndexImpl.java | 9 -
.../index/impl/EsIndexBufferConsumerImpl.java | 74 +--
.../usergrid/persistence/index/query/Query.java | 58 +-
.../persistence/index/utils/ListUtils.java | 3 +-
.../persistence/index/impl/EntityIndexTest.java | 26 +-
.../index/impl/IndexLoadTestsIT.java | 18 +-
.../organizations/OrganizationResource.java | 26 +-
.../applications/ApplicationResource.java | 44 +-
.../applications/imports/ImportsResource.java | 19 +-
.../java/org/apache/usergrid/rest/BasicIT.java | 302 +--------
.../apache/usergrid/rest/SystemResourceIT.java | 10 +-
.../applications/ApplicationResourceIT.java | 4 +-
.../collection/CollectionsResourceIT.java | 19 +-
.../collection/users/OwnershipResourceIT.java | 4 +-
.../collection/users/RetrieveUsersTest.java | 4 +-
.../collection/users/UserResourceIT.java | 4 +-
.../usergrid/rest/management/AccessTokenIT.java | 418 +++++-------
.../usergrid/rest/management/AdminUsersIT.java | 60 +-
.../rest/management/ExportResourceIT.java | 652 +++++++------------
.../rest/management/ImportResourceIT.java | 20 +-
.../rest/management/OrganizationsIT.java | 16 +-
.../organizations/AdminEmailEncodingIT.java | 3 +-
.../test/resource2point0/AbstractRestIT.java | 4 +-
.../rest/test/resource2point0/ClientSetup.java | 30 +-
.../rest/test/resource2point0/RestClient.java | 1 +
.../endpoints/NamedResource.java | 112 +++-
.../endpoints/SetupResource.java | 6 +
.../endpoints/mgmt/ApplicationResource.java | 8 +-
.../endpoints/mgmt/ManagementResource.java | 4 +
.../endpoints/mgmt/MeResource.java | 32 +
.../endpoints/mgmt/PasswordResource.java | 16 -
.../endpoints/mgmt/RevokeTokenResource.java | 32 +
.../endpoints/mgmt/RevokeTokensResource.java | 33 +
.../endpoints/mgmt/TokenResource.java | 25 +-
.../endpoints/mgmt/UserResource.java | 8 +
.../endpoints/mgmt/UsersResource.java | 15 -
.../cassandra/ManagementServiceImpl.java | 21 +-
61 files changed, 1638 insertions(+), 1617 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e2e43ca,3cfc1a4..baac821
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -122,9 -132,11 +125,10 @@@ public class CpEntityManagerFactory imp
this.counterUtils = counterUtils;
this.injector = injector;
this.entityIndex = injector.getInstance(EntityIndex.class);
+ this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
-
- this.orgApplicationCache = new OrgApplicationCacheImpl( this );
+ this.applicationIdCache = new ApplicationIdCacheImpl( this );
}
@@@ -152,9 -164,12 +156,11 @@@
em.getApplication();
}
- entityIndex.initializeIndex();
+ ApplicationScope appScope = new ApplicationScopeImpl(new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ) );
+ ApplicationEntityIndex applicationEntityIndex = entityIndexFactory.createApplicationEntityIndex(appScope);
+ applicationEntityIndex.initializeIndex();
entityIndex.refresh();
-
} catch (Exception ex) {
throw new RuntimeException("Fatal error creating system application", ex);
}
@@@ -233,14 -248,15 +239,17 @@@
}
+ /**
+ * @return UUID of newly created Entity of type application_info
+ */
@Override
- public UUID initializeApplication( String organizationName, UUID applicationId, String name,
+ public Entity initializeApplicationV2( String organizationName, final UUID applicationId, String name,
Map<String, Object> properties ) throws Exception {
- EntityManager em = getEntityManager(getManagementAppId());
-
- //Ensure our management system exists before creating our application
++ // Ensure our management system exists before creating our application
+ init();
+
- EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
++ EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
final String appName = buildAppName( organizationName, name );
@@@ -250,18 -265,63 +259,14 @@@
throw new ApplicationAlreadyExistsException( appName );
}
- // create application info entity
+ ApplicationScope applicationScope = new ApplicationScopeImpl(new SimpleId( applicationId,"application"));
+ ApplicationEntityIndex applicationEntityIndex = entityIndexFactory.createApplicationEntityIndex(applicationScope);
+ applicationEntityIndex.initializeIndex();
- try {
- em.create( CpNamingUtils.APPLICATION_INFO, properties );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- throw new ApplicationAlreadyExistsException( appName );
- }
- entityIndex.refresh();
+ getSetup().setupApplicationKeyspace( applicationId, appName );
- final Optional<UUID> cachedValue = orgApplicationCache.getOrganizationId( organizationName );
-
-
- UUID orgUuid;
-
- if ( !cachedValue.isPresent() ) {
-
-
- // create new org because the specified one does not exist
- final String orgName = organizationName;
-
-
-
- try {
- final Entity orgInfo = em.create( "organization", new HashMap<String, Object>() {{
- put( PROPERTY_NAME, orgName );
- }} );
- orgUuid = orgInfo.getUuid();
- //evit so it's re-loaded later
- orgApplicationCache.evictOrgId( name );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- //swallow, if it exists, just get it
- orgApplicationCache.evictOrgId( organizationName );
- orgUuid = orgApplicationCache.getOrganizationId( organizationName ).get();
- }
-
- } else{
- orgUuid = cachedValue.get();
- }
-
- // create appinfo entry in the system app
- final UUID appId = applicationId;
- final UUID orgId = orgUuid;
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put( PROPERTY_NAME, appName );
- put( "applicationUuid", appId );
- put( "organizationUuid", orgId );
- }};
-
- try {
- em.create( "appinfo", appInfoMap );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- throw new ApplicationAlreadyExistsException( appName );
- }
- entityIndex.refresh();
-
- // create application entity
if ( properties == null ) {
- properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
+ properties = new TreeMap<>( CASE_INSENSITIVE_ORDER );
}
properties.put( PROPERTY_NAME, appName );
EntityManager appEm = getEntityManager( applicationId);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index 4ab7874,040f60f..b3eef4b
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@@ -98,13 -107,22 +107,10 @@@ public class CpSetup implements Setup
setupStaticKeyspace();
- //force the EMF creation of indexes before creating the default applications
- entityIndex.initializeIndex();
-
- logger.info( "Setting up management app" );
+ injector.getInstance( DataMigrationManager.class ).migrate();
- logger.info( "Setting up default applications" );
-
try {
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getDefaultAppId(), DEFAULT_APPLICATION, null );
- }
- catch ( ApplicationAlreadyExistsException ex ) {
- logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, DEFAULT_APPLICATION );
- }
- catch ( OrganizationAlreadyExistsException oaee ) {
- logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
- }
-
- try {
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
+ emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
}
catch ( ApplicationAlreadyExistsException ex ) {
logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index ecee76b,d064b97..b2baac9
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@@ -189,10 -200,10 +200,10 @@@ public class EsIndexBufferConsumerImpl
}
while ( true );
}
- } ).subscribeOn(Schedulers.newThread()).doOnNext(new Action1<List<IndexOperationMessage>>() {
+ } ).doOnNext( new Action1<List<IndexOperationMessage>>() {
@Override
- public void call( List<IndexOperationMessage> containerList ) {
- if ( containerList.size() == 0 ) {
+ public void call(List<IndexOperationMessage> containerList) {
+ if (containerList.size() == 0) {
return;
}
@@@ -200,38 -211,22 +211,21 @@@
Timer.Context time = flushTimer.time();
- execute( containerList );
+ execute(containerList);
time.stop();
-
}
- } )
+ })
//ack after we process
- .doOnNext( new Action1<List<IndexOperationMessage>>() {
+ .doOnNext(new Action1<List<IndexOperationMessage>>() {
@Override
- public void call( final List<IndexOperationMessage> indexOperationMessages ) {
- bufferQueue.ack( indexOperationMessages );
+ public void call(final List<IndexOperationMessage> indexOperationMessages) {
+ bufferQueue.ack(indexOperationMessages);
//release so we know we've done processing
- inFlight.addAndGet( -1 * indexOperationMessages.size() );
+ inFlight.addAndGet(-1 * indexOperationMessages.size());
}
- })
- // TODO: implement on error resume next instead of onError
- // .onErrorResumeNext(new Func1<Throwable, Observable<IndexOperationMessage>>() {
- //
- // @Override
- // public Observable<IndexOperationMessage> call(Throwable throwable) {
- // return null;
- // }
- // })
- .doOnError(new Action1<Throwable>() {
- @Override
- public void call(final Throwable throwable) {
- } )
- log.error("An exception occurred when trying to deque and write to elasticsearch. Ignoring",
- throwable);
- indexErrorCounter.inc();
- }
- });
- .subscribeOn( Schedulers.newThread() );
++ } ).subscribeOn( Schedulers.newThread() );
//start in the background
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --cc stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index 1e7d1f9,d7dcd87..0bebb75
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@@ -21,8 -24,10 +21,9 @@@ import com.google.common.base.Precondit
import com.sun.jersey.api.json.JSONWithPadding;
import org.apache.amber.oauth2.common.exception.OAuthSystemException;
import org.apache.amber.oauth2.common.message.OAuthResponse;
+ import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang.StringUtils;
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.export.ExportService;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
----------------------------------------------------------------------
diff --cc stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
index 7d047a3,bb5f958..5755c8e
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
@@@ -107,32 -114,37 +107,33 @@@ public class ImportsResource extends Ab
Map<String, Object> properties;
Map<String, Object> storage_info;
- if ((properties = (Map<String, Object>) json.get("properties")) == null) {
- throw new NullArgumentException("Could not find 'properties'");
++ if ( ( properties = ( Map<String, Object> ) json.get( "properties" ) ) == null ) {
++ throw new NullArgumentException( "Could not find 'properties'" );
+ }
- storage_info = (Map<String, Object>) properties.get("storage_info");
- String storage_provider = (String) properties.get("storage_provider");
- if (storage_provider == null) {
- throw new NullArgumentException("Could not find field 'storage_provider'");
++ storage_info = ( Map<String, Object> ) properties.get( "storage_info" );
++ String storage_provider = ( String ) properties.get( "storage_provider" );
++ if ( storage_provider == null ) {
++ throw new NullArgumentException( "Could not find field 'storage_provider'" );
+ }
- if (storage_info == null) {
- throw new NullArgumentException("Could not find field 'storage_info'");
++ if ( storage_info == null ) {
++ throw new NullArgumentException( "Could not find field 'storage_info'" );
+ }
- String bucketName = (String) storage_info.get("bucket_location");
- if ( ( properties = ( Map<String, Object> ) json.get( "properties" ) ) == null ) {
- throw new NullArgumentException( "Could not find 'properties'" );
- }
- storage_info = ( Map<String, Object> ) properties.get( "storage_info" );
- String storage_provider = ( String ) properties.get( "storage_provider" );
- if ( storage_provider == null ) {
- throw new NullArgumentException( "Could not find field 'storage_provider'" );
- }
- if ( storage_info == null ) {
- throw new NullArgumentException( "Could not find field 'storage_info'" );
- }
-
- String bucketName = ( String ) storage_info.get( "bucket_location" );
-
-
- String accessId = ( String ) storage_info.get( "s3_access_id" );
- String secretKey = ( String ) storage_info.get( "s3_key" );
-
- if ( bucketName == null ) {
- throw new NullArgumentException( "Could not find field 'bucketName'" );
- }
- if ( accessId == null ) {
- throw new NullArgumentException( "Could not find field 's3_access_id'" );
- }
- if ( secretKey == null ) {
++ String bucketName = ( String ) storage_info.get( "bucket_location" );
+
- throw new NullArgumentException( "Could not find field 's3_key'" );
- }
+ String accessId = (String) storage_info.get("s3_access_id");
+ String secretKey = (String) storage_info.get("s3_key");
+ if (bucketName == null) {
+ throw new NullArgumentException("Could not find field 'bucketName'");
+ }
+ if (accessId == null) {
+ throw new NullArgumentException("Could not find field 's3_access_id'");
+ }
+ if (secretKey == null) {
+ throw new NullArgumentException("Could not find field 's3_key'");
+ }
json.put( "organizationId", organization.getUuid() );
json.put( "applicationId", application.getId() );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
----------------------------------------------------------------------
diff --cc stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
index a943bba,5e40037..67bc650
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
@@@ -575,8 -584,7 +575,8 @@@ public class ApplicationResourceIT exte
String clientId = orgCredentials.getClientId();
String clientSecret = orgCredentials.getClientSecret();
- Token token = clientSetup.getRestClient().management().token().post(
- new Token("client_credentials", clientId, clientSecret));
- Token token = clientSetup.getRestClient().management().token().post(Token.class,new Token("client_credentials", clientId, clientSecret));
++ Token token = clientSetup.getRestClient().management().token()
++ .post(Token.class,new Token("client_credentials", clientId, clientSecret));
//GET the token endpoint, adding authorization header
Token apiResponse = this.app().token().getResource(false)
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
----------------------------------------------------------------------
diff --cc stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
index 1ea9770,355c57a..9b5b09a
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
@@@ -173,11 -171,15 +173,11 @@@ public class ImportResourceIT extends A
Entity payload = payloadBuilder();
// /management/orgs/orgname/apps/appname/import
- Entity entity = this.management()
- .orgs()
- .organization(org)
- .app()
+ Entity entity = this.management().orgs().organization(org).app()
.addToPath(app)
.addToPath("imports")
- .post(payload);
+ .post(Entity.class,payload);
-
assertNotNull(entity);
// test that you can access the organization using the currently set token.
@@@ -644,10 -625,8 +644,10 @@@
}});
}});
- Entity importEntity = this.management().orgs().organization(org).app().addToPath(app).addToPath("imports")
- .post(Entity.class,importPayload);
+ Entity importEntity = this.management().orgs().organization(org).app()
+ .addToPath(app)
+ .addToPath("imports")
- .post(importPayload);
++ .post(Entity.class,importPayload);
int maxRetries = 120;
int retries = 0;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
----------------------------------------------------------------------
diff --cc stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
index 034c302,90e2c64..c02c48b
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationResource.java
@@@ -22,7 -22,7 +22,8 @@@ package org.apache.usergrid.rest.test.r
import javax.ws.rs.core.MediaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+ import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionEndpoint;
import org.apache.usergrid.rest.test.resource2point0.endpoints.NamedResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.UrlResource;
import org.apache.usergrid.rest.test.resource2point0.model.Application;
@@@ -57,29 -47,17 +58,30 @@@ public class ApplicationResource extend
}
- public void post(Application application) {
- getResource(true).type(MediaType.APPLICATION_JSON_TYPE)
- .accept(MediaType.APPLICATION_JSON).post(application);
+ public ApiResponse post(Application application) {
+ ApiResponse apiResponse =getResource(true).type(MediaType.APPLICATION_JSON_TYPE)
+ .accept(MediaType.APPLICATION_JSON).post(ApiResponse.class,application);
+ return apiResponse;
}
-// public Entity post(Entity payload){
-// ApiResponse response = getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
-// .post(ApiResponse.class, payload);
-// return new Entity(response);
-// }
+ public Entity post(Entity payload) {
+
+ String responseString = getResource(true)
+ .type( MediaType.APPLICATION_JSON_TYPE )
+ .accept(MediaType.APPLICATION_JSON)
+ .post(String.class, payload);
+
+ logger.debug("Response from post: " + responseString);
+
+ ApiResponse response;
+ try {
+ response = mapper.readValue(new StringReader(responseString), ApiResponse.class);
+ } catch (IOException e) {
+ throw new RuntimeException("Error parsing response", e);
+ }
+
+ return new Entity(response);
+ }
public Entity get() {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2be54be/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --cc stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index cd8a404,0cf80b4..682044b
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@@ -1445,9 -1477,8 +1445,8 @@@ public class ManagementServiceImpl impl
BiMap<UUID, String> organizations = HashBiMap.create();
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- Results results = em.getCollection(
- new SimpleEntityRef( User.ENTITY_TYPE, userId ), Schema.COLLECTION_GROUPS, null, 10000,
- Level.ALL_PROPERTIES, false );
- Results results = em.getCollection( new SimpleEntityRef( User.ENTITY_TYPE, userId ), "groups", null, 1000,
- Level.ALL_PROPERTIES, false );
++ Results results = em.getCollection( new SimpleEntityRef( User.ENTITY_TYPE, userId ),
++ Schema.COLLECTION_GROUPS, null, 1000, Level.ALL_PROPERTIES, false );
String path = null;
[17/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerFactoryImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9eeb2b58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9eeb2b58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9eeb2b58
Branch: refs/heads/two-dot-o-dev
Commit: 9eeb2b589e92c46d7fae759c8d06ef63bc192f73
Parents: a095681 5c7a5f8
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 11 09:48:58 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 11 09:48:58 2015 -0400
----------------------------------------------------------------------
.../persistence/map/guice/MapModule.java | 4 +-
.../index/impl/EsEntityIndexBatchImpl.java | 14 +--
.../index/impl/EsEntityIndexImpl.java | 37 +++++--
.../persistence/index/impl/IndexingUtils.java | 109 ++++++++++---------
.../persistence/index/impl/EntityIndexTest.java | 74 ++++++++++++-
5 files changed, 158 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9eeb2b58/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
index 56f8770,22d37c7..ec28106
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
@@@ -42,8 -42,8 +42,8 @@@ public class MapModule extends Abstract
@Override
protected void configure() {
- bind(MapManagerFactory.class).to( MapManagerFactoryImpl.class );
- bind(MapManagerFactory.class).to(MapManagerFactoryImpl.class);
-- bind(MapSerialization.class).to( MapSerializationImpl.class );
++ bind( MapManagerFactory.class ).to( MapManagerFactoryImpl.class );
++ bind( MapSerialization.class ).to( MapSerializationImpl.class );
Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
migrationBinding.addBinding().to( Key.get( MapSerialization.class ) );
[07/50] incubator-usergrid git commit: Some fixes in Service module's
import tests, some still failing.
Posted by sn...@apache.org.
Some fixes in Service module's import tests, some still failing.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/10481ce3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/10481ce3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/10481ce3
Branch: refs/heads/two-dot-o-dev
Commit: 10481ce32ca6938da8617e3004ba7f80188e4117
Parents: 531e659
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 6 12:27:39 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 6 12:27:39 2015 -0500
----------------------------------------------------------------------
.../resources/testImport.testApplication.2.json | 56 -------
.../resources/testImportCorrect.testCol.1.json | 18 ---
...testImportInvalidJson.testApplication.3.json | 153 -------------------
.../testimport-bad-json-testapp.3.json | 153 +++++++++++++++++++
.../resources/testimport-correct-testcol.1.json | 18 +++
.../test/resources/testimport-test-app.2.json | 56 +++++++
.../cassandra/ManagementServiceImpl.java | 22 ++-
.../management/importer/FileImportJob.java | 2 +-
.../management/importer/ImportServiceImpl.java | 26 ++--
9 files changed, 251 insertions(+), 253 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/rest/src/test/resources/testImport.testApplication.2.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testImport.testApplication.2.json b/stack/rest/src/test/resources/testImport.testApplication.2.json
deleted file mode 100644
index f45d129..0000000
--- a/stack/rest/src/test/resources/testImport.testApplication.2.json
+++ /dev/null
@@ -1,56 +0,0 @@
-[ {
- "Metadata" : {
- "uuid" : "589d95fa-ad7c-11e4-98bc-0f85bf181834",
- "type" : "qtsmagic",
- "created" : 1423171030223,
- "modified" : 1423171030223,
- "email" : "test0@anuff.com",
- "username" : "billybob0"
- },
- "connections" : { },
- "dictionaries" : { }
-}, {
- "Metadata" : {
- "uuid" : "589f91ca-ad7c-11e4-a250-63b6975ea888",
- "type" : "qtsmagic",
- "created" : 1423171030236,
- "modified" : 1423171030236,
- "email" : "test1@anuff.com",
- "username" : "billybob1"
- },
- "connections" : { },
- "dictionaries" : { }
-}, {
- "Metadata" : {
- "uuid" : "58a1186a-ad7c-11e4-bfc2-89e1e7bff3a8",
- "type" : "qtsmagic",
- "created" : 1423171030246,
- "modified" : 1423171030246,
- "email" : "test2@anuff.com",
- "username" : "billybob2"
- },
- "connections" : { },
- "dictionaries" : { }
-}, {
- "Metadata" : {
- "uuid" : "58a2c61a-ad7c-11e4-b2be-ab36d8b017f3",
- "type" : "qtsmagic",
- "created" : 1423171030257,
- "modified" : 1423171030257,
- "email" : "test3@anuff.com",
- "username" : "billybob3"
- },
- "connections" : { },
- "dictionaries" : { }
-}, {
- "Metadata" : {
- "uuid" : "58a44cba-ad7c-11e4-9fe5-fb8577a1f4a5",
- "type" : "qtsmagic",
- "created" : 1423171030267,
- "modified" : 1423171030267,
- "email" : "test4@anuff.com",
- "username" : "billybob4"
- },
- "connections" : { },
- "dictionaries" : { }
-} ]
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/rest/src/test/resources/testImportCorrect.testCol.1.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testImportCorrect.testCol.1.json b/stack/rest/src/test/resources/testImportCorrect.testCol.1.json
deleted file mode 100644
index f5fb6c4..0000000
--- a/stack/rest/src/test/resources/testImportCorrect.testCol.1.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "collections" : {
- "things" : [
- {
- "Metadata" : {
- "uuid" : "e2c5fed0-a7ea-11e4-a129-a1a7aeaea66e",
- "name" : "thing0",
- "created" : 1422558799676,
- "modified" : 1422558799676,
- "index" : 0
- },
- "connections" : {
- "related" : [ "e2c896ea-a7ea-11e4-bebf-77bfb1f0c5f4" ]
- }
- }
- ]
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/rest/src/test/resources/testImportInvalidJson.testApplication.3.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testImportInvalidJson.testApplication.3.json b/stack/rest/src/test/resources/testImportInvalidJson.testApplication.3.json
deleted file mode 100644
index 7551100..0000000
--- a/stack/rest/src/test/resources/testImportInvalidJson.testApplication.3.json
+++ /dev/null
@@ -1,153 +0,0 @@
-{
- "collections": {
- "things": [
- {
- "Metadata": {
- "uuid": "a48f87da-ad7b-11e4-a929-1903ccb95468",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-0",
- "created": 1423170728141,
- "modified": 1423170728141,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport",
- "connections": {
- "related": ["a4921fea-ad7b-11e4-ab93-5b5c80acc33f"]
- },
- "dictionaries": {
- "connected_types": {
- "related": ""
- },
- "connecting_types": {
- "related": ""
- }
- }
- },
- {
- "Metadata": {
- "uuid": "a4921fea-ad7b-11e4-ab93-5b5c80acc33f",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-1",
- "created": 1423170728158,
- "modified": 1423170728158,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {
- "related": ["a48f87da-ad7b-11e4-a929-1903ccb95468"]
- },
- "dictionaries": {
- "connected_types": {
- "related": ""
- },
- "connecting_types": {
- "related": ""
- }
- }
- },
- {
- "Metadata": {
- "uuid": "a494b7fa-ad7b-11e4-b590-df421e4b4225",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-2",
- "created": 1423170728175,
- "modified": 1423170728175,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a497771a-ad7b-11e4-9168-173fd0d6b09b",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-3",
- "created": 1423170728193,
- "modified": 1423170728193,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a49a0f2a-ad7b-11e4-b8c5-01f63321a18b",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-4",
- "created": 1423170728210,
- "modified": 1423170728210,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a49ca73a-ad7b-11e4-afa9-abe6d52a0752",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-5",
- "created": 1423170728227,
- "modified": 1423170728227,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a49f1844-ad7b-11e4-a9b2-71d39c6a3448",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-6",
- "created": 1423170728243,
- "modified": 1423170728243,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a4a1622a-ad7b-11e4-bf9f-3facb3ba8073",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-7",
- "created": 1423170728258,
- "modified": 1423170728258,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a4a3ac1a-ad7b-11e4-868c-b1d8d4f657f1",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-8",
- "created": 1423170728273,
- "modified": 1423170728273,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- },
- {
- "Metadata": {
- "uuid": "a4a6442a-ad7b-11e4-867e-976ae355c744",
- "type": "thing",
- "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-9",
- "created": 1423170728290,
- "modified": 1423170728290,
- "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
- "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
- },
- "connections": {},
- "dictionaries": {}
- }
- ]
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/rest/src/test/resources/testimport-bad-json-testapp.3.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testimport-bad-json-testapp.3.json b/stack/rest/src/test/resources/testimport-bad-json-testapp.3.json
new file mode 100644
index 0000000..7551100
--- /dev/null
+++ b/stack/rest/src/test/resources/testimport-bad-json-testapp.3.json
@@ -0,0 +1,153 @@
+{
+ "collections": {
+ "things": [
+ {
+ "Metadata": {
+ "uuid": "a48f87da-ad7b-11e4-a929-1903ccb95468",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-0",
+ "created": 1423170728141,
+ "modified": 1423170728141,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport",
+ "connections": {
+ "related": ["a4921fea-ad7b-11e4-ab93-5b5c80acc33f"]
+ },
+ "dictionaries": {
+ "connected_types": {
+ "related": ""
+ },
+ "connecting_types": {
+ "related": ""
+ }
+ }
+ },
+ {
+ "Metadata": {
+ "uuid": "a4921fea-ad7b-11e4-ab93-5b5c80acc33f",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-1",
+ "created": 1423170728158,
+ "modified": 1423170728158,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {
+ "related": ["a48f87da-ad7b-11e4-a929-1903ccb95468"]
+ },
+ "dictionaries": {
+ "connected_types": {
+ "related": ""
+ },
+ "connecting_types": {
+ "related": ""
+ }
+ }
+ },
+ {
+ "Metadata": {
+ "uuid": "a494b7fa-ad7b-11e4-b590-df421e4b4225",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-2",
+ "created": 1423170728175,
+ "modified": 1423170728175,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a497771a-ad7b-11e4-9168-173fd0d6b09b",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-3",
+ "created": 1423170728193,
+ "modified": 1423170728193,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a49a0f2a-ad7b-11e4-b8c5-01f63321a18b",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-4",
+ "created": 1423170728210,
+ "modified": 1423170728210,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a49ca73a-ad7b-11e4-afa9-abe6d52a0752",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-5",
+ "created": 1423170728227,
+ "modified": 1423170728227,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a49f1844-ad7b-11e4-a9b2-71d39c6a3448",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-6",
+ "created": 1423170728243,
+ "modified": 1423170728243,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a4a1622a-ad7b-11e4-bf9f-3facb3ba8073",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-7",
+ "created": 1423170728258,
+ "modified": 1423170728258,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a4a3ac1a-ad7b-11e4-868c-b1d8d4f657f1",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-8",
+ "created": 1423170728273,
+ "modified": 1423170728273,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "a4a6442a-ad7b-11e4-867e-976ae355c744",
+ "type": "thing",
+ "name": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport-thing-9",
+ "created": 1423170728290,
+ "modified": 1423170728290,
+ "originalAppId": "a445ad9e-ad7b-11e4-9e42-e2c2c83d257d",
+ "originalAppName": "org.apache.usergrid.management.importer.importcollectionit9dc7ff35ad7b11e49e42e2c2c83d257d/testupdatebyimport"
+ },
+ "connections": {},
+ "dictionaries": {}
+ }
+ ]
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/rest/src/test/resources/testimport-correct-testcol.1.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testimport-correct-testcol.1.json b/stack/rest/src/test/resources/testimport-correct-testcol.1.json
new file mode 100644
index 0000000..f5fb6c4
--- /dev/null
+++ b/stack/rest/src/test/resources/testimport-correct-testcol.1.json
@@ -0,0 +1,18 @@
+{
+ "collections" : {
+ "things" : [
+ {
+ "Metadata" : {
+ "uuid" : "e2c5fed0-a7ea-11e4-a129-a1a7aeaea66e",
+ "name" : "thing0",
+ "created" : 1422558799676,
+ "modified" : 1422558799676,
+ "index" : 0
+ },
+ "connections" : {
+ "related" : [ "e2c896ea-a7ea-11e4-bebf-77bfb1f0c5f4" ]
+ }
+ }
+ ]
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/rest/src/test/resources/testimport-test-app.2.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testimport-test-app.2.json b/stack/rest/src/test/resources/testimport-test-app.2.json
new file mode 100644
index 0000000..f45d129
--- /dev/null
+++ b/stack/rest/src/test/resources/testimport-test-app.2.json
@@ -0,0 +1,56 @@
+[ {
+ "Metadata" : {
+ "uuid" : "589d95fa-ad7c-11e4-98bc-0f85bf181834",
+ "type" : "qtsmagic",
+ "created" : 1423171030223,
+ "modified" : 1423171030223,
+ "email" : "test0@anuff.com",
+ "username" : "billybob0"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "589f91ca-ad7c-11e4-a250-63b6975ea888",
+ "type" : "qtsmagic",
+ "created" : 1423171030236,
+ "modified" : 1423171030236,
+ "email" : "test1@anuff.com",
+ "username" : "billybob1"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "58a1186a-ad7c-11e4-bfc2-89e1e7bff3a8",
+ "type" : "qtsmagic",
+ "created" : 1423171030246,
+ "modified" : 1423171030246,
+ "email" : "test2@anuff.com",
+ "username" : "billybob2"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "58a2c61a-ad7c-11e4-b2be-ab36d8b017f3",
+ "type" : "qtsmagic",
+ "created" : 1423171030257,
+ "modified" : 1423171030257,
+ "email" : "test3@anuff.com",
+ "username" : "billybob3"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "58a44cba-ad7c-11e4-9fe5-fb8577a1f4a5",
+ "type" : "qtsmagic",
+ "created" : 1423171030267,
+ "modified" : 1423171030267,
+ "email" : "test4@anuff.com",
+ "username" : "billybob4"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+} ]
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 34a3f5f..d8fc0f5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -1638,24 +1638,22 @@ public class ManagementServiceImpl implements ManagementService {
properties = new HashMap<>();
}
- OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
- UUID applicationId = emf.createApplication( organizationInfo.getName(), applicationName, properties );
-
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- em.refreshIndex();
- // TODO: move this logic into the EntityManagerFactory implementation
+ OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
+ UUID applicationId = emf.createApplication(
+ organizationInfo.getName(), applicationName, properties );
+ em.refreshIndex();
- String appName = buildAppName( applicationName, organizationInfo );
- Query q = Query.fromQL(PROPERTY_NAME + " = '" + appName + "'");
- Results results = em.searchCollection( em.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS, q);
- Entity appInfo = results.iterator().next();
+ Entity appInfo = em.get(
+ new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ));
writeUserToken( smf.getManagementAppId(), appInfo,
- encryptionService.plainTextCredentials( generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
- null, smf.getManagementAppId() ) );
+ encryptionService.plainTextCredentials(
+ generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
+ null,
+ smf.getManagementAppId() ) );
- // TODO: migration needed to make sure this gets called for all existing apps
addApplicationToOrganization( organizationId, applicationId, appInfo );
UserInfo user = null;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
index a77bb99..bdfcb61 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
@@ -82,7 +82,7 @@ public class FileImportJob extends OnlyOnceJob {
throw t;
}
- logger.error("File Import Service completed job");
+ logger.info("File Import Service completed job: " + jobExecution.getJobName() );
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10481ce3/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
index 35155c0..120e76e 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
@@ -126,10 +126,10 @@ public class ImportServiceImpl implements ImportService {
importEntity.setState(Import.State.SCHEDULED);
rootEM.update(importEntity);
- final EntityRef source = getApplicationEntity( rootEM, application );
+ final EntityRef appInfo = getApplicationInfoEntity(rootEM, application);
//now link it to the application
- rootEM.createConnection(source, APP_IMPORT_CONNECTION, importEntity);
+ rootEM.createConnection(appInfo, APP_IMPORT_CONNECTION, importEntity);
return importEntity;
}
@@ -141,9 +141,7 @@ public class ImportServiceImpl implements ImportService {
try {
final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
-
-
- final Entity applicationEntity = getApplicationEntity( rootEm, applicationId );
+ final Entity appInfo = getApplicationInfoEntity(rootEm, applicationId);
Query query = Query.fromQLNullSafe( ql );
query.setCursor( cursor );
@@ -151,7 +149,7 @@ public class ImportServiceImpl implements ImportService {
//set our entity type
query.setEntityType( Schema.getDefaultSchema().getEntityType( Import.class ) );
- return rootEm.searchCollection( applicationEntity, APP_IMPORT_CONNECTION, query );
+ return rootEm.searchCollection( appInfo, APP_IMPORT_CONNECTION, query );
}
catch ( Exception e ) {
throw new RuntimeException( "Unable to get import entity", e );
@@ -167,11 +165,11 @@ public class ImportServiceImpl implements ImportService {
try {
final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
- final Entity applicationEntity = getApplicationEntity( rootEm, applicationId );
+ final Entity appInfo = getApplicationInfoEntity(rootEm, applicationId);
final Import importEntity = rootEm.get( importId, Import.class );
// check if it's on the path
- if ( !rootEm.isConnectionMember( applicationEntity, APP_IMPORT_CONNECTION, importEntity ) ) {
+ if ( !rootEm.isConnectionMember( appInfo, APP_IMPORT_CONNECTION, importEntity ) ) {
return null;
}
@@ -183,7 +181,7 @@ public class ImportServiceImpl implements ImportService {
}
- private Entity getApplicationEntity(final EntityManager rootEm, final UUID applicationId) throws Exception {
+ private Entity getApplicationInfoEntity(final EntityManager rootEm, final UUID applicationId) throws Exception {
final Entity entity = rootEm.get( new SimpleEntityRef( CpNamingUtils.APPLICATION_INFO, applicationId ) );
if(entity == null){
@@ -252,7 +250,8 @@ public class ImportServiceImpl implements ImportService {
@Override
- public Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId, @Nullable final String ql, @Nullable final String cursor ) {
+ public Results getFailedImportEntities(final UUID applicationId, final UUID importId, final UUID fileImportId,
+ @Nullable final String ql, @Nullable final String cursor ) {
Preconditions.checkNotNull( applicationId, "applicationId must be specified" );
Preconditions.checkNotNull( importId, "importId must be specified" );
@@ -282,8 +281,8 @@ public class ImportServiceImpl implements ImportService {
@Override
- public FailedImportEntity getFailedImportEntity(final UUID applicationId, final UUID importId, final UUID fileImportId,
- final UUID failedImportId ) {
+ public FailedImportEntity getFailedImportEntity(final UUID applicationId, final UUID importId,
+ final UUID fileImportId, final UUID failedImportId ) {
try {
final EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
@@ -588,7 +587,6 @@ public class ImportServiceImpl implements ImportService {
} else {
-
if (config.get("applicationId") == null) {
throw new UnsupportedOperationException("Import applications not supported");
@@ -855,6 +853,8 @@ public class ImportServiceImpl implements ImportService {
try {
rootEM.update( importEntity );
+ logger.debug("Updated import entity {}:{} with state {}",
+ new Object[] { importEntity.getType(), importEntity.getUuid(), importEntity.getState() } );
}
catch ( Exception e ) {
logger.error( "Error updating import entity", e );
[02/50] incubator-usergrid git commit: Merge branch
'USERGRID-361-appdeletetest' into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-361-appdeletetest' into USERGRID-448-appinfofix
Conflicts:
stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/4d8678cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/4d8678cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/4d8678cf
Branch: refs/heads/two-dot-o-dev
Commit: 4d8678cfdcb95f811bf7fe3b551a28be37ee76d9
Parents: 6791df6 3b91da0
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 4 09:07:56 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 4 09:07:56 2015 -0500
----------------------------------------------------------------------
stack/rest/catalina_base/bin/setenv.sh | 8 -
stack/rest/catalina_base/conf/server.xml | 144 -
stack/rest/catalina_base/conf/tomcat-users.xml | 36 -
stack/rest/catalina_base/conf/web.xml | 4614 ------------------
.../lib/usergrid-deployment.properties | 113 -
.../webapps/host-manager/META-INF/context.xml | 27 -
.../webapps/host-manager/WEB-INF/jsp/401.jsp | 70 -
.../webapps/host-manager/WEB-INF/jsp/403.jsp | 84 -
.../webapps/host-manager/WEB-INF/jsp/404.jsp | 61 -
.../webapps/host-manager/WEB-INF/web.xml | 144 -
.../webapps/host-manager/images/add.gif | Bin 1037 -> 0 bytes
.../webapps/host-manager/images/asf-logo.gif | Bin 7279 -> 0 bytes
.../webapps/host-manager/images/code.gif | Bin 394 -> 0 bytes
.../webapps/host-manager/images/design.gif | Bin 608 -> 0 bytes
.../webapps/host-manager/images/docs.gif | Bin 261 -> 0 bytes
.../webapps/host-manager/images/fix.gif | Bin 345 -> 0 bytes
.../webapps/host-manager/images/tomcat.gif | Bin 1934 -> 0 bytes
.../webapps/host-manager/images/update.gif | Bin 627 -> 0 bytes
.../webapps/host-manager/images/void.gif | Bin 43 -> 0 bytes
.../webapps/host-manager/index.jsp | 18 -
.../webapps/host-manager/manager.xml | 26 -
.../webapps/manager/META-INF/context.xml | 27 -
.../webapps/manager/WEB-INF/jsp/401.jsp | 79 -
.../webapps/manager/WEB-INF/jsp/403.jsp | 94 -
.../webapps/manager/WEB-INF/jsp/404.jsp | 62 -
.../manager/WEB-INF/jsp/sessionDetail.jsp | 197 -
.../manager/WEB-INF/jsp/sessionsList.jsp | 172 -
.../webapps/manager/WEB-INF/web.xml | 209 -
.../webapps/manager/images/add.gif | Bin 1037 -> 0 bytes
.../webapps/manager/images/asf-logo.gif | Bin 7279 -> 0 bytes
.../webapps/manager/images/code.gif | Bin 394 -> 0 bytes
.../webapps/manager/images/design.gif | Bin 608 -> 0 bytes
.../webapps/manager/images/docs.gif | Bin 261 -> 0 bytes
.../webapps/manager/images/fix.gif | Bin 345 -> 0 bytes
.../webapps/manager/images/tomcat.gif | Bin 2066 -> 0 bytes
.../webapps/manager/images/update.gif | Bin 627 -> 0 bytes
.../webapps/manager/images/void.gif | Bin 43 -> 0 bytes
.../catalina_base/webapps/manager/index.jsp | 18 -
.../catalina_base/webapps/manager/status.xsd | 84 -
.../catalina_base/webapps/manager/xform.xsl | 125 -
stack/rest/catalina_base/webapps/portal | 1 -
.../manager/org/apache/jsp/index_jsp.java | 83 -
.../rest/applications/ApplicationResource.java | 5 +
.../usergrid/rest/test/PropertiesResource.java | 2 +-
.../apache/usergrid/rest/IndexResourceIT.java | 1 +
.../applications/ApplicationDeleteTest.java | 190 +-
.../collection/users/UserResourceIT.java | 2 +-
.../rest/applications/queries/OrderByTest.java | 2 +-
.../usergrid/rest/management/AdminUsersIT.java | 967 ++--
.../rest/test/resource2point0/ClientSetup.java | 14 +-
.../rest/test/resource2point0/RestClient.java | 4 +-
.../resource2point0/TestPropertiesResource.java | 47 +
.../endpoints/ApplicationsResource.java | 34 +-
.../endpoints/mgmt/ApplicationsResource.java | 4 +-
.../endpoints/mgmt/ConfirmResource.java | 46 +
.../endpoints/mgmt/ManagementResponse.java | 63 +
.../endpoints/mgmt/OrgResource.java | 12 +-
.../endpoints/mgmt/OrganizationResource.java | 5 +-
.../endpoints/mgmt/ReactivateResource.java | 46 +
.../endpoints/mgmt/ResetResource.java | 42 +
.../endpoints/mgmt/TokenResource.java | 4 +-
.../endpoints/mgmt/UserResource.java | 25 +
.../endpoints/mgmt/UsersResource.java | 7 +
.../resources/usergrid-custom-test.properties | 6 -
64 files changed, 930 insertions(+), 7094 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4d8678cf/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --cc stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index 3133f33,269d0eb..4f8002b
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@@ -539,11 -544,16 +539,16 @@@ public class ApplicationResource extend
emf.deleteApplication( applicationId );
+ LOG.debug( "ApplicationResource.delete() deleted appId = {} appName = {}",
+ applicationId, app.getName() );
+
ApiResponse response = createApiResponse();
response.setAction( "delete" );
- response.setApplication( services.getApplication() );
- response.setParams( ui.getQueryParameters() );
+ response.setApplication(services.getApplication());
+ response.setParams(ui.getQueryParameters());
+ LOG.debug( "ApplicationResource.delete() sending response ");
+
return new JSONWithPadding( response, callback );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4d8678cf/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/UserResourceIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4d8678cf/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
----------------------------------------------------------------------
diff --cc stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
index f634c06,01f78f2..d06322c
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/ApplicationsResource.java
@@@ -53,6 -53,7 +53,6 @@@ public class ApplicationsResource exten
logger.info("Response: " + responseString);
return mapper.readValue(
- new StringReader(responseString), OrganizationApplicationResponse.class);
+ new StringReader(responseString), ManagementResponse.class);
}
}
-
[16/50] incubator-usergrid git commit: Merge branch 'two-dot-o' into
USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'two-dot-o' into USERGRID-448-appinfofix
Conflicts:
stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/impl/MapManagerFactoryImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a0956810
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a0956810
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a0956810
Branch: refs/heads/two-dot-o-dev
Commit: a0956810593d7aa34280c8e30cf50223574969db
Parents: 2190a5a 06e7ad6
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 11 09:48:08 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 11 09:48:08 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 111 +++++++++-------
.../usergrid/persistence/map/MapManager.java | 8 ++
.../persistence/map/guice/MapModule.java | 2 +-
.../map/impl/MapManagerFactoryImpl.java | 29 +++--
.../persistence/map/impl/MapManagerImpl.java | 6 +
.../persistence/map/impl/MapSerialization.java | 20 ++-
.../map/impl/MapSerializationImpl.java | 106 +++++++++++++---
.../persistence/map/MapManagerTest.java | 49 +++++++-
stack/corepersistence/queryindex/pom.xml | 16 ++-
.../persistence/index/guice/IndexModule.java | 4 +
.../index/impl/EsEntityIndexFactoryImpl.java | 12 +-
.../index/impl/EsEntityIndexImpl.java | 57 +++++++--
.../index/impl/EsIndexBufferConsumerImpl.java | 15 ++-
.../persistence/index/impl/IndexingUtils.java | 2 +-
.../persistence/index/utils/StringUtils.java | 126 ++-----------------
.../persistence/index/utils/UUIDUtils.java | 4 -
.../persistence/index/impl/EntityIndexTest.java | 99 ++++++++++++++-
17 files changed, 433 insertions(+), 233 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0956810/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/MapManager.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0956810/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
index 22d37c7,5c46c87..56f8770
--- a/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
+++ b/stack/corepersistence/map/src/main/java/org/apache/usergrid/persistence/map/guice/MapModule.java
@@@ -42,8 -42,12 +42,8 @@@ public class MapModule extends Abstract
@Override
protected void configure() {
- bind(MapManagerFactory.class).to(MapManagerFactoryImpl.class);
-
- // create a guice factory for getting our collection manager
+ bind(MapManagerFactory.class).to( MapManagerFactoryImpl.class );
-
- bind( MapSerialization.class).to( MapSerializationImpl.class );
-
+ bind(MapSerialization.class).to( MapSerializationImpl.class );
Multibinder<Migration> migrationBinding = Multibinder.newSetBinder( binder(), Migration.class );
migrationBinding.addBinding().to( Key.get( MapSerialization.class ) );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a0956810/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
[19/50] incubator-usergrid git commit: AppInfoMigrationPlugin should
manage its own version numbering.
Posted by sn...@apache.org.
AppInfoMigrationPlugin should manage its own version numbering.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/44b56908
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/44b56908
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/44b56908
Branch: refs/heads/two-dot-o-dev
Commit: 44b56908ad64ec63212bfb7b751678e06706dd30
Parents: 6078526
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 12 17:36:09 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 12 17:36:09 2015 -0400
----------------------------------------------------------------------
.../migration/AppInfoMigrationPlugin.java | 16 +++++++++++++++-
.../migration/MigrationModuleVersionPlugin.java | 19 ++++++++++++-------
.../apache/usergrid/rest/MigrateResource.java | 12 ++----------
3 files changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44b56908/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 1c38615..59fafd5 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
@@ -21,6 +21,7 @@ package org.apache.usergrid.corepersistence.migration;
import com.google.inject.Inject;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
import org.apache.usergrid.persistence.core.migration.data.MigrationPlugin;
import org.apache.usergrid.persistence.core.migration.data.PluginPhase;
import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
@@ -51,6 +52,9 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
public static String PLUGIN_NAME = "appinfo-migration";
@Inject
+ private MigrationInfoSerialization migrationInfoSerialization;
+
+ @Inject
protected EntityManagerFactory emf; // protected for test purposes only
@Override
@@ -61,6 +65,13 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
@Override
public void run(ProgressObserver observer) {
+ final int version = migrationInfoSerialization.getVersion( getName() );
+
+ if ( version == getMaxVersion() ) {
+ logger.debug("Skipping Migration Plugin: " + getName());
+ return;
+ }
+
observer.start();
EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
@@ -132,6 +143,8 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
em.delete(oldAppInfo);
}
+ migrationInfoSerialization.setVersion( getName(), getMaxVersion() );
+
} catch (Exception e) {
// stop on any exception and return failure
@@ -146,6 +159,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
}
observer.complete();
+
}
private Entity getApplicationInfo( EntityManagerFactory emf, UUID appId ) throws Exception {
@@ -162,7 +176,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
@Override
public int getMaxVersion() {
- return CoreDataVersions.APPINFO_FIX.getVersion();
+ return 1; // standalone plugin, happens once
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44b56908/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
index c979ed5..439c3f6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/MigrationModuleVersionPlugin.java
@@ -95,20 +95,25 @@ public class MigrationModuleVersionPlugin implements MigrationPlugin{
//now we store versions for each of our modules
switch ( legacyVersion ) {
+
//we need to set the version of the entity data, and our edge shard migration. The fall through (no break) is deliberate
//if it's initial, set both
case INITIAL:
- //if it's entity v2, set all, it's current
+
+ //if it's entity v2, set all, it's current
case ENTITY_V2_MIGRATION:
- migrationInfoSerialization.setVersion( CollectionMigrationPlugin.PLUGIN_NAME, serializationStrategyV2.getImplementationVersion() );
- //if it's edge shard, we need to run the v2 migration
+ migrationInfoSerialization.setVersion(
+ CollectionMigrationPlugin.PLUGIN_NAME, serializationStrategyV2.getImplementationVersion() );
+
+ //if it's edge shard, we need to run the v2 migration
case EDGE_SHARD_MIGRATION:
//set our shard migration to the migrated version
- migrationInfoSerialization.setVersion( GraphMigrationPlugin.PLUGIN_NAME, edgeMetadataSerializationV2.getImplementationVersion() );
+ migrationInfoSerialization.setVersion(
+ GraphMigrationPlugin.PLUGIN_NAME, edgeMetadataSerializationV2.getImplementationVersion() );
+
case ID_MIGRATION:
- migrationInfoSerialization.setVersion( CoreMigrationPlugin.PLUGIN_NAME, CoreDataVersions.ID_MAP_FIX.getVersion() );
- case APPINFO_MIGRATION:
- migrationInfoSerialization.setVersion( AppInfoMigrationPlugin.PLUGIN_NAME, AppInfoVersions.APPINFO_FIX.getVersion() );
+ migrationInfoSerialization.setVersion(
+ CoreMigrationPlugin.PLUGIN_NAME, CoreDataVersions.ID_MAP_FIX.getVersion() );
}
//save the version
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44b56908/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
index a6d2daa..f249512 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
@@ -88,7 +88,7 @@ public class MigrateResource extends AbstractContextResource {
logger.info( "Migrating Data " );
try {
- getMigrationManager().migrate();
+ getDataMigrationManager().migrate();
}
catch ( Exception e ) {
logger.error( "Unable to migrate data", e );
@@ -114,7 +114,7 @@ public class MigrateResource extends AbstractContextResource {
@QueryParam( "callback" ) @DefaultValue( "" ) String callback )
throws Exception {
- logger.debug( "newOrganization" );
+ logger.debug( "setMigrationVersion" );
Preconditions.checkNotNull( json, "You must provide a json body" );
@@ -193,13 +193,5 @@ public class MigrateResource extends AbstractContextResource {
private DataMigrationManager getDataMigrationManager() {
return guiceInjector.getInstance( DataMigrationManager.class );
}
-
-
- /**
- * Get the Data migraiton manager
- */
- private MigrationManager getMigrationManager() {
- return guiceInjector.getInstance( MigrationManager.class );
- }
}
[12/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a4bdc1fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a4bdc1fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a4bdc1fc
Branch: refs/heads/two-dot-o-dev
Commit: a4bdc1fccc98bfd4f005f325cad80f259bdf368e
Parents: 7f84f4a b635113
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 9 13:42:29 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 9 13:42:29 2015 -0400
----------------------------------------------------------------------
.../main/dist/init_instance/init_rest_server.sh | 24 +-
stack/core/pom.xml | 10 +
.../AllApplicationsObservable.java | 39 ++
.../usergrid/corepersistence/CoreModule.java | 77 ++-
.../corepersistence/CpEntityManagerFactory.java | 63 +-
.../corepersistence/CpManagerCache.java | 55 +-
.../usergrid/corepersistence/ManagerCache.java | 12 +-
.../events/EntityVersionDeletedHandler.java | 17 +-
.../migration/CoreDataVersions.java | 43 ++
.../migration/CoreMigration.java | 53 ++
.../migration/CoreMigrationPlugin.java | 64 ++
.../migration/EntityDataMigration.java | 147 ----
.../migration/EntityTypeMappingMigration.java | 78 ++-
.../migration/GraphShardVersionMigration.java | 152 -----
.../migration/MigrationModuleVersionPlugin.java | 133 ++++
.../migration/MigrationSystemVersions.java | 43 ++
.../corepersistence/migration/Versions.java | 14 -
.../rx/AllEntitiesInSystemObservable.java | 101 ---
.../rx/ApplicationObservable.java | 123 ----
.../rx/EdgesFromSourceObservable.java | 63 --
.../rx/EdgesToTargetObservable.java | 63 --
.../corepersistence/rx/TargetIdObservable.java | 66 --
.../rx/impl/AbstractGraphVisitorImpl.java | 107 +++
.../rx/impl/AllApplicationsObservableImpl.java | 135 ++++
.../rx/impl/AllEntitiesInSystemImpl.java | 62 ++
.../rx/impl/AllNodesInGraphImpl.java | 55 ++
.../corepersistence/util/CpEntityMapUtils.java | 19 +-
.../corepersistence/util/CpNamingUtils.java | 2 +
.../migration/EntityDataMigrationIT.java | 262 -------
.../migration/EntityTypeMappingMigrationIT.java | 183 ++---
.../migration/GraphShardVersionMigrationIT.java | 226 ------
.../MigrationModuleVersionPluginTest.java | 259 +++++++
.../migration/MigrationTestRule.java | 99 ---
.../migration/TestProgressObserver.java | 71 --
.../rx/AllEntitiesInSystemObservableIT.java | 41 +-
.../rx/ApplicationObservableTestIT.java | 14 +-
.../rx/EdgesFromSourceObservableIT.java | 10 +-
.../rx/EdgesToTargetObservableIT.java | 8 +-
.../rx/TargetIdObservableTestIT.java | 7 +-
.../org/apache/usergrid/persistence/GeoIT.java | 5 +-
.../usergrid/persistence/LargeEntityIT.java | 3 +-
.../collection/EntityCollectionManager.java | 11 +-
.../EntityCollectionManagerFactory.java | 27 +-
.../collection/EntityCollectionManagerSync.java | 49 --
.../persistence/collection/MvccEntity.java | 5 +-
.../persistence/collection/MvccLogEntry.java | 1 +
.../cache/CachedEntityCollectionManager.java | 7 -
.../collection/event/EntityVersionDeleted.java | 3 +-
.../collection/guice/CollectionModule.java | 56 +-
.../persistence/collection/guice/Write.java | 17 -
.../collection/guice/WriteUpdate.java | 17 -
.../EntityCollectionManagerFactoryImpl.java | 103 ++-
.../impl/EntityCollectionManagerImpl.java | 68 +-
.../impl/EntityCollectionManagerSyncImpl.java | 71 --
.../collection/impl/EntityDeletedTask.java | 20 +-
.../impl/EntityVersionCleanupTask.java | 208 +++---
.../mvcc/MvccEntitySerializationStrategy.java | 102 ---
.../mvcc/stage/delete/MarkCommit.java | 2 +-
.../mvcc/stage/write/WriteCommit.java | 9 +-
.../collection/mvcc/stage/write/WriteStart.java | 6 +-
.../collection/serialization/EntityRepair.java | 38 --
.../MvccEntitySerializationStrategy.java | 119 ++++
.../serialization/OptimisticUpdate.java | 23 -
.../UniqueValueSerializationStrategy.java | 37 +-
.../serialization/UniqueValueSet.java | 4 +
.../impl/CollectionDataVersions.java | 44 ++
.../serialization/impl/EntityRepairImpl.java | 149 ----
.../impl/EntityVersionSerializer.java | 2 -
.../serialization/impl/FieldSerializer.java | 118 ----
.../MvccEntitySerializationStrategyImpl.java | 24 +-
...vccEntitySerializationStrategyProxyImpl.java | 151 +++--
.../MvccEntitySerializationStrategyV1Impl.java | 7 +-
.../MvccEntitySerializationStrategyV2Impl.java | 8 +-
.../MvccEntitySerializationStrategyV3Impl.java | 616 +++++++++++++++++
.../serialization/impl/SerializationModule.java | 85 ++-
.../serialization/impl/UniqueFieldEntry.java | 61 ++
.../impl/UniqueFieldEntrySerializer.java | 141 ++++
.../impl/UniqueFieldRowKeySerializer.java | 122 ++++
.../UniqueValueSerializationStrategyImpl.java | 256 +++++--
.../impl/migration/CollectionMigration.java | 53 ++
.../migration/CollectionMigrationPlugin.java | 68 ++
.../impl/migration/EntityIdScope.java | 49 ++
.../migration/MvccEntityDataMigrationImpl.java | 283 ++++++++
.../collection/util/EntityUtils.java | 29 +-
.../collection/EntityCollectionManagerIT.java | 106 +--
.../EntityCollectionManagerSyncIT.java | 193 ------
.../collection/guice/TestCollectionModule.java | 22 +-
.../impl/EntityVersionCleanupTaskTest.java | 679 ++++++++-----------
.../impl/EntityVersionCreatedTaskTest.java | 2 -
.../mvcc/stage/delete/MarkCommitTest.java | 2 +-
.../mvcc/stage/write/FieldSerializerTest.java | 52 --
.../write/UniqueFieldRowKeySerializerTest.java | 52 ++
...niqueValueSerializationStrategyImplTest.java | 149 +++-
.../mvcc/stage/write/WriteCommitTest.java | 2 +-
.../mvcc/stage/write/WriteStartTest.java | 6 +-
.../serialization/EntityRepairImplTest.java | 147 ----
.../impl/LogEntryIteratorTest.java | 3 +-
...MvccEntitySerializationStrategyImplTest.java | 117 +---
...cEntitySerializationStrategyProxyV1Test.java | 85 ---
...ntitySerializationStrategyProxyV1_3Test.java | 80 +++
...cEntitySerializationStrategyProxyV2Test.java | 83 ---
...ntitySerializationStrategyProxyV2_3Test.java | 81 +++
...ccEntitySerializationStrategyV1ImplTest.java | 80 ++-
...ccEntitySerializationStrategyV2ImplTest.java | 75 +-
.../MvccEntitySerializationStrategyV2Test.java | 7 +-
...ccEntitySerializationStrategyV3ImplTest.java | 74 ++
.../impl/UniqueFieldEntrySerializerTest.java | 108 +++
...ctMvccEntityDataMigrationV1ToV3ImplTest.java | 215 ++++++
.../MvccEntityDataMigrationV1ToV3ImplTest.java | 105 +++
.../MvccEntityDataMigrationV2ToV3ImplTest.java | 99 +++
.../collection/util/LogEntryMock.java | 39 +-
.../collection/util/UniqueValueEntryMock.java | 161 +++++
.../collection/util/VersionGenerator.java | 55 ++
.../usergrid/persistence/core/CPManager.java | 28 +
.../astyanax/DynamicCompositeParserImpl.java | 81 +++
.../core/astyanax/FieldBufferBuilder.java | 15 +
.../core/astyanax/FieldBufferParser.java | 13 +
.../persistence/core/guice/CommonModule.java | 17 +-
.../persistence/core/guice/CurrentImpl.java | 42 --
.../persistence/core/guice/PreviousImpl.java | 42 --
.../core/hystrix/HystrixCassandra.java | 4 +-
.../migration/data/AbstractMigrationPlugin.java | 128 ++++
.../core/migration/data/DataMigration.java | 97 +--
.../migration/data/DataMigrationManager.java | 18 +-
.../data/DataMigrationManagerImpl.java | 234 ++++---
.../migration/data/MigrationDataProvider.java | 43 ++
.../core/migration/data/MigrationInfoCache.java | 52 ++
.../migration/data/MigrationInfoCacheImpl.java | 84 +++
.../data/MigrationInfoSerialization.java | 28 +-
.../data/MigrationInfoSerializationImpl.java | 67 +-
.../core/migration/data/MigrationPlugin.java | 56 ++
.../migration/data/MigrationRelationship.java | 100 +++
.../core/migration/data/PluginPhase.java | 42 ++
.../core/migration/data/ProgressObserver.java | 63 ++
.../core/migration/data/VersionedData.java | 38 ++
.../migration/data/VersionedMigrationSet.java | 153 +++++
.../core/scope/ApplicationScope.java | 1 +
.../core/guice/DataMigrationResetRule.java | 88 +++
.../core/guice/MaxMigrationModule.java | 39 --
.../core/guice/MaxMigrationVersion.java | 40 --
.../core/guice/MigrationManagerRule.java | 7 +
.../core/guice/TestCommonModule.java | 1 +
.../persistence/core/guice/TestModule.java | 5 +-
.../data/DataMigrationManagerImplTest.java | 326 +++++----
.../data/MigrationInfoSerializationTest.java | 32 +-
.../data/TestMigrationDataProvider.java | 61 ++
.../migration/data/TestProgressObserver.java | 89 +++
.../data/VersionedMigrationSetTest.java | 198 ++++++
.../persistence/core/util/IdGenerator.java | 51 ++
.../persistence/graph/GraphManager.java | 3 +-
.../persistence/graph/GraphManagerFactory.java | 2 +
.../persistence/graph/guice/GraphModule.java | 103 ++-
.../graph/impl/GraphManagerImpl.java | 2 +-
.../EdgeMetadataSerialization.java | 3 +-
.../graph/serialization/EdgesObservable.java | 33 +
.../graph/serialization/TargetIdObservable.java | 38 ++
.../EdgeMetadataSerializationProxyImpl.java | 161 +++--
.../impl/EdgeMetadataSerializationV1Impl.java | 6 +
.../impl/EdgeMetadataSerializationV2Impl.java | 6 +
.../serialization/impl/EdgesObservableImpl.java | 80 +++
.../serialization/impl/GraphDataVersions.java | 43 ++
.../impl/GraphManagerFactoryImpl.java | 94 +++
.../impl/TargetIdObservableImpl.java | 72 ++
.../impl/migration/EdgeDataMigrationImpl.java | 149 ++++
.../impl/migration/GraphMigration.java | 53 ++
.../impl/migration/GraphMigrationPlugin.java | 69 ++
.../serialization/impl/migration/GraphNode.java | 39 ++
.../persistence/graph/GraphManagerIT.java | 21 +-
.../persistence/graph/GraphManagerLoadTest.java | 13 +-
.../graph/GraphManagerShardConsistencyIT.java | 10 +-
.../graph/GraphManagerShardingIT.java | 13 +-
.../graph/GraphManagerStressTest.java | 11 +-
.../graph/guice/TestGraphModule.java | 27 +-
.../graph/impl/EdgeDeleteListenerTest.java | 11 +-
.../graph/impl/NodeDeleteListenerTest.java | 9 +-
.../graph/impl/stage/EdgeDeleteRepairTest.java | 7 +-
.../graph/impl/stage/EdgeMetaRepairTest.java | 29 +-
.../EdgeMetaDataSerializationProxyV1Test.java | 14 +-
.../EdgeMetaDataSerializationProxyV2Test.java | 21 +-
.../EdgeMetaDataSerializationV1Test.java | 7 +-
.../EdgeMetaDataSerializationV2Test.java | 7 +-
.../EdgeMetadataSerializationTest.java | 39 +-
.../EdgeSerializationChopTest.java | 7 +-
.../serialization/EdgeSerializationTest.java | 21 +-
.../serialization/NodeSerializationTest.java | 15 +-
.../migration/EdgeDataMigrationImplTest.java | 177 +++++
.../impl/shard/EdgeShardSerializationTest.java | 7 +-
.../impl/shard/NodeShardAllocationTest.java | 27 +-
.../impl/shard/NodeShardCacheTest.java | 7 +-
.../impl/shard/ShardGroupCompactionTest.java | 7 +-
.../shard/count/NodeShardApproximationTest.java | 9 +-
.../NodeShardCounterSerializationTest.java | 6 +-
.../shard/impl/ShardEntryGroupIteratorTest.java | 15 +-
...rceDirectedEdgeDescendingComparatorTest.java | 23 +-
...getDirectedEdgeDescendingComparatorTest.java | 23 +-
.../graph/test/util/EdgeTestUtils.java | 29 +-
.../usergrid/persistence/map/MapManager.java | 4 +-
.../persistence/map/MapManagerFactory.java | 2 +
.../persistence/map/guice/MapModule.java | 10 +-
.../map/impl/MapManagerFactoryImpl.java | 68 ++
.../persistence/map/guice/TestMapModule.java | 3 +-
.../persistence/model/entity/Entity.java | 23 +-
.../persistence/model/entity/EntityMap.java | 66 ++
.../model/entity/EntityToMapConverter.java | 133 ++++
.../model/entity/MapToEntityConverter.java | 203 ++++++
.../persistence/model/entity/SimpleId.java | 1 -
.../persistence/model/field/AbstractField.java | 8 +
.../persistence/model/field/ListField.java | 2 +-
.../persistence/model/field/StringField.java | 20 +
.../usergrid/persistence/index/EntityIndex.java | 4 +-
.../index/impl/EsEntityIndexImpl.java | 3 +
.../index/guice/TestIndexModule.java | 5 +-
.../index/impl/EntityIndexMapUtils.java | 52 +-
.../queue/guice/TestQueueModule.java | 3 +-
stack/pom.xml | 2 +-
.../org/apache/usergrid/rest/IndexResource.java | 3 +
.../apache/usergrid/rest/MigrateResource.java | 4 +-
217 files changed, 8953 insertions(+), 4773 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a4bdc1fc/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 783261a,a897ad2..4e22b12
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -19,20 -19,40 +19,23 @@@ import com.google.common.base.Optional
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
-import com.google.inject.Guice;
import com.google.inject.Injector;
++import com.google.inject.Key;
++import com.google.inject.TypeLiteral;
import com.yammer.metrics.annotation.Metered;
-import static java.lang.String.CASE_INSENSITIVE_ORDER;
-
-import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
import org.apache.commons.lang.StringUtils;
- import org.apache.usergrid.corepersistence.rx.AllEntitiesInSystemObservable;
-
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.AbstractEntity;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityFactory;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.persistence.*;
import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.cassandra.CounterUtils;
import org.apache.usergrid.persistence.cassandra.Setup;
import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
+ import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
+import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
+ import org.apache.usergrid.persistence.core.migration.data.MigrationDataProvider;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.core.util.Health;
@@@ -306,76 -347,57 +323,76 @@@ public class CpEntityManagerFactory imp
@Override
public void deleteApplication(UUID applicationId) throws Exception {
- //throw new UnsupportedOperationException("Delete application not supported");
+ // make a copy of the app to delete application_info entity
+
+ EntityManager em = getEntityManager( this.getManagementAppId() );
+ Entity appToDelete = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+
+ // and put it in a deleted_application_info collection
- // remove old appinfo Entity, which is in the System App's appinfos collection
- EntityManager em = getEntityManager(CpNamingUtils.SYSTEM_APP_ID);
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
+ Entity deletedApp = em.create(
- applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, appToDelete.getProperties() );
++ applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, appToDelete.getProperties());
- Entity appToDelete = results.getEntity();
- if(appToDelete != null) {
- // create new Entity in deleted_appinfos collection, with same UUID and properties as deleted appinfo
- em.create("deleted_appinfo", appToDelete.getProperties());
- em.delete(appToDelete);
+ // copy its connections too
+ final Set<String> connectionTypes = em.getConnectionTypes(appToDelete);
+ for ( String connType : connectionTypes ) {
+ final Results results =
+ em.getConnectedEntities(appToDelete, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : results.getEntities() ) {
+ em.createConnection( deletedApp, connType, entity );
+ }
}
- // delete the application's index
- EntityIndex ei = managerCache.getEntityIndex(new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
- ei.deleteIndex();
+
+ // delete the app from the application_info collection and delete its index
+
- em.delete( appToDelete);
++ em.delete(appToDelete);
em.refreshIndex();
+
+ final EntityIndex entityIndex = managerCache.getEntityIndex(
+ new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
+ entityIndex.deleteIndex();
}
@Override
public void restoreApplication(UUID applicationId) throws Exception {
- // remove old delete_appinfos Entity
- EntityManager em = getEntityManager(CpNamingUtils.SYSTEM_APP_ID);
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection( em.getApplicationRef(), "deleted_appinfos", q);
- Entity appToRestore = results.getEntity();
+ // get the deleted_application_info for the deleted app
+
+ EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ Entity deletedApp = em.get(
- new SimpleEntityRef( CpNamingUtils.DELETED_APPLICATION_INFO, applicationId ));
++ new SimpleEntityRef(CpNamingUtils.DELETED_APPLICATION_INFO, applicationId));
- if ( appToRestore == null ) {
+ if ( deletedApp == null ) {
throw new EntityNotFoundException("Cannot restore. Deleted Application not found: " + applicationId );
}
- em.delete( appToRestore );
+ // create application_info for restored app
- // restore entity in appinfo collection
- Map<String, Object> appProps = appToRestore.getProperties();
- appProps.remove("uuid");
- appProps.put("type", "appinfo");
- Entity restoredApp = em.create("appinfo", appToRestore.getProperties());
+ Entity restoredApp = em.create(
+ deletedApp.getUuid(), CpNamingUtils.APPLICATION_INFO, deletedApp.getProperties());
- em.refreshIndex();
+ // copy connections from deleted app entity
+
+ final Set<String> connectionTypes = em.getConnectionTypes(deletedApp);
+ for ( String connType : connectionTypes ) {
+ final Results results =
+ em.getConnectedEntities(deletedApp, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : results.getEntities() ) {
+ em.createConnection( restoredApp, connType, entity );
+ }
+ }
+
+ // delete the deleted app entity rebuild the app index
+
- em.delete( deletedApp );
++ em.delete(deletedApp);
- // rebuild the apps index
this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@Override
public void onProgress(EntityRef entity) {
- logger.debug("Restored oldAppInfo {}:{}", entity.getType(), entity.getUuid());
+ logger.info( "Restored entity {}:{}", entity.getType(), entity.getUuid() );
}
-
});
}
@@@ -546,7 -507,7 +563,7 @@@
Map<String, String> props = new HashMap<String,String>();
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
++ EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
Query q = Query.fromQL("select *");
Results results = null;
try {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a4bdc1fc/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
index 0000000,0fc5452..f48b930
mode 000000,100644..100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
@@@ -1,0 -1,142 +1,135 @@@
+ /*
+ * 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.rx.impl;
+
+
+ import java.util.Arrays;
+ import java.util.UUID;
+
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+
+ import org.apache.usergrid.corepersistence.AllApplicationsObservable;
+ import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+ import org.apache.usergrid.persistence.collection.CollectionScope;
+ import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+ import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+ import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+ import org.apache.usergrid.persistence.graph.Edge;
+ 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.model.entity.Entity;
+ import org.apache.usergrid.persistence.model.entity.Id;
+
+ import com.google.inject.Inject;
+
+ import rx.Observable;
+ import rx.functions.Func1;
+
+ import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getApplicationScope;
+
+
+ /**
+ * An observable that will emit all application stored in the system.
+ */
+ public class AllApplicationsObservableImpl implements AllApplicationsObservable {
+
+ private static final Logger logger = LoggerFactory.getLogger( AllApplicationsObservableImpl.class );
+ private final EntityCollectionManagerFactory entityCollectionManagerFactory;
+ private final GraphManagerFactory graphManagerFactory;
+
+ @Inject
+ public AllApplicationsObservableImpl( EntityCollectionManagerFactory entityCollectionManagerFactory,
+ GraphManagerFactory graphManagerFactory ){
+
+ this.entityCollectionManagerFactory = entityCollectionManagerFactory;
+ this.graphManagerFactory = graphManagerFactory;
+ }
+
+
+
+ @Override
+ public Observable<ApplicationScope> getAllApplications() {
+
- //emit our 3 hard coded applications that are used the manage the system first.
++ //emit our hard coded applications that are used the manage the system first.
+ //this way consumers can perform whatever work they need to on the root system first
- final Observable<ApplicationScope> systemIds = Observable.from( Arrays
- .asList( getApplicationScope( CpNamingUtils.DEFAULT_APPLICATION_ID ),
- getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID ),
- getApplicationScope( CpNamingUtils.SYSTEM_APP_ID ) ) );
++ final Observable<ApplicationScope> systemIds = Observable.from(
++ Arrays.asList( getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID )));
+
-
- final ApplicationScope appScope = getApplicationScope( CpNamingUtils.SYSTEM_APP_ID );
++ final ApplicationScope appScope = getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+
+ final CollectionScope appInfoCollectionScope =
- new CollectionScopeImpl( appScope.getApplication(), appScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPINFOS ) );
++ new CollectionScopeImpl( appScope.getApplication(), appScope.getApplication(),
++ CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPLICATION_INFOS) );
+
+ final EntityCollectionManager collectionManager =
+ entityCollectionManagerFactory.createCollectionManager( appInfoCollectionScope );
+
-
+ final GraphManager gm = graphManagerFactory.createEdgeManager(appScope);
+
+
- String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPINFOS );
++ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS );
+
+ Id rootAppId = appScope.getApplication();
+
+
+ //we have app infos. For each of these app infos, we have to load the application itself
+ Observable<ApplicationScope> appIds = gm.loadEdgesFromSource(
+ new SimpleSearchByEdgeType( rootAppId, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
+ null ) ).flatMap( new Func1<Edge, Observable<ApplicationScope>>() {
+ @Override
+ public Observable<ApplicationScope> call( final Edge edge ) {
+ //get the app info and load it
+ final Id appInfo = edge.getTargetNode();
+
+ return collectionManager.load( appInfo )
+ //filter out null entities
+ .filter( new Func1<Entity, Boolean>() {
+ @Override
+ public Boolean call( final Entity entity ) {
+ if ( entity == null ) {
+ logger.warn( "Encountered a null application info for id {}", appInfo );
+ return false;
+ }
+
+ return true;
+ }
+ } )
+ //get the id from the entity
+ .map( new Func1<Entity, ApplicationScope>() {
+
-
+ @Override
+ public ApplicationScope call( final Entity entity ) {
-
- final UUID uuid = ( UUID ) entity.getField( "applicationUuid" ).getValue();
-
++ final UUID uuid = entity.getId().getUuid();
+ return getApplicationScope( uuid );
+ }
+ } );
+ }
+ } );
+
+ return Observable.merge( systemIds, appIds );
+ }
+
+
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a4bdc1fc/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a4bdc1fc/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
----------------------------------------------------------------------
[30/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c8fcf2de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c8fcf2de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c8fcf2de
Branch: refs/heads/two-dot-o-dev
Commit: c8fcf2de9cd3fe3fdbf4b480a4420062ee88d44b
Parents: 7d7c54b f1bf035
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 19 17:10:00 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 19 17:10:00 2015 -0400
----------------------------------------------------------------------
.../main/dist/init_instance/init_rest_server.sh | 2 +
.../dist/init_instance/install_elasticsearch.sh | 22 +-
.../main/groovy/configure_elasticsearch.groovy | 80 ++--
.../src/main/groovy/configure_usergrid.groovy | 12 +-
stack/awscluster/ugcluster-cf.json | 466 +++++++++++++------
stack/core/pom.xml | 10 -
.../batch/service/JobSchedulerService.java | 5 -
.../usergrid/corepersistence/CoreModule.java | 20 +-
.../corepersistence/CpEntityManager.java | 64 ++-
.../corepersistence/CpEntityManagerFactory.java | 5 -
.../corepersistence/CpRelationManager.java | 21 +-
.../events/EntityDeletedHandler.java | 58 ++-
.../events/EntityVersionCreatedHandler.java | 60 ++-
.../events/EntityVersionDeletedHandler.java | 55 ++-
.../results/FilteringLoader.java | 52 ++-
.../usergrid/persistence/EntityManager.java | 10 +-
.../persistence/EntityManagerFactory.java | 2 -
.../cassandra/EntityManagerFactoryImpl.java | 3 -
.../cassandra/EntityManagerImpl.java | 31 +-
.../cassandra/RelationManagerImpl.java | 58 +--
.../cassandra/index/ConnectedIndexScanner.java | 2 -
.../cassandra/index/IndexBucketScanner.java | 2 -
.../corepersistence/StaleIndexCleanupTest.java | 86 +++-
.../usergrid/persistence/EntityManagerIT.java | 1 +
.../PerformanceEntityRebuildIndexTest.java | 2 +
.../collection/EntityCollectionManager.java | 14 +-
.../collection/EntityDeletedFactory.java | 34 --
.../collection/EntityVersionCleanupFactory.java | 35 --
.../collection/EntityVersionCreatedFactory.java | 31 --
.../persistence/collection/FieldSet.java | 48 ++
.../cache/CachedEntityCollectionManager.java | 11 +-
.../collection/guice/CollectionModule.java | 11 +-
.../EntityCollectionManagerFactoryImpl.java | 30 +-
.../impl/EntityCollectionManagerImpl.java | 240 ++++++++--
.../collection/impl/EntityDeletedTask.java | 9 +-
.../impl/EntityVersionCleanupTask.java | 39 +-
.../impl/EntityVersionTaskFactory.java | 65 +++
.../mvcc/stage/write/WriteUniqueVerify.java | 140 +++---
.../UniqueValueSerializationStrategy.java | 12 +
.../serialization/impl/MutableFieldSet.java | 63 +++
.../MvccEntitySerializationStrategyV1Impl.java | 2 +-
.../MvccEntitySerializationStrategyV3Impl.java | 1 -
.../UniqueValueSerializationStrategyImpl.java | 27 +-
.../migration/MvccEntityDataMigrationImpl.java | 8 +-
.../collection/util/EntityUtils.java | 4 +-
.../collection/EntityCollectionManagerIT.java | 68 +++
.../impl/EntityVersionCleanupTaskTest.java | 13 +-
.../mvcc/stage/write/WriteUniqueVerifyTest.java | 6 +-
...ntitySerializationStrategyProxyV1_3Test.java | 3 +
...ntitySerializationStrategyProxyV2_3Test.java | 3 +
...ccEntitySerializationStrategyV1ImplTest.java | 2 +
.../core/astyanax/CassandraConfig.java | 6 +
.../core/astyanax/CassandraConfigImpl.java | 8 +-
.../persistence/core/astyanax/CassandraFig.java | 9 +-
.../core/astyanax/MultiRowColumnIterator.java | 12 +-
.../persistence/core/future/BetterFuture.java | 43 +-
.../core/hystrix/HystrixCassandra.java | 94 ----
.../core/metrics/MetricsFactory.java | 9 +
.../core/metrics/MetricsFactoryImpl.java | 121 +++--
.../persistence/core/task/TaskExecutor.java | 4 +-
.../core/astyanax/ColumnNameIteratorTest.java | 7 +-
.../MultiKeyColumnNameIteratorTest.java | 7 +-
.../astyanax/MultiRowColumnIteratorTest.java | 7 +-
stack/corepersistence/graph/pom.xml | 28 +-
.../graph/impl/GraphManagerImpl.java | 310 ++++++++++--
.../graph/impl/stage/EdgeDeleteRepairImpl.java | 9 +-
.../graph/impl/stage/EdgeMetaRepairImpl.java | 16 +-
.../impl/stage/NodeDeleteListenerImpl.java | 16 +-
.../impl/GraphManagerFactoryImpl.java | 17 +-
.../impl/NodeSerializationImpl.java | 36 +-
.../shard/count/NodeShardApproximationImpl.java | 4 +-
.../NodeShardCounterSerializationImpl.java | 25 +-
.../shard/impl/NodeShardAllocationImpl.java | 16 +-
.../shard/impl/ShardGroupCompactionImpl.java | 64 +--
.../usergrid/persistence/map/MapManager.java | 14 +-
.../persistence/map/impl/MapManagerImpl.java | 8 +
.../persistence/map/impl/MapSerialization.java | 9 +
.../map/impl/MapSerializationImpl.java | 93 ++++
.../persistence/map/MapManagerTest.java | 49 +-
stack/corepersistence/queryindex/pom.xml | 17 +-
.../usergrid/persistence/index/EntityIndex.java | 26 +-
.../persistence/index/IndexBufferConsumer.java | 11 +
.../persistence/index/IndexBufferProducer.java | 1 -
.../usergrid/persistence/index/IndexFig.java | 73 ++-
.../index/IndexOperationMessage.java | 115 ++++-
.../persistence/index/guice/IndexModule.java | 7 +
.../persistence/index/guice/QueueProvider.java | 116 +++++
.../persistence/index/impl/BatchRequest.java | 41 ++
.../persistence/index/impl/BufferQueue.java | 68 +++
.../index/impl/BufferQueueInMemoryImpl.java | 108 +++++
.../index/impl/BufferQueueSQSImpl.java | 307 ++++++++++++
.../persistence/index/impl/DeIndexRequest.java | 115 +++++
.../index/impl/EsEntityIndexBatchImpl.java | 64 ++-
.../index/impl/EsEntityIndexImpl.java | 349 +++++---------
.../index/impl/EsIndexBufferConsumerImpl.java | 286 ++++++++----
.../index/impl/EsIndexBufferProducerImpl.java | 16 +-
.../persistence/index/impl/EsIndexCache.java | 138 +++---
.../persistence/index/impl/IndexRequest.java | 125 +++++
.../persistence/index/impl/IndexingUtils.java | 109 +++--
.../index/guice/TestIndexModule.java | 3 +-
.../index/impl/BufferQueueSQSImplTest.java | 169 +++++++
.../impl/EntityConnectionIndexImplTest.java | 5 +-
.../persistence/index/impl/EntityIndexTest.java | 58 +--
.../persistence/index/impl/EsTestUtils.java | 48 --
.../persistence/queue/QueueManager.java | 4 +-
.../usergrid/persistence/queue/QueueScope.java | 2 +-
.../persistence/queue/QueueScopeFactory.java | 34 --
.../persistence/queue/guice/QueueModule.java | 17 +-
.../queue/impl/QueueScopeFactoryImpl.java | 48 --
.../persistence/queue/impl/QueueScopeImpl.java | 27 +-
.../queue/impl/SQSQueueManagerImpl.java | 214 +++++----
.../persistence/queue/NoAWSCredsRule.java | 98 ++++
.../persistence/queue/QueueManagerTest.java | 29 +-
stack/pom.xml | 49 +-
stack/rest/pom.xml | 4 -
.../org/apache/usergrid/rest/RootResource.java | 6 -
.../applications/ApplicationsResource.java | 6 -
stack/services/pom.xml | 13 +-
.../cassandra/ManagementServiceImpl.java | 9 +-
.../services/AbstractCollectionService.java | 40 +-
.../services/AbstractConnectionsService.java | 39 +-
.../notifications/NotificationsService.java | 50 +-
.../services/notifications/QueueListener.java | 5 +-
.../usergrid/services/queues/QueueListener.java | 5 +-
.../notifications/NotifiersServiceIT.java | 6 +
stack/test-utils/pom.xml | 5 -
126 files changed, 4188 insertions(+), 1986 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/main/java/org/apache/usergrid/batch/service/JobSchedulerService.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index adbc499,2e9b780..b62cdf8
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@@ -117,7 -117,7 +118,6 @@@ public class CoreModule extends Abstra
/**
* Create our migrations for within our core plugin
-- *
*/
Multibinder<DataMigration<EntityIdScope>> dataMigrationMultibinder =
Multibinder.newSetBinder( binder(), new TypeLiteral<DataMigration<EntityIdScope>>() {}, CoreMigration.class );
@@@ -129,14 -129,13 +129,10 @@@
//wire up the collection migration plugin
final Multibinder<MigrationPlugin> plugins = Multibinder.newSetBinder( binder(), MigrationPlugin.class );
plugins.addBinding().to( CoreMigrationPlugin.class );
- plugins.addBinding().to(MigrationModuleVersionPlugin.class );
+ plugins.addBinding().to( AppInfoMigrationPlugin.class );
+ plugins.addBinding().to( MigrationModuleVersionPlugin.class );
bind( AllApplicationsObservable.class).to(AllApplicationsObservableImpl.class);
--
--
--
--
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index efae477,f76b9fc..3b47fa2
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -15,18 -15,32 +15,16 @@@
*/
package org.apache.usergrid.corepersistence;
- import com.google.common.base.Optional;
-
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
- import com.yammer.metrics.annotation.Metered;
import org.apache.commons.lang.StringUtils;
-
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.AbstractEntity;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityFactory;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.exception.ConflictException;
+import org.apache.usergrid.persistence.*;
import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.cassandra.CounterUtils;
import org.apache.usergrid.persistence.cassandra.Setup;
@@@ -391,9 -412,8 +389,8 @@@ public class CpEntityManagerFactory imp
@Override
- @Metered(group = "core", name = "EntityManagerFactory_getApplication")
public Map<String, UUID> getApplications() throws Exception {
- return getApplications( false );
+ return getApplications(false);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 88f02ab,8814583..e2d09b3
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@@ -663,114 -649,8 +649,6 @@@ public class EsEntityIndexImpl implemen
return parseResults(searchResponse, new Query());
}
-
- @Override
- public ListenableActionFuture deleteAllVersionsOfEntity(final Id entityId ) {
-
- String idString = IndexingUtils.idString(entityId).toLowerCase();
-
- final TermQueryBuilder tqb = QueryBuilders.termQuery(ENTITYID_ID_FIELDNAME, idString);
-
- //Added For Graphite Metrics
- final Timer.Context timeDeleteAllVersions =allVersionsTimer.time();
- final Timer.Context timeDeleteAllVersionsFuture = allVersionsTimerFuture.time();
- final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient()
- .prepareDeleteByQuery( alias.getWriteAlias() ).setQuery( tqb ).execute();
-
- response.addListener( new ActionListener<DeleteByQueryResponse>() {
-
- @Override
- public void onResponse( DeleteByQueryResponse response) {
- timeDeleteAllVersions.stop();
- logger.debug( "Deleted entity {}:{} from all index scopes with response status = {}",
- entityId.getType(), entityId.getUuid(), response.status().toString() );
-
- checkDeleteByQueryResponse(tqb, response);
- }
-
-
- @Override
- public void onFailure( Throwable e ) {
- timeDeleteAllVersions.stop();
- logger.error( "Failed to delete entity {}:{} from all index scopes with error {}",
- entityId.getType(), entityId.getUuid(), e);
-
-
- }
- });
- timeDeleteAllVersionsFuture.stop();
- return response;
- }
-
-
- @Override
- public ListenableActionFuture deletePreviousVersions(final Id entityId, final UUID version) {
-
- String idString = IndexingUtils.idString( entityId ).toLowerCase();
-
- final FilteredQueryBuilder fqb = QueryBuilders.filteredQuery(
- QueryBuilders.termQuery(ENTITYID_ID_FIELDNAME, idString),
- FilterBuilders.rangeFilter(ENTITY_VERSION_FIELDNAME).lt(version.timestamp())
- );
-
- //Added For Graphite Metrics
- //Checks the time from the execute to the response below
- final Timer.Context timeDeletePreviousVersions = deletePreviousTimer.time();
- final Timer.Context timeDeletePreviousVersionFuture = deletePreviousTimerFuture.time();
- final ListenableActionFuture<DeleteByQueryResponse> response = esProvider.getClient()
- .prepareDeleteByQuery(alias.getWriteAlias()).setQuery(fqb).execute();
-
- //Added For Graphite Metrics
- response.addListener(new ActionListener<DeleteByQueryResponse>() {
- @Override
- public void onResponse(DeleteByQueryResponse response) {
- timeDeletePreviousVersions.stop();
- //error message needs to be retooled so that it describes the entity more throughly
- logger
- .debug("Deleted entity {}:{} with version {} from all " + "index scopes with response status = {}",
- entityId.getType(), entityId.getUuid(), version, response.status().toString());
-
- checkDeleteByQueryResponse( fqb, response );
- }
-
-
- @Override
- public void onFailure( Throwable e ) {
- logger.error( "Deleted entity {}:{} from all index scopes with error {}", entityId.getType(),
- entityId.getUuid(), e );
- }
- } );
-
- timeDeletePreviousVersionFuture.stop();
-
- return response;
- }
-
-
- /**
- * Validate the response doesn't contain errors, if it does, fail fast at the first error we encounter
- */
- private void checkDeleteByQueryResponse(
- final QueryBuilder query, final DeleteByQueryResponse response ) {
-
- for ( IndexDeleteByQueryResponse indexDeleteByQueryResponse : response ) {
- final ShardOperationFailedException[] failures = indexDeleteByQueryResponse.getFailures();
-
- for ( ShardOperationFailedException failedException : failures ) {
- logger.error( String.format("Unable to delete by query %s. "
- + "Failed with code %d and reason %s on shard %s in index %s",
- query.toString(),
- failedException.status().getStatus(),
- failedException.reason(),
- failedException.shardId(),
- failedException.index() )
- );
- }
-
- }
- }
--
--
/**
* Completely delete an index.
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c8fcf2de/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --cc stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 43617c4,854c3e0..16bb703
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@@ -1606,98 -1636,40 +1605,98 @@@ public class ManagementServiceImpl impl
}
if ( properties == null ) {
- properties = new HashMap<String, Object>();
+ properties = new HashMap<>();
}
+ EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+
OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
+ Entity appInfo = emf.createApplicationV2(
+ organizationInfo.getName(), applicationName, properties);
+ em.refreshIndex();
- UUID applicationId = emf.createApplication( organizationInfo.getName(), applicationName, properties );
+ writeUserToken( smf.getManagementAppId(), appInfo,
+ encryptionService.plainTextCredentials(
+ generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
+ null,
+ smf.getManagementAppId() ) );
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- properties.put( "name", buildAppName( applicationName, organizationInfo ) );
- properties.put( "appUuid", applicationId );
- Entity appInfo = em.create( applicationId, APPLICATION_INFO, properties );
+ UUID applicationId = addApplicationToOrganization( organizationId, appInfo );
+ UserInfo user = null;
+ try {
+ user = SubjectUtils.getUser();
+ }
+ catch ( UnavailableSecurityManagerException e ) {
+ // occurs in the rare case that this is called before the full stack is initialized
+ logger.warn("Error getting user, application created activity will not be created", e);
+ }
+ if ( ( user != null ) && user.isAdminUser() ) {
+ postOrganizationActivity( organizationId, user, "create", appInfo, "Application", applicationName,
+ "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
+ + ")</a> created a new application named " + applicationName, null );
+ }
- em.refreshIndex();
+
- writeUserToken( smf.getManagementAppId(), appInfo, encryptionService
- .plainTextCredentials( generateOAuthSecretKey( AuthPrincipalType.APPLICATION ), null,
- smf.getManagementAppId() ) );
- addApplicationToOrganization( organizationId, applicationId, appInfo );
+
+ return new ApplicationInfo( applicationId, appInfo.getName() );
+ }
+
+
+ @Override
+ public void deleteApplication(UUID applicationId) throws Exception {
+ emf.deleteApplication( applicationId );
+ }
+
+
+ @Override
+ public ApplicationInfo restoreApplication(UUID applicationId) throws Exception {
+
+ ApplicationInfo app = getDeletedApplicationInfo( applicationId );
+ if ( app == null ) {
+ throw new EntityNotFoundException("Deleted application ID " + applicationId + " not found");
+ }
+
+ if ( emf.lookupApplication( app.getName() ) != null ) {
+ throw new ConflictException("Cannot restore application, one with that name already exists.");
+ }
+
+ // restore application_info entity
+
+ EntityManager em = emf.getEntityManager( emf.getManagementAppId() );
+ Entity appInfo = emf.restoreApplication(applicationId);
+
+ // restore token
+
+ writeUserToken( smf.getManagementAppId(), appInfo,
+ encryptionService.plainTextCredentials(
+ generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
+ null,
+ smf.getManagementAppId() ) );
+
+ String orgName = appInfo.getName().split("/")[0];
+ EntityRef alias = em.getAlias( Group.ENTITY_TYPE, orgName );
+ Entity orgEntity = em.get( alias );
+
+ addApplicationToOrganization( orgEntity.getUuid(), appInfo );
+
+ // create activity
UserInfo user = null;
- // if we call this method before the full stack is initialized
- // we'll get an exception
try {
user = SubjectUtils.getUser();
}
catch ( UnavailableSecurityManagerException e ) {
+ // occurs in the rare case that this is called before the full stack is initialized
+ logger.warn("Error getting user, application restored created activity will not be created", e);
}
if ( ( user != null ) && user.isAdminUser() ) {
- postOrganizationActivity( organizationId, user, "create", appInfo, "Application", applicationName,
- "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
- + ")</a> created a new application named " + applicationName, null );
+ postOrganizationActivity( orgEntity.getUuid(), user, "restore", appInfo, "Application", appInfo.getName(),
+ "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
+ + ")</a> restored an application named " + appInfo.getName(), null );
}
- em.refreshIndex();
+
return new ApplicationInfo( applicationId, appInfo.getName() );
}
[11/50] incubator-usergrid git commit: Merge branch 'two-dot-o' into
USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'two-dot-o' into USERGRID-448-appinfofix
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/7f84f4ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/7f84f4ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/7f84f4ad
Branch: refs/heads/two-dot-o-dev
Commit: 7f84f4ad42386564ba0bceafc1ffb5f946a9dada
Parents: 2664f6f 673c057
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 9 12:56:41 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 9 12:56:41 2015 -0400
----------------------------------------------------------------------
.../Client/IUsergridClient.cs | 2 +-
.../Usergrid.Notifications/Client/PushClient.cs | 24 +++
.../Usergrid.Notifications/MainPage.xaml | 1 +
.../Usergrid.Notifications/MainPage.xaml.cs | 29 ++-
.../main/dist/init_instance/init_rest_server.sh | 3 -
.../src/main/groovy/configure_usergrid.groovy | 6 +-
stack/awscluster/ugcluster-cf.json | 8 +
stack/core/pom.xml | 7 +-
.../corepersistence/CpEntityManager.java | 109 +++++++++-
.../corepersistence/CpEntityManagerFactory.java | 149 ++++++--------
.../corepersistence/CpRelationManager.java | 39 +++-
.../corepersistence/OrgApplicationCache.java | 67 +++++++
.../OrgApplicationCacheImpl.java | 181 +++++++++++++++++
.../corepersistence/results/EntityVerifier.java | 4 +-
.../results/FilteringLoader.java | 2 +-
.../cassandra/CassandraPersistenceUtils.java | 2 +-
.../main/resources/usergrid-core-context.xml | 12 +-
.../cassandra/EntityManagerFactoryImplIT.java | 1 +
.../core/metrics/MetricsFactoryImpl.java | 3 +-
.../persistence/index/EntityIndexFactory.java | 4 +-
.../persistence/index/IndexBufferProducer.java | 10 +-
.../usergrid/persistence/index/IndexFig.java | 12 +-
.../persistence/index/guice/IndexModule.java | 7 +-
.../index/impl/EsEntityIndexBatchImpl.java | 15 +-
.../index/impl/EsEntityIndexFactoryImpl.java | 79 ++++++++
.../index/impl/EsEntityIndexImpl.java | 198 +++++++++++++++----
.../index/impl/EsIndexBufferConsumerImpl.java | 39 +++-
.../index/impl/EsIndexBufferProducerImpl.java | 30 ++-
.../persistence/index/impl/IndexingUtils.java | 5 +-
.../persistence/index/impl/EntityIndexTest.java | 2 +-
.../datagenerators/EntityDataGenerator.scala | 25 +++
.../datagenerators/FeederGenerator.scala | 18 +-
.../usergrid/scenarios/EntityScenarios.scala | 8 +-
.../org/apache/usergrid/settings/Settings.scala | 4 +-
.../simulations/PutCustomEntitySimulation.scala | 75 +++++++
stack/pom.xml | 24 ++-
stack/rest/pom.xml | 2 +-
.../org/apache/usergrid/rest/IndexResource.java | 19 ++
stack/services/pom.xml | 7 +-
.../services/notifications/wns/WNSAdapter.java | 39 ++++
.../resources/usergrid-services-context.xml | 8 +-
.../usergrid/management/OrganizationIT.java | 2 +-
42 files changed, 1056 insertions(+), 225 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f84f4ad/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e1a7c60,12504ed..783261a
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -18,23 -19,27 +19,12 @@@ import com.google.common.base.Optional
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
-import com.google.inject.Guice;
import com.google.inject.Injector;
import com.yammer.metrics.annotation.Metered;
--import static java.lang.String.CASE_INSENSITIVE_ORDER;
--
--import java.util.*;
--import java.util.concurrent.atomic.AtomicBoolean;
--
import org.apache.commons.lang.StringUtils;
--
import org.apache.usergrid.corepersistence.rx.AllEntitiesInSystemObservable;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.AbstractEntity;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityFactory;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
-import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
+import org.apache.usergrid.persistence.*;
-
- import static org.apache.usergrid.persistence.Schema.PROPERTY_PATH;
- import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
- import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
- import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.cassandra.CounterUtils;
import org.apache.usergrid.persistence.cassandra.Setup;
@@@ -50,7 -55,7 +41,6 @@@ import org.apache.usergrid.persistence.
import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
--import org.apache.usergrid.persistence.exceptions.OrganizationAlreadyExistsException;
import org.apache.usergrid.persistence.graph.Edge;
import org.apache.usergrid.persistence.graph.GraphManager;
import org.apache.usergrid.persistence.graph.SearchByEdgeType;
@@@ -59,8 -64,8 +49,8 @@@ import org.apache.usergrid.persistence.
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
--import org.apache.usergrid.utils.UUIDUtils;
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;
@@@ -68,6 -73,6 +58,12 @@@ import org.springframework.context.Appl
import org.springframework.context.ApplicationContextAware;
import rx.Observable;
++import java.util.*;
++import java.util.concurrent.atomic.AtomicBoolean;
++
++import static java.lang.String.CASE_INSENSITIVE_ORDER;
++import static org.apache.usergrid.persistence.Schema.*;
++
/**
* Implement good-old Usergrid EntityManagerFactory with the new-fangled Core Persistence API.
@@@ -84,11 -89,7 +80,11 @@@ public class CpEntityManagerFactory imp
/** Have we already initialized the index for the management app? */
private AtomicBoolean indexInitialized = new AtomicBoolean( );
+ /** Keep track of applications that already have indexes to avoid redundant re-creation. */
+ private static final Set<UUID> applicationIndexesCreated = new HashSet<UUID>();
+
+
- // cache of already instantiated oldAppInfo managers
+ // cache of already instantiated entity managers
private LoadingCache<UUID, EntityManager> entityManagers
= CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<UUID, EntityManager>() {
public EntityManager load(UUID appId) { // no checked exception
@@@ -113,12 -116,9 +111,14 @@@
this.injector = injector;
this.managerCache = injector.getInstance( ManagerCache.class );
this.dataMigrationManager = injector.getInstance( DataMigrationManager.class );
+ this.metricsFactory = injector.getInstance( MetricsFactory.class );
+ // can be removed after everybody moves to Usergrid 2.0, default is true
+ Properties configProps = cassandraService.getProperties();
+ if ( configProps.getProperty("usergrid.twodoto.appinfo.migration", "true").equals("true")) {
+ migrateOldAppInfos();
+ }
+ this.orgApplicationCache = new OrgApplicationCacheImpl( this );
}
@@@ -222,8 -220,13 +220,11 @@@
public UUID initializeApplication( String organizationName, UUID applicationId, String name,
Map<String, Object> properties ) throws Exception {
+ EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
-
- //Ensure our management system exists before creating our application
++ // Ensure our management system exists before creating our application
+ init();
+
- EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
-
final String appName = buildAppName( organizationName, name );
// check for pre-existing application
@@@ -232,13 -234,47 +233,36 @@@
throw new ApplicationAlreadyExistsException( appName );
}
- // create application info entity in the management app
-
getSetup().setupApplicationKeyspace( applicationId, appName );
+
-
+ final Optional<UUID> cachedValue = orgApplicationCache.getOrganizationId( organizationName );
+
-
- UUID orgUuid;
-
+ if ( !cachedValue.isPresent() ) {
+
+
+ // create new org because the specified one does not exist
+ final String orgName = organizationName;
+
+
+
+ try {
+ final Entity orgInfo = em.create( "organization", new HashMap<String, Object>() {{
+ put( PROPERTY_NAME, orgName );
+ }} );
- orgUuid = orgInfo.getUuid();
+ //evit so it's re-loaded later
+ orgApplicationCache.evictOrgId( name );
+ }
+ catch ( DuplicateUniquePropertyExistsException e ) {
+ //swallow, if it exists, just get it
+ orgApplicationCache.evictOrgId( organizationName );
- orgUuid = orgApplicationCache.getOrganizationId( organizationName ).get();
+ }
-
- } else{
- orgUuid = cachedValue.get();
+ }
+
+ // create appinfo entry in the system app
final UUID appId = applicationId;
- final UUID orgId = orgUuid;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
- put( "applicationUuid", appId );
- put( "organizationUuid", orgId );
+ put( PROPERTY_UUID, appId );
}};
try {
@@@ -255,7 -291,9 +279,8 @@@
}
properties.put( PROPERTY_NAME, appName );
EntityManager appEm = getEntityManager( applicationId );
-
appEm.create( applicationId, TYPE_APPLICATION, properties );
+ appEm.createIndex();
appEm.resetRoles();
appEm.refreshIndex();
@@@ -360,68 -383,10 +389,8 @@@
}
- @Override
- public UUID lookupApplication( final String name ) throws Exception {
- init();
-
- // attempt to look up APPLICATION_INFO by name
-
- UUID applicationId = null;
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
- final EntityRef alias = em.getAlias( CpNamingUtils.APPLICATION_INFO, name );
- if ( alias != null ) {
- Entity entity = em.get(alias);
- applicationId = (UUID) entity.getProperty("uuid");
- }
-
- // below is not necessary if migrateOldAppInfos() has already run
-
- // if ( applicationId == null ) {
- //
- // // maybe there is a record in the old and deprecated "appinfos" collection
- //
- // UUID organizationId = null;
- //
- // Query q = Query.fromQL( PROPERTY_NAME + " = '" + name + "'");
- // Results results = em.searchCollection( em.getApplicationRef(), "appinfos" , q);
- // if ( !results.isEmpty() ) {
- // Entity entity = results.iterator().next();
- // Object uuidObject = entity.getProperty("applicationUuid");
- // if (uuidObject instanceof UUID) {
- // applicationId = (UUID)uuidObject;
- // } else {
- // applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
- // }
- // uuidObject = entity.getProperty("organizationUuid");
- // if (uuidObject instanceof UUID) {
- // organizationId = (UUID)uuidObject;
- // } else {
- // organizationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
- // }
- // }
- //
- // if ( applicationId != null ) {
- //
- // // copy application information into new APPLICATION_INFO collection
- //
- // final UUID appId = applicationId;
- // Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- // put( PROPERTY_NAME, name );
- // put( PROPERTY_UUID, appId );
- // }};
- //
- // final Entity appInfo;
- // try {
- // appInfo = em.create( appId, CpNamingUtils.APPLICATION_INFO, appInfoMap );
- // } catch (DuplicateUniquePropertyExistsException e) {
- // throw new ApplicationAlreadyExistsException(name);
- // }
- // em.createConnection( new SimpleEntityRef( Group.ENTITY_TYPE, organizationId ), "owns", appInfo );
- // em.refreshIndex();
- // }
- // }
--
- return applicationId;
- @Override
+ public UUID lookupApplication( String orgAppName ) throws Exception {
+ return orgApplicationCache.getApplicationId( orgAppName ).orNull();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f84f4ad/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
index 0000000,4baf598..23410d8
mode 000000,100644..100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
@@@ -1,0 -1,181 +1,181 @@@
+ /*
+ * 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;
+
+
+ import java.util.UUID;
+ import java.util.concurrent.ExecutionException;
+
+ import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+ import org.apache.usergrid.persistence.Entity;
+ import org.apache.usergrid.persistence.EntityManager;
+ import org.apache.usergrid.persistence.EntityManagerFactory;
+ import org.apache.usergrid.persistence.EntityRef;
+ import org.apache.usergrid.persistence.Results;
+ import org.apache.usergrid.persistence.index.query.Query;
+ import org.apache.usergrid.utils.UUIDUtils;
+
+ import com.google.common.base.Optional;
+ import com.google.common.cache.CacheBuilder;
+ import com.google.common.cache.CacheLoader;
+ import com.google.common.cache.LoadingCache;
+
+ import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
+
+
+ /**
+ * 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
+ */
+ public class OrgApplicationCacheImpl implements OrgApplicationCache {
+
+
+ /**
+ * Cache the pointer to our root entity manager for reference
+ */
+ private final EntityManager rootEm;
+
+ private final LoadingCache<String, Optional<UUID>> orgCache =
+ CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, Optional<UUID>>() {
+ @Override
+ public Optional<UUID> load( final String key ) throws Exception {
+ return fetchOrganizationId( key );
+ }
+ } );
+
+
+ private final LoadingCache<String, Optional<UUID>> appCache =
+ CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, Optional<UUID>>() {
+ @Override
+ public Optional<UUID> load( final String key ) throws Exception {
+ return fetchApplicationId( key );
+ }
+ } );
+
+
+ public OrgApplicationCacheImpl( final EntityManagerFactory emf ) {
- this.rootEm = emf.getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
++ this.rootEm = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ }
+
+
+ @Override
+ public Optional<UUID> getOrganizationId( final String orgName ) {
+ try {
+ return orgCache.get( orgName );
+ }
+ catch ( ExecutionException e ) {
+ throw new RuntimeException( "Unable to load org cache", e );
+ }
+ }
+
+
+ /**
+ * Fetches the organization
+ */
+ private Optional<UUID> fetchOrganizationId( final String orgName ) {
+
+ try {
+ final EntityRef alias = rootEm.getAlias( "organizations", orgName );
+
+ if ( alias == null ) {
+ return Optional.absent();
+ }
+
+ final Entity entity;
+
+ entity = rootEm.get( alias );
+
+
+ if ( entity == null ) {
+ return Optional.absent();
+ }
+
+ return Optional.of( entity.getUuid() );
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to load organization Id for caching", e );
+ }
+ }
+
+
+ @Override
+ public void evictOrgId( final String orgName ) {
+ orgCache.invalidate( orgName );
+ }
+
+
+ @Override
+ public Optional<UUID> getApplicationId( final String applicationName ) {
+ try {
+ return appCache.get( applicationName );
+ }
+ catch ( ExecutionException e ) {
+ throw new RuntimeException( "Unable to load org cache", e );
+ }
+ }
+
+
+ /**
+ * Fetch our application id
+ */
+ private Optional<UUID> fetchApplicationId( final String applicationName ) {
+
+ try {
+ Query q = Query.fromQL( PROPERTY_NAME + " = '" + applicationName + "'" );
+
+
+ Results results = rootEm.searchCollection( rootEm.getApplicationRef(), "appinfos", q );
+
+ if ( results.isEmpty() ) {
+ return Optional.absent();
+ }
+
+ Entity entity = results.iterator().next();
+ Object uuidObject = entity.getProperty( "applicationUuid" );
+
+ final UUID value;
+ if ( uuidObject instanceof UUID ) {
+ value = ( UUID ) uuidObject;
+ }
+ else {
+ value = UUIDUtils.tryExtractUUID( entity.getProperty( "applicationUuid" ).toString() );
+ }
+
+
+ return Optional.of( value );
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to retreive application id", e );
+ }
+ }
+
+
+ @Override
+ public void evictAppId( final String applicationName ) {
+ appCache.invalidate( applicationName );
+ }
+
+
+ @Override
+ public void evictAll() {
+ orgCache.invalidateAll();
+ appCache.invalidateAll();
+ }
+ }
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f84f4ad/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7f84f4ad/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
[41/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/44deb61c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/44deb61c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/44deb61c
Branch: refs/heads/two-dot-o-dev
Commit: 44deb61ce4789ec5b0dcee9bf8250788454424b0
Parents: e3d9cc9 c0384d5
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 23 14:34:41 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 23 14:34:41 2015 -0400
----------------------------------------------------------------------
.../batch/service/SchedulerServiceImpl.java | 17 +-
.../corepersistence/CpEntityManager.java | 41 +-
.../corepersistence/CpEntityManagerFactory.java | 70 +--
.../corepersistence/CpManagerCache.java | 6 +-
.../corepersistence/CpRelationManager.java | 19 +-
.../usergrid/corepersistence/CpSetup.java | 6 +-
.../usergrid/corepersistence/ManagerCache.java | 3 +-
.../events/EntityDeletedHandler.java | 3 +-
.../events/EntityVersionDeletedHandler.java | 4 +-
.../results/FilteringLoader.java | 3 +-
.../usergrid/persistence/EntityManager.java | 19 +-
.../cassandra/EntityManagerFactoryImpl.java | 3 +-
.../cassandra/EntityManagerImpl.java | 20 +-
.../org/apache/usergrid/CoreApplication.java | 24 +-
.../java/org/apache/usergrid/CoreITSetup.java | 6 +
.../org/apache/usergrid/CoreITSetupImpl.java | 45 +-
.../org/apache/usergrid/TestEntityIndex.java | 27 ++
.../corepersistence/StaleIndexCleanupTest.java | 87 ++--
.../usergrid/persistence/CollectionIT.java | 80 ++--
.../usergrid/persistence/CountingMutatorIT.java | 4 +-
.../persistence/EntityConnectionsIT.java | 14 +-
.../usergrid/persistence/EntityManagerIT.java | 16 +-
.../org/apache/usergrid/persistence/GeoIT.java | 26 +-
.../persistence/GeoQueryBooleanTest.java | 4 +-
.../apache/usergrid/persistence/IndexIT.java | 14 +-
.../usergrid/persistence/PathQueryIT.java | 6 +-
.../PerformanceEntityRebuildIndexTest.java | 27 +-
.../usergrid/persistence/PermissionsIT.java | 4 +-
.../cassandra/EntityManagerFactoryImplIT.java | 4 +-
.../persistence/query/CollectionIoHelper.java | 2 +-
.../persistence/query/ConnectionHelper.java | 2 +-
.../query/IntersectionTransitivePagingIT.java | 2 +-
.../query/IntersectionUnionPagingIT.java | 2 +-
.../persistence/query/IteratingQueryIT.java | 34 +-
.../resources/usergrid-custom-test.properties | 1 +
stack/corepersistence/queryindex/pom.xml | 57 +--
.../persistence/index/AliasedEntityIndex.java | 7 +-
.../index/ApplicationEntityIndex.java | 50 ++
.../usergrid/persistence/index/EntityIndex.java | 46 +-
.../persistence/index/EntityIndexBatch.java | 5 +
.../persistence/index/EntityIndexFactory.java | 2 +-
.../persistence/index/IndexIdentifier.java | 26 +-
.../usergrid/persistence/index/SearchType.java | 49 ++
.../usergrid/persistence/index/SearchTypes.java | 14 +-
.../persistence/index/guice/IndexModule.java | 5 +-
.../impl/EsApplicationEntityIndexImpl.java | 371 ++++++++++++++
.../index/impl/EsEntityIndexBatchImpl.java | 80 ++--
.../index/impl/EsEntityIndexFactoryImpl.java | 27 +-
.../index/impl/EsEntityIndexImpl.java | 478 ++++---------------
.../index/impl/EsIndexBufferConsumerImpl.java | 68 +--
.../persistence/index/impl/EsQueryVistor.java | 88 ++--
.../persistence/index/impl/IndexingUtils.java | 140 +++---
.../usergrid/persistence/index/query/Query.java | 6 +-
.../persistence/index/guice/IndexTestFig.java | 7 +-
.../index/impl/CorePerformanceIT.java | 0
.../impl/EntityConnectionIndexImplTest.java | 0
.../persistence/index/impl/EntityIndexTest.java | 181 +++----
.../index/impl/IndexLoadTestsIT.java | 328 +++++++++++--
.../usergrid/rest/AbstractContextResource.java | 102 ++--
.../org/apache/usergrid/rest/IndexResource.java | 2 +-
.../rest/test/RefreshIndexResource.java | 17 +-
.../resources/usergrid-custom-test.properties | 2 +
.../cassandra/ManagementServiceImpl.java | 1 -
.../org/apache/usergrid/ServiceApplication.java | 18 +-
.../apache/usergrid/management/EmailFlowIT.java | 6 +-
.../usergrid/management/OrganizationIT.java | 10 +-
.../org/apache/usergrid/management/RoleIT.java | 4 +-
.../cassandra/ManagementServiceIT.java | 22 +-
.../management/export/ExportServiceIT.java | 12 +-
.../management/importer/ImportCollectionIT.java | 15 +-
.../usergrid/services/ConnectionsServiceIT.java | 10 +-
.../usergrid/services/GroupServiceIT.java | 6 +-
.../usergrid/services/RolesServiceIT.java | 2 +-
.../usergrid/services/UsersServiceIT.java | 2 +-
.../AbstractServiceNotificationIT.java | 2 +-
.../apns/NotificationsServiceIT.java | 40 +-
.../gcm/NotificationsServiceIT.java | 4 +-
.../resources/usergrid-custom-test.properties | 2 +
78 files changed, 1706 insertions(+), 1253 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 782b273,1388462..2d155a8
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -15,16 -15,33 +15,33 @@@
*/
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.Injector;
+import com.google.inject.Key;
+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.index.ApplicationEntityIndex;
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+ import org.springframework.beans.BeansException;
+ import org.springframework.context.ApplicationContext;
+ import org.springframework.context.ApplicationContextAware;
+
import org.apache.commons.lang.StringUtils;
-
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.AbstractEntity;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityFactory;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
+import org.apache.usergrid.exception.ConflictException;
+import org.apache.usergrid.persistence.*;
import org.apache.usergrid.persistence.cassandra.CassandraService;
import org.apache.usergrid.persistence.cassandra.CounterUtils;
import org.apache.usergrid.persistence.cassandra.Setup;
@@@ -103,9 -128,11 +121,10 @@@ public class CpEntityManagerFactory imp
this.cassandraService = cassandraService;
this.counterUtils = counterUtils;
this.injector = injector;
+ this.entityIndex = injector.getInstance(EntityIndex.class);
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
-
- this.orgApplicationCache = new OrgApplicationCacheImpl( this );
+ this.applicationIdCache = new ApplicationIdCacheImpl( this );
}
@@@ -122,19 -149,21 +141,20 @@@
private void init() {
- EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
try {
- if (em.getApplication() == null) {
- logger.info("Creating system application");
- Map sysAppProps = new HashMap<String, Object>();
- sysAppProps.put(PROPERTY_NAME, "systemapp");
- em.create(CpNamingUtils.SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps);
+ if ( em.getApplication() == null ) {
+ logger.info("Creating management application");
+ Map mgmtAppProps = new HashMap<String, Object>();
+ mgmtAppProps.put(PROPERTY_NAME, "systemapp");
+ em.create( getManagementAppId(), TYPE_APPLICATION, mgmtAppProps);
em.getApplication();
- em.createIndex();
- em.refreshIndex();
}
+ entityIndex.initializeIndex();
+ entityIndex.refresh();
+
-
} catch (Exception ex) {
throw new RuntimeException("Fatal error creating system application", ex);
}
@@@ -161,9 -190,9 +181,9 @@@
return entityManagers.get( applicationId );
}
catch ( Exception ex ) {
- logger.error("Error getting entity manager", ex);
+ logger.error("Error getting oldAppInfo manager", ex);
}
-- return _getEntityManager( applicationId );
++ return _getEntityManager(applicationId);
}
@@@ -230,40 -260,74 +250,44 @@@
throw new ApplicationAlreadyExistsException( appName );
}
- getSetup().setupApplicationKeyspace( applicationId, appName );
-
-
- final Optional<UUID> cachedValue = orgApplicationCache.getOrganizationId( organizationName );
-
-
- UUID orgUuid;
-
- if ( !cachedValue.isPresent() ) {
-
-
- // create new org because the specified one does not exist
- final String orgName = organizationName;
-
-
-
- try {
- final Entity orgInfo = em.create( "organization", new HashMap<String, Object>() {{
- put( PROPERTY_NAME, orgName );
- }} );
- orgUuid = orgInfo.getUuid();
- //evit so it's re-loaded later
- orgApplicationCache.evictOrgId( name );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- //swallow, if it exists, just get it
- orgApplicationCache.evictOrgId( organizationName );
- orgUuid = orgApplicationCache.getOrganizationId( organizationName ).get();
- }
-
- } else{
- orgUuid = cachedValue.get();
- }
-
- // create appinfo entry in the system app
- final UUID appId = applicationId;
- final UUID orgId = orgUuid;
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put( PROPERTY_NAME, appName );
- put( "applicationUuid", appId );
- put( "organizationUuid", orgId );
- }};
+ // create application info entity
- getSetup().setupApplicationKeyspace( applicationId, appName );
+ try {
- em.create( "appinfo", appInfoMap );
++ em.create( CpNamingUtils.APPLICATION_INFO, properties );
+ }
+ catch ( DuplicateUniquePropertyExistsException e ) {
+ throw new ApplicationAlreadyExistsException( appName );
+ }
+ entityIndex.refresh();
- // create application entity
if ( properties == null ) {
- properties = new TreeMap<String, Object>( CASE_INSENSITIVE_ORDER );
+ properties = new TreeMap<>( CASE_INSENSITIVE_ORDER );
}
properties.put( PROPERTY_NAME, appName );
- EntityManager appEm = getEntityManager( applicationId );
- appEm.create( applicationId, TYPE_APPLICATION, properties );
- appEm.createIndex();
+ EntityManager appEm = getEntityManager( applicationId);
-
+ appEm.create(applicationId, TYPE_APPLICATION, properties);
appEm.resetRoles();
- appEm.refreshIndex();
+ entityIndex.refresh();
- logger.info("Initialized application {}", appName );
+ // create application info entity in the management app
- //evict app Id from cache
- orgApplicationCache.evictAppId( appName );
+ Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
+ put( PROPERTY_NAME, appName );
+ put( PROPERTY_APPLICATION_ID, applicationId );
+ }};
+
+ Entity appInfo;
+ try {
+ appInfo = em.create(CpNamingUtils.APPLICATION_INFO, appInfoMap);
+ } catch (DuplicateUniquePropertyExistsException e) {
+ throw new ApplicationAlreadyExistsException(appName);
+ }
- em.refreshIndex();
+
+ // evict app Id from cache
+ applicationIdCache.evictAppId(appName);
- return applicationId;
+ logger.info("Initialized application {}", appName);
+ return appInfo;
}
@@@ -281,88 -344,48 +305,87 @@@
@Override
public void deleteApplication(UUID applicationId) throws Exception {
- //throw new UnsupportedOperationException("Delete application not supported");
+ // find application_info for application to delete
+
+ EntityManager em = getEntityManager(getManagementAppId());
- // remove old appinfo Entity, which is in the System App's appinfos collection
- EntityManager em = getEntityManager(CpNamingUtils.SYSTEM_APP_ID);
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
+ final Results results = em.searchCollection(em.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS,
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+ Entity appInfoToDelete = results.getEntity();
- Entity appToDelete = results.getEntity();
- if(appToDelete != null) {
- // create new Entity in deleted_appinfos collection, with same UUID and properties as deleted appinfo
- em.create("deleted_appinfo", appToDelete.getProperties());
- em.delete(appToDelete);
+ // ensure that there is not already a deleted app with the same name
+ final EntityRef alias = em.getAlias(
+ CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName());
+ if ( alias != null ) {
+ throw new ConflictException("Cannot delete app with same name as already deleted app");
}
- entityIndex.refresh();
+
+ // make a copy of the app to delete application_info entity
+ // and put it in a deleted_application_info collection
+
+ Entity deletedApp = em.create(
+ CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getProperties());
+
+ // copy its connections too
+
+ final Set<String> connectionTypes = em.getConnectionTypes(appInfoToDelete);
+ for ( String connType : connectionTypes ) {
+ final Results connResults =
+ em.getConnectedEntities(appInfoToDelete, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : connResults.getEntities() ) {
+ em.createConnection( deletedApp, connType, entity );
+ }
+ }
+
+ // delete the app from the application_info collection and delete its index
+
+ em.delete(appInfoToDelete);
- em.refreshIndex();
+
- final EntityIndex entityIndex = managerCache.getEntityIndex(
++ final ApplicationEntityIndex entityIndex = managerCache.getEntityIndex(
+ new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
+
+ applicationIdCache.evictAppId(appInfoToDelete.getName());
-
- entityIndex.deleteIndex();
}
@Override
- public void restoreApplication(UUID applicationId) throws Exception {
+ public Entity restoreApplication(UUID applicationId) throws Exception {
- // remove old delete_appinfos Entity
- EntityManager em = getEntityManager(CpNamingUtils.SYSTEM_APP_ID);
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection(em.getApplicationRef(), "deleted_appinfos", q);
- Entity appToRestore = results.getEntity();
+ // get the deleted_application_info for the deleted app
- if ( appToRestore == null ) {
+ EntityManager em = getEntityManager(getManagementAppId());
+
- final Results results = em.searchCollection(em.getApplicationRef(), CpNamingUtils.DELETED_APPLICATION_INFOS,
++ final Results results = em.searchCollection(
++ em.getApplicationRef(), CpNamingUtils.DELETED_APPLICATION_INFOS,
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+ Entity deletedAppInfo = results.getEntity();
+
+ if ( deletedAppInfo == null ) {
throw new EntityNotFoundException("Cannot restore. Deleted Application not found: " + applicationId );
}
- em.delete( appToRestore );
+ // create application_info for restored app
- // restore entity in appinfo collection
- Map<String, Object> appProps = appToRestore.getProperties();
- appProps.remove("uuid");
- appProps.put("type", "appinfo");
- Entity restoredApp = em.create("appinfo", appToRestore.getProperties());
+ Entity restoredAppInfo = em.create(
+ deletedAppInfo.getUuid(), CpNamingUtils.APPLICATION_INFO, deletedAppInfo.getProperties());
+ // copy connections from deleted app entity
+
+ final Set<String> connectionTypes = em.getConnectionTypes(deletedAppInfo);
+ for ( String connType : connectionTypes ) {
+ final Results connResults =
+ em.getConnectedEntities(deletedAppInfo, connType, null, Query.Level.ALL_PROPERTIES);
+ for ( Entity entity : connResults.getEntities() ) {
+ em.createConnection( restoredAppInfo, connType, entity );
+ }
+ }
+
+ // delete the deleted app entity rebuild the app index
+
+ em.delete(deletedAppInfo);
+ entityIndex.refresh();
- // rebuild the apps index
this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@Override
public void onProgress(EntityRef entity) {
@@@ -633,14 -664,13 +656,11 @@@
// refresh special indexes without calling EntityManager refresh because stack overflow
maybeCreateIndexes();
- // system app
+
- for ( EntityIndex index : getManagementIndexes() ) {
- index.refresh();
- }
+ entityIndex.refresh();
}
--
private void maybeCreateIndexes() {
- // system app
if ( indexInitialized.getAndSet( true ) ) {
return;
}
@@@ -651,11 -679,18 +669,11 @@@
}
- private List<EntityIndex> getManagementIndexes() {
+ private List<ApplicationEntityIndex> getManagementIndexes() {
- return Arrays.asList( managerCache.getEntityIndex(
- new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ) ) ),
-
- // management app
- managerCache
- .getEntityIndex( new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) ),
-
- // default app TODO: do we need this in two-dot-o
- managerCache
- .getEntityIndex( new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) ) );
+ return Arrays.asList(
+ managerCache.getEntityIndex( // management app
+ new ApplicationScopeImpl(new SimpleId(getManagementAppId(), "application"))));
}
@@@ -723,13 -750,12 +741,12 @@@
EntityManager em = getEntityManager( appId );
//explicitly invoke create index, we don't know if it exists or not in ES during a rebuild.
- em.createIndex();
Application app = em.getApplication();
-- em.reindexCollection( po, collectionName, reverse );
++ em.reindexCollection(po, collectionName, reverse);
logger.info("\n\nRebuilt index for application {} id {} collection {}\n",
- new Object[] { app.getName(), appId, collectionName } );
+ new Object[]{app.getName(), appId, collectionName});
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index c5c792b,a9e6cee..4ab7874
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@@ -95,12 -99,24 +99,12 @@@ public class CpSetup implements Setup
setupStaticKeyspace();
//force the EMF creation of indexes before creating the default applications
- emf.refreshIndex();
+ entityIndex.initializeIndex();
- injector.getInstance( DataMigrationManager.class ).migrate();
-
- logger.info( "Setting up default applications" );
-
- try {
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getDefaultAppId(), DEFAULT_APPLICATION, null );
- }
- catch ( ApplicationAlreadyExistsException ex ) {
- logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, DEFAULT_APPLICATION );
- }
- catch ( OrganizationAlreadyExistsException oaee ) {
- logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
- }
+ logger.info( "Setting up management app" );
try {
- emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
+ emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
}
catch ( ApplicationAlreadyExistsException ex ) {
logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
index cc70a3c,0e1e62a..e8aae01
--- 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
@@@ -405,10 -403,9 +405,9 @@@ public class EntityManagerFactoryImpl i
return MANAGEMENT_APPLICATION_ID;
}
-
@Override
- public UUID getDefaultAppId() {
- return DEFAULT_APPLICATION_ID;
+ public void refreshIndex() {
- // no op
++ throw new UnsupportedOperationException("Not supported.");
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/test/java/org/apache/usergrid/CoreITSetup.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --cc stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
index efa6a47,3cc0815..26254b1
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@@ -17,32 -17,30 +17,29 @@@
package org.apache.usergrid;
--import java.util.UUID;
--
- import org.apache.usergrid.persistence.Entity;
- import org.apache.usergrid.utils.UUIDUtils;
-import org.apache.usergrid.persistence.index.EntityIndex;
--import org.junit.runner.Description;
--import org.junit.runners.model.Statement;
--import org.slf4j.Logger;
--import org.slf4j.LoggerFactory;
--
++import com.google.inject.Injector;
import org.apache.usergrid.cassandra.SpringResource;
import org.apache.usergrid.mq.QueueManagerFactory;
++import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManagerFactory;
import org.apache.usergrid.persistence.IndexBucketLocator;
import org.apache.usergrid.persistence.cassandra.CassandraService;
--import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
--import org.apache.usergrid.persistence.core.migration.schema.MigrationException;
import org.apache.usergrid.setup.ConcurrentProcessSingleton;
import org.apache.usergrid.utils.JsonUtils;
++import org.apache.usergrid.utils.UUIDUtils;
++import org.junit.runner.Description;
++import org.junit.runners.model.Statement;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
--import com.google.inject.Injector;
++import java.util.UUID;
+
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
- public class CoreITSetupImpl implements CoreITSetup {
+ public class CoreITSetupImpl implements CoreITSetup, TestEntityIndex {
private static final Logger LOG = LoggerFactory.getLogger( CoreITSetupImpl.class );
+ private final Injector injector;
protected EntityManagerFactory emf;
protected QueueManagerFactory qmf;
@@@ -145,4 -149,24 +144,24 @@@
LOG.info( name + ":\n" + JsonUtils.mapToFormattedJsonString( obj ) );
}
}
+
+ @Override
+ public Injector getInjector() {
+ return injector;
+ }
+
+ @Override
+ public TestEntityIndex getEntityIndex(){
+ return this;
+ }
+
+ @Override
+ public void refresh(){
- try{
++ try {
+ Thread.sleep(50);
- }catch (InterruptedException ie){
++ } catch (InterruptedException ie){
+
+ }
+ getEntityIndex().refresh();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --cc stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index 8363a24,4b284df..9336df8
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@@ -309,13 -311,16 +310,17 @@@ public class PerformanceEntityRebuildIn
// ----------------- delete the system and application indexes
- logger.debug("Deleting app index and system app index");
+ logger.debug("Deleting app index");
deleteIndex( em.getApplicationId() );
-//
-// // deleting sytem app index will interfere with other concurrently running tests
+
++ // ----------------- test that we can read them, should fail
++
++ // deleting sytem app index will interfere with other concurrently running tests
+ //deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
-//
-//
-// // ----------------- test that we can read them, should fail
-//
+
+ // ----------------- test that we can read them, should fail
+
logger.debug("Reading data, should fail this time ");
try {
readData( em, "testTypes", entityCount, 3 );
@@@ -377,12 -383,13 +383,13 @@@
Injector injector = SpringResource.getInstance().getBean( Injector.class );
EntityIndexFactory eif = injector.getInstance( EntityIndexFactory.class );
- Id appId = new SimpleId( appUuid, "application");
+ Id appId = new SimpleId( appUuid, Schema.TYPE_APPLICATION );
ApplicationScope scope = new ApplicationScopeImpl( appId );
- EntityIndex ei = eif.createEntityIndex(scope);
- EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;
+ ApplicationEntityIndex ei = eif.createApplicationEntityIndex(scope);
+
+ ei.deleteApplication().toBlocking().lastOrDefault(null);
+ app.refreshIndex();
- eeii.deleteIndex();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 5de6f72,4290f23..771a11a
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@@ -18,83 -18,53 +18,44 @@@
package org.apache.usergrid.persistence.index.impl;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.atomic.AtomicBoolean;
-
+ import com.codahale.metrics.Meter;
+ import com.codahale.metrics.Timer;
+ import com.google.common.collect.ImmutableMap;
+ import com.google.inject.Inject;
+ import com.google.inject.Singleton;
+ import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang3.ArrayUtils;
+ import org.apache.usergrid.persistence.core.future.BetterFuture;
+ import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
+ import org.apache.usergrid.persistence.core.util.Health;
+ import org.apache.usergrid.persistence.index.*;
+ import org.apache.usergrid.persistence.index.exceptions.IndexException;
-
+ import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
import org.elasticsearch.action.ActionFuture;
-
+ import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
--import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest;
--import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse;
-import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
-import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
-import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder;
--import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
- import org.elasticsearch.action.search.SearchRequestBuilder;
- import org.elasticsearch.action.search.SearchResponse;
- import org.elasticsearch.action.search.SearchScrollRequestBuilder;
-
+ import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
- import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.*;
+import org.elasticsearch.index.query.MatchAllQueryBuilder;
- import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexMissingException;
- import org.elasticsearch.search.SearchHit;
- import org.elasticsearch.search.SearchHits;
- import org.elasticsearch.search.sort.FieldSortBuilder;
- import org.elasticsearch.search.sort.SortBuilders;
- import org.elasticsearch.search.sort.SortOrder;
-
-import org.elasticsearch.indices.InvalidAliasNameException;
-import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
- import org.apache.commons.lang.StringUtils;
- import org.apache.commons.lang3.ArrayUtils;
-
- import org.apache.usergrid.persistence.core.future.BetterFuture;
- import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
- import org.apache.usergrid.persistence.core.scope.ApplicationScope;
- import org.apache.usergrid.persistence.core.util.Health;
- import org.apache.usergrid.persistence.core.util.ValidationUtils;
- import org.apache.usergrid.persistence.index.AliasedEntityIndex;
- import org.apache.usergrid.persistence.index.EntityIndexBatch;
- import org.apache.usergrid.persistence.index.IndexBufferProducer;
- import org.apache.usergrid.persistence.index.IndexFig;
- import org.apache.usergrid.persistence.index.IndexIdentifier;
- import org.apache.usergrid.persistence.index.IndexOperationMessage;
- import org.apache.usergrid.persistence.index.IndexScope;
- import org.apache.usergrid.persistence.index.SearchTypes;
- import org.apache.usergrid.persistence.index.exceptions.IndexException;
- import org.apache.usergrid.persistence.index.query.CandidateResult;
- import org.apache.usergrid.persistence.index.query.CandidateResults;
- import org.apache.usergrid.persistence.index.query.Query;
- import org.apache.usergrid.persistence.map.MapManager;
- import org.apache.usergrid.persistence.map.MapManagerFactory;
- import org.apache.usergrid.persistence.map.MapScope;
- import org.apache.usergrid.persistence.map.impl.MapScopeImpl;
- 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 com.codahale.metrics.Timer;
- import com.google.common.base.Preconditions;
- import com.google.common.collect.ImmutableMap;
- import com.google.inject.Inject;
- import com.google.inject.assistedinject.Assisted;
-
- import static org.apache.usergrid.persistence.index.impl.IndexingUtils.BOOLEAN_PREFIX;
- import static org.apache.usergrid.persistence.index.impl.IndexingUtils.NUMBER_PREFIX;
- import static org.apache.usergrid.persistence.index.impl.IndexingUtils.SPLITTER;
- import static org.apache.usergrid.persistence.index.impl.IndexingUtils.STRING_PREFIX;
+ import java.io.IOException;
-import java.util.*;
++import java.util.Arrays;
++import java.util.HashSet;
++import java.util.List;
++import java.util.Set;
/**
@@@ -600,72 -370,16 +361,35 @@@ public class EsEntityIndexImpl implemen
}
};
- doInRetry( retryOperation );
- }
-
-
- @Override
- public int getPendingTasks() {
-
- final PendingClusterTasksResponse tasksResponse = esProvider.getClient().admin()
- .cluster().pendingClusterTasks( new PendingClusterTasksRequest() ).actionGet();
-
- return tasksResponse.pendingTasks().size();
- }
-
-
- @Override
- public CandidateResults getEntityVersions( final IndexScope scope, final Id id ) {
-
- //since we don't have paging inputs, there's no point in executing a query for paging.
-
- final String context = IndexingUtils.createContextName(scope);
- final SearchTypes searchTypes = SearchTypes.fromTypes(id.getType());
-
- final QueryBuilder queryBuilder =
- QueryBuilders.termQuery( IndexingUtils.ENTITY_CONTEXT_FIELDNAME, context );
-
- final SearchRequestBuilder srb = esProvider.getClient().prepareSearch( alias.getReadAlias() )
- .setTypes(searchTypes.getTypeNames())
- .setScroll(cursorTimeout + "m")
- .setQuery(queryBuilder);
-
- final SearchResponse searchResponse;
- try {
- //Added For Graphite Metrics
- Timer.Context timeEntityIndex = getVersionsTimer.time();
- searchResponse = srb.execute().actionGet();
- timeEntityIndex.stop();
- }
- catch ( Throwable t ) {
- logger.error( "Unable to communicate with elasticsearch" );
- failureMonitor.fail( "Unable to execute batch", t);
- throw t;
- }
-
-
- failureMonitor.success();
-
- return parseResults(searchResponse, new Query());
+ doInRetry(retryOperation);
}
+ /**
+ * Completely delete an index.
+ */
+ public void deleteIndex() {
+ AdminClient adminClient = esProvider.getClient().admin();
+
+ DeleteIndexResponse response = adminClient.indices()
- .prepareDelete( indexIdentifier.getIndex(null) ).get();
++ .prepareDelete(indexIdentifier.getIndex(null)).get();
+
- if ( response.isAcknowledged() ) {
- logger.info( "Deleted index: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
++ if (response.isAcknowledged()) {
++ logger.info("Deleted index: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
+ //invalidate the alias
+ aliasCache.invalidate(alias);
++ } else {
++ logger.info("Failed to delete index: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
+ }
- else {
- logger.info( "Failed to delete index: read {} write {}", alias.getReadAlias(), alias.getWriteAlias());
- }
++ }
++
++
+ public String[] getUniqueIndexes() {
+ Set<String> indexSet = new HashSet<>();
+ List<String> reads = Arrays.asList(getIndexes(AliasType.Read));
+ List<String> writes = Arrays.asList(getIndexes(AliasType.Write));
+ indexSet.addAll(reads);
+ indexSet.addAll(writes);
+ return indexSet.toArray(new String[0]);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --cc stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 16bb703,854c3e0..cd8a404
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@@ -1605,84 -1636,28 +1605,83 @@@ public class ManagementServiceImpl impl
}
if ( properties == null ) {
- properties = new HashMap<String, Object>();
+ properties = new HashMap<>();
}
+ EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+
OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
+ Entity appInfo = emf.createApplicationV2(
+ organizationInfo.getName(), applicationName, properties);
- em.refreshIndex();
- UUID applicationId = emf.createApplication( organizationInfo.getName(), applicationName, properties );
+ writeUserToken( smf.getManagementAppId(), appInfo,
+ encryptionService.plainTextCredentials(
+ generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
+ null,
+ smf.getManagementAppId() ) );
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- properties.put( "name", buildAppName( applicationName, organizationInfo ) );
- properties.put( "appUuid", applicationId );
- Entity appInfo = em.create( applicationId, APPLICATION_INFO, properties );
+ UUID applicationId = addApplicationToOrganization( organizationId, appInfo );
+ UserInfo user = null;
+ try {
+ user = SubjectUtils.getUser();
+ }
+ catch ( UnavailableSecurityManagerException e ) {
+ // occurs in the rare case that this is called before the full stack is initialized
+ logger.warn("Error getting user, application created activity will not be created", e);
+ }
+ if ( ( user != null ) && user.isAdminUser() ) {
+ postOrganizationActivity( organizationId, user, "create", appInfo, "Application", applicationName,
+ "<a href=\"mailto:" + user.getEmail() + "\">" + user.getName() + " (" + user.getEmail()
+ + ")</a> created a new application named " + applicationName, null );
+ }
- writeUserToken( smf.getManagementAppId(), appInfo, encryptionService
- .plainTextCredentials( generateOAuthSecretKey( AuthPrincipalType.APPLICATION ), null,
- smf.getManagementAppId() ) );
- addApplicationToOrganization( organizationId, applicationId, appInfo );
+
+ return new ApplicationInfo( applicationId, appInfo.getName() );
+ }
+
+
+ @Override
+ public void deleteApplication(UUID applicationId) throws Exception {
+ emf.deleteApplication( applicationId );
+ }
+
+
+ @Override
+ public ApplicationInfo restoreApplication(UUID applicationId) throws Exception {
+
+ ApplicationInfo app = getDeletedApplicationInfo( applicationId );
+ if ( app == null ) {
+ throw new EntityNotFoundException("Deleted application ID " + applicationId + " not found");
+ }
+
+ if ( emf.lookupApplication( app.getName() ) != null ) {
+ throw new ConflictException("Cannot restore application, one with that name already exists.");
+ }
+
+ // restore application_info entity
+
+ EntityManager em = emf.getEntityManager( emf.getManagementAppId() );
+ Entity appInfo = emf.restoreApplication(applicationId);
+
+ // restore token
+
+ writeUserToken( smf.getManagementAppId(), appInfo,
+ encryptionService.plainTextCredentials(
+ generateOAuthSecretKey( AuthPrincipalType.APPLICATION ),
+ null,
+ smf.getManagementAppId() ) );
+
+ String orgName = appInfo.getName().split("/")[0];
+ EntityRef alias = em.getAlias( Group.ENTITY_TYPE, orgName );
+ Entity orgEntity = em.get( alias );
+
+ addApplicationToOrganization( orgEntity.getUuid(), appInfo );
+
+ // create activity
UserInfo user = null;
- // if we call this method before the full stack is initialized
- // we'll get an exception
try {
user = SubjectUtils.getUser();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/44deb61c/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
----------------------------------------------------------------------
[42/50] incubator-usergrid git commit: Delete app index on app delete.
Posted by sn...@apache.org.
Delete app index on app delete.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f007f479
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f007f479
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f007f479
Branch: refs/heads/two-dot-o-dev
Commit: f007f47916a69b17234368572c33f69bc3ada2c7
Parents: 44deb61
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 24 12:44:23 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 24 12:44:23 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 35 ++++++----
.../cassandra/EntityManagerFactoryImplIT.java | 68 +++++++++++---------
2 files changed, 61 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f007f479/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 2d155a8..9b7b2bb 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
@@ -307,7 +307,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// find application_info for application to delete
- EntityManager em = getEntityManager(getManagementAppId());
+ final EntityManager em = getEntityManager(getManagementAppId());
final Results results = em.searchCollection(em.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS,
Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
@@ -344,6 +344,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
final ApplicationEntityIndex entityIndex = managerCache.getEntityIndex(
new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
+ entityIndex.deleteApplication();
applicationIdCache.evictAppId(appInfoToDelete.getName());
}
@@ -425,23 +426,29 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public Map<String, UUID> getApplications(boolean deleted) throws Exception {
- Map<String, UUID> appMap = new HashMap<String, UUID>();
+ Map<String, UUID> appMap = new HashMap<>();
- ApplicationScope appScope = CpNamingUtils.getApplicationScope(getManagementAppId());
- GraphManager gm = managerCache.getGraphManager(appScope);
+ ApplicationScope mgmtAppScope = CpNamingUtils.getApplicationScope(getManagementAppId());
+ GraphManager gm = managerCache.getGraphManager(mgmtAppScope);
EntityManager em = getEntityManager(getManagementAppId());
- Application app = em.getApplication();
- Id fromEntityId = new SimpleId( app.getUuid(), app.getType() );
+ Application mgmtApp = em.getApplication();
+ Id fromEntityId = new SimpleId( mgmtApp.getUuid(), mgmtApp.getType() );
final String scopeName;
final String edgeType;
+
if ( deleted ) {
- edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.DELETED_APPLICATION_INFOS);
- scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(CpNamingUtils.DELETED_APPLICATION_INFOS);
+ edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(
+ CpNamingUtils.DELETED_APPLICATION_INFOS);
+ scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(
+ CpNamingUtils.DELETED_APPLICATION_INFOS);
+
} else {
- edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.APPLICATION_INFOS );
- scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(CpNamingUtils.APPLICATION_INFOS);
+ edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(
+ CpNamingUtils.APPLICATION_INFOS );
+ scopeName = CpNamingUtils.getCollectionScopeNameFromCollectionName(
+ CpNamingUtils.APPLICATION_INFOS);
}
logger.debug("getApplications(): Loading edges of edgeType {} from {}:{}",
@@ -451,7 +458,9 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
fromEntityId, edgeType, Long.MAX_VALUE,
SearchByEdgeType.Order.DESCENDING, null ));
- //TODO This is wrong, and will result in OOM if there are too many applications. This needs to stream properly with a buffer
+ // TODO This is wrong, and will result in OOM if there are too many applications.
+ // This needs to stream properly with a buffer
+
Iterator<Edge> iter = edges.toBlocking().getIterator();
while ( iter.hasNext() ) {
@@ -464,8 +473,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
});
CollectionScope collScope = new CollectionScopeImpl(
- appScope.getApplication(),
- appScope.getApplication(),
+ mgmtAppScope.getApplication(),
+ mgmtAppScope.getApplication(),
scopeName);
org.apache.usergrid.persistence.model.entity.Entity appInfo =
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f007f479/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index ff3dc2b..d52f3f6 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -103,13 +103,17 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
@Test
public void testDeleteApplication() throws Exception {
+ int maxRetries = 10;
+
String rand = UUIDGenerator.newTimeUUID().toString();
// create an application with a collection and an entity
- final UUID applicationId = setup.createApplication( "test-org-" + rand, "test-app-" + rand );
+ String appName = "test-app-" + rand;
+ String orgName = "test-org-" + rand;
+ final UUID deletedAppId = setup.createApplication( orgName, appName );
- EntityManager em = setup.getEmf().getEntityManager( applicationId );
+ EntityManager em = setup.getEmf().getEntityManager(deletedAppId);
Map<String, Object> properties1 = new LinkedHashMap<String, Object>();
properties1.put( "Name", "12 Angry Men" );
@@ -121,16 +125,18 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
properties2.put( "Year", 1992 );
Entity film2 = em.create( "film", properties2 );
- app.refreshIndex();
-
- // TODO: this assertion should work!
- //assertNotNull( "cannot lookup app by name", setup.getEmf().lookupApplication("test-app-" + rand) );
+ for ( int j=0; j<maxRetries; j++ ) {
+ if ( setup.getEmf().lookupApplication( orgName + "/" + appName ) != null ) {
+ break;
+ }
+ Thread.sleep( 500 );
+ }
// delete the application
- setup.getEmf().deleteApplication( applicationId );
+ setup.getEmf().deleteApplication( deletedAppId );
- app.refreshIndex();
+ // wait for it to appear in delete apps list
Func2<UUID, Map<String, UUID> ,Boolean> findApps = new Func2<UUID,Map<String, UUID> ,Boolean>() {
@Override
@@ -148,31 +154,35 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
};
boolean found = false;
- for(int i=0;i<10;i++){
- found = findApps.call(applicationId,emf.getDeletedApplications());
- if(found){
+ for ( int i=0; i<maxRetries; i++) {
+ found = findApps.call( deletedAppId, emf.getDeletedApplications() );
+ if ( found ) {
break;
- } else{
- Thread.sleep(500);
+ } else {
+ Thread.sleep( 500 );
}
}
-
assertTrue( "Deleted app must be found in in deleted apps collection", found );
// attempt to get entities in application's collections in various ways should all fail
- assertNull( setup.getEmf().lookupApplication("test-app-" + rand) );
+ assertNull( setup.getEmf().lookupApplication( orgName + "/" + appName ));
+
+ // app must not be found in apps collection
- Map<String, UUID> appMap = setup.getEmf().getApplications();
- for ( String appName : appMap.keySet() ) {
- UUID appId = appMap.get( appName );
- assertNotEquals( appId, applicationId );
- assertNotEquals( appName, "test-app-" + rand );
+ for ( int i=0; i<maxRetries; i++ ) {
+ found = findApps.call( deletedAppId, emf.getApplications() );
+ if ( found ) {
+ Thread.sleep( 500 );
+ } else {
+ break;
+ }
}
+ assertFalse( "Deleted app must not be found in apps collection", found );
// restore the app
- emf.restoreApplication( applicationId );
+ emf.restoreApplication( deletedAppId );
emf.rebuildAllIndexes(new EntityManagerFactory.ProgressObserver() {
@Override
@@ -184,18 +194,18 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
// test to see that app now works and is happy
// it should not be found in the deleted apps collection
- for(int i=0;i<10;i++){
- found = findApps.call(applicationId,emf.getDeletedApplications());
- if(!found){
+ for ( int i=0; i<maxRetries; i++ ) {
+ found = findApps.call( deletedAppId, emf.getDeletedApplications() );
+ if ( !found ) {
break;
- } else{
- Thread.sleep(500);
+ } else {
+ Thread.sleep( 500 );
}
}
assertFalse("Restored app found in deleted apps collection", found);
- for(int i=0;i<10;i++){
- found = findApps.call(applicationId,setup.getEmf().getApplications());
+ for(int i=0;i<maxRetries;i++){
+ found = findApps.call(deletedAppId,setup.getEmf().getApplications());
if(!found){
break;
} else{
@@ -205,7 +215,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
assertTrue("Restored app not found in apps collection", found);
// TODO: this assertion should work!
- //assertNotNull(setup.getEmf().lookupApplication("test-app-" + rand));
+ //assertNotNull(setup.getEmf().lookupApplication( orgName + "/" + appName ));
}
[10/50] incubator-usergrid git commit: Move ApplicationInfo back
where it started in the Services module.
Posted by sn...@apache.org.
Move ApplicationInfo back where it started in the Services module.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2664f6f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2664f6f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2664f6f5
Branch: refs/heads/two-dot-o-dev
Commit: 2664f6f57b2629cce24ad19abbbd19aefb729062
Parents: 14f45ed
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 9 11:19:36 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 9 11:19:36 2015 -0400
----------------------------------------------------------------------
.../persistence/entities/ApplicationInfo.java | 135 -------------------
.../usergrid/mongo/commands/Collstats.java | 2 +-
.../apache/usergrid/mongo/commands/Count.java | 2 +-
.../usergrid/mongo/protocol/OpDelete.java | 2 +-
.../usergrid/mongo/protocol/OpInsert.java | 2 +-
.../apache/usergrid/mongo/protocol/OpQuery.java | 2 +-
.../usergrid/mongo/protocol/OpUpdate.java | 2 +-
.../rest/applications/ApplicationResource.java | 4 +-
.../applications/ApplicationResource.java | 2 +-
.../applications/ApplicationsResource.java | 4 +-
.../imports/FileErrorsResource.java | 2 +-
.../imports/FileIncludesResource.java | 2 +-
.../applications/imports/ImportsResource.java | 6 +-
.../security/SecuredResourceFilterFactory.java | 2 +-
.../OAuth2AccessTokenSecurityFilter.java | 2 +-
.../apache/usergrid/rest/AbstractRestIT.java | 2 +-
.../usergrid/management/ApplicationCreator.java | 1 -
.../usergrid/management/ApplicationInfo.java | 135 +++++++++++++++++++
.../usergrid/management/ManagementService.java | 1 -
.../cassandra/ApplicationCreatorImpl.java | 2 +-
.../cassandra/ManagementServiceImpl.java | 5 +-
.../management/export/ExportServiceImpl.java | 2 +-
.../shiro/PrincipalCredentialsToken.java | 2 +-
.../apache/usergrid/security/shiro/Realm.java | 2 +-
.../principals/ApplicationGuestPrincipal.java | 2 +-
.../shiro/principals/ApplicationPrincipal.java | 2 +-
.../security/shiro/utils/SubjectUtils.java | 2 +-
.../org/apache/usergrid/NewOrgAppAdminRule.java | 2 +-
.../apache/usergrid/management/EmailFlowIT.java | 1 -
.../cassandra/ApplicationCreatorIT.java | 2 +-
.../management/export/ExportServiceIT.java | 2 +-
.../security/tokens/TokenServiceIT.java | 2 +-
.../org/apache/usergrid/tools/AppAudit.java | 2 +-
.../org/apache/usergrid/tools/CredExport.java | 2 +-
.../org/apache/usergrid/tools/EntityUpdate.java | 2 +-
.../java/org/apache/usergrid/tools/Import.java | 2 +-
.../java/org/apache/usergrid/tools/Metrics.java | 2 +-
.../usergrid/tools/UniqueIndexCleanup.java | 2 +-
38 files changed, 171 insertions(+), 179 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/core/src/main/java/org/apache/usergrid/persistence/entities/ApplicationInfo.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/ApplicationInfo.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/ApplicationInfo.java
deleted file mode 100644
index 25ced82..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/ApplicationInfo.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.persistence.entities;
-
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.UUID;
-
-import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
-
-
-public class ApplicationInfo {
-
- private final UUID id;
- private final String name;
-
-
- public ApplicationInfo( UUID id, String name ) {
- this.id = id;
- this.name = name;
- }
-
-
- public ApplicationInfo( Map<String, Object> properties ) {
- id = ( UUID ) properties.get( PROPERTY_UUID );
- name = ( String ) properties.get( PROPERTY_NAME );
- }
-
-
- public UUID getId() {
- return id;
- }
-
-
- public String getName() {
- return name;
- }
-
-
- public static List<ApplicationInfo> fromNameIdMap( Map<String, UUID> map ) {
- List<ApplicationInfo> list = new ArrayList<ApplicationInfo>();
- for ( Entry<String, UUID> s : map.entrySet() ) {
- list.add( new ApplicationInfo( s.getValue(), s.getKey() ) );
- }
- return list;
- }
-
-
- public static List<ApplicationInfo> fromIdNameMap( Map<UUID, String> map ) {
- List<ApplicationInfo> list = new ArrayList<ApplicationInfo>();
- for ( Entry<UUID, String> s : map.entrySet() ) {
- list.add( new ApplicationInfo( s.getKey(), s.getValue() ) );
- }
- return list;
- }
-
-
- public static Map<String, UUID> toNameIdMap( List<ApplicationInfo> list ) {
- Map<String, UUID> map = new LinkedHashMap<String, UUID>();
- for ( ApplicationInfo i : list ) {
- map.put( i.getName(), i.getId() );
- }
- return map;
- }
-
-
- public static Map<UUID, String> toIdNameMap( List<ApplicationInfo> list ) {
- Map<UUID, String> map = new LinkedHashMap<UUID, String>();
- for ( ApplicationInfo i : list ) {
- map.put( i.getId(), i.getName() );
- }
- return map;
- }
-
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
- result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
- return result;
- }
-
-
- @Override
- public boolean equals( Object obj ) {
- if ( this == obj ) {
- return true;
- }
- if ( obj == null ) {
- return false;
- }
- if ( getClass() != obj.getClass() ) {
- return false;
- }
- ApplicationInfo other = ( ApplicationInfo ) obj;
- if ( id == null ) {
- if ( other.id != null ) {
- return false;
- }
- }
- else if ( !id.equals( other.id ) ) {
- return false;
- }
- if ( name == null ) {
- if ( other.name != null ) {
- return false;
- }
- }
- else if ( !name.equals( other.name ) ) {
- return false;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java
index cc97d8a..02a0e9a 100644
--- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java
+++ b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Collstats.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.mongo.commands;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.protocol.OpQuery;
import org.apache.usergrid.mongo.protocol.OpReply;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java
index 85a1a9c..bac3e4f 100644
--- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java
+++ b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/commands/Count.java
@@ -21,7 +21,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.protocol.OpQuery;
import org.apache.usergrid.mongo.protocol.OpReply;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java
index 6973d73..be94463 100644
--- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java
+++ b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpDelete.java
@@ -30,7 +30,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.query.MongoQueryParser;
import org.apache.usergrid.mongo.utils.BSONUtils;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpInsert.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpInsert.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpInsert.java
index d28b9d9..fdd72ab 100644
--- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpInsert.java
+++ b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpInsert.java
@@ -32,7 +32,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.utils.BSONUtils;
import org.apache.usergrid.persistence.EntityManager;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpQuery.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpQuery.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpQuery.java
index 9e2852b..e411c28 100644
--- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpQuery.java
+++ b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpQuery.java
@@ -34,7 +34,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.commands.MongoCommand;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpUpdate.java
----------------------------------------------------------------------
diff --git a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpUpdate.java b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpUpdate.java
index b4d2762..8062f86 100644
--- a/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpUpdate.java
+++ b/stack/mongo-emulator/src/main/java/org/apache/usergrid/mongo/protocol/OpUpdate.java
@@ -29,7 +29,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.mongo.MongoChannelHandler;
import org.apache.usergrid.mongo.query.MongoQueryParser;
import org.apache.usergrid.mongo.utils.BSONUtils;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
index e62a9cb..5726466 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ApplicationResource.java
@@ -30,15 +30,13 @@ import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import com.sun.jersey.api.ConflictException;
-import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
import org.apache.usergrid.rest.ApiResponse;
import org.apache.usergrid.rest.security.annotations.RequireOrganizationAccess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.exceptions.DisabledAdminUserException;
import org.apache.usergrid.management.exceptions.DisabledAppUserException;
import org.apache.usergrid.management.exceptions.UnactivatedAdminUserException;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index 8def33f..1e7d1f9 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -23,7 +23,7 @@ import org.apache.amber.oauth2.common.exception.OAuthSystemException;
import org.apache.amber.oauth2.common.message.OAuthResponse;
import org.apache.commons.lang.StringUtils;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.export.ExportService;
import org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
index 5691e2e..272378d 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
@@ -31,7 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
import org.apache.usergrid.rest.AbstractContextResource;
@@ -136,7 +136,7 @@ public class ApplicationsResource extends AbstractContextResource {
@Context UriInfo ui, @PathParam( "applicationId" ) String applicationIdStr ) throws Exception {
return getSubResource( ApplicationResource.class )
- .init( organization, UUID.fromString( applicationIdStr ) );
+ .init(organization, UUID.fromString(applicationIdStr));
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
index 1f2da84..a72a8f0 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileErrorsResource.java
@@ -37,7 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.importer.ImportService;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.Results;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
index 783ea5b..1cb44d0 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/FileIncludesResource.java
@@ -37,7 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.importer.ImportService;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.Results;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
index 859f0f5..7d047a3 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
@@ -45,7 +45,7 @@ import org.springframework.stereotype.Component;
import org.apache.commons.lang.NullArgumentException;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.importer.ImportService;
import org.apache.usergrid.persistence.Entity;
@@ -180,8 +180,8 @@ public class ImportsResource extends AbstractContextResource {
}
ApiResponse response = createApiResponse();
- response.setAction( "get" );
- response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
+ response.setAction("get");
+ response.setApplication(emf.getEntityManager(application.getId()).getApplication());
response.setParams( ui.getQueryParameters() );
response.setEntities( Collections.<Entity>singletonList( importEntity ) );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/security/SecuredResourceFilterFactory.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/SecuredResourceFilterFactory.java b/stack/rest/src/main/java/org/apache/usergrid/rest/security/SecuredResourceFilterFactory.java
index a4b4557..202eb31 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/SecuredResourceFilterFactory.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/SecuredResourceFilterFactory.java
@@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityManagerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
index 8c669f1..fa39b28 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/filters/OAuth2AccessTokenSecurityFilter.java
@@ -23,7 +23,7 @@ import javax.ws.rs.core.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.management.exceptions.ManagementException;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index f9abff2..1b3ee65 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -29,7 +29,7 @@ import com.sun.jersey.test.framework.WebAppDescriptor;
import com.sun.jersey.test.framework.spi.container.TestContainerFactory;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.usergrid.java.client.Client;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/management/ApplicationCreator.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationCreator.java b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationCreator.java
index 2f9bcb9..f4f8598 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationCreator.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationCreator.java
@@ -18,7 +18,6 @@ package org.apache.usergrid.management;
import org.apache.usergrid.management.exceptions.ApplicationCreationException;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
new file mode 100644
index 0000000..30c494f
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
@@ -0,0 +1,135 @@
+/*
+ * 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.management;
+
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.UUID;
+
+import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
+
+
+public class ApplicationInfo {
+
+ private final UUID id;
+ private final String name;
+
+
+ public ApplicationInfo( UUID id, String name ) {
+ this.id = id;
+ this.name = name;
+ }
+
+
+ public ApplicationInfo( Map<String, Object> properties ) {
+ id = ( UUID ) properties.get( PROPERTY_UUID );
+ name = ( String ) properties.get( PROPERTY_NAME );
+ }
+
+
+ public UUID getId() {
+ return id;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+
+ public static List<ApplicationInfo> fromNameIdMap( Map<String, UUID> map ) {
+ List<ApplicationInfo> list = new ArrayList<ApplicationInfo>();
+ for ( Entry<String, UUID> s : map.entrySet() ) {
+ list.add( new ApplicationInfo( s.getValue(), s.getKey() ) );
+ }
+ return list;
+ }
+
+
+ public static List<ApplicationInfo> fromIdNameMap( Map<UUID, String> map ) {
+ List<ApplicationInfo> list = new ArrayList<ApplicationInfo>();
+ for ( Entry<UUID, String> s : map.entrySet() ) {
+ list.add( new ApplicationInfo( s.getKey(), s.getValue() ) );
+ }
+ return list;
+ }
+
+
+ public static Map<String, UUID> toNameIdMap( List<ApplicationInfo> list ) {
+ Map<String, UUID> map = new LinkedHashMap<String, UUID>();
+ for ( ApplicationInfo i : list ) {
+ map.put( i.getName(), i.getId() );
+ }
+ return map;
+ }
+
+
+ public static Map<UUID, String> toIdNameMap( List<ApplicationInfo> list ) {
+ Map<UUID, String> map = new LinkedHashMap<UUID, String>();
+ for ( ApplicationInfo i : list ) {
+ map.put( i.getId(), i.getName() );
+ }
+ return map;
+ }
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
+ result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
+ return result;
+ }
+
+
+ @Override
+ public boolean equals( Object obj ) {
+ if ( this == obj ) {
+ return true;
+ }
+ if ( obj == null ) {
+ return false;
+ }
+ if ( getClass() != obj.getClass() ) {
+ return false;
+ }
+ ApplicationInfo other = ( ApplicationInfo ) obj;
+ if ( id == null ) {
+ if ( other.id != null ) {
+ return false;
+ }
+ }
+ else if ( !id.equals( other.id ) ) {
+ return false;
+ }
+ if ( name == null ) {
+ if ( other.name != null ) {
+ return false;
+ }
+ }
+ else if ( !name.equals( other.name ) ) {
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index aff9e15..8ed15f2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -26,7 +26,6 @@ import java.util.UUID;
import org.apache.usergrid.persistence.CredentialsInfo;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.apache.usergrid.persistence.index.query.Identifier;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.persistence.entities.Group;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ApplicationCreatorImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ApplicationCreatorImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ApplicationCreatorImpl.java
index 95e3b55..900d3d0 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ApplicationCreatorImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ApplicationCreatorImpl.java
@@ -23,7 +23,7 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.management.ApplicationCreator;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.exceptions.ApplicationCreationException;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index a33c324..84f5d13 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -30,9 +30,6 @@ import java.util.UUID;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.management.exceptions.*;
-import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +40,7 @@ import org.apache.usergrid.locking.Lock;
import org.apache.usergrid.locking.LockManager;
import org.apache.usergrid.management.AccountCreationProps;
import org.apache.usergrid.management.ActivationState;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
index 4af3403..8caecbc 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/export/ExportServiceImpl.java
@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
import org.apache.usergrid.batch.JobExecution;
import org.apache.usergrid.batch.service.SchedulerService;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.persistence.ConnectionRef;
import org.apache.usergrid.persistence.Entity;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/security/shiro/PrincipalCredentialsToken.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/PrincipalCredentialsToken.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/PrincipalCredentialsToken.java
index 1ecc904..f7705cd 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/PrincipalCredentialsToken.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/PrincipalCredentialsToken.java
@@ -18,7 +18,7 @@ package org.apache.usergrid.security.shiro;
import java.util.UUID;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.security.shiro.credentials.AdminUserAccessToken;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
index e1a6517..9de1763 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
@@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.apache.usergrid.management.AccountCreationProps;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationGuestPrincipal.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationGuestPrincipal.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationGuestPrincipal.java
index 01aba11..da93994 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationGuestPrincipal.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationGuestPrincipal.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.security.shiro.principals;
import java.util.UUID;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
public class ApplicationGuestPrincipal extends PrincipalIdentifier {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationPrincipal.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationPrincipal.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationPrincipal.java
index 8635044..bdaa68e 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationPrincipal.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/ApplicationPrincipal.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.security.shiro.principals;
import java.util.UUID;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
public class ApplicationPrincipal extends PrincipalIdentifier {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
index 5f524c1..5c222b4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/utils/SubjectUtils.java
@@ -22,7 +22,7 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.security.shiro.PrincipalCredentialsToken;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java b/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
index 19df848..ab7857e 100644
--- a/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
+++ b/stack/services/src/test/java/org/apache/usergrid/NewOrgAppAdminRule.java
@@ -28,7 +28,7 @@ import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
import org.apache.usergrid.management.UserInfo;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java b/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
index d887b6b..5dd6915 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
@@ -28,7 +28,6 @@ import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMultipart;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
index f95103a..20b2e17 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
@@ -26,7 +26,7 @@ import org.apache.usergrid.ServiceITSetup;
import org.apache.usergrid.ServiceITSetupImpl;
import org.apache.usergrid.cassandra.ClearShiroSubject;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationOwnerInfo;
import static org.apache.usergrid.TestHelper.uniqueApp;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
index f259b2d..3a6d8f9 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
@@ -45,7 +45,7 @@ import org.apache.usergrid.ServiceITSetupImpl;
import org.apache.usergrid.batch.JobExecution;
import org.apache.usergrid.cassandra.ClearShiroSubject;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.persistence.Entity;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/services/src/test/java/org/apache/usergrid/security/tokens/TokenServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/security/tokens/TokenServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/security/tokens/TokenServiceIT.java
index 05b2126..f5cd3df 100644
--- a/stack/services/src/test/java/org/apache/usergrid/security/tokens/TokenServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/security/tokens/TokenServiceIT.java
@@ -32,7 +32,7 @@ import org.apache.usergrid.ServiceITSetup;
import org.apache.usergrid.ServiceITSetupImpl;
import org.apache.usergrid.cassandra.ClearShiroSubject;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.entities.Application;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/tools/src/main/java/org/apache/usergrid/tools/AppAudit.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/AppAudit.java b/stack/tools/src/main/java/org/apache/usergrid/tools/AppAudit.java
index ed7efd1..0d6e96b 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/AppAudit.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/AppAudit.java
@@ -29,7 +29,7 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityRef;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/tools/src/main/java/org/apache/usergrid/tools/CredExport.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/CredExport.java b/stack/tools/src/main/java/org/apache/usergrid/tools/CredExport.java
index 086bbe9..c30df24 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/CredExport.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/CredExport.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.tools;
import java.util.UUID;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.utils.UUIDUtils;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/tools/src/main/java/org/apache/usergrid/tools/EntityUpdate.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/EntityUpdate.java b/stack/tools/src/main/java/org/apache/usergrid/tools/EntityUpdate.java
index 55eeba9..1847595 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/EntityUpdate.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/EntityUpdate.java
@@ -23,7 +23,7 @@ import java.util.Map;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.DynamicEntity;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/tools/src/main/java/org/apache/usergrid/tools/Import.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/Import.java b/stack/tools/src/main/java/org/apache/usergrid/tools/Import.java
index eb1e24d..01313e3 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/Import.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/Import.java
@@ -31,7 +31,7 @@ import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.persistence.Entity;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/tools/src/main/java/org/apache/usergrid/tools/Metrics.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/Metrics.java b/stack/tools/src/main/java/org/apache/usergrid/tools/Metrics.java
index d962280..b308290 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/Metrics.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/Metrics.java
@@ -27,7 +27,7 @@ import java.util.Set;
import java.util.UUID;
import org.codehaus.jackson.JsonGenerator;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.management.OrganizationInfo;
import org.apache.usergrid.management.UserInfo;
import org.apache.usergrid.persistence.AggregateCounter;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2664f6f5/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
index b0c158c..0ae45d6 100644
--- a/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
+++ b/stack/tools/src/main/java/org/apache/usergrid/tools/UniqueIndexCleanup.java
@@ -29,7 +29,7 @@ import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.entities.ApplicationInfo;
+import org.apache.usergrid.management.ApplicationInfo;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityManagerFactory;
[08/50] incubator-usergrid git commit: Fixes to REST module import
tests.
Posted by sn...@apache.org.
Fixes to REST module import tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/b7e41f25
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/b7e41f25
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/b7e41f25
Branch: refs/heads/two-dot-o-dev
Commit: b7e41f2570540a006291418f9870b008290cee4c
Parents: 10481ce
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 6 12:30:12 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 6 12:30:12 2015 -0500
----------------------------------------------------------------------
.../applications/imports/ImportsResource.java | 73 +++++++----------
.../rest/management/ImportResourceIT.java | 82 +++++++++++---------
2 files changed, 75 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b7e41f25/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
index aa5160b..859f0f5 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/imports/ImportsResource.java
@@ -37,6 +37,8 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.UriInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@@ -63,6 +65,7 @@ import com.sun.jersey.api.json.JSONWithPadding;
@Produces( MediaType.APPLICATION_JSON )
public class ImportsResource extends AbstractContextResource {
+ private static final Logger logger = LoggerFactory.getLogger(ImportsResource.class);
@Autowired
protected ImportService importService;
@@ -94,10 +97,7 @@ public class ImportsResource extends AbstractContextResource {
@QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
throws Exception {
-
ApiResponse response = createApiResponse();
-
-
response.setAction( "post" );
response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
response.setParams( ui.getQueryParameters() );
@@ -106,42 +106,33 @@ public class ImportsResource extends AbstractContextResource {
Map<String, Object> properties;
Map<String, Object> storage_info;
- // UsergridAwsCredentialsProvider uacp = new UsergridAwsCredentialsProvider();
-
- // try {
- //checkJsonExportProperties(json);
-
-
- if ( ( properties = ( Map<String, Object> ) json.get( "properties" ) ) == null ) {
- throw new NullArgumentException( "Could not find 'properties'" );
- }
- storage_info = ( Map<String, Object> ) properties.get( "storage_info" );
- String storage_provider = ( String ) properties.get( "storage_provider" );
- if ( storage_provider == null ) {
- throw new NullArgumentException( "Could not find field 'storage_provider'" );
- }
- if ( storage_info == null ) {
- throw new NullArgumentException( "Could not find field 'storage_info'" );
- }
-
- String bucketName = ( String ) storage_info.get( "bucket_location" );
+ if ((properties = (Map<String, Object>) json.get("properties")) == null) {
+ throw new NullArgumentException("Could not find 'properties'");
+ }
+ storage_info = (Map<String, Object>) properties.get("storage_info");
+ String storage_provider = (String) properties.get("storage_provider");
+ if (storage_provider == null) {
+ throw new NullArgumentException("Could not find field 'storage_provider'");
+ }
+ if (storage_info == null) {
+ throw new NullArgumentException("Could not find field 'storage_info'");
+ }
- String accessId = ( String ) storage_info.get( "s3_access_id" );
- String secretKey = ( String ) storage_info.get( "s3_key" );
-
- if ( bucketName == null ) {
- throw new NullArgumentException( "Could not find field 'bucketName'" );
- }
- if ( accessId == null ) {
- throw new NullArgumentException( "Could not find field 's3_access_id'" );
- }
- if ( secretKey == null ) {
-
- throw new NullArgumentException( "Could not find field 's3_key'" );
- }
+ String bucketName = (String) storage_info.get("bucket_location");
+ String accessId = (String) storage_info.get("s3_access_id");
+ String secretKey = (String) storage_info.get("s3_key");
+ if (bucketName == null) {
+ throw new NullArgumentException("Could not find field 'bucketName'");
+ }
+ if (accessId == null) {
+ throw new NullArgumentException("Could not find field 's3_access_id'");
+ }
+ if (secretKey == null) {
+ throw new NullArgumentException("Could not find field 's3_key'");
+ }
json.put( "organizationId", organization.getUuid() );
json.put( "applicationId", application.getId() );
@@ -157,7 +148,6 @@ public class ImportsResource extends AbstractContextResource {
@GET
public JSONWithPadding getImports( @Context UriInfo ui, @QueryParam( "ql" ) String query, @QueryParam( "cursor" ) String cursor ) throws Exception {
-
final Results importResults = importService.getImports( application.getId(), query, cursor );
if ( importResults == null ) {
@@ -165,13 +155,9 @@ public class ImportsResource extends AbstractContextResource {
}
ApiResponse response = createApiResponse();
-
-
response.setAction( "get" );
response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
response.setParams( ui.getQueryParameters() );
-
-
response.withResults( importResults );
return new JSONWithPadding( response );
@@ -186,18 +172,17 @@ public class ImportsResource extends AbstractContextResource {
final UUID importId = UUID.fromString( entityId.getPath() );
final Import importEntity = importService.getImport( application.getId(), importId );
+ logger.debug("Loaded import entity {}:{} with state {}",
+ new Object[] { importEntity.getType(), importEntity.getUuid(), importEntity.getState() } );
+
if ( importEntity == null ) {
throw new EntityNotFoundException( "could not find import with uuid " + importId );
}
ApiResponse response = createApiResponse();
-
-
response.setAction( "get" );
response.setApplication( emf.getEntityManager( application.getId() ).getApplication() );
response.setParams( ui.getQueryParameters() );
-
-
response.setEntities( Collections.<Entity>singletonList( importEntity ) );
return new JSONWithPadding( response );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b7e41f25/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
index 2edeb65..1ea9770 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
@@ -29,7 +29,6 @@ import org.apache.usergrid.ServiceITSetup;
import org.apache.usergrid.ServiceITSetupImpl;
import org.apache.usergrid.batch.service.JobSchedulerService;
import org.apache.usergrid.management.importer.S3Upload;
-import org.apache.usergrid.persistence.index.impl.ElasticSearchResource;
import org.apache.usergrid.persistence.index.utils.UUIDUtils;
import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
@@ -88,7 +87,9 @@ public class ImportResourceIT extends AbstractRestIT {
bucketPrefix = System.getProperty("bucketName");
// start the scheduler after we're all set up
- JobSchedulerService jobScheduler = ConcurrentProcessSingleton.getInstance().getSpringResource().getBean( JobSchedulerService.class );
+ JobSchedulerService jobScheduler = ConcurrentProcessSingleton.getInstance()
+ .getSpringResource().getBean( JobSchedulerService.class );
+
if (jobScheduler.state() != Service.State.RUNNING) {
jobScheduler.startAsync();
jobScheduler.awaitRunning();
@@ -113,9 +114,9 @@ public class ImportResourceIT extends AbstractRestIT {
});
}
- if (!StringUtils.isEmpty(bucketPrefix)) {
- deleteBucketsWithPrefix();
- }
+// if (!StringUtils.isEmpty(bucketPrefix)) {
+// deleteBucketsWithPrefix();
+// }
bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase();
}
@@ -172,15 +173,11 @@ public class ImportResourceIT extends AbstractRestIT {
Entity payload = payloadBuilder();
// /management/orgs/orgname/apps/appname/import
- Entity entity = this.management()
- .orgs()
- .organization(org)
- .app()
+ Entity entity = this.management().orgs().organization(org).app()
.addToPath(app)
.addToPath("imports")
.post(payload);
-
assertNotNull(entity);
// test that you can access the organization using the currently set token.
@@ -421,7 +418,7 @@ public class ImportResourceIT extends AbstractRestIT {
+ File.separator + "test-classes" + File.separator;
List<String> filenames = new ArrayList<>( 1 );
- filenames.add( basePath + "testImportCorrect.testCol.1.json" );
+ filenames.add( basePath + "testimport-correct-testcol.1.json");
// create 10 applications each with collection of 10 things, export all to S3
S3Upload s3Upload = new S3Upload();
@@ -458,7 +455,7 @@ public class ImportResourceIT extends AbstractRestIT {
final Entity includesEntity = importGetIncludesResponse.getEntities().get( 0 );
- assertTrue( includesEntity.getAsString("fileName").endsWith("testImportCorrect.testCol.1.json"));
+ assertTrue( includesEntity.getAsString("fileName").endsWith("testimport-correct-testcol.1.json"));
assertEquals(1, includesEntity.get( "importedConnectionCount" ));
assertEquals(1, includesEntity.get( "importedEntityCount" ));
@@ -493,7 +490,7 @@ public class ImportResourceIT extends AbstractRestIT {
+ File.separator + "test-classes" + File.separator;
List<String> filenames = new ArrayList<>( 2 );
- filenames.add( basePath + "testImportCorrect.testCol.1.json");
+ filenames.add( basePath + "testimport-correct-testcol.1.json");
filenames.add( basePath + "testImport.testApplication.2.json");
// create 10 applications each with collection of 10 things, export all to S3
@@ -522,8 +519,6 @@ public class ImportResourceIT extends AbstractRestIT {
assertNotNull(collection);
assertEquals(1, collection.getNumOfEntities());
assertEquals("thing0", collection.getResponse().getEntities().get(0).get("name"));
-
-
}
/**
@@ -554,16 +549,17 @@ public class ImportResourceIT extends AbstractRestIT {
Entity importEntity = importCollection();
- Entity importGet = this.management().orgs().organization(org).app().addToPath(app)
- .addToPath("imports" ).addToPath(importEntity.getUuid().toString() ).get();
-
+ Entity importGet = this.management().orgs().organization(org).app()
+ .addToPath(app)
+ .addToPath("imports" )
+ .addToPath(importEntity.getUuid().toString() )
+ .get();
assertNotNull(importGet);
assertEquals("FAILED", importGet.get("state"));
assertEquals(1, importGet.get("fileCount"));
-
Collection collection = this.app().collection("things").get();
assertNotNull(collection);
@@ -571,14 +567,14 @@ public class ImportResourceIT extends AbstractRestIT {
}
-//export with two files and import the two files.
- //also test the includes endpoint.
+
/**
* TODO: Test that importing bad JSON will result in an informative error message.
*/
@Test
public void testImportBadJson() throws Exception {
+
// import from a bad JSON file
Assume.assumeTrue(configured);
@@ -589,7 +585,7 @@ public class ImportResourceIT extends AbstractRestIT {
+ File.separator + "test-classes" + File.separator;
List<String> filenames = new ArrayList<>( 1 );
- filenames.add( basePath + "testImportInvalidJson.testApplication.3.json");
+ filenames.add( basePath + "testimport-bad-json-testapp.3.json");
// create 10 applications each with collection of 10 things, export all to S3
S3Upload s3Upload = new S3Upload();
@@ -604,14 +600,21 @@ public class ImportResourceIT extends AbstractRestIT {
// we should now have 100 Entities in the default app
- Entity importGet = this.management().orgs().organization( org ).app().addToPath( app ).addToPath("imports")
- .addToPath( importEntity.getUuid().toString() ).get();
+ Entity importGet = this.management().orgs().organization( org ).app()
+ .addToPath( app )
+ .addToPath("imports")
+ .addToPath( importEntity.getUuid().toString() )
+ .get();
- Entity importGetIncludes = this.management().orgs().organization(org).app().addToPath(app)
- .addToPath("imports" ).addToPath(importEntity.getUuid().toString() )
- .addToPath("files" ).get();
+ Entity importGetIncludes = this.management().orgs().organization(org).app()
+ .addToPath(app)
+ .addToPath("imports" )
+ .addToPath(importEntity.getUuid().toString() )
+ .addToPath("files" )
+ .get();
assertNotNull(importGet);
+
//TODO: needs better error checking
assertNotNull(importGetIncludes);
@@ -641,8 +644,10 @@ public class ImportResourceIT extends AbstractRestIT {
}});
}});
- Entity importEntity = this.management().orgs().organization(org).app().addToPath(app).addToPath("imports")
- .post(importPayload);
+ Entity importEntity = this.management().orgs().organization(org).app()
+ .addToPath(app)
+ .addToPath("imports")
+ .post(importPayload);
int maxRetries = 120;
int retries = 0;
@@ -766,17 +771,22 @@ public class ImportResourceIT extends AbstractRestIT {
/*Creates fake payload for testing purposes.*/
public Entity payloadBuilder() {
- Entity payload = new Entity();
- Entity properties = new Entity();
+
+ String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
+ String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );
+
Entity storage_info = new Entity();
- //TODO: always put dummy values here and ignore this test.
- //TODO: add a ret for when s3 values are invalid.
- storage_info.put("s3_key", "insert key here");
- storage_info.put("s3_access_id", "insert access id here");
- storage_info.put("bucket_location", "insert bucket name here");
+ storage_info.put("s3_key", secretKey);
+ storage_info.put("s3_access_id", accessId);
+ storage_info.put("bucket_location", bucketName) ;
+
+ Entity properties = new Entity();
properties.put("storage_provider", "s3");
properties.put("storage_info", storage_info);
+
+ Entity payload = new Entity();
payload.put("properties", properties);
+
return payload;
}
}
[21/50] incubator-usergrid git commit: Use emf.getManagementAppId()
everywhere possible instead of static from CpNamingUtils.
Posted by sn...@apache.org.
Use emf.getManagementAppId() everywhere possible instead of static from CpNamingUtils.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/50cb3bf5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/50cb3bf5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/50cb3bf5
Branch: refs/heads/two-dot-o-dev
Commit: 50cb3bf5eb28a20e5224555402bd901ce81841b9
Parents: 01d22ec
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 13 08:34:20 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 13 08:34:20 2015 -0400
----------------------------------------------------------------------
.../corepersistence/ApplicationIdCacheImpl.java | 2 +-
.../corepersistence/CpEntityManagerFactory.java | 32 ++++++++++----------
.../cassandra/ManagementServiceImpl.java | 2 +-
.../management/importer/FileImportJob.java | 4 +--
.../management/importer/FileImportTracker.java | 6 ++--
.../usergrid/management/importer/ImportJob.java | 4 +--
.../management/importer/ImportServiceImpl.java | 16 +++++-----
.../importer/FileImportTrackerTest.java | 12 ++++----
.../importer/ImportConnectionsTest.java | 7 ++---
9 files changed, 42 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/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 b03f422..379f306 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
@@ -59,7 +59,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
public ApplicationIdCacheImpl(final EntityManagerFactory emf) {
- this.rootEm = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ this.rootEm = emf.getEntityManager( emf.getManagementAppId());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/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 8e432e8..36bbd12 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
@@ -124,14 +124,14 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private void init() {
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
try {
if ( em.getApplication() == null ) {
logger.info("Creating management application");
Map mgmtAppProps = new HashMap<String, Object>();
mgmtAppProps.put(PROPERTY_NAME, "systemapp");
- em.create(CpNamingUtils.MANAGEMENT_APPLICATION_ID, TYPE_APPLICATION, mgmtAppProps);
+ em.create( getManagementAppId(), TYPE_APPLICATION, mgmtAppProps);
em.getApplication();
em.createIndex();
em.refreshIndex();
@@ -222,7 +222,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public Entity initializeApplicationV2( String organizationName, final UUID applicationId, String name,
Map<String, Object> properties ) throws Exception {
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
final String appName = buildAppName( organizationName, name );
@@ -294,7 +294,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// ensure that there is not already a deleted app with the same name
final EntityRef alias = em.getAlias(
- CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName() );
+ CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getName());
if ( alias != null ) {
throw new ConflictException("Cannot delete app with same name as already deleted app");
}
@@ -368,7 +368,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@Override
public void onProgress(EntityRef entity) {
- logger.info( "Restored entity {}:{}", entity.getType(), entity.getUuid() );
+ logger.info("Restored entity {}:{}", entity.getType(), entity.getUuid());
}
});
@@ -386,7 +386,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public UUID lookupApplication( String orgAppName ) throws Exception {
- return applicationIdCache.getApplicationId( orgAppName );
+ return applicationIdCache.getApplicationId(orgAppName);
}
@@ -409,10 +409,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
Map<String, UUID> appMap = new HashMap<String, UUID>();
- ApplicationScope appScope = CpNamingUtils.getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ ApplicationScope appScope = CpNamingUtils.getApplicationScope(getManagementAppId());
GraphManager gm = managerCache.getGraphManager(appScope);
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
Application app = em.getApplication();
Id fromEntityId = new SimpleId( app.getUuid(), app.getType() );
@@ -477,7 +477,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
Map<String, String> props = new HashMap<String,String>();
- EntityManager em = getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
Query q = Query.fromQL("select *");
Results results = null;
try {
@@ -502,7 +502,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public boolean updateServiceProperties(Map<String, String> properties) {
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
Query q = Query.fromQL("select *");
Results results = null;
try {
@@ -551,7 +551,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public boolean deleteServiceProperty(String name) {
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = getEntityManager(getManagementAppId());
Query q = Query.fromQL("select *");
@@ -684,7 +684,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void rebuildInternalIndexes( ProgressObserver po ) throws Exception {
- rebuildApplicationIndexes( CpNamingUtils.MANAGEMENT_APPLICATION_ID, po );
+ rebuildApplicationIndexes( getManagementAppId(), po );
}
@@ -699,7 +699,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
em.reindex( po );
- logger.info("\n\nRebuilt index for applicationId {} \n", appId );
+ logger.info("\n\nRebuilt index for applicationId {} \n", appId);
}
@@ -731,7 +731,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
em.reindexCollection( po, collectionName, reverse );
logger.info("\n\nRebuilt index for application {} id {} collection {}\n",
- new Object[] { app.getName(), appId, collectionName } );
+ new Object[]{app.getName(), appId, collectionName});
}
@Override
@@ -746,8 +746,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// could use any collection scope here, does not matter
EntityCollectionManager ecm = getManagerCache().getEntityCollectionManager(
new CollectionScopeImpl(
- new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, "application"),
- new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, "application"),
+ new SimpleId( getManagementAppId(), "application"),
+ new SimpleId( getManagementAppId(), "application"),
"dummy"
));
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 2874ffc..ab70810 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -1662,7 +1662,7 @@ public class ManagementServiceImpl implements ManagementService {
// restore application_info entity
- EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ EntityManager em = emf.getEntityManager( emf.getManagementAppId() );
Entity appInfo = emf.restoreApplication(applicationId);
// restore token
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
index bdfcb61..264c752 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportJob.java
@@ -74,7 +74,7 @@ public class FileImportJob extends OnlyOnceJob {
// update file import record
UUID fileImportId = (UUID) jobExecution.getJobData().getProperty(FILE_IMPORT_ID);
- EntityManager em = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = emf.getEntityManager(emf.getManagementAppId());
FileImport fileImport = em.get(fileImportId, FileImport.class);
fileImport.setState( FileImport.State.FAILED );
em.update( fileImport );
@@ -103,7 +103,7 @@ public class FileImportJob extends OnlyOnceJob {
public void dead( final JobExecution execution ) throws Exception {
// Get the root entity manager
- EntityManager rootEm = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId() );
// Mark the sub-job i.e. File Import Job as Failed
FileImport fileImport = null;//importService.getFileImportEntity(execution);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
index 62c01dc..e1170c3 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/FileImportTracker.java
@@ -105,7 +105,7 @@ public class FileImportTracker {
failedImportEntity.setErrorMessage( message );
try {
- EntityManager entityManager = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager entityManager = emf.getEntityManager(emf.getManagementAppId());
failedImportEntity = entityManager.create( failedImportEntity );
entityManager.createConnection( fileImport, ERRORS_CONNECTION_NAME, failedImportEntity );
}
@@ -136,7 +136,7 @@ public class FileImportTracker {
failedImportConnection.setErrorMessage( message );
try {
- EntityManager entityManager = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager entityManager = emf.getEntityManager(emf.getManagementAppId());
failedImportConnection = entityManager.create( failedImportConnection );
entityManager.createConnection( fileImport, ERRORS_CONNECTION_NAME, failedImportConnection );
}
@@ -309,7 +309,7 @@ public class FileImportTracker {
fileImport.setState( state );
fileImport.setErrorMessage( message );
- EntityManager entityManager = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager entityManager = emf.getEntityManager(emf.getManagementAppId());
entityManager.update( fileImport );
}
catch ( Exception e ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportJob.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportJob.java
index 995850c..4640681 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportJob.java
@@ -73,7 +73,7 @@ public class ImportJob extends OnlyOnceJob {
// update import job record
UUID importId = (UUID) jobExecution.getJobData().getProperty(IMPORT_ID);
- EntityManager mgmtApp = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager mgmtApp = emf.getEntityManager(emf.getManagementAppId());
Import importEntity = mgmtApp.get(importId, Import.class);
importEntity.setState(Import.State.FAILED);
importEntity.setErrorMessage(t.getMessage());
@@ -104,7 +104,7 @@ public class ImportJob extends OnlyOnceJob {
public void dead( final JobExecution execution ) throws Exception {
// marks the job as failed as it will not be retried by the scheduler.
- EntityManager rootEm = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager rootEm = emf.getEntityManager( emf.getManagementAppId());
Import importUG = importService.getImportEntity(execution);
importUG.setErrorMessage("The Job has been tried maximum times but still failed");
importUG.setState(Import.State.FAILED);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
index 120e76e..3c30b39 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
@@ -325,7 +325,7 @@ public class ImportServiceImpl implements ImportService {
EntityManager rootEM;
try {
- rootEM = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ rootEM = emf.getEntityManager(emf.getManagementAppId());
} catch (Exception e) {
logger.error("application doesn't exist within the current context");
return null;
@@ -375,7 +375,7 @@ public class ImportServiceImpl implements ImportService {
try {
- EntityManager rootEM = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ EntityManager rootEM = emf.getEntityManager( emf.getManagementAppId() );
Query query = Query.fromQL( "select *" );
query.setEntityType("file_import");
query.setConnectionType( IMPORT_FILE_INCLUDES_CONNECTION );
@@ -424,7 +424,7 @@ public class ImportServiceImpl implements ImportService {
Preconditions.checkNotNull( uuid, "uuid cannot be null" );
- EntityManager rootEm = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId());
//retrieve the import entity.
Import importUG = rootEm.get(uuid, Import.class);
@@ -450,7 +450,7 @@ public class ImportServiceImpl implements ImportService {
return "UUID passed in cannot be null";
}
- EntityManager rootEm = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager rootEm = emf.getEntityManager(emf.getManagementAppId());
//retrieve the import entity.
Import importUG = rootEm.get(uuid, Import.class);
@@ -473,7 +473,7 @@ public class ImportServiceImpl implements ImportService {
public Import getImportEntity(final JobExecution jobExecution) throws Exception {
UUID importId = (UUID) jobExecution.getJobData().getProperty(IMPORT_ID);
- EntityManager importManager = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager importManager = emf.getEntityManager(emf.getManagementAppId());
return importManager.get(importId, Import.class);
}
@@ -486,7 +486,7 @@ public class ImportServiceImpl implements ImportService {
@Override
public FileImport getFileImportEntity(final JobExecution jobExecution) throws Exception {
UUID fileImportId = (UUID) jobExecution.getJobData().getProperty(FILE_IMPORT_ID);
- EntityManager em = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager em = emf.getEntityManager(emf.getManagementAppId());
return em.get(fileImportId, FileImport.class);
}
@@ -545,7 +545,7 @@ public class ImportServiceImpl implements ImportService {
// get Import Entity from the management app, update it to show that job has started
- final EntityManager rootEM = emf.getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ final EntityManager rootEM = emf.getEntityManager(emf.getManagementAppId());
UUID importId = (UUID) jobExecution.getJobData().getProperty(IMPORT_ID);
Import importEntity = rootEM.get(importId, Import.class);
@@ -679,7 +679,7 @@ public class ImportServiceImpl implements ImportService {
String accessId = (String) storage_info.get( "s3_access_id");
String secretKey = (String) storage_info.get( "s3_key" );
- EntityManager rootEM = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ EntityManager rootEM = emf.getEntityManager( emf.getManagementAppId() );
// get the file import entity
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/test/java/org/apache/usergrid/management/importer/FileImportTrackerTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/importer/FileImportTrackerTest.java b/stack/services/src/test/java/org/apache/usergrid/management/importer/FileImportTrackerTest.java
index 158f3b8..fab62ca 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/importer/FileImportTrackerTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/importer/FileImportTrackerTest.java
@@ -58,7 +58,7 @@ public class FileImportTrackerTest {
final EntityManagerFactory emf = mock( EntityManagerFactory.class );
final EntityManager em = mock( EntityManager.class );
- when( emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ).thenReturn( em );
+ when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
final UUID importFileId = UUIDGenerator.newTimeUUID();
@@ -101,7 +101,7 @@ public class FileImportTrackerTest {
final EntityManagerFactory emf = mock( EntityManagerFactory.class );
final EntityManager em = mock( EntityManager.class );
- when( emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ).thenReturn( em );
+ when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
// create tracker and call its entityWritten() and entityFailed() methods some number of times
@@ -171,7 +171,7 @@ public class FileImportTrackerTest {
final EntityManagerFactory emf = mock( EntityManagerFactory.class );
final EntityManager em = mock( EntityManager.class );
- when( emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ).thenReturn( em );
+ when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
final UUID importFileId = UUIDGenerator.newTimeUUID();
@@ -218,7 +218,7 @@ public class FileImportTrackerTest {
final EntityManagerFactory emf = mock( EntityManagerFactory.class );
final EntityManager em = mock( EntityManager.class );
- when( emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ).thenReturn( em );
+ when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
final UUID importFileId = UUIDGenerator.newTimeUUID();
@@ -333,7 +333,7 @@ public class FileImportTrackerTest {
final EntityManagerFactory emf = mock( EntityManagerFactory.class );
final EntityManager em = mock( EntityManager.class );
- when( emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ).thenReturn( em );
+ when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
final UUID importFileId = UUIDGenerator.newTimeUUID();
@@ -368,7 +368,7 @@ public class FileImportTrackerTest {
final EntityManagerFactory emf = mock( EntityManagerFactory.class );
final EntityManager em = mock( EntityManager.class );
- when( emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID ) ).thenReturn( em );
+ when( emf.getEntityManager( emf.getManagementAppId() ) ).thenReturn( em );
final UUID importFileId = UUIDGenerator.newTimeUUID();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/50cb3bf5/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportConnectionsTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportConnectionsTest.java b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportConnectionsTest.java
index 192e784..5e6651c 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportConnectionsTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportConnectionsTest.java
@@ -93,8 +93,7 @@ public class ImportConnectionsTest {
final int connectionCount = 15;
- EntityManager emMgmtApp = setup.getEmf()
- .getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ EntityManager emMgmtApp = setup.getEmf().getEntityManager(setup.getEmf().getManagementAppId());
Import importEntity = new Import();
importEntity = emMgmtApp.create( importEntity );
@@ -134,7 +133,7 @@ public class ImportConnectionsTest {
try {
EntityManager emMgmtApp = setup.getEmf()
- .getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ .getEntityManager(setup.getEmf().getManagementAppId() );
Results entities = emMgmtApp.getConnectedEntities(
importRoot, "includes", null, Query.Level.ALL_PROPERTIES );
@@ -158,7 +157,7 @@ public class ImportConnectionsTest {
try {
EntityManager emMgmtApp = setup.getEmf()
- .getEntityManager(CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ .getEntityManager(setup.getEmf().getManagementAppId() );
Query query = Query.fromQL("select *");
query.setEntityType("file_import");
[38/50] incubator-usergrid git commit: Merge branch 'USERGRID-405' of
git://git.apache.org/incubator-usergrid into USERGRID-405
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' of git://git.apache.org/incubator-usergrid into USERGRID-405
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/665a1708
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/665a1708
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/665a1708
Branch: refs/heads/two-dot-o-dev
Commit: 665a17088b459d4415dc1e694f19e9e29a8b5c2a
Parents: e60ffeb a40fb8d
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 18:19:40 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 18:19:40 2015 -0400
----------------------------------------------------------------------
.../batch/service/SchedulerServiceImpl.java | 17 +-
.../corepersistence/CpEntityManager.java | 41 +-
.../corepersistence/CpEntityManagerFactory.java | 50 +-
.../corepersistence/CpManagerCache.java | 6 +-
.../corepersistence/CpRelationManager.java | 19 +-
.../usergrid/corepersistence/CpSetup.java | 6 +-
.../usergrid/corepersistence/ManagerCache.java | 3 +-
.../events/EntityDeletedHandler.java | 3 +-
.../events/EntityVersionDeletedHandler.java | 4 +-
.../results/FilteringLoader.java | 3 +-
.../usergrid/persistence/EntityManager.java | 19 +-
.../persistence/EntityManagerFactory.java | 2 -
.../cassandra/EntityManagerFactoryImpl.java | 5 -
.../cassandra/EntityManagerImpl.java | 20 +-
.../org/apache/usergrid/CoreApplication.java | 24 +-
.../java/org/apache/usergrid/CoreITSetup.java | 6 +
.../org/apache/usergrid/CoreITSetupImpl.java | 27 +-
.../org/apache/usergrid/TestEntityIndex.java | 27 +
.../corepersistence/StaleIndexCleanupTest.java | 87 ++--
.../usergrid/persistence/CollectionIT.java | 80 +--
.../usergrid/persistence/CountingMutatorIT.java | 4 +-
.../persistence/EntityConnectionsIT.java | 14 +-
.../usergrid/persistence/EntityManagerIT.java | 16 +-
.../org/apache/usergrid/persistence/GeoIT.java | 26 +-
.../persistence/GeoQueryBooleanTest.java | 4 +-
.../apache/usergrid/persistence/IndexIT.java | 14 +-
.../usergrid/persistence/PathQueryIT.java | 6 +-
.../PerformanceEntityRebuildIndexTest.java | 35 +-
.../usergrid/persistence/PermissionsIT.java | 4 +-
.../cassandra/EntityManagerFactoryImplIT.java | 4 +-
.../persistence/query/CollectionIoHelper.java | 2 +-
.../persistence/query/ConnectionHelper.java | 2 +-
.../query/IntersectionTransitivePagingIT.java | 2 +-
.../query/IntersectionUnionPagingIT.java | 2 +-
.../persistence/query/IteratingQueryIT.java | 34 +-
.../resources/usergrid-custom-test.properties | 1 +
stack/corepersistence/queryindex/pom.xml | 57 +--
.../persistence/index/AliasedEntityIndex.java | 7 +-
.../index/ApplicationEntityIndex.java | 50 ++
.../usergrid/persistence/index/EntityIndex.java | 46 +-
.../persistence/index/EntityIndexBatch.java | 5 +
.../persistence/index/EntityIndexFactory.java | 2 +-
.../persistence/index/IndexIdentifier.java | 26 +-
.../usergrid/persistence/index/SearchType.java | 49 ++
.../usergrid/persistence/index/SearchTypes.java | 14 +-
.../persistence/index/guice/IndexModule.java | 5 +-
.../impl/EsApplicationEntityIndexImpl.java | 371 ++++++++++++++
.../index/impl/EsEntityIndexBatchImpl.java | 80 ++-
.../index/impl/EsEntityIndexFactoryImpl.java | 27 +-
.../index/impl/EsEntityIndexImpl.java | 490 ++++---------------
.../persistence/index/impl/EsQueryVistor.java | 88 ++--
.../persistence/index/impl/IndexingUtils.java | 140 +++---
.../usergrid/persistence/index/query/Query.java | 6 +-
.../persistence/index/guice/IndexTestFig.java | 7 +-
.../index/impl/CorePerformanceIT.java | 0
.../impl/EntityConnectionIndexImplTest.java | 0
.../persistence/index/impl/EntityIndexTest.java | 181 +++----
.../index/impl/IndexLoadTestsIT.java | 328 +++++++++++--
.../usergrid/rest/AbstractContextResource.java | 102 ++--
.../org/apache/usergrid/rest/IndexResource.java | 2 +-
.../rest/test/RefreshIndexResource.java | 17 +-
.../resources/usergrid-custom-test.properties | 2 +
.../org/apache/usergrid/ServiceApplication.java | 18 +-
.../apache/usergrid/management/EmailFlowIT.java | 6 +-
.../usergrid/management/OrganizationIT.java | 10 +-
.../org/apache/usergrid/management/RoleIT.java | 4 +-
.../cassandra/ManagementServiceIT.java | 22 +-
.../management/export/ExportServiceIT.java | 12 +-
.../management/importer/ImportCollectionIT.java | 15 +-
.../usergrid/services/ConnectionsServiceIT.java | 10 +-
.../usergrid/services/GroupServiceIT.java | 6 +-
.../usergrid/services/RolesServiceIT.java | 2 +-
.../usergrid/services/UsersServiceIT.java | 2 +-
.../AbstractServiceNotificationIT.java | 2 +-
.../apns/NotificationsServiceIT.java | 40 +-
.../gcm/NotificationsServiceIT.java | 4 +-
.../resources/usergrid-custom-test.properties | 2 +
77 files changed, 1639 insertions(+), 1237 deletions(-)
----------------------------------------------------------------------
[46/50] incubator-usergrid git commit: Strings in where clause must
be quoted
Posted by sn...@apache.org.
Strings in where clause must be quoted
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2eca36f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2eca36f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2eca36f0
Branch: refs/heads/two-dot-o-dev
Commit: 2eca36f0af78b61bab24acafbb5bc8858cfe40cf
Parents: efb7d6f
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 30 09:48:37 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 30 09:48:37 2015 -0400
----------------------------------------------------------------------
.../apache/usergrid/corepersistence/CpEntityManagerFactory.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2eca36f0/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 9b7b2bb..e2e43ca 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
@@ -359,7 +359,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
final Results results = em.searchCollection(
em.getApplicationRef(), CpNamingUtils.DELETED_APPLICATION_INFOS,
- Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = " + applicationId.toString()));
+ Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = '" + applicationId.toString() + "'"));
Entity deletedAppInfo = results.getEntity();
if ( deletedAppInfo == null ) {
[23/50] incubator-usergrid git commit: Ensure that old System App is
still included here, so that it's entities get migrated too.
Posted by sn...@apache.org.
Ensure that old System App is still included here, so that it's entities get migrated too.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/fd43a1d1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/fd43a1d1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/fd43a1d1
Branch: refs/heads/two-dot-o-dev
Commit: fd43a1d1d51b075cfa551b9e00a10180232381cc
Parents: f4f17d6
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 13 10:33:05 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 13 10:33:05 2015 -0400
----------------------------------------------------------------------
.../corepersistence/rx/impl/AllApplicationsObservableImpl.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fd43a1d1/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
index f48b930..7f2b27d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
@@ -74,7 +74,9 @@ public class AllApplicationsObservableImpl implements AllApplicationsObservable
//emit our hard coded applications that are used the manage the system first.
//this way consumers can perform whatever work they need to on the root system first
final Observable<ApplicationScope> systemIds = Observable.from(
- Arrays.asList( getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID )));
+ Arrays.asList(
+ getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID ),
+ getApplicationScope( CpNamingUtils.SYSTEM_APP_ID ))); // still need deprecated system app here
final ApplicationScope appScope = getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
@@ -87,7 +89,6 @@ public class AllApplicationsObservableImpl implements AllApplicationsObservable
final GraphManager gm = graphManagerFactory.createEdgeManager(appScope);
-
String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS );
Id rootAppId = appScope.getApplication();
[22/50] incubator-usergrid git commit: Need to look for old appinfos
in the (old and now deprecated) Sytem App, not the Management App.
Posted by sn...@apache.org.
Need to look for old appinfos in the (old and now deprecated) Sytem App, not the Management App.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f4f17d68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f4f17d68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f4f17d68
Branch: refs/heads/two-dot-o-dev
Commit: f4f17d68d350d15565e9eccdfeb745cf27eeb96b
Parents: 50cb3bf
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 13 09:59:38 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 13 09:59:38 2015 -0400
----------------------------------------------------------------------
.../migration/AppInfoMigrationPlugin.java | 11 ++++---
.../corepersistence/util/CpNamingUtils.java | 4 +++
.../org/apache/usergrid/ServiceITSetup.java | 3 ++
.../org/apache/usergrid/ServiceITSetupImpl.java | 34 ++++++++++++++------
.../migration/AppInfoMigrationPluginTest.java | 24 ++++++++------
.../src/test/resources/log4j.properties | 6 ++--
.../setup/ConcurrentProcessSingleton.java | 20 ++++++++----
7 files changed, 71 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/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 59fafd5..3d386d9 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
@@ -52,7 +52,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
public static String PLUGIN_NAME = "appinfo-migration";
@Inject
- private MigrationInfoSerialization migrationInfoSerialization;
+ protected MigrationInfoSerialization migrationInfoSerialization;
@Inject
protected EntityManagerFactory emf; // protected for test purposes only
@@ -74,12 +74,13 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
observer.start();
- EntityManager em = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ // Search the old and now deprecated System App for appinfo entities
+ EntityManager systemAppEm = emf.getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
Query q = Query.fromQL("select *");
Results results;
try {
- results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
+ results = systemAppEm.searchCollection(systemAppEm.getApplicationRef(), "appinfos", q);
} catch (Exception e) {
logger.error("Error reading old appinfos collection, not migrating", e);
return;
@@ -87,10 +88,10 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
if ( !results.isEmpty() ) {
- // applications still found in old appinfos collection, migrate them.
+ // we found appinfos, let's migrate them to application_infos in the Management App
+ EntityManager em = emf.getEntityManager( emf.getManagementAppId());
String currentAppName = null;
-
try {
logger.info("Migrating old appinfos");
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 356367b..7fa6bea 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -49,6 +49,10 @@ public class CpNamingUtils {
public static final UUID MANAGEMENT_APPLICATION_ID =
UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
+ /** Old and deprecated SYSTEM_APP */
+ public static final UUID SYSTEM_APP_ID =
+ UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
+
/**
* Information about applications is stored in the management app using these types
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
index 2a04c52..b4d43b4 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
@@ -17,6 +17,7 @@
package org.apache.usergrid;
+import org.apache.usergrid.corepersistence.migration.AppInfoMigrationPlugin;
import org.apache.usergrid.management.ApplicationCreator;
import org.apache.usergrid.management.ManagementService;
import org.apache.usergrid.management.export.ExportService;
@@ -63,4 +64,6 @@ public interface ServiceITSetup extends CoreITSetup {
String get( String key );
SignInProviderFactory getProviderFactory();
+
+ AppInfoMigrationPlugin getAppInfoMigrationPlugin();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
index cb7040b..04f1e49 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
@@ -19,6 +19,8 @@ package org.apache.usergrid;
import java.util.Properties;
+import org.apache.usergrid.corepersistence.GuiceFactory;
+import org.apache.usergrid.corepersistence.migration.AppInfoMigrationPlugin;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
@@ -45,7 +47,7 @@ import java.util.Properties;
/** A {@link org.junit.rules.TestRule} that sets up services. */
public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetup {
- private static final Logger LOG = LoggerFactory.getLogger( ServiceITSetupImpl.class );
+ private static final Logger logger = LoggerFactory.getLogger( ServiceITSetupImpl.class );
private ServiceManagerFactory smf;
private ManagementService managementService;
@@ -55,18 +57,27 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu
private Properties properties;
private ExportService exportService;
private ImportService importService;
+ private AppInfoMigrationPlugin appInfoMigrationPlugin;
public ServiceITSetupImpl() {
super();
- managementService = springResource.getBean( ManagementService.class );
+
+ managementService = springResource.getBean( ManagementService.class );
applicationCreator = springResource.getBean( ApplicationCreator.class );
- tokenService = springResource.getBean( TokenService.class );
- providerFactory = springResource.getBean( SignInProviderFactory.class );
- properties = springResource.getBean( "properties", Properties.class );
- smf = springResource.getBean( ServiceManagerFactory.class );
- exportService = springResource.getBean( ExportService.class );
- importService = springResource.getBean( ImportService.class );
+ tokenService = springResource.getBean( TokenService.class );
+ providerFactory = springResource.getBean( SignInProviderFactory.class );
+ properties = springResource.getBean( "properties", Properties.class );
+ smf = springResource.getBean( ServiceManagerFactory.class );
+ exportService = springResource.getBean( ExportService.class );
+ importService = springResource.getBean( ImportService.class );
+
+ try {
+ appInfoMigrationPlugin = springResource.getBean(GuiceFactory.class)
+ .getObject().getInstance(AppInfoMigrationPlugin.class);
+ } catch ( Exception e ) {
+ logger.error("Unable to instantiate AppInfoMigrationPlugin", e);
+ }
//set our security manager for shiro
SecurityUtils.setSecurityManager(springResource.getBean( org.apache.shiro.mgt.SecurityManager.class ));
@@ -75,7 +86,7 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu
protected void after( Description description ) {
super.after( description );
- LOG.info( "Test {}: finish with application", description.getDisplayName() );
+ logger.info( "Test {}: finish with application", description.getDisplayName() );
}
@@ -163,4 +174,9 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu
public SignInProviderFactory getProviderFactory() {
return providerFactory;
}
+
+ @Override
+ public AppInfoMigrationPlugin getAppInfoMigrationPlugin() {
+ return appInfoMigrationPlugin;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/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 30b7a3c..d0fa848 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
@@ -23,8 +23,10 @@ import org.apache.usergrid.NewOrgAppAdminRule;
import org.apache.usergrid.ServiceITSetup;
import org.apache.usergrid.ServiceITSetupImpl;
import org.apache.usergrid.cassandra.ClearShiroSubject;
+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.core.migration.data.ProgressObserver;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.persistence.index.query.Query;
@@ -35,11 +37,12 @@ import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.UUID;
-import static org.apache.usergrid.TestHelper.uniqueEmail;
-import static org.apache.usergrid.TestHelper.uniqueOrg;
-import static org.apache.usergrid.TestHelper.uniqueUsername;
+import static org.apache.usergrid.TestHelper.*;
import static org.junit.Assert.*;
@@ -100,6 +103,11 @@ public class AppInfoMigrationPluginTest {
List<Entity> deletedApps = new ArrayList<>();
+ setup.getEmf().initializeApplicationV2(
+ CassandraService.DEFAULT_ORGANIZATION, CpNamingUtils.SYSTEM_APP_ID, "systemapp", null);
+
+ EntityManager systemAppEm = setup.getEmf().getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
+
int count = 0;
for ( UUID appId : appIds ) {
@@ -108,7 +116,7 @@ public class AppInfoMigrationPluginTest {
final String appName = applicationInfo.getName();
final String finalOrgId = organization.getOrganization().getUuid().toString();
final String finalAppId = applicationInfo.getProperty( Schema.PROPERTY_APPLICATION_ID ).toString();
- rootEm.create("appinfo", new HashMap<String, Object>() {{
+ systemAppEm.create("appinfo", new HashMap<String, Object>() {{
put("name", appName );
put("organizationUuid", finalOrgId );
put("applicationUuid", finalAppId );
@@ -130,16 +138,14 @@ public class AppInfoMigrationPluginTest {
// test that applications are now broken
- checkApplicationsBroken( orgName, deletedApps );
+ checkApplicationsBroken(orgName, deletedApps);
// run the migration, which should restore the application_info entities
logger.debug("\n\nRun the migration\n");
ProgressObserver po = Mockito.mock(ProgressObserver.class);
- AppInfoMigrationPlugin plugin = new AppInfoMigrationPlugin();
- plugin.emf = setup.getEmf();
- plugin.run( po );
+ setup.getAppInfoMigrationPlugin().run(po);
logger.debug("\n\nVerify migration results\n");
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/services/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/log4j.properties b/stack/services/src/test/resources/log4j.properties
index e1c378f..07e2dde 100644
--- a/stack/services/src/test/resources/log4j.properties
+++ b/stack/services/src/test/resources/log4j.properties
@@ -26,7 +26,7 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n
-log4j.logger.org.apache.usergrid=WARN
+log4j.logger.org.apache.usergrid=INFO
log4j.logger.org.apache.usergrid.persistence.cassandra.DB=WARN, stdout
log4j.logger.org.apache.usergrid.persistence.cassandra.BATCH=WARN, stdout
@@ -55,10 +55,12 @@ log4j.logger.org.apache.usergrid.locking.singlenode.SingleNodeLockManagerImpl=DE
#log4j.logger.org.apache.cassandra.service.StorageProxy=DEBUG, stdout
#log4j.logger.org.apache.usergrid.corepersistence=DEBUG
-
#log4j.logger.org.apache.usergrid.persistence.index=DEBUG
#log4j.logger.org.apache.usergrid.batch=DEBUG
#log4j.logger.org.apache.usergrid.management.export=DEBUG
#log4j.logger.org.apache.usergrid.management.importer=DEBUG
+log4j.logger.org.apache.usergrid.corepersistence.migration=DEBUG
+log4j.logger.org.apache.usergrid.persistence.core.migration.data=DEBUG
+
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f4f17d68/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index e8c5ace..66e5d12 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@ -28,6 +28,9 @@ import org.apache.usergrid.cassandra.SpringResource;
import org.apache.usergrid.lock.MultiProcessBarrier;
import org.apache.usergrid.lock.MultiProcessLocalLock;
+import java.io.IOException;
+import java.util.concurrent.TimeoutException;
+
/**
* A singleton that starts cassandra and configures it once per JVM
@@ -75,6 +78,7 @@ public class ConcurrentProcessSingleton {
try {
logger.info( "Trying to get a lock to setup system" );
+
//we have a lock, so init the system
if ( lock.tryLock() ) {
@@ -96,18 +100,22 @@ public class ConcurrentProcessSingleton {
logger.info("Populating database");
schemaManager.populateBaseData();
-
//signal to other processes we've migrated, and they can proceed
barrier.proceed();
- }
+ logger.info( "Waiting for setup to complete" );
+ barrier.await( ONE_MINUTE );
+ logger.info( "Setup to complete" );
- logger.info( "Waiting for setup to complete" );
- barrier.await( ONE_MINUTE );
- logger.info( "Setup to complete" );
+ lock.maybeReleaseLock();
+
+ } else {
+ throw new RuntimeException( "Unable to initialize system: could not get lock."
+ +" Some other process must be binding to port " + LOCK_PORT );
+ }
- lock.maybeReleaseLock();
}
+
catch ( Exception e ) {
throw new RuntimeException( "Unable to initialize system", e );
}
[27/50] incubator-usergrid git commit: Use available-port finder to
avoid conflicts.
Posted by sn...@apache.org.
Use available-port finder to avoid conflicts.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9f3bb94d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9f3bb94d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9f3bb94d
Branch: refs/heads/two-dot-o-dev
Commit: 9f3bb94ddb16381c425552a4ebf1cb7c23903cab
Parents: 285230f
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 16 13:47:20 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 16 13:47:20 2015 -0400
----------------------------------------------------------------------
.../org/apache/usergrid/setup/ConcurrentProcessSingleton.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9f3bb94d/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index 66e5d12..c5d9a71 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@ -20,6 +20,7 @@
package org.apache.usergrid.setup;
+import org.apache.usergrid.persistence.core.util.AvailablePortFinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +42,7 @@ public class ConcurrentProcessSingleton {
private static final String TEMP_FILE_PATH =
"target/surefirelocks/start_barrier-" + System.getProperty( "test.barrier.timestamp", "default" );
- public static final int LOCK_PORT = Integer.parseInt( System.getProperty( "test.lock.port", "10101" ) );
+ public static final int LOCK_PORT = AvailablePortFinder.getNextAvailable();
public static final boolean CLEAN_STORAGE =
Boolean.parseBoolean( System.getProperty( "test.clean.storage", "false" ) );
[24/50] incubator-usergrid git commit: Use constants for Group type
and collection names instead of quoted strings.
Posted by sn...@apache.org.
Use constants for Group type and collection names instead of quoted strings.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/055eb916
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/055eb916
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/055eb916
Branch: refs/heads/two-dot-o-dev
Commit: 055eb91685f0f6ec0e2356964e4ab49119d52230
Parents: fd43a1d
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 13 11:42:55 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 13 11:42:55 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 5 +--
.../cassandra/ManagementServiceImpl.java | 42 ++++++++++----------
2 files changed, 24 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/055eb916/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 36bbd12..010672e 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
@@ -634,7 +634,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// refresh special indexes without calling EntityManager refresh because stack overflow
maybeCreateIndexes();
- // system app
for ( EntityIndex index : getManagementIndexes() ) {
index.refresh();
@@ -643,7 +642,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private void maybeCreateIndexes() {
- // system app
if ( indexInitialized.getAndSet( true ) ) {
return;
}
@@ -684,7 +682,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void rebuildInternalIndexes( ProgressObserver po ) throws Exception {
- rebuildApplicationIndexes( getManagementAppId(), po );
+ rebuildApplicationIndexes( CpNamingUtils.SYSTEM_APP_ID, po);
+ rebuildApplicationIndexes( CpNamingUtils.MANAGEMENT_APPLICATION_ID, po );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/055eb916/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index ab70810..43617c4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -386,7 +386,7 @@ public class ManagementServiceImpl implements ManagementService {
}
} );
- sm.newRequest( ServiceAction.POST, parameters( "groups", organizationId, "activities" ), payload( properties ) )
+ sm.newRequest( ServiceAction.POST, parameters( Schema.COLLECTION_GROUPS, organizationId, "activities" ), payload( properties ) )
.execute().getEntity();
}
@@ -394,7 +394,7 @@ public class ManagementServiceImpl implements ManagementService {
@Override
public ServiceResults getOrganizationActivity( OrganizationInfo organization ) throws Exception {
ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
- return sm.newRequest( ServiceAction.GET, parameters( "groups", organization.getUuid(), "feed" ) ).execute();
+ return sm.newRequest( ServiceAction.GET, parameters( Schema.COLLECTION_GROUPS, organization.getUuid(), "feed" ) ).execute();
}
@@ -403,7 +403,7 @@ public class ManagementServiceImpl implements ManagementService {
throws Exception {
ServiceManager sm = smf.getServiceManager( smf.getManagementAppId() );
return sm.newRequest( ServiceAction.GET,
- parameters( "groups", organization.getUuid(), "users", user.getUuid(), "feed" ) ).execute();
+ parameters( Schema.COLLECTION_GROUPS, organization.getUuid(), "users", user.getUuid(), "feed" ) ).execute();
}
@@ -452,7 +452,7 @@ public class ManagementServiceImpl implements ManagementService {
* node is trying to set the property do a different value
*/
Lock groupLock =
- getUniqueUpdateLock( lockManager, smf.getManagementAppId(), organizationName, "groups", PROPERTY_PATH );
+ getUniqueUpdateLock( lockManager, smf.getManagementAppId(), organizationName, Schema.COLLECTION_GROUPS, PROPERTY_PATH );
Lock userLock = getUniqueUpdateLock( lockManager, smf.getManagementAppId(), username, "users", "username" );
@@ -467,8 +467,8 @@ public class ManagementServiceImpl implements ManagementService {
userLock.lock();
emailLock.lock();
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- if ( !em.isPropertyValueUniqueForEntity( "group", PROPERTY_PATH, organizationName ) ) {
- throw new DuplicateUniquePropertyExistsException( "group", PROPERTY_PATH, organizationName );
+ if ( !em.isPropertyValueUniqueForEntity( Group.ENTITY_TYPE, PROPERTY_PATH, organizationName ) ) {
+ throw new DuplicateUniquePropertyExistsException( Group.ENTITY_TYPE, PROPERTY_PATH, organizationName );
}
if ( !validateAdminInfo( username, name, email, password ) ) {
return null;
@@ -558,11 +558,12 @@ public class ManagementServiceImpl implements ManagementService {
return null;
}
- Lock groupLock =
- getUniqueUpdateLock( lockManager, smf.getManagementAppId(), organizationName, "groups", PROPERTY_PATH );
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- if ( !em.isPropertyValueUniqueForEntity( "group", PROPERTY_PATH, organizationName ) ) {
- throw new DuplicateUniquePropertyExistsException( "group", PROPERTY_PATH, organizationName );
+ Lock groupLock = getUniqueUpdateLock(
+ lockManager, smf.getManagementAppId(), organizationName, Schema.COLLECTION_GROUPS, PROPERTY_PATH );
+
+ EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+ if ( !em.isPropertyValueUniqueForEntity( Group.ENTITY_TYPE, PROPERTY_PATH, organizationName ) ) {
+ throw new DuplicateUniquePropertyExistsException( Group.ENTITY_TYPE, PROPERTY_PATH, organizationName );
}
try {
groupLock.lock();
@@ -599,8 +600,8 @@ public class ManagementServiceImpl implements ManagementService {
Map<String, Object> properties ) throws Exception {
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- if ( !em.isPropertyValueUniqueForEntity( "group", PROPERTY_PATH, organizationInfo.getName() ) ) {
- throw new DuplicateUniquePropertyExistsException( "group", PROPERTY_PATH, organizationInfo.getName() );
+ if ( !em.isPropertyValueUniqueForEntity( Group.ENTITY_TYPE, PROPERTY_PATH, organizationInfo.getName() ) ) {
+ throw new DuplicateUniquePropertyExistsException( Group.ENTITY_TYPE, PROPERTY_PATH, organizationInfo.getName() );
}
if ( properties == null ) {
properties = new HashMap<String, Object>();
@@ -660,9 +661,9 @@ public class ManagementServiceImpl implements ManagementService {
public List<OrganizationInfo> getOrganizations( UUID startResult, int count ) throws Exception {
// still need the bimap to search for existing
BiMap<UUID, String> organizations = HashBiMap.create();
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+ EntityManager em = emf.getEntityManager(smf.getManagementAppId());
Results results =
- em.getCollection( em.getApplicationRef(), "groups", startResult, count, Level.ALL_PROPERTIES, false );
+ em.getCollection(em.getApplicationRef(), Schema.COLLECTION_GROUPS, startResult, count, Level.ALL_PROPERTIES, false);
List<OrganizationInfo> orgs = new ArrayList<OrganizationInfo>( results.size() );
OrganizationInfo orgInfo;
for ( Entity entity : results.getEntities() ) {
@@ -715,7 +716,7 @@ public class ManagementServiceImpl implements ManagementService {
}
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- EntityRef ref = em.getAlias( "group", organizationName );
+ EntityRef ref = em.getAlias( Group.ENTITY_TYPE, organizationName );
if ( ref == null ) {
return null;
}
@@ -1205,7 +1206,7 @@ public class ManagementServiceImpl implements ManagementService {
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
Results orgResults = em.getCollection( new SimpleEntityRef( User.ENTITY_TYPE, userId ),
- "groups", null, 10000, Level.REFS, false );
+ Schema.COLLECTION_GROUPS, null, 10000, Level.REFS, false );
logger.debug( " orgResults.size() = " + orgResults.size() );
@@ -1445,8 +1446,9 @@ public class ManagementServiceImpl implements ManagementService {
BiMap<UUID, String> organizations = HashBiMap.create();
EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
- Results results = em.getCollection( new SimpleEntityRef( User.ENTITY_TYPE, userId ), "groups", null, 10000,
- Level.ALL_PROPERTIES, false );
+ Results results = em.getCollection(
+ new SimpleEntityRef( User.ENTITY_TYPE, userId ), Schema.COLLECTION_GROUPS, null, 10000,
+ Level.ALL_PROPERTIES, false );
String path = null;
@@ -1712,7 +1714,7 @@ public class ManagementServiceImpl implements ManagementService {
Results r = em.getConnectingEntities(
new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
- "owns", "group", Level.ALL_PROPERTIES );
+ "owns", Group.ENTITY_TYPE, Level.ALL_PROPERTIES );
Entity entity = r.getEntity();
if ( entity != null ) {
[43/50] incubator-usergrid git commit: Merge branch 'two-dot-o' into
USERGRID-405
Posted by sn...@apache.org.
Merge branch 'two-dot-o' into USERGRID-405
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e4466e11
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e4466e11
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e4466e11
Branch: refs/heads/two-dot-o-dev
Commit: e4466e112af89b530e57afc5191835e9ba3673d3
Parents: c0384d5 5937f9f
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 24 12:44:46 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 24 12:44:46 2015 -0400
----------------------------------------------------------------------
.../usergrid/security/providers/PingIdentityProvider.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------
[06/50] incubator-usergrid git commit: Fixes for most of the
ImportResourceIT tests.
Posted by sn...@apache.org.
Fixes for most of the ImportResourceIT tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/531e6590
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/531e6590
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/531e6590
Branch: refs/heads/two-dot-o-dev
Commit: 531e6590a35396ba10df960fa459cb743a0810a0
Parents: c298a45
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 5 13:03:32 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 5 13:03:32 2015 -0500
----------------------------------------------------------------------
.../rest/management/ImportResourceIT.java | 77 ++++++++++++--------
stack/rest/src/test/resources/log4j.properties | 5 +-
.../resources/testImport.testApplication.2.json | 56 ++++++++++++++
.../src/test/resources/testimport-bad-json.json | 67 +++++++++++++++++
.../management/importer/ImportCollectionIT.java | 1 -
5 files changed, 171 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/531e6590/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
index 52a095a..2edeb65 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ImportResourceIT.java
@@ -52,6 +52,7 @@ import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -98,7 +99,7 @@ public class ImportResourceIT extends AbstractRestIT {
@Before
public void before() {
configured =
- !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ))
+ !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ))
&& !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ))
&& !StringUtils.isEmpty(System.getProperty("bucketName"));
@@ -416,11 +417,12 @@ public class ImportResourceIT extends AbstractRestIT {
String org = clientSetup.getOrganizationName();
String app = clientSetup.getAppName();
+ String basePath = System.getProperty("target.directory")
+ + File.separator + "test-classes" + File.separator;
- //list out all the files in the resource directory you want uploaded
- List<String> filenames = new ArrayList<>(1);
+ List<String> filenames = new ArrayList<>( 1 );
+ filenames.add( basePath + "testImportCorrect.testCol.1.json" );
- filenames.add("testImportCorrect.testCol.1.json");
// create 10 applications each with collection of 10 things, export all to S3
S3Upload s3Upload = new S3Upload();
s3Upload.copyToS3(
@@ -432,15 +434,20 @@ public class ImportResourceIT extends AbstractRestIT {
Entity importEntity = importCollection();
- Entity importGet = this.management().orgs().organization( org ).app().addToPath( app )
- .addToPath( "imports" ).addToPath( importEntity.getUuid().toString() ).get();
-
+ Entity importGet = this.management().orgs().organization( org ).app()
+ .addToPath(app)
+ .addToPath( "imports" )
+ .addToPath(importEntity.getUuid().toString())
+ .get();
refreshIndex();
- Entity importGetIncludes = this.management().orgs().organization(org).app().addToPath(app)
- .addToPath("imports" ).addToPath(importEntity.getUuid().toString() )
- .addToPath("files" ).get();
+ Entity importGetIncludes = this.management().orgs().organization(org).app()
+ .addToPath(app)
+ .addToPath("imports")
+ .addToPath(importEntity.getUuid().toString())
+ .addToPath("files")
+ .get();
ApiResponse importGetIncludesResponse = importGetIncludes.getResponse();
@@ -451,7 +458,8 @@ public class ImportResourceIT extends AbstractRestIT {
final Entity includesEntity = importGetIncludesResponse.getEntities().get( 0 );
- assertEquals( "testImportCorrect.testCol.1.json", includesEntity.getAsString( "fileName" ) );
+ assertTrue( includesEntity.getAsString("fileName").endsWith("testImportCorrect.testCol.1.json"));
+
assertEquals(1, includesEntity.get( "importedConnectionCount" ));
assertEquals(1, includesEntity.get( "importedEntityCount" ));
@@ -474,18 +482,20 @@ public class ImportResourceIT extends AbstractRestIT {
*/
@Test
public void testImportOneGoodOneBad() throws Exception {
+
// import from a bad JSON file
Assume.assumeTrue(configured);
String org = clientSetup.getOrganizationName();
String app = clientSetup.getAppName();
+ String basePath = System.getProperty("target.directory")
+ + File.separator + "test-classes" + File.separator;
- //list out all the files in the resource directory you want uploaded
- List<String> filenames = new ArrayList<>(1);
+ List<String> filenames = new ArrayList<>( 2 );
+ filenames.add( basePath + "testImportCorrect.testCol.1.json");
+ filenames.add( basePath + "testImport.testApplication.2.json");
- filenames.add("testImportCorrect.testCol.1.json");
- filenames.add("testImport.testApplication.2.json");
// create 10 applications each with collection of 10 things, export all to S3
S3Upload s3Upload = new S3Upload();
s3Upload.copyToS3(
@@ -497,9 +507,10 @@ public class ImportResourceIT extends AbstractRestIT {
Entity importEntity = importCollection();
- Entity importGet = this.management().orgs().organization(org).app().addToPath(app)
- .addToPath( "imports" ).addToPath(importEntity.getUuid().toString() ).get();
-
+ Entity importGet = this.management().orgs().organization(org).app()
+ .addToPath(app)
+ .addToPath("imports")
+ .addToPath(importEntity.getUuid().toString()).get();
assertNotNull(importGet);
@@ -526,11 +537,12 @@ public class ImportResourceIT extends AbstractRestIT {
String org = clientSetup.getOrganizationName();
String app = clientSetup.getAppName();
+ String basePath = System.getProperty("target.directory")
+ + File.separator + "test-classes" + File.separator;
- //list out all the files in the resource directory you want uploaded
- List<String> filenames = new ArrayList<>(1);
+ List<String> filenames = new ArrayList<>( 1 );
+ filenames.add( basePath + "testimport-bad-json.json");
- filenames.add("testImport.testApplication.2.json");
// create 10 applications each with collection of 10 things, export all to S3
S3Upload s3Upload = new S3Upload();
s3Upload.copyToS3(
@@ -573,12 +585,16 @@ public class ImportResourceIT extends AbstractRestIT {
String org = clientSetup.getOrganizationName();
String app = clientSetup.getAppName();
- //list out all the files in the resource directory you want uploaded
- List<String> filenames = new ArrayList<>(1);
- filenames.add("testImportInvalidJson.testApplication.3.json");
+ String basePath = System.getProperty("target.directory")
+ + File.separator + "test-classes" + File.separator;
+
+ List<String> filenames = new ArrayList<>( 1 );
+ filenames.add( basePath + "testImportInvalidJson.testApplication.3.json");
+
// create 10 applications each with collection of 10 things, export all to S3
S3Upload s3Upload = new S3Upload();
- s3Upload.copyToS3(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ),
+ s3Upload.copyToS3(
+ System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ),
System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ),
bucketName, filenames);
@@ -633,13 +649,10 @@ public class ImportResourceIT extends AbstractRestIT {
while (retries++ < maxRetries) {
- Entity importGet = this.management()
- .orgs()
- .organization(org)
- .app()
- .addToPath(app)
- .addToPath("imports")
- .addToPath(importEntity.getUuid().toString())
+ Entity importGet = this.management().orgs().organization(org).app()
+ .addToPath( app )
+ .addToPath( "imports")
+ .addToPath( importEntity.getUuid().toString() )
.get();
if (importGet.get("state").equals("FINISHED") || importGet.get( "state" ).equals( "FAILED" )) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/531e6590/stack/rest/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/log4j.properties b/stack/rest/src/test/resources/log4j.properties
index 26d4306..4c9c709 100644
--- a/stack/rest/src/test/resources/log4j.properties
+++ b/stack/rest/src/test/resources/log4j.properties
@@ -71,13 +71,14 @@ log4j.logger.org.apache.usergrid.rest.filters.MeteringFilter=ERROR
#log4j.logger.org.apache.usergrid.cassandra.CassandraResource=DEBUG
#log4j.logger.org.apache.usergrid.rest.TomcatResource=INFO
#log4j.logger.org.apache.usergrid.rest=INFO
+log4j.logger.org.apache.usergrid.rest.management=DEBUG
#log4j.logger.org.apache.usergrid.rest.management.users=DEBUG
#log4j.logger.org.apache.usergrid.rest.organizations.users=DEBUG
#log4j.logger.org.apache.usergrid.rest.applications.users.UsersResource=DEBUG
#log4j.logger.org.apache.usergrid.rest.applications.ServiceResource=DEBUG
-log4j.logger.org.apache.usergrid.rest.security=DEBUG
-log4j.logger.org.apache.usergrid.security=DEBUG
+#log4j.logger.org.apache.usergrid.rest.security=DEBUG
+#log4j.logger.org.apache.usergrid.security=DEBUG
#log4j.logger.org.elasticsearch=DEBUG
#log4j.logger.com.netflix.hystrix=DEBUG
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/531e6590/stack/rest/src/test/resources/testImport.testApplication.2.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testImport.testApplication.2.json b/stack/rest/src/test/resources/testImport.testApplication.2.json
new file mode 100644
index 0000000..f45d129
--- /dev/null
+++ b/stack/rest/src/test/resources/testImport.testApplication.2.json
@@ -0,0 +1,56 @@
+[ {
+ "Metadata" : {
+ "uuid" : "589d95fa-ad7c-11e4-98bc-0f85bf181834",
+ "type" : "qtsmagic",
+ "created" : 1423171030223,
+ "modified" : 1423171030223,
+ "email" : "test0@anuff.com",
+ "username" : "billybob0"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "589f91ca-ad7c-11e4-a250-63b6975ea888",
+ "type" : "qtsmagic",
+ "created" : 1423171030236,
+ "modified" : 1423171030236,
+ "email" : "test1@anuff.com",
+ "username" : "billybob1"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "58a1186a-ad7c-11e4-bfc2-89e1e7bff3a8",
+ "type" : "qtsmagic",
+ "created" : 1423171030246,
+ "modified" : 1423171030246,
+ "email" : "test2@anuff.com",
+ "username" : "billybob2"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "58a2c61a-ad7c-11e4-b2be-ab36d8b017f3",
+ "type" : "qtsmagic",
+ "created" : 1423171030257,
+ "modified" : 1423171030257,
+ "email" : "test3@anuff.com",
+ "username" : "billybob3"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+}, {
+ "Metadata" : {
+ "uuid" : "58a44cba-ad7c-11e4-9fe5-fb8577a1f4a5",
+ "type" : "qtsmagic",
+ "created" : 1423171030267,
+ "modified" : 1423171030267,
+ "email" : "test4@anuff.com",
+ "username" : "billybob4"
+ },
+ "connections" : { },
+ "dictionaries" : { }
+} ]
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/531e6590/stack/rest/src/test/resources/testimport-bad-json.json
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/testimport-bad-json.json b/stack/rest/src/test/resources/testimport-bad-json.json
new file mode 100644
index 0000000..b744893
--- /dev/null
+++ b/stack/rest/src/test/resources/testimport-bad-json.json
@@ -0,0 +1,67 @@
+{
+ "collections": {
+ "badjsons": [
+ {
+ "Metadata": {
+ "uuid": "589d95fa-ad7c-11e4-98bc-0f85bf181834",
+ "type": "qtsmagic",
+ "created": 1423171030223,
+ "modified": 1423171030223,
+ "email": "test0@anuff.com",
+ "username": "billybob0"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "589f91ca-ad7c-11e4-a250-63b6975ea888",
+ "type": "qtsmagic",
+ "created": 1423171030236,
+ "modified": 1423171030236,
+ "email": "test1@anuff.com",
+ "username": "billybob1"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "58a1186a-ad7c-11e4-bfc2-89e1e7bff3a8",
+ "type": "qtsmagic",
+ "created": 1423171030246,
+ "modified": 1423171030246,
+ "email": "test2@anuff.com",
+ "username": "billybob2"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ {
+ "Metadata": {
+ "uuid": "58a2c61a-ad7c-11e4-b2be-ab36d8b017f3",
+ "type": "qtsmagic",
+ "created": 1423171030257,
+ "modified": 1423171030257,
+ "email": "test3@anuff.com",
+ "username": "billybob3"
+ },
+ "connections": {},
+ "dictionaries": {}
+ },
+ <INTENTIONALLY BAD JSON>
+ {
+ "Metadata": {
+ "uuid": "58a44cba-ad7c-11e4-9fe5-fb8577a1f4a5",
+ "type": "qtsmagic",
+ "created": 1423171030267,
+ "modified": 1423171030267,
+ "email": "test4@anuff.com",
+ "username": "billybob4"
+ },
+ "connections": {},
+ "dictionaries": {}
+ }
+ ]
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/531e6590/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
index d8e104d..c9aeb9a 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
@@ -375,7 +375,6 @@ public class ImportCollectionIT {
// export and upload a bad JSON file to the S3 bucket
- File cwd = new File(".");
String basePath = System.getProperty("target.directory")
+ File.separator + "test-classes" + File.separator;
[25/50] incubator-usergrid git commit: Do not trust the
organizationUuid stored in the appinfo entities,
it is different from the actual Group UUID that we need. Also,
do not delete appinfos -- just in case.
Posted by sn...@apache.org.
Do not trust the organizationUuid stored in the appinfo entities, it is different from the actual Group UUID that we need. Also, do not delete appinfos -- just in case.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/f8378834
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f8378834
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f8378834
Branch: refs/heads/two-dot-o-dev
Commit: f8378834b9beabd87049bb575edb59b61d25a03c
Parents: 055eb91
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 13 15:06:50 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 13 15:06:50 2015 -0400
----------------------------------------------------------------------
.../migration/AppInfoMigrationPlugin.java | 25 +++++++++-----------
1 file changed, 11 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f8378834/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 3d386d9..1f8f784 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
@@ -90,7 +90,8 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
// we found appinfos, let's migrate them to application_infos in the Management App
- EntityManager em = emf.getEntityManager( emf.getManagementAppId());
+ final EntityManager em = emf.getEntityManager( emf.getManagementAppId());
+
String currentAppName = null;
try {
logger.info("Migrating old appinfos");
@@ -98,9 +99,9 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
for (Entity oldAppInfo : results.getEntities()) {
final String appName = currentAppName = oldAppInfo.getName();
+ final String orgName = appName.split("/")[0];
UUID applicationId;
- UUID organizationId;
Object uuidObject = oldAppInfo.getProperty("applicationUuid");
if (uuidObject instanceof UUID) {
@@ -108,12 +109,6 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
} else {
applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
}
- uuidObject = oldAppInfo.getProperty("organizationUuid");
- if (uuidObject instanceof UUID) {
- organizationId = (UUID) uuidObject;
- } else {
- organizationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
- }
// create and connect new APPLICATION_INFO oldAppInfo to Organization
@@ -133,16 +128,18 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
em.update(appInfo);
observer.update( getMaxVersion(), "Updated existing application_info for " + appName);
}
- em.createConnection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "owns", appInfo);
+
+ // create org->app connections, but not for apps in dummy "usergrid" internal organization
+
+ if ( !orgName.equals("usergrid") ) {
+ EntityRef orgRef = em.getAlias(Group.ENTITY_TYPE, appName.split("/")[0]);
+ em.createConnection(orgRef, "owns", appInfo);
+ }
}
em.refreshIndex();
- // after we've successfully created all of the application_infos, we delete the old appoinfos
-
- for (Entity oldAppInfo : results.getEntities()) {
- em.delete(oldAppInfo);
- }
+ // note that the old appinfos are not deleted
migrationInfoSerialization.setVersion( getName(), getMaxVersion() );
[04/50] incubator-usergrid git commit: Merge branch 'two-dot-o' into
USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'two-dot-o' into USERGRID-448-appinfofix
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/54ce892a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/54ce892a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/54ce892a
Branch: refs/heads/two-dot-o-dev
Commit: 54ce892a49b3bb737c25f19c27d5a15b3fb65a35
Parents: c0d5039 710a1a3
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 5 11:12:27 2015 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 5 11:12:27 2015 -0500
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 26 ++++---
.../corepersistence/CpEntityManagerFactory.java | 19 +++---
.../usergrid/corepersistence/CpWalker.java | 10 ++-
.../persistence/EntityManagerFactory.java | 3 +-
.../cassandra/EntityManagerFactoryImpl.java | 2 +-
.../corepersistence/StaleIndexCleanupTest.java | 34 ++++-----
.../cassandra/EntityManagerFactoryImplIT.java | 55 +++++++++------
.../usergrid/persistence/index/EntityIndex.java | 9 ++-
.../usergrid/persistence/index/IndexFig.java | 2 +-
.../index/IndexOperationMessage.java | 7 +-
.../index/impl/EsEntityIndexImpl.java | 72 ++++++++++++++------
.../index/impl/EsIndexBufferConsumerImpl.java | 27 ++++++--
.../persistence/index/impl/EntityIndexTest.java | 6 +-
stack/pom.xml | 24 ++++---
.../org/apache/usergrid/rest/IndexResource.java | 9 ++-
.../usergrid/rest/JobServiceBoostrap.java | 12 ++++
.../apache/usergrid/rest/AbstractRestIT.java | 8 ++-
.../apache/usergrid/rest/IndexResourceIT.java | 1 +
.../apache/usergrid/rest/SystemResourceIT.java | 60 ++++++++++++++++
.../rest/test/resource2point0/RestClient.java | 5 ++
.../endpoints/DatabaseResource.java | 39 +++++++++++
.../endpoints/SetupResource.java | 46 +++++++++++++
.../endpoints/SystemResource.java | 36 ++++++++++
.../cassandra/ManagementServiceImpl.java | 7 +-
.../services/notifications/QueueListener.java | 11 ++-
.../resources/usergrid-services-context.xml | 3 +-
.../resources/usergrid-custom-test.properties | 3 +
.../usergrid/cassandra/ClearShiroSubject.java | 19 +++---
28 files changed, 422 insertions(+), 133 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 99e07a5,9aa36a0..0144ea8
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -297,20 -310,24 +297,19 @@@ public class CpEntityManagerFactory imp
@Override
public void deleteApplication(UUID applicationId) throws Exception {
- // remove old appinfo Entity, which is in the Management App's appinfos collection
- //throw new UnsupportedOperationException("Delete application not supported");
++ // remove old application info Entity, which is in the Management App's application infos collection
+ EntityManager em = getEntityManager( this.getManagementAppId() );
+ Entity applicationInfo = em.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+ em.delete( applicationInfo );
- // create new Entity in deleted_appinfos collection, with same UUID and properties as deleted appinfo
- // remove old appinfo Entity, which is in the System App's appinfos collection
- EntityManager em = getEntityManager(CpNamingUtils.SYSTEM_APP_ID);
- Query q = Query.fromQL(String.format("select * where applicationUuid = '%s'", applicationId.toString()));
- Results results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
++ // create new Entity in deleted_application_infos collection,
++ // with same UUID and properties as deleted application info
+ em.create( applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, applicationInfo.getProperties() );
- Entity appToDelete = results.getEntity();
- if(appToDelete != null) {
- // create new Entity in deleted_appinfos collection, with same UUID and properties as deleted appinfo
- em.create("deleted_appinfo", appToDelete.getProperties());
- em.delete(appToDelete);
+ em.refreshIndex();
- }
// delete the application's index
- EntityIndex ei = managerCache.getEntityIndex(
- new ApplicationScopeImpl( new SimpleId(applicationId, TYPE_APPLICATION)) );
- EntityIndex ei = managerCache.getEntityIndex(new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
-- ei.deleteIndex();
- em.refreshIndex();
++ managerCache.getEntityIndex( new ApplicationScopeImpl(new SimpleId(applicationId, TYPE_APPLICATION)));
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --cc stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 2f29735,9392d06..463daae
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@@ -122,17 -126,31 +126,32 @@@ public class EntityManagerFactoryImplI
em.refreshIndex();
+ Func2<UUID, Map<String, UUID> ,Boolean> findApps = new Func2<UUID,Map<String, UUID> ,Boolean>() {
+ @Override
+ public Boolean call(UUID applicationId, Map<String, UUID> apps) {
+ boolean found = false;
+ for (String appName : apps.keySet()) {
+ UUID appId = apps.get(appName);
+ if (appId.equals(applicationId)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+ }
+ };
+
boolean found = false;
- Map<String, UUID> deletedApps = emf.getDeletedApplications();
- for ( String appName : deletedApps.keySet() ) {
- UUID appId = deletedApps.get( appName );
- if ( appId.equals( applicationId )) {
- found = true;
+ for(int i=0;i<10;i++){
+ found = findApps.call(applicationId,emf.getDeletedApplications());
+ if(found){
break;
+ } else{
+ Thread.sleep(500);
}
}
- assertTrue("Deleted app not found in deleted apps collection", found );
+
+ assertTrue( "Deleted app must be found in in deleted apps collection", found );
// attempt to get entities in application's collections in various ways should all fail
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/rest/src/test/java/org/apache/usergrid/rest/IndexResourceIT.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54ce892a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
[32/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/68f56dd2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/68f56dd2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/68f56dd2
Branch: refs/heads/two-dot-o-dev
Commit: 68f56dd26762afeacd84eebd8d608ff865354985
Parents: c8fcf2d 774324c
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 09:49:49 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 09:49:49 2015 -0400
----------------------------------------------------------------------
stack/pom.xml | 5 ++--
.../setup/ConcurrentProcessSingleton.java | 28 ++++++++++----------
2 files changed, 16 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f56dd2/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --cc stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index c5d9a71,63aa70d..d8e124f
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@@ -38,11 -36,13 +38,12 @@@ import java.util.concurrent.TimeoutExce
*/
public class ConcurrentProcessSingleton {
+ private static final Logger logger = LoggerFactory.getLogger( ConcurrentProcessSingleton.class );
- private static final String TEMP_FILE_PATH =
- "target/surefirelocks/start_barrier-" + System.getProperty( "test.barrier.timestamp", "default" );
+ private static final String TEMP_FILE_PATH = "target/surefirelocks/start_barrier-"
+ + System.getProperty( "test.barrier.timestamp", "default" );
- public static final int LOCK_PORT = AvailablePortFinder.getNextAvailable();
- public static final int LOCK_PORT = Integer.parseInt(
- System.getProperty( "test.lock.port", "10101" ) );
++ public static final int LOCK_PORT = Integer.parseInt( System.getProperty( "test.lock.port", "10101" ) );
public static final boolean CLEAN_STORAGE =
Boolean.parseBoolean( System.getProperty( "test.clean.storage", "false" ) );
@@@ -101,22 -100,18 +101,24 @@@
logger.info("Populating database");
schemaManager.populateBaseData();
- //signal to other processes we've migrated, and they can proceed
+ // signal to other processes we've migrated, and they can proceed
barrier.proceed();
- }
+ logger.info( "Waiting for setup to complete" );
+ barrier.await( ONE_MINUTE );
+ logger.info( "Setup to complete" );
+
+ lock.maybeReleaseLock();
- logger.info( "Waiting for setup to complete" );
- barrier.await( ONE_MINUTE );
- logger.info( "Setup to complete" );
+ } else {
+ throw new RuntimeException( "Unable to initialize system: could not get lock."
+ +" Some other process must be binding to port " + LOCK_PORT );
+ }
+ // Commented out: Never release the lock, otherwise some other JVM may destroy the schema
+ // lock.maybeReleaseLock();
}
+
catch ( Exception e ) {
throw new RuntimeException( "Unable to initialize system", e );
}
[35/50] incubator-usergrid git commit: Match what is in 405.
Posted by sn...@apache.org.
Match what is in 405.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3b71f5e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3b71f5e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3b71f5e3
Branch: refs/heads/two-dot-o-dev
Commit: 3b71f5e373a96eb7503ae5de2b82265559957996
Parents: e47555e
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 11:08:45 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 11:08:45 2015 -0400
----------------------------------------------------------------------
.../usergrid/setup/ConcurrentProcessSingleton.java | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3b71f5e3/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index 64a2f7a..7cb5073 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@ -40,7 +40,8 @@ public class ConcurrentProcessSingleton {
private static final String TEMP_FILE_PATH = "target/surefirelocks/start_barrier-"
+ System.getProperty( "test.barrier.timestamp", "default" );
- public static final int LOCK_PORT = Integer.parseInt( System.getProperty( "test.lock.port", "10101" ) );
+ public static final int LOCK_PORT = Integer.parseInt(
+ System.getProperty( "test.lock.port", "10101" ) );
public static final boolean CLEAN_STORAGE =
Boolean.parseBoolean( System.getProperty( "test.clean.storage", "false" ) );
@@ -100,17 +101,12 @@ public class ConcurrentProcessSingleton {
// signal to other processes we've migrated, and they can proceed
barrier.proceed();
+ }
- logger.info( "Waiting for setup to complete" );
- barrier.await( ONE_MINUTE );
- logger.info( "Setup to complete" );
-
- lock.maybeReleaseLock();
- } else {
- throw new RuntimeException( "Unable to initialize system: could not get lock."
- +" Some other process must be binding to port " + LOCK_PORT );
- }
+ logger.info( "Waiting for setup to complete" );
+ barrier.await( ONE_MINUTE );
+ logger.info( "Setup to complete" );
Runtime.getRuntime().addShutdownHook( new Thread( ){
@Override
@@ -125,7 +121,6 @@ public class ConcurrentProcessSingleton {
});
}
-
catch ( Exception e ) {
throw new RuntimeException( "Unable to initialize system", e );
}
[48/50] incubator-usergrid git commit: Merge branch 'two-dot-o' into
two-dot-o-dev
Posted by sn...@apache.org.
Merge branch 'two-dot-o' 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/a099d0fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a099d0fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a099d0fc
Branch: refs/heads/two-dot-o-dev
Commit: a099d0fcd198b83c07551324d2516e068a20b159
Parents: 6db7ce9 2d1c8b8
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 30 09:58:07 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 30 09:58:07 2015 -0400
----------------------------------------------------------------------
.../index/impl/EsIndexBufferConsumerImpl.java | 39 +++++++-------------
1 file changed, 14 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
[31/50] incubator-usergrid git commit: JVM that does the keyspace
should hold the lock forever and ever, amen.
Posted by sn...@apache.org.
JVM that does the keyspace should hold the lock forever and ever, amen.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/774324cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/774324cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/774324cd
Branch: refs/heads/two-dot-o-dev
Commit: 774324cd5672495a49b37c042f791a2fed3940be
Parents: f1bf035
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Mar 19 21:40:01 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Mar 19 21:40:01 2015 -0400
----------------------------------------------------------------------
stack/pom.xml | 5 ++-
.../setup/ConcurrentProcessSingleton.java | 34 +++++++++++---------
2 files changed, 20 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/774324cd/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index da8e696..2809dd3 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -122,9 +122,8 @@
<usergrid.it.parallel>methods</usergrid.it.parallel>
<usergrid.it.reuseForks>true</usergrid.it.reuseForks>
- <!-- run with 1 fork and 1 thread until we figure out how to make tests run concurrently again -->
- <usergrid.it.forkCount>1</usergrid.it.forkCount>
- <usergrid.it.threads>1</usergrid.it.threads>
+ <usergrid.it.forkCount>4</usergrid.it.forkCount>
+ <usergrid.it.threads>8</usergrid.it.threads>
<metrics.version>3.0.0</metrics.version>
<rx.version>0.19.6</rx.version>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/774324cd/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index e8c5ace..63aa70d 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@ -28,17 +28,21 @@ import org.apache.usergrid.cassandra.SpringResource;
import org.apache.usergrid.lock.MultiProcessBarrier;
import org.apache.usergrid.lock.MultiProcessLocalLock;
+import java.io.IOException;
+
/**
* A singleton that starts cassandra and configures it once per JVM
*/
public class ConcurrentProcessSingleton {
+ private static final Logger logger = LoggerFactory.getLogger( ConcurrentProcessSingleton.class );
- private static final String TEMP_FILE_PATH =
- "target/surefirelocks/start_barrier-" + System.getProperty( "test.barrier.timestamp", "default" );
+ private static final String TEMP_FILE_PATH = "target/surefirelocks/start_barrier-"
+ + System.getProperty( "test.barrier.timestamp", "default" );
- public static final int LOCK_PORT = Integer.parseInt( System.getProperty( "test.lock.port", "10101" ) );
+ public static final int LOCK_PORT = Integer.parseInt(
+ System.getProperty( "test.lock.port", "10101" ) );
public static final boolean CLEAN_STORAGE =
Boolean.parseBoolean( System.getProperty( "test.clean.storage", "false" ) );
@@ -46,7 +50,6 @@ public class ConcurrentProcessSingleton {
public static final long ONE_MINUTE = 60000;
- private static final Logger logger = LoggerFactory.getLogger( ConcurrentProcessSingleton.class );
private final MultiProcessLocalLock lock = new MultiProcessLocalLock( LOCK_PORT );
private final MultiProcessBarrier barrier = new MultiProcessBarrier( TEMP_FILE_PATH );
@@ -75,29 +78,29 @@ public class ConcurrentProcessSingleton {
try {
logger.info( "Trying to get a lock to setup system" );
- //we have a lock, so init the system
+
+ // we have a lock, so init the system
if ( lock.tryLock() ) {
logger.info( "Lock acquired, setting up system" );
- final SchemaManager schemaManager = SpringResource.getInstance().getBean( SchemaManager.class );
+ final SchemaManager schemaManager =
+ SpringResource.getInstance().getBean( SchemaManager.class );
-
- //maybe delete existing column families and indexes
+ // maybe delete existing column families and indexes
if ( CLEAN_STORAGE ) {
logger.info("Destroying current database");
schemaManager.destroy();
}
- //create our schema
+ // create our schema
logger.info("Creating database");
schemaManager.create();
logger.info("Populating database");
schemaManager.populateBaseData();
-
- //signal to other processes we've migrated, and they can proceed
+ // signal to other processes we've migrated, and they can proceed
barrier.proceed();
}
@@ -106,7 +109,8 @@ public class ConcurrentProcessSingleton {
barrier.await( ONE_MINUTE );
logger.info( "Setup to complete" );
- lock.maybeReleaseLock();
+ // Commented out: Never release the lock, otherwise some other JVM may destroy the schema
+ // lock.maybeReleaseLock();
}
catch ( Exception e ) {
throw new RuntimeException( "Unable to initialize system", e );
@@ -115,19 +119,17 @@ public class ConcurrentProcessSingleton {
/**
- * Get an instance of this singleton. If it is the first time this instance is created it will also initialize the
- * system
+ * Get an instance of this singleton. If it is the first time this instance is
+ * created it will also initialize the system
*/
public static synchronized ConcurrentProcessSingleton getInstance() {
if ( instance != null ) {
return instance;
}
-
instance = new ConcurrentProcessSingleton();
instance.startSystem();
-
return instance;
}
}
[39/50] incubator-usergrid git commit: Start of onErrorResumeNext()
implementation.
Posted by sn...@apache.org.
Start of onErrorResumeNext() implementation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0c25d852
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0c25d852
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0c25d852
Branch: refs/heads/two-dot-o-dev
Commit: 0c25d852ae6edd479a8694fe1b570c497e540570
Parents: 665a170
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 18:23:43 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 18:23:43 2015 -0400
----------------------------------------------------------------------
.../index/impl/EsIndexBufferConsumerImpl.java | 39 ++++++++++++--------
1 file changed, 24 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0c25d852/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index 284cd2a..b0d6047 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@ -189,40 +189,49 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
}
while ( true );
}
- } ).subscribeOn( Schedulers.newThread() ).doOnNext( new Action1<List<IndexOperationMessage>>() {
+ } ).subscribeOn(Schedulers.newThread()).doOnNext(new Action1<List<IndexOperationMessage>>() {
@Override
- public void call( List<IndexOperationMessage> containerList ) {
- if ( containerList.size() == 0 ) {
+ public void call(List<IndexOperationMessage> containerList) {
+ if (containerList.size() == 0) {
return;
}
- flushMeter.mark( containerList.size() );
+ flushMeter.mark(containerList.size());
Timer.Context time = flushTimer.time();
- execute( containerList );
+ execute(containerList);
time.stop();
}
- } )
+ })
//ack after we process
- .doOnNext( new Action1<List<IndexOperationMessage>>() {
+ .doOnNext(new Action1<List<IndexOperationMessage>>() {
@Override
- public void call( final List<IndexOperationMessage> indexOperationMessages ) {
- bufferQueue.ack( indexOperationMessages );
+ public void call(final List<IndexOperationMessage> indexOperationMessages) {
+ bufferQueue.ack(indexOperationMessages);
//release so we know we've done processing
- inFlight.addAndGet( -1 * indexOperationMessages.size() );
+ inFlight.addAndGet(-1 * indexOperationMessages.size());
}
- } ).doOnError( new Action1<Throwable>() {
+ })
+ // TODO: implement on error resume next instead of onError
+// .onErrorResumeNext(new Func1<Throwable, Observable<IndexOperationMessage>>() {
+//
+// @Override
+// public Observable<IndexOperationMessage> call(Throwable throwable) {
+// return null;
+// }
+// })
+ .doOnError(new Action1<Throwable>() {
@Override
- public void call( final Throwable throwable ) {
+ public void call(final Throwable throwable) {
- log.error( "An exception occurred when trying to deque and write to elasticsearch. Ignoring",
- throwable );
+ log.error("An exception occurred when trying to deque and write to elasticsearch. Ignoring",
+ throwable);
indexErrorCounter.inc();
}
- } );
+ });
//start in the background
[34/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e47555e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e47555e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e47555e7
Branch: refs/heads/two-dot-o-dev
Commit: e47555e72c1c858b27787438f5ec3e5512298811
Parents: 68f56dd 9a391fe
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 10:03:06 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 10:03:06 2015 -0400
----------------------------------------------------------------------
stack/core/pom.xml | 33 +-
.../corepersistence/CpEntityManager.java | 2 +-
.../corepersistence/CpEntityManagerFactory.java | 7 +-
.../corepersistence/CpRelationManager.java | 24 +-
.../usergrid/corepersistence/CpWalker.java | 81 ++---
.../events/EntityVersionDeletedHandler.java | 72 ++--
.../migration/EntityTypeMappingMigration.java | 41 +--
.../persistence/ObservableIterator.java | 1 +
.../migration/EntityTypeMappingMigrationIT.java | 2 +-
.../PerformanceEntityRebuildIndexTest.java | 3 +-
stack/corepersistence/collection/pom.xml | 14 +-
.../impl/EntityCollectionManagerImpl.java | 10 +-
.../collection/impl/EntityDeletedTask.java | 20 +-
.../impl/EntityVersionCleanupTask.java | 40 +--
.../impl/EntityVersionCreatedTask.java | 26 +-
.../mvcc/stage/write/WriteCommit.java | 2 +-
.../mvcc/stage/write/WriteUniqueVerify.java | 8 +-
.../MvccEntitySerializationStrategyImpl.java | 92 ++---
.../MvccEntitySerializationStrategyV3Impl.java | 94 ++---
.../UniqueValueSerializationStrategyImpl.java | 8 -
.../migration/MvccEntityDataMigrationImpl.java | 171 ++++------
.../collection/util/EntityUtils.java | 72 ----
.../mvcc/stage/AbstractEntityStageTest.java | 2 +-
.../mvcc/stage/AbstractMvccEntityStageTest.java | 2 +-
.../mvcc/stage/TestEntityGenerator.java | 2 +-
.../persistence/collection/rx/ParallelTest.java | 10 +-
...MvccEntitySerializationStrategyImplTest.java | 4 +-
...ccEntitySerializationStrategyV1ImplTest.java | 4 +-
...ccEntitySerializationStrategyV2ImplTest.java | 2 +-
.../impl/SerializationComparison.java | 4 +-
...ctMvccEntityDataMigrationV1ToV3ImplTest.java | 2 +-
.../collection/util/InvalidEntityGenerator.java | 1 +
stack/corepersistence/common/pom.xml | 15 +-
.../astyanax/MultiKeyColumnNameIterator.java | 4 +-
.../MultiKeyColumnNameIteratorTest.java | 187 +++++-----
.../astyanax/MultiRowColumnIteratorTest.java | 50 ++-
.../graph/impl/GraphManagerImpl.java | 6 +-
.../graph/impl/stage/EdgeMetaRepairImpl.java | 2 +
.../impl/stage/NodeDeleteListenerImpl.java | 2 +-
.../impl/migration/EdgeDataMigrationImpl.java | 87 +++--
.../persistence/graph/GraphManagerIT.java | 17 +-
.../graph/GraphManagerShardConsistencyIT.java | 2 +-
.../usergrid/persistence/graph/SimpleTest.java | 12 +-
.../migration/EdgeDataMigrationImplTest.java | 2 +-
stack/corepersistence/model/pom.xml | 1 -
.../persistence/model/util/EntityUtils.java | 72 ++++
stack/corepersistence/pom.xml | 8 +-
stack/corepersistence/queryindex/pom.xml | 6 -
.../index/impl/EsEntityIndexImpl.java | 2 +-
.../persistence/index/query/EntityResults.java | 108 ------
.../persistence/index/query/Results.java | 148 --------
.../persistence/index/utils/ListUtils.java | 6 +-
.../persistence/index/guice/IndexTestFig.java | 57 ++++
.../index/guice/TestIndexModule.java | 8 +-
.../index/impl/CorePerformanceIT.java | 339 -------------------
.../impl/EntityConnectionIndexImplTest.java | 306 -----------------
.../persistence/index/impl/EntityIndexTest.java | 32 +-
.../index/impl/IndexLoadTestsIT.java | 138 ++++++++
stack/pom.xml | 14 +-
stack/rest/pom.xml | 1 +
stack/services/pom.xml | 1 +
.../management/importer/ImportServiceImpl.java | 34 +-
.../impl/ApplicationQueueManagerImpl.java | 195 +++++------
.../setup/ConcurrentProcessSingleton.java | 21 +-
64 files changed, 908 insertions(+), 1831 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e47555e7/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 3b47fa2,83c3d85..782b273
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -444,12 -468,12 +445,12 @@@ public class CpEntityManagerFactory imp
appScope.getApplication(),
scopeName);
- org.apache.usergrid.persistence.model.entity.Entity e =
+ org.apache.usergrid.persistence.model.entity.Entity appInfo =
managerCache.getEntityCollectionManager( collScope ).load( targetId )
- .toBlockingObservable().lastOrDefault(null);
+ .toBlocking().lastOrDefault(null);
- if ( e == null ) {
- logger.warn("Applicaion {} in index but not found in collections", targetId );
+ if ( appInfo == null ) {
+ logger.warn("Application {} in index but not found in collections", targetId );
continue;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e47555e7/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --cc stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index 86b5c0f,52d4a48..8363a24
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@@ -424,8 -427,7 +423,8 @@@ public class PerformanceEntityRebuildIn
}
if ( expectedEntities != -1 && expectedEntities != count ) {
- throw new RuntimeException("Did not get expected " + expectedEntities + " entities, instead got " + count );
+ throw new RuntimeException("Did not get expected "
- + expectedEntities + " entities, instead got " + count );
++ + expectedEntities + " entities, instead got " + count );
}
return count;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e47555e7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e47555e7/stack/services/src/main/java/org/apache/usergrid/management/importer/ImportServiceImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e47555e7/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --cc stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index d8e124f,7cb5073..64a2f7a
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@@ -103,22 -101,26 +100,32 @@@ public class ConcurrentProcessSingleto
// signal to other processes we've migrated, and they can proceed
barrier.proceed();
- }
+ logger.info( "Waiting for setup to complete" );
+ barrier.await( ONE_MINUTE );
+ logger.info( "Setup to complete" );
+
+ lock.maybeReleaseLock();
- logger.info( "Waiting for setup to complete" );
- barrier.await( ONE_MINUTE );
- logger.info( "Setup to complete" );
+ } else {
+ throw new RuntimeException( "Unable to initialize system: could not get lock."
+ +" Some other process must be binding to port " + LOCK_PORT );
+ }
- // Commented out: Never release the lock, otherwise some other JVM may destroy the schema
- // lock.maybeReleaseLock();
+ Runtime.getRuntime().addShutdownHook( new Thread( ){
+ @Override
+ public void run() {
+ try {
+ lock.maybeReleaseLock();
+ }
+ catch ( IOException e ) {
+ throw new RuntimeException( "Unable to release lock" );
+ }
+ }
+ });
+
}
+
catch ( Exception e ) {
throw new RuntimeException( "Unable to initialize system", e );
}
[28/50] incubator-usergrid git commit: Fixing EMF getApplications()
and the all-apps observable to use the app ID and not the application_info ID,
plus some section comments in related tests.
Posted by sn...@apache.org.
Fixing EMF getApplications() and the all-apps observable to use the app ID and not the application_info ID, plus some section comments in related tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/7d7c54b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/7d7c54b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/7d7c54b9
Branch: refs/heads/two-dot-o-dev
Commit: 7d7c54b9fab1fe322f5960f97dee979a5e8f9001
Parents: 9f3bb94
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 17 09:32:54 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 17 09:32:54 2015 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 9 ++--
.../rx/impl/AllApplicationsObservableImpl.java | 6 ++-
.../rx/AllEntitiesInSystemObservableIT.java | 44 ++++++++++----------
.../PerformanceEntityRebuildIndexTest.java | 12 ++----
4 files changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/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 010672e..efae477 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
@@ -449,16 +449,19 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
appScope.getApplication(),
scopeName);
- org.apache.usergrid.persistence.model.entity.Entity e =
+ org.apache.usergrid.persistence.model.entity.Entity appInfo =
managerCache.getEntityCollectionManager( collScope ).load( targetId )
.toBlockingObservable().lastOrDefault(null);
- if ( e == null ) {
+ if ( appInfo == null ) {
logger.warn("Application {} in index but not found in collections", targetId );
continue;
}
- appMap.put( (String)e.getField( PROPERTY_NAME ).getValue(), e.getId().getUuid());
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getField( PROPERTY_APPLICATION_ID ).getValue().toString() );
+
+ appMap.put( (String)appInfo.getField( PROPERTY_NAME ).getValue(), applicationId);
}
return appMap;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
index 7f2b27d..8dbea19 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/impl/AllApplicationsObservableImpl.java
@@ -23,6 +23,8 @@ package org.apache.usergrid.corepersistence.rx.impl;
import java.util.Arrays;
import java.util.UUID;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.utils.UUIDUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -100,6 +102,7 @@ public class AllApplicationsObservableImpl implements AllApplicationsObservable
null ) ).flatMap( new Func1<Edge, Observable<ApplicationScope>>() {
@Override
public Observable<ApplicationScope> call( final Edge edge ) {
+
//get the app info and load it
final Id appInfo = edge.getTargetNode();
@@ -121,7 +124,8 @@ public class AllApplicationsObservableImpl implements AllApplicationsObservable
@Override
public ApplicationScope call( final Entity entity ) {
- final UUID uuid = entity.getId().getUuid();
+ final UUID uuid = UUIDUtils.tryExtractUUID(
+ entity.getField( Schema.PROPERTY_APPLICATION_ID ).getValue().toString());
return getApplicationScope( uuid );
}
} );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
index 7a6ec22..b2b8aaf 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
@@ -55,12 +55,16 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
@Test
public void testEntities() throws Exception {
+
Injector injector = SpringResource.getInstance().getBean(Injector.class);
- AllEntitiesInSystemImpl allEntitiesInSystemObservableImpl =injector.getInstance(AllEntitiesInSystemImpl.class);
+ AllEntitiesInSystemImpl allEntitiesInSystemObservableImpl =
+ injector.getInstance(AllEntitiesInSystemImpl.class);
TargetIdObservable targetIdObservable = injector.getInstance(TargetIdObservable.class);
final EntityManager em = app.getEntityManager();
+ // create two types of entities
+
final String type1 = "type1thing";
final String type2 = "type2thing";
final int size = 10;
@@ -68,9 +72,9 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
final Set<Id> type1Identities = EntityWriteHelper.createTypes( em, type1, size );
final Set<Id> type2Identities = EntityWriteHelper.createTypes( em, type2, size );
- //create a connection and put that in our connection types
- final Id source = type1Identities.iterator().next();
+ // connect the first type1 entity to all type2 entities
+ final Id source = type1Identities.iterator().next();
final Set<Id> allEntities = new HashSet<>();
allEntities.addAll( type1Identities );
@@ -79,20 +83,17 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
final Set<Id> connections = new HashSet<>();
for ( Id target : type2Identities ) {
- em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
+ em.createConnection( SimpleEntityRef.fromId( source ),
+ "likes", SimpleEntityRef.fromId( target ) );
connections.add( target );
}
+ // use the all-entities-in-system observable to delete all type1 and type2 entities
- //this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
- //clean up our wiring
- //
- ManagerCache managerCache = SpringResource.getInstance().getBean( Injector.class ).getInstance( ManagerCache.class );
-
-
+ // TODO: clean this up when we clean up our Guice and Spring wiring
+ ManagerCache managerCache = SpringResource.getInstance()
+ .getBean( Injector.class ).getInstance( ManagerCache.class );
final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );
-
-
final GraphManager gm = managerCache.getGraphManager( scope );
allEntitiesInSystemObservableImpl.getData().doOnNext( new Action1<EntityIdScope>() {
@@ -102,22 +103,23 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
assertNotNull(entityIdScope.getCollectionScope());
assertNotNull(entityIdScope.getId());
- //we should only emit each node once
- if ( entityIdScope.getId().getType().equals( type1 ) ) {
- assertTrue( "Element should be present on removal", type1Identities.remove(entityIdScope.getId() ) );
- }
- else if ( entityIdScope.getId().getType().equals( type2 ) ) {
- assertTrue( "Element should be present on removal", type2Identities.remove(entityIdScope.getId() ) );
- }
-
+ // we should only emit each node once
+ if ( entityIdScope.getId().getType().equals( type1 ) ) {
+ assertTrue( "Element should be present on removal",
+ type1Identities.remove(entityIdScope.getId() ) );
+ }
+ else if ( entityIdScope.getId().getType().equals( type2 ) ) {
+ assertTrue( "Element should be present on removal",
+ type2Identities.remove(entityIdScope.getId() ) );
+ }
}
} ).toBlocking().lastOrDefault( null );
+ // there should now be no type1 or type2 entities
assertEquals( "Every element should have been encountered", 0, type1Identities.size() );
assertEquals( "Every element should have been encountered", 0, type2Identities.size() );
-
//test connections
targetIdObservable.getTargetNodes( gm, source ).doOnNext( new Action1<Id>() {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7d7c54b9/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index def9ed5..48191bf 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -174,8 +174,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
// ----------------- delete the system and application indexes
- logger.debug("Deleting app index index");
- //deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
+ logger.debug("Deleting apps");
deleteIndex( em.getApplicationId() );
// ----------------- test that we can read them, should fail
@@ -311,13 +310,10 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
// ----------------- delete the system and application indexes
- logger.debug("Deleting app index and system app index");
+ logger.debug("Deleting app index");
deleteIndex( em.getApplicationId() );
- // deleting sytem app index will interfere with other concurrently running tests
- //deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
-
// ----------------- test that we can read them, should fail
@@ -373,14 +369,14 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
}
/**
- * Delete index for all applications, just need the one to get started.
+ * Delete app index
*/
private void deleteIndex( UUID appUuid ) {
Injector injector = SpringResource.getInstance().getBean( Injector.class );
EntityIndexFactory eif = injector.getInstance( EntityIndexFactory.class );
- Id appId = new SimpleId( appUuid, "application");
+ Id appId = new SimpleId( appUuid, Schema.TYPE_APPLICATION );
ApplicationScope scope = new ApplicationScopeImpl( appId );
EntityIndex ei = eif.createEntityIndex(scope);
EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;
[36/50] incubator-usergrid git commit: Merge branch 'USERGRID-405'
into USERGRID-448-appinfofix
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' into USERGRID-448-appinfofix
Conflicts:
stack/pom.xml
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e3d9cc97
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e3d9cc97
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e3d9cc97
Branch: refs/heads/two-dot-o-dev
Commit: e3d9cc97985b643040f73e4ec8f78b3a08b1daf0
Parents: 3b71f5e c864ab6
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 18:10:18 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 18:10:18 2015 -0400
----------------------------------------------------------------------
stack/core/pom.xml | 13 +++++++------
.../java/org/apache/usergrid/persistence/GeoIT.java | 2 +-
stack/pom.xml | 2 +-
3 files changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e3d9cc97/stack/pom.xml
----------------------------------------------------------------------
diff --cc stack/pom.xml
index 3834609,19573d3..96faee0
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@@ -121,8 -121,7 +121,8 @@@
<!-- only use half the cores on the machine for testing -->
<usergrid.it.parallel>methods</usergrid.it.parallel>
<usergrid.it.reuseForks>true</usergrid.it.reuseForks>
+
- <usergrid.it.forkCount>4</usergrid.it.forkCount>
+ <usergrid.it.forkCount>1</usergrid.it.forkCount>
<usergrid.it.threads>8</usergrid.it.threads>
<metrics.version>3.0.0</metrics.version>
[37/50] incubator-usergrid git commit: Log error and continue instead
of throwing RuntimeError.
Posted by sn...@apache.org.
Log error and continue instead of throwing RuntimeError.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e60ffeb6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e60ffeb6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e60ffeb6
Branch: refs/heads/two-dot-o-dev
Commit: e60ffeb6925ddc5ba8277ad6a177a38a4577a506
Parents: c864ab6
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 18:11:06 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 18:11:06 2015 -0400
----------------------------------------------------------------------
.../index/impl/EsIndexBufferConsumerImpl.java | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e60ffeb6/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index b31cf39..284cd2a 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@ -321,19 +321,15 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
failureMonitor.success();
for (BulkItemResponse response : responses) {
- if (response.isFailed()) {
-
- final BulkItemResponse.Failure failure = response.getFailure();
-
- final String message;
- if(failure != null) {
- message = "Unable to index documents. Errors are :" + response.getFailure().getMessage();
- }else{
- message = "Unable to index documents. Response is :" + response.getResponse();
- }
-
- throw new RuntimeException(message);
+ if (response.isFailed()) {
+ // log error and continue processing
+ log.error("Unable to index id={}, type={}, index={}, failureMessage={} ",
+ response.getId(),
+ response.getType(),
+ response.getIndex(),
+ response.getFailureMessage()
+ );
}
}
}
[14/50] incubator-usergrid git commit: Change OrgApplicationCache to
ApplicationId cache because we need no org lookup,
and update it to use EM alias instead of Query to lookup app UUID.
Posted by sn...@apache.org.
Change OrgApplicationCache to ApplicationId cache because we need no org lookup, and update it to use EM alias instead of Query to lookup app UUID.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ae111dac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ae111dac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ae111dac
Branch: refs/heads/two-dot-o-dev
Commit: ae111dac87bbdf5df0ba172ccbc267f4f9c4ca32
Parents: 07f1f62
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Mar 10 11:07:36 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Mar 10 11:07:36 2015 -0400
----------------------------------------------------------------------
.../corepersistence/ApplicationIdCache.java | 52 ++++++
.../corepersistence/ApplicationIdCacheImpl.java | 106 +++++++++++
.../corepersistence/CpEntityManagerFactory.java | 108 +----------
.../corepersistence/OrgApplicationCache.java | 67 -------
.../OrgApplicationCacheImpl.java | 181 -------------------
5 files changed, 163 insertions(+), 351 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ae111dac/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
new file mode 100644
index 0000000..71637bd
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCache.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.Entity;
+
+import com.google.common.base.Optional;
+
+
+/**
+ * A simple cache interface for looking up entities from an EM
+ */
+public interface ApplicationIdCache {
+
+
+ /**
+ * Evict the application by name
+ */
+ public Optional<UUID> getApplicationId(final String applicationName);
+
+
+ /**
+ * Evict the app id by the name
+ */
+ public void evictAppId(final String applicationName);
+
+
+ /**
+ * Evict all caches
+ */
+ public void evictAll();
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ae111dac/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
new file mode 100644
index 0000000..d415259
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -0,0 +1,106 @@
+/*
+ * 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;
+
+
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.EntityRef;
+
+import com.google.common.base.Optional;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
+
+/**
+ * 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
+ */
+public class ApplicationIdCacheImpl implements ApplicationIdCache {
+
+
+ /**
+ * Cache the pointer to our root entity manager for reference
+ */
+ private final EntityManager rootEm;
+
+ private final LoadingCache<String, Optional<UUID>> appCache =
+ CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, Optional<UUID>>() {
+ @Override
+ public Optional<UUID> load( final String key ) throws Exception {
+ return fetchApplicationId( key );
+ }
+ } );
+
+
+ public ApplicationIdCacheImpl(final EntityManagerFactory emf) {
+ this.rootEm = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
+ }
+
+ @Override
+ public Optional<UUID> getApplicationId( final String applicationName ) {
+ try {
+ return appCache.get( applicationName );
+ }
+ catch ( ExecutionException e ) {
+ throw new RuntimeException( "Unable to load org cache", e );
+ }
+ }
+
+
+ /**
+ * Fetch our application id
+ */
+ private Optional<UUID> fetchApplicationId( final String applicationName ) {
+
+ try {
+ UUID applicationId = null;
+
+ final EntityRef alias = rootEm.getAlias( CpNamingUtils.APPLICATION_INFO, applicationName );
+ if ( alias != null ) {
+ Entity entity = rootEm.get(alias);
+ applicationId = (UUID) entity.getProperty("uuid");
+ }
+
+ return Optional.of( applicationId );
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to retrieve application id", e );
+ }
+ }
+
+
+ @Override
+ public void evictAppId( final String applicationName ) {
+ appCache.invalidate( applicationName );
+ }
+
+
+ @Override
+ public void evictAll() {
+ appCache.invalidateAll();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ae111dac/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 78f2095..e435cb2 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
@@ -34,13 +34,11 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
-import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
import org.apache.usergrid.persistence.core.migration.data.MigrationDataProvider;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.core.util.Health;
import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
@@ -95,7 +93,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
});
- private final OrgApplicationCache orgApplicationCache;
+ private final ApplicationIdCache orgApplicationCache;
private ManagerCache managerCache;
@@ -116,13 +114,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.injector = injector;
this.managerCache = injector.getInstance( ManagerCache.class );
this.metricsFactory = injector.getInstance( MetricsFactory.class );
-
- // can be removed after everybody moves to Usergrid 2.0, default is true
- Properties configProps = cassandraService.getProperties();
- if ( configProps.getProperty("usergrid.twodoto.appinfo.migration", "true").equals("true")) {
- migrateOldAppInfos();
- }
- this.orgApplicationCache = new OrgApplicationCacheImpl( this );
+ this.orgApplicationCache = new ApplicationIdCacheImpl( this );
}
@@ -236,9 +228,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- // Ensure our management system exists before creating our application
- init();
-
final String appName = buildAppName( organizationName, name );
// check for pre-existing application
@@ -247,32 +236,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
throw new ApplicationAlreadyExistsException( appName );
}
- getSetup().setupApplicationKeyspace( applicationId, appName );
-
- final Optional<UUID> cachedValue = orgApplicationCache.getOrganizationId( organizationName );
-
- if ( !cachedValue.isPresent() ) {
-
-
- // create new org because the specified one does not exist
- final String orgName = organizationName;
+ // create application info entity in the management app
+ getSetup().setupApplicationKeyspace( applicationId, appName );
-
- try {
- final Entity orgInfo = em.create( "organization", new HashMap<String, Object>() {{
- put( PROPERTY_NAME, orgName );
- }} );
- //evit so it's re-loaded later
- orgApplicationCache.evictOrgId( name );
- }
- catch ( DuplicateUniquePropertyExistsException e ) {
- //swallow, if it exists, just get it
- orgApplicationCache.evictOrgId( organizationName );
- }
- }
-
- // create appinfo entry in the system app
final UUID appId = applicationId;
Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
put( PROPERTY_NAME, appName );
@@ -298,7 +265,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
appEm.resetRoles();
appEm.refreshIndex();
- logger.info("Initialized application {}", appName );
+ logger.info("Initialized application {}", appName);
//evict app Id from cache
orgApplicationCache.evictAppId( appName );
@@ -483,71 +450,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
- private void migrateOldAppInfos() {
-
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
-
- Query q = Query.fromQL("select *");
- Results results = null;
- try {
- results = em.searchCollection(em.getApplicationRef(), "appinfos", q);
- } catch (Exception e) {
- logger.error("Error reading old appinfos collection, not migrating", e);
- return;
- }
-
- if ( !results.isEmpty() ) {
-
- // applications still found in old appinfos collection, migrate them.
- logger.info("Migrating old appinfos");
-
- for ( Entity oldAppInfo : results.getEntities() ) {
-
- final String appName = oldAppInfo.getName();
-
- UUID applicationId = null, organizationId = null;
- Object uuidObject = oldAppInfo.getProperty("applicationUuid");
- if (uuidObject instanceof UUID) {
- applicationId = (UUID) uuidObject;
- } else {
- applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
- }
- uuidObject = oldAppInfo.getProperty("organizationUuid");
- if (uuidObject instanceof UUID) {
- organizationId = (UUID) uuidObject;
- } else {
- organizationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
- }
-
- // create and connect new APPLICATION_INFO oldAppInfo to Organization
-
- final UUID appId = applicationId;
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put(PROPERTY_NAME, appName);
- put(PROPERTY_UUID, appId);
- }};
-
- final Entity appInfo;
- try {
- appInfo = em.create(appId, CpNamingUtils.APPLICATION_INFO, appInfoMap);
- em.createConnection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "owns", appInfo);
- em.delete( oldAppInfo );
- logger.info("Migrated old appinfo for app {}", appName);
-
- } catch (Exception e) {
- logger.error("Error migration application " + appName + " continuing ", e);
- }
- }
-
- em.refreshIndex();
-
- } else {
- logger.info("No old appinfos found, no need for migration");
- }
-
- }
-
-
@Override
public void setup() throws Exception {
getSetup().init();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ae111dac/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCache.java
deleted file mode 100644
index b20dbe1..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCache.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.Entity;
-
-import com.google.common.base.Optional;
-
-
-/**
- * A simple cache interface for looking up entities from an EM
- */
-public interface OrgApplicationCache {
-
-
- /**
- * Get an entity by it's alias property. The result is cached. To clear it call evict or evict all
- * @param
- * @return
- */
- public Optional<UUID> getOrganizationId(final String orgName);
-
- /**
- * Evict the org by name
- * @param orgName
- */
- public void evictOrgId(final String orgName);
-
- /**
- * Evict the application by name
- * @param applicationName
- * @return
- */
- public Optional<UUID> getApplicationId(final String applicationName);
-
-
- /**
- * Evict the app id by the name
- */
- public void evictAppId(final String applicationname);
-
-
- /**
- * Evict all caches
- */
- public void evictAll();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ae111dac/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
deleted file mode 100644
index 23410d8..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/OrgApplicationCacheImpl.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * 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;
-
-
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
-
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityManagerFactory;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.utils.UUIDUtils;
-
-import com.google.common.base.Optional;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-
-import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
-
-
-/**
- * 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
- */
-public class OrgApplicationCacheImpl implements OrgApplicationCache {
-
-
- /**
- * Cache the pointer to our root entity manager for reference
- */
- private final EntityManager rootEm;
-
- private final LoadingCache<String, Optional<UUID>> orgCache =
- CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, Optional<UUID>>() {
- @Override
- public Optional<UUID> load( final String key ) throws Exception {
- return fetchOrganizationId( key );
- }
- } );
-
-
- private final LoadingCache<String, Optional<UUID>> appCache =
- CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String, Optional<UUID>>() {
- @Override
- public Optional<UUID> load( final String key ) throws Exception {
- return fetchApplicationId( key );
- }
- } );
-
-
- public OrgApplicationCacheImpl( final EntityManagerFactory emf ) {
- this.rootEm = emf.getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
- }
-
-
- @Override
- public Optional<UUID> getOrganizationId( final String orgName ) {
- try {
- return orgCache.get( orgName );
- }
- catch ( ExecutionException e ) {
- throw new RuntimeException( "Unable to load org cache", e );
- }
- }
-
-
- /**
- * Fetches the organization
- */
- private Optional<UUID> fetchOrganizationId( final String orgName ) {
-
- try {
- final EntityRef alias = rootEm.getAlias( "organizations", orgName );
-
- if ( alias == null ) {
- return Optional.absent();
- }
-
- final Entity entity;
-
- entity = rootEm.get( alias );
-
-
- if ( entity == null ) {
- return Optional.absent();
- }
-
- return Optional.of( entity.getUuid() );
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Unable to load organization Id for caching", e );
- }
- }
-
-
- @Override
- public void evictOrgId( final String orgName ) {
- orgCache.invalidate( orgName );
- }
-
-
- @Override
- public Optional<UUID> getApplicationId( final String applicationName ) {
- try {
- return appCache.get( applicationName );
- }
- catch ( ExecutionException e ) {
- throw new RuntimeException( "Unable to load org cache", e );
- }
- }
-
-
- /**
- * Fetch our application id
- */
- private Optional<UUID> fetchApplicationId( final String applicationName ) {
-
- try {
- Query q = Query.fromQL( PROPERTY_NAME + " = '" + applicationName + "'" );
-
-
- Results results = rootEm.searchCollection( rootEm.getApplicationRef(), "appinfos", q );
-
- if ( results.isEmpty() ) {
- return Optional.absent();
- }
-
- Entity entity = results.iterator().next();
- Object uuidObject = entity.getProperty( "applicationUuid" );
-
- final UUID value;
- if ( uuidObject instanceof UUID ) {
- value = ( UUID ) uuidObject;
- }
- else {
- value = UUIDUtils.tryExtractUUID( entity.getProperty( "applicationUuid" ).toString() );
- }
-
-
- return Optional.of( value );
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Unable to retreive application id", e );
- }
- }
-
-
- @Override
- public void evictAppId( final String applicationName ) {
- appCache.invalidate( applicationName );
- }
-
-
- @Override
- public void evictAll() {
- orgCache.invalidateAll();
- appCache.invalidateAll();
- }
-}
[26/50] incubator-usergrid git commit: Use Graph instead of ES to get
AppInfo information for migration.
Posted by sn...@apache.org.
Use Graph instead of ES to get AppInfo information for migration.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/285230f3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/285230f3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/285230f3
Branch: refs/heads/two-dot-o-dev
Commit: 285230f36cd79519f7c158aaf4acbe48589d891a
Parents: f837883
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 16 12:16:37 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 16 12:16:37 2015 -0400
----------------------------------------------------------------------
.../migration/AppInfoMigrationPlugin.java | 297 ++++++++++++++-----
.../org/apache/usergrid/CoreITSetupImpl.java | 9 +-
.../apache/usergrid/persistence/CounterIT.java | 5 +-
.../usergrid/persistence/EntityManagerIT.java | 5 +-
.../cassandra/EntityManagerFactoryImplIT.java | 7 +-
.../cassandra/ManagementServiceIT.java | 13 +-
.../management/export/ExportServiceIT.java | 8 +-
.../usergrid/services/ServiceFactoryIT.java | 8 +-
8 files changed, 273 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/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 1f8f784..c0f3f15 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
@@ -19,25 +19,40 @@
package org.apache.usergrid.corepersistence.migration;
import com.google.inject.Inject;
+import org.apache.usergrid.corepersistence.util.CpEntityMapUtils;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
import org.apache.usergrid.persistence.core.migration.data.MigrationPlugin;
import org.apache.usergrid.persistence.core.migration.data.PluginPhase;
import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.entities.Group;
+import org.apache.usergrid.persistence.graph.Edge;
+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;
import org.slf4j.LoggerFactory;
+import rx.Observable;
+import rx.functions.Func1;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getApplicationScope;
+import static org.apache.usergrid.persistence.Schema.*;
/**
@@ -52,16 +67,50 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
public static String PLUGIN_NAME = "appinfo-migration";
@Inject
- protected MigrationInfoSerialization migrationInfoSerialization;
+ final private MigrationInfoSerialization migrationInfoSerialization;
@Inject
- protected EntityManagerFactory emf; // protected for test purposes only
+ final private EntityManagerFactory emf;
+
+ @Inject
+ final private EntityCollectionManagerFactory entityCollectionManagerFactory;
+
+ @Inject
+ final private GraphManagerFactory graphManagerFactory;
+
+
+ @Inject
+ public AppInfoMigrationPlugin(
+ EntityManagerFactory emf,
+ MigrationInfoSerialization migrationInfoSerialization,
+ EntityCollectionManagerFactory entityCollectionManagerFactory,
+ GraphManagerFactory graphManagerFactory ) {
+
+ this.emf = emf;
+ this.migrationInfoSerialization = migrationInfoSerialization;
+ this.entityCollectionManagerFactory = entityCollectionManagerFactory;
+ this.graphManagerFactory = graphManagerFactory;
+ }
+
@Override
public String getName() {
return PLUGIN_NAME;
}
+
+ @Override
+ public int getMaxVersion() {
+ return 1; // standalone plugin, happens once
+ }
+
+
+ @Override
+ public PluginPhase getPhase() {
+ return PluginPhase.MIGRATE;
+ }
+
+
@Override
public void run(ProgressObserver observer) {
@@ -74,21 +123,14 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
observer.start();
- // Search the old and now deprecated System App for appinfo entities
+ // Get appinfos from the Graph, we don't expect many so use iterator
- EntityManager systemAppEm = emf.getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
- Query q = Query.fromQL("select *");
- Results results;
- try {
- results = systemAppEm.searchCollection(systemAppEm.getApplicationRef(), "appinfos", q);
- } catch (Exception e) {
- logger.error("Error reading old appinfos collection, not migrating", e);
- return;
- }
+ final Iterator<org.apache.usergrid.persistence.model.entity.Entity> iterator =
+ getOldAppInfos().toBlocking().getIterator();
- if ( !results.isEmpty() ) {
+ if ( iterator.hasNext() ) {
- // we found appinfos, let's migrate them to application_infos in the Management App
+ // we found appinfos, now migrate them to application_infos in the Management App
final EntityManager em = emf.getEntityManager( emf.getManagementAppId());
@@ -96,49 +138,14 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
try {
logger.info("Migrating old appinfos");
- for (Entity oldAppInfo : results.getEntities()) {
-
- final String appName = currentAppName = oldAppInfo.getName();
- final String orgName = appName.split("/")[0];
-
- UUID applicationId;
-
- Object uuidObject = oldAppInfo.getProperty("applicationUuid");
- if (uuidObject instanceof UUID) {
- applicationId = (UUID) uuidObject;
- } else {
- applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
- }
-
- // create and connect new APPLICATION_INFO oldAppInfo to Organization
+ while ( iterator.hasNext() ) {
- final UUID appId = applicationId;
+ Map oldAppInfo = CpEntityMapUtils.toMap( iterator.next() );
+ currentAppName = (String)oldAppInfo.get( PROPERTY_NAME );
- Entity appInfo = getApplicationInfo( emf, appId );
- if ( appInfo == null ) {
- Map<String, Object> appInfoMap = new HashMap<String, Object>() {{
- put(PROPERTY_NAME, appName);
- 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
-
- if ( !orgName.equals("usergrid") ) {
- EntityRef orgRef = em.getAlias(Group.ENTITY_TYPE, appName.split("/")[0]);
- em.createConnection(orgRef, "owns", appInfo);
- }
+ migragrateOneAppInfo(em, oldAppInfo, observer);
}
- em.refreshIndex();
-
// note that the old appinfos are not deleted
migrationInfoSerialization.setVersion( getName(), getMaxVersion() );
@@ -160,25 +167,177 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
}
- private Entity getApplicationInfo( EntityManagerFactory emf, UUID appId ) throws Exception {
- UUID mgmtAppId = emf.getManagementAppId();
- EntityManager rootEm = emf.getEntityManager( mgmtAppId );
+ 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];
+
+ UUID applicationId;
+
+ Object uuidObject = oldAppInfo.get("applicationUuid");
+ if (uuidObject instanceof UUID) {
+ applicationId = (UUID) uuidObject;
+ } else {
+ applicationId = UUIDUtils.tryExtractUUID(uuidObject.toString());
+ }
+
+ // 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);
+ }
- final Results applicationInfoResults = rootEm.searchCollection(
- new SimpleEntityRef("application", mgmtAppId), "application_infos",
- Query.fromQL("select * where applicationId=" + appId.toString()));
+ // create org->app connections, but not for apps in dummy "usergrid" internal organization
- return applicationInfoResults.getEntity();
+ if ( !orgName.equals("usergrid") ) {
+ EntityRef orgRef = em.getAlias(Group.ENTITY_TYPE, orgName );
+ em.createConnection(orgRef, "owns", appInfo);
+ }
}
- @Override
- public int getMaxVersion() {
- return 1; // standalone plugin, happens once
+
+ /**
+ * 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 CollectionScope appInfoCollectionScope =
+ new CollectionScopeImpl( appScope.getApplication(), appScope.getApplication(),
+ CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPLICATION_INFOS ));
+
+ final EntityCollectionManager collectionManager =
+ entityCollectionManagerFactory.createCollectionManager( appInfoCollectionScope );
+
+ final GraphManager gm = graphManagerFactory.createEdgeManager(appScope);
+
+ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS );
+
+ Id rootAppId = appScope.getApplication();
+
+ final SimpleSearchByEdgeType simpleSearchByEdgeType = new SimpleSearchByEdgeType(
+ rootAppId, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null);
+
+ // TODO: is there a better way?
+
+ 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;
+ }
+ });
+ }
+ });
+
+ // don't expect many applications, so we block
+
+ org.apache.usergrid.persistence.model.entity.Entity applicationInfo =
+ entityObs.toBlocking().lastOrDefault(null);
+
+ if ( applicationInfo == null ) {
+ return null;
+ }
+
+ Class clazz = Schema.getDefaultSchema().getEntityClass(applicationInfo.getId().getType());
+
+ Entity entity = EntityFactory.newEntity(
+ applicationInfo.getId().getUuid(), applicationInfo.getId().getType(), clazz );
+
+ entity.setProperties( CpEntityMapUtils.toMap( applicationInfo ) );
+
+ 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();
}
- @Override
- public PluginPhase getPhase() {
- return PluginPhase.MIGRATE;
+
+ /**
+ * Use Graph to get old appinfos from the old and deprecated System App.
+ */
+ public Observable<org.apache.usergrid.persistence.model.entity.Entity> getOldAppInfos( ) {
+
+ final ApplicationScope appScope = getApplicationScope( CpNamingUtils.SYSTEM_APP_ID );
+
+ final CollectionScope appInfoCollectionScope =
+ new CollectionScopeImpl( appScope.getApplication(), appScope.getApplication(),
+ CpNamingUtils.getCollectionScopeNameFromCollectionName( "appinfos" ));
+
+ final EntityCollectionManager collectionManager =
+ entityCollectionManagerFactory.createCollectionManager( appInfoCollectionScope );
+
+ final GraphManager gm = graphManagerFactory.createEdgeManager(appScope);
+
+ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( "appinfos" );
+
+ Id rootAppId = appScope.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>>() {
+
+ @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 entityObs;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/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 6557b02..efa6a47 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,8 @@ package org.apache.usergrid;
import java.util.UUID;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.utils.UUIDUtils;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
@@ -36,6 +38,8 @@ import org.apache.usergrid.utils.JsonUtils;
import com.google.inject.Injector;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
+
public class CoreITSetupImpl implements CoreITSetup {
private static final Logger LOG = LoggerFactory.getLogger( CoreITSetupImpl.class );
@@ -129,7 +133,10 @@ public class CoreITSetupImpl implements CoreITSetup {
@Override
public UUID createApplication( String organizationName, String applicationName ) throws Exception {
- return emf.createApplication( organizationName, applicationName );
+ Entity appInfo = emf.createApplicationV2(organizationName, applicationName);
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
+ return applicationId;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
index 00e81d3..a5e1493 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
@@ -45,6 +45,7 @@ import org.apache.usergrid.utils.UUIDUtils;
import net.jcip.annotations.NotThreadSafe;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -218,7 +219,9 @@ public class CounterIT extends AbstractCoreIT {
organizationEntity.setProperty( "name", orgName );
organizationEntity = em.create( organizationEntity );
- UUID applicationId = setup.getEmf().createApplication( orgName, appName );
+ Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName );
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "name", orgName + "/" + appName );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
index e0d3ffb..6681b2c 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
@@ -42,6 +42,7 @@ import org.apache.usergrid.persistence.index.query.Query.Level;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import org.apache.usergrid.utils.UUIDUtils;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -388,8 +389,10 @@ public class EntityManagerIT extends AbstractCoreIT {
organizationEntity.setProperty( "name", "testCounterOrg" );
organizationEntity = em.create( organizationEntity );
- UUID applicationId = setup.getEmf().createApplication(
+ Entity appInfo = setup.getEmf().createApplicationV2(
"testCounterOrg", "testEntityCounters" + UUIDGenerator.newTimeUUID() );
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "name", "testEntityCounters" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index 08267ee..d554f45 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.UUID;
import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.utils.UUIDUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -45,6 +46,7 @@ import rx.functions.Func2;
import javax.annotation.concurrent.NotThreadSafe;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -82,7 +84,10 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
public UUID createApplication( String organizationName, String applicationName ) throws Exception {
- return emf.createApplication( organizationName, applicationName );
+ Entity appInfo = emf.createApplicationV2(organizationName, applicationName);
+ UUID appId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
+ return appId;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
index 8d551cf..5145b65 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
@@ -59,6 +59,7 @@ import static org.apache.usergrid.TestHelper.uniqueEmail;
import static org.apache.usergrid.TestHelper.uniqueOrg;
import static org.apache.usergrid.TestHelper.uniqueUsername;
import static org.apache.usergrid.persistence.Schema.DICTIONARY_CREDENTIALS;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -637,7 +638,9 @@ public class ManagementServiceIT {
String orgName = uniqueOrg();
String appName = uniqueApp();
- UUID appId = setup.getEmf().createApplication( orgName, appName );
+ Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName );
+ UUID appId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
User user = new User();
user.setActivated( true );
@@ -681,7 +684,9 @@ public class ManagementServiceIT {
String orgName = "testAppUserPasswordChangeShaType"+newUUIDString();
String appName = "testAppUserPasswordChangeShaType"+newUUIDString();
- UUID appId = setup.getEmf().createApplication( orgName, appName );
+ Entity appInfo = setup.getEmf().createApplicationV2(orgName, appName);
+ UUID appId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
User user = new User();
user.setActivated( true );
@@ -740,7 +745,9 @@ public class ManagementServiceIT {
String orgName = uniqueOrg();
String appName = uniqueApp();
- UUID appId = setup.getEmf().createApplication( orgName, appName );
+ Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName );
+ UUID appId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
User user = new User();
user.setActivated( true );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
index 3a6d8f9..0e73a82 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
@@ -28,6 +28,7 @@ import com.google.common.util.concurrent.Service;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.usergrid.batch.service.JobSchedulerService;
+import org.apache.usergrid.utils.UUIDUtils;
import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
@@ -61,6 +62,7 @@ import com.google.inject.Module;
import static org.apache.usergrid.TestHelper.newUUIDString;
import static org.apache.usergrid.TestHelper.uniqueApp;
import static org.apache.usergrid.TestHelper.uniqueOrg;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -404,10 +406,12 @@ public class ExportServiceIT {
f.deleteOnExit();
- UUID appId = setup.getEmf().createApplication( orgName, appName );
+ Entity appInfo = setup.getEmf().createApplicationV2(orgName, appName);
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
- EntityManager em = setup.getEmf().getEntityManager( appId );
+ EntityManager em = setup.getEmf().getEntityManager( applicationId );
//intialize user object to be posted
Map<String, Object> userProperties = null;
Entity[] entity;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/285230f3/stack/services/src/test/java/org/apache/usergrid/services/ServiceFactoryIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ServiceFactoryIT.java b/stack/services/src/test/java/org/apache/usergrid/services/ServiceFactoryIT.java
index c4603ff..cc05451 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ServiceFactoryIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ServiceFactoryIT.java
@@ -19,6 +19,8 @@ package org.apache.usergrid.services;
import java.util.UUID;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.utils.UUIDUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,6 +30,7 @@ import org.apache.usergrid.services.simple.SimpleService;
import static org.apache.usergrid.TestHelper.uniqueApp;
import static org.apache.usergrid.TestHelper.uniqueOrg;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -42,7 +45,10 @@ public class ServiceFactoryIT extends AbstractServiceIT {
public void testPackagePrefixes() throws Exception {
logger.info( "test package prefixes" );
- UUID applicationId = setup.getEmf().createApplication(uniqueOrg(), uniqueApp() );
+ Entity appInfo = setup.getEmf().createApplicationV2(uniqueOrg(), uniqueApp());
+ UUID applicationId = UUIDUtils.tryExtractUUID(
+ appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
+
ServiceManager sm = setup.getSmf().getServiceManager( applicationId );
Service service = sm.getService( "simple" );
assertEquals( "/simple", service.getServiceType() );
[33/50] incubator-usergrid git commit: Merge branch 'USERGRID-405' of
https://github.com/apache/incubator-usergrid into USERGRID-405
Posted by sn...@apache.org.
Merge branch 'USERGRID-405' of https://github.com/apache/incubator-usergrid into USERGRID-405
Conflicts:
stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9a391fe1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9a391fe1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9a391fe1
Branch: refs/heads/two-dot-o-dev
Commit: 9a391fe18eecd6d87eafa36406fcb6a1d662d36f
Parents: 774324c dcf4693
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 09:56:18 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 09:56:18 2015 -0400
----------------------------------------------------------------------
stack/core/pom.xml | 33 +-
.../corepersistence/CpEntityManager.java | 2 +-
.../corepersistence/CpEntityManagerFactory.java | 7 +-
.../corepersistence/CpRelationManager.java | 24 +-
.../usergrid/corepersistence/CpWalker.java | 81 ++---
.../events/EntityVersionDeletedHandler.java | 72 ++--
.../migration/EntityTypeMappingMigration.java | 41 +--
.../persistence/ObservableIterator.java | 1 +
.../migration/EntityTypeMappingMigrationIT.java | 2 +-
.../PerformanceEntityRebuildIndexTest.java | 4 +-
stack/corepersistence/collection/pom.xml | 14 +-
.../impl/EntityCollectionManagerImpl.java | 10 +-
.../collection/impl/EntityDeletedTask.java | 20 +-
.../impl/EntityVersionCleanupTask.java | 40 +--
.../impl/EntityVersionCreatedTask.java | 26 +-
.../mvcc/stage/write/WriteCommit.java | 2 +-
.../mvcc/stage/write/WriteUniqueVerify.java | 8 +-
.../MvccEntitySerializationStrategyImpl.java | 92 ++---
.../MvccEntitySerializationStrategyV3Impl.java | 94 ++---
.../UniqueValueSerializationStrategyImpl.java | 8 -
.../migration/MvccEntityDataMigrationImpl.java | 171 ++++------
.../collection/util/EntityUtils.java | 72 ----
.../mvcc/stage/AbstractEntityStageTest.java | 2 +-
.../mvcc/stage/AbstractMvccEntityStageTest.java | 2 +-
.../mvcc/stage/TestEntityGenerator.java | 2 +-
.../persistence/collection/rx/ParallelTest.java | 10 +-
...MvccEntitySerializationStrategyImplTest.java | 4 +-
...ccEntitySerializationStrategyV1ImplTest.java | 4 +-
...ccEntitySerializationStrategyV2ImplTest.java | 2 +-
.../impl/SerializationComparison.java | 4 +-
...ctMvccEntityDataMigrationV1ToV3ImplTest.java | 2 +-
.../collection/util/InvalidEntityGenerator.java | 1 +
stack/corepersistence/common/pom.xml | 15 +-
.../astyanax/MultiKeyColumnNameIterator.java | 4 +-
.../MultiKeyColumnNameIteratorTest.java | 187 +++++-----
.../astyanax/MultiRowColumnIteratorTest.java | 50 ++-
.../graph/impl/GraphManagerImpl.java | 6 +-
.../graph/impl/stage/EdgeMetaRepairImpl.java | 2 +
.../impl/stage/NodeDeleteListenerImpl.java | 2 +-
.../impl/migration/EdgeDataMigrationImpl.java | 87 +++--
.../persistence/graph/GraphManagerIT.java | 17 +-
.../graph/GraphManagerShardConsistencyIT.java | 2 +-
.../usergrid/persistence/graph/SimpleTest.java | 12 +-
.../migration/EdgeDataMigrationImplTest.java | 2 +-
stack/corepersistence/model/pom.xml | 1 -
.../persistence/model/util/EntityUtils.java | 72 ++++
stack/corepersistence/pom.xml | 8 +-
stack/corepersistence/queryindex/pom.xml | 6 -
.../index/impl/EsEntityIndexImpl.java | 2 +-
.../persistence/index/query/EntityResults.java | 108 ------
.../persistence/index/query/Results.java | 148 --------
.../persistence/index/utils/ListUtils.java | 6 +-
.../persistence/index/guice/IndexTestFig.java | 57 ++++
.../index/guice/TestIndexModule.java | 8 +-
.../index/impl/CorePerformanceIT.java | 339 -------------------
.../impl/EntityConnectionIndexImplTest.java | 306 -----------------
.../persistence/index/impl/EntityIndexTest.java | 32 +-
.../index/impl/IndexLoadTestsIT.java | 138 ++++++++
stack/pom.xml | 14 +-
stack/rest/pom.xml | 1 +
stack/services/pom.xml | 1 +
.../management/importer/ImportServiceImpl.java | 34 +-
.../impl/ApplicationQueueManagerImpl.java | 195 +++++------
.../setup/ConcurrentProcessSingleton.java | 19 +-
64 files changed, 908 insertions(+), 1830 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a391fe1/stack/pom.xml
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9a391fe1/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
----------------------------------------------------------------------
diff --cc stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
index 63aa70d,6d0419a..7cb5073
--- a/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/setup/ConcurrentProcessSingleton.java
@@@ -20,15 -20,15 +20,14 @@@
package org.apache.usergrid.setup;
-import java.io.IOException;
-
--import org.slf4j.Logger;
--import org.slf4j.LoggerFactory;
--
import org.apache.usergrid.cassandra.SchemaManager;
import org.apache.usergrid.cassandra.SpringResource;
import org.apache.usergrid.lock.MultiProcessBarrier;
import org.apache.usergrid.lock.MultiProcessLocalLock;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
/**
@@@ -109,8 -108,19 +108,18 @@@ public class ConcurrentProcessSingleto
barrier.await( ONE_MINUTE );
logger.info( "Setup to complete" );
- // Commented out: Never release the lock, otherwise some other JVM may destroy the schema
- // lock.maybeReleaseLock();
-
+ Runtime.getRuntime().addShutdownHook( new Thread( ){
+ @Override
+ public void run() {
+ try {
+ lock.maybeReleaseLock();
+ }
+ catch ( IOException e ) {
+ throw new RuntimeException( "Unable to release lock" );
+ }
+ }
+ });
+
}
catch ( Exception e ) {
throw new RuntimeException( "Unable to initialize system", e );
[40/50] incubator-usergrid git commit: TODO for proper error handling
once onErrorResumeNext() is implemented.
Posted by sn...@apache.org.
TODO for proper error handling once onErrorResumeNext() is implemented.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c0384d51
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c0384d51
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c0384d51
Branch: refs/heads/two-dot-o-dev
Commit: c0384d51e1842ed39649f54b4c5829aba27c9b50
Parents: 0c25d85
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 20 18:40:47 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 20 18:40:47 2015 -0400
----------------------------------------------------------------------
.../persistence/index/impl/EsIndexBufferConsumerImpl.java | 9 +++++++++
1 file changed, 9 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0384d51/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
index b0d6047..ecee76b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsIndexBufferConsumerImpl.java
@@ -329,6 +329,8 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
failureMonitor.success();
+ boolean error = false;
+
for (BulkItemResponse response : responses) {
if (response.isFailed()) {
@@ -339,7 +341,14 @@ public class EsIndexBufferConsumerImpl implements IndexBufferConsumer {
response.getIndex(),
response.getFailureMessage()
);
+
+ error = true;
}
}
+
+ if ( error ) {
+ // TODO: throw error once onErrorResumeNext() implemented in startWorker()
+ //throw new RuntimeException("Error during processing of bulk index operations")
+ }
}
}