You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/04/13 19:45:48 UTC
[23/50] incubator-usergrid git commit: fix cp head entity null
fix cp head entity null
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/552361b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/552361b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/552361b7
Branch: refs/heads/USERGRID-536
Commit: 552361b7bfd1af066c8b5e4217be9c8457daf332
Parents: f5d77b1
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Apr 6 17:10:36 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Apr 6 17:10:36 2015 -0600
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 23 ++++++++--
.../corepersistence/CpEntityManagerFactory.java | 11 +++--
.../corepersistence/CpRelationManager.java | 46 ++++++++------------
.../CpRelationManagerFactory.java | 46 ++++++++++++++++++++
.../usergrid/persistence/EntityManager.java | 10 +++++
.../cassandra/EntityManagerImpl.java | 7 +++
.../cassandra/ManagementServiceImpl.java | 12 ++---
.../usergrid/management/OrganizationIT.java | 6 +--
8 files changed, 118 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index a254a5f..8fcc505 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -348,11 +348,25 @@ public class CpEntityManager implements EntityManager {
public Entity create( UUID importId, String entityType, Map<String, Object> properties ) throws Exception {
UUID timestampUuid = importId != null ? importId : UUIDUtils.newTimeUUID();
+ Keyspace ko = cass.getApplicationKeyspace( applicationId );
+ Mutator<ByteBuffer> m = createMutator( ko, be );
+
+ Entity entity = batchCreate( m,entityType, null, properties, importId, timestampUuid );
+
+ //Adding graphite metrics
+ Timer.Context timeCassCreation = entCreateTimer.time();
+ m.execute();
+ timeCassCreation.stop();
+ return entity;
+ }
+
+ @Override
+ public Entity create( Id id, Map<String, Object> properties ) throws Exception {
Keyspace ko = cass.getApplicationKeyspace( applicationId );
Mutator<ByteBuffer> m = createMutator( ko, be );
- Entity entity = batchCreate( m, entityType, null, properties, importId, timestampUuid );
+ Entity entity = batchCreate( m, id.getType(), null, properties, id.getUuid(), UUIDUtils.newTimeUUID() );
//Adding graphite metrics
Timer.Context timeCassCreation = entCreateTimer.time();
@@ -727,9 +741,10 @@ public class CpEntityManager implements EntityManager {
@Override
public RelationManager getRelationManager( EntityRef entityRef ) {
- Preconditions.checkNotNull( entityRef, "entityRef cannot be null" );
- CpRelationManager rmi = new CpRelationManager();
- rmi.init( this, emf, applicationId, entityRef, null, metricsFactory );
+ Preconditions.checkNotNull(entityRef, "entityRef cannot be null");
+ CpRelationManager rmi = CpRelationManagerFactory.get(
+ this, emf, applicationId, entityRef, null, metricsFactory
+ );
return rmi;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/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 3dfdfd2..0cdf7cc 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
@@ -244,7 +244,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// Ensure our management system exists before creating our application
init();
- EntityManager em = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ EntityManager managementEm = getEntityManager( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
final String appName = buildAppName( organizationName, name );
@@ -274,7 +274,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
Entity appInfo;
try {
- appInfo = em.create(CpNamingUtils.APPLICATION_INFO, appInfoMap);
+ appInfo = managementEm.create(applicationId,CpNamingUtils.APPLICATION_INFO, appInfoMap);
} catch (DuplicateUniquePropertyExistsException e) {
throw new ApplicationAlreadyExistsException(appName);
}
@@ -312,11 +312,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.APPLICATION_INFOS);
+ //TODO: this could be due to app info issue
Observable<Edge> appInfoEdges = managementGraphManager.loadEdgesFromSource(new SimpleSearchByEdgeType(
managementAppId, edgeType, Long.MAX_VALUE,
SearchByEdgeType.Order.DESCENDING, null));
- appInfoEdges.flatMap(appInfoEdge -> {
+ appInfoEdges
+ .filter(appInfoEdge -> {
+ return appInfoEdge.getTargetNode().getUuid().equals(applicationId);
+ })
+ .flatMap(appInfoEdge -> {
try {
Entity appInfoToDelete = managementEm.get(appInfoEdge.getTargetNode().getUuid());
final Id deletedAppId = new SimpleId(appInfoToDelete.getUuid(), appInfoToDelete.getType());
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index b76f38f..e0bddad 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -203,56 +203,46 @@ public class CpRelationManager implements RelationManager {
IndexBucketLocator indexBucketLocator,
MetricsFactory metricsFactory) {
- Assert.notNull( em, "Entity manager cannot be null" );
- Assert.notNull( emf, "Entity manager factory cannot be null" );
- Assert.notNull( applicationId, "Application Id cannot be null" );
- Assert.notNull( headEntity, "Head entity cannot be null" );
- Assert.notNull( headEntity.getUuid(), "Head entity uuid cannot be null" );
-
+ Assert.notNull(em, "Entity manager cannot be null");
+ Assert.notNull(emf, "Entity manager factory cannot be null");
+ Assert.notNull(applicationId, "Application Id cannot be null");
+ Assert.notNull(headEntity, "Head entity cannot be null");
+ Assert.notNull(headEntity.getUuid(), "Head entity uuid cannot be null");
// TODO: this assert should not be failing
//Assert.notNull( indexBucketLocator, "indexBucketLocator cannot be null" );
-
this.em = em;
this.emf = emf;
this.applicationId = applicationId;
this.headEntity = headEntity;
this.managerCache = emf.getManagerCache();
- this.applicationScope = CpNamingUtils.getApplicationScope( applicationId );
-
+ this.applicationScope = CpNamingUtils.getApplicationScope(applicationId);
this.cass = em.getCass(); // TODO: eliminate need for this via Core Persistence
this.indexBucketLocator = indexBucketLocator; // TODO: this also
this.metricsFactory = metricsFactory;
this.updateCollectionTimer = metricsFactory
- .getTimer( CpRelationManager.class, "relation.manager.es.update.collection" );
+ .getTimer(CpRelationManager.class, "relation.manager.es.update.collection");
this.createConnectionTimer = metricsFactory
- .getTimer( CpRelationManager.class, "relation.manager.es.create.connection.timer" );
+ .getTimer(CpRelationManager.class, "relation.manager.es.create.connection.timer");
this.cassConnectionDelete = metricsFactory
- .getTimer( CpRelationManager.class, "relation.manager.cassandra.delete.connection.batch.timer" );
- this.esDeleteConnectionTimer = metricsFactory.getTimer( CpRelationManager.class,
- "relation.manager.es.delete.connection.batch.timer" );
+ .getTimer(CpRelationManager.class, "relation.manager.cassandra.delete.connection.batch.timer");
+ this.esDeleteConnectionTimer = metricsFactory.getTimer(CpRelationManager.class,
+ "relation.manager.es.delete.connection.batch.timer");
-
- if ( logger.isDebugEnabled() ) {
- logger.debug( "Loading head entity {}:{} from app {}",
- new Object[] {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Loading head entity {}:{} from app {}",
+ new Object[]{
headEntity.getType(),
headEntity.getUuid(),
applicationScope
- } );
+ });
}
- Id entityId = new SimpleId( headEntity.getUuid(), headEntity.getType() );
+ Id entityId = new SimpleId(headEntity.getUuid(), headEntity.getType());
-// if(headEntity instanceof Entity){
-// cpHeadEntity = entityToCpEntity( (Entity)headEntity, headEntity.getUuid() );
-// }else {
- this.cpHeadEntity =
- ( ( CpEntityManager ) em ).load( entityId );
-// }
+ this.cpHeadEntity = ((CpEntityManager) em).load(entityId);
// commented out because it is possible that CP entity has not been created yet
- Assert.notNull( cpHeadEntity, "cpHeadEntity cannot be null" );
-
+ Assert.notNull(cpHeadEntity, "cpHeadEntity cannot be null for app id " + applicationScope.getApplication().getUuid());
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManagerFactory.java
new file mode 100644
index 0000000..4223f37
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManagerFactory.java
@@ -0,0 +1,46 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. The ASF licenses this file to You
+ * * under the Apache License, Version 2.0 (the "License"); you may not
+ * * use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License. For additional information regarding
+ * * copyright in this work, please see the NOTICE file in the top level
+ * * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence;
+
+import com.google.inject.Inject;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.IndexBucketLocator;
+import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
+
+import java.util.UUID;
+
+/**
+ * Factory to return and init relation manager instances
+ */
+public class CpRelationManagerFactory {
+
+
+ public static CpRelationManager get( EntityManager em,
+ CpEntityManagerFactory emf,
+ UUID applicationId,
+ EntityRef headEntity,
+ IndexBucketLocator indexBucketLocator,
+ MetricsFactory metricsFactory){
+ CpRelationManager relationManager = new CpRelationManager();
+ relationManager.init(em,emf,applicationId,headEntity,indexBucketLocator,metricsFactory);
+ return relationManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 83f1973..d070756 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -35,6 +35,7 @@ import org.apache.usergrid.persistence.entities.Role;
import org.apache.usergrid.persistence.index.query.CounterResolution;
import org.apache.usergrid.persistence.index.query.Identifier;
import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.model.entity.Id;
/**
@@ -93,6 +94,15 @@ public interface EntityManager {
public Entity create( UUID importId, String entityType, Map<String, Object> properties )
throws Exception;
+ /**
+ * Creates an entity of the specified type attached to the specified application.
+ * @param id
+ * @param properties
+ * @return
+ * @throws Exception
+ */
+ public Entity create(Id id, Map<String, Object> properties )
+ throws Exception;
public void createApplicationCollection( String entityType ) throws Exception;
public EntityRef getAlias( String aliasType, String alias ) throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index a5ee067..39fed25 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -36,7 +36,9 @@ import java.util.UUID;
import javax.annotation.Resource;
+import org.apache.usergrid.exception.NotImplementedException;
import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.model.entity.Id;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
@@ -706,6 +708,11 @@ public class EntityManagerImpl implements EntityManager {
return create( entityType, null, properties, importId );
}
+ @Override
+ public Entity create(Id id, Map<String, Object> properties) throws Exception {
+ throw new NotImplementedException();
+ }
+
@SuppressWarnings( "unchecked" )
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/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 682044b..1049c85 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
@@ -32,6 +32,9 @@ 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.graph.Edge;
+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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -144,6 +147,8 @@ import static org.apache.usergrid.persistence.entities.Activity.PROPERTY_OBJECT_
import static org.apache.usergrid.persistence.entities.Activity.PROPERTY_TITLE;
import static org.apache.usergrid.persistence.entities.Activity.PROPERTY_VERB;
import org.apache.usergrid.persistence.index.query.Query.Level;
+import rx.Observable;
+
import static org.apache.usergrid.security.AuthPrincipalType.ADMIN_USER;
import static org.apache.usergrid.security.AuthPrincipalType.APPLICATION;
import static org.apache.usergrid.security.AuthPrincipalType.APPLICATION_USER;
@@ -1611,8 +1616,6 @@ public class ManagementServiceImpl implements ManagementService {
properties = new HashMap<>();
}
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
-
OrganizationInfo organizationInfo = getOrganizationByUuid( organizationId );
Entity appInfo = emf.createApplicationV2(
organizationInfo.getName(), applicationName, properties);
@@ -1711,7 +1714,7 @@ public class ManagementServiceImpl implements ManagementService {
return null;
}
- EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
+ final EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
Results r = em.getConnectingEntities(
new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
@@ -1786,8 +1789,7 @@ public class ManagementServiceImpl implements ManagementService {
@Override
public UUID addApplicationToOrganization(UUID organizationId, Entity appInfo) throws Exception {
- UUID applicationId = UUIDUtils.tryExtractUUID(
- appInfo.getProperty(PROPERTY_APPLICATION_ID).toString());
+ UUID applicationId = appInfo.getUuid();
if ( ( organizationId == null ) || ( applicationId == null ) ) {
return null;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/552361b7/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
index 7bd6574..cbd0e6d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
@@ -79,8 +79,8 @@ public class OrganizationIT {
organization.getOrganization().getUuid() );
assertEquals( "wrong number of users", 1, users.size() );
- UUID applicationId = setup.getMgmtSvc().createApplication( organization.getOrganization().getUuid(), "ed-application" ).getId();
- assertNotNull( applicationId );
+ ApplicationInfo applicationInfo = setup.getMgmtSvc().createApplication(organization.getOrganization().getUuid(), "ed-application");
+ assertNotNull( applicationInfo.getId() );
setup.getEntityIndex().refresh();
@@ -88,7 +88,7 @@ public class OrganizationIT {
Map<UUID, String> applications = setup.getMgmtSvc().getApplicationsForOrganization( organization.getOrganization().getUuid() );
assertEquals( "wrong number of applications", 1, applications.size() );
- OrganizationInfo organization2 = setup.getMgmtSvc().getOrganizationForApplication( applicationId );
+ OrganizationInfo organization2 = setup.getMgmtSvc().getOrganizationForApplication( applicationInfo.getId() );
assertNotNull( organization2 );
assertEquals( "wrong organization name", organization.getOrganization().getName(), organization2.getName() );