You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/05/19 10:27:41 UTC
[2/4] brooklyn-server git commit: Move `newBrooklynMemento` to
RebindTestUtils
Move `newBrooklynMemento` to RebindTestUtils
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4dac225b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4dac225b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4dac225b
Branch: refs/heads/master
Commit: 4dac225ba633468cf3a362ad6dcc1bdf20eca103
Parents: 846314a
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:14:31 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:47:26 2017 +0100
----------------------------------------------------------------------
.../mgmt/rebind/dto/BrooklynMementoImpl.java | 3 ++
.../mgmt/rebind/dto/MementosGenerators.java | 39 --------------------
.../core/mgmt/rebind/RebindTestUtils.java | 33 +++++++++++++++--
3 files changed, 33 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4dac225b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BrooklynMementoImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BrooklynMementoImpl.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BrooklynMementoImpl.java
index d60c8f3..68a3392 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BrooklynMementoImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BrooklynMementoImpl.java
@@ -74,6 +74,9 @@ public class BrooklynMementoImpl implements BrooklynMemento, Serializable {
public Builder applicationIds(Collection<String> vals) {
applicationIds.addAll(vals); return this;
}
+ public Builder topLevelLocationId(String val) {
+ topLevelLocationIds.add(val); return this;
+ }
public Builder topLevelLocationIds(Collection<String> vals) {
topLevelLocationIds.addAll(vals); return this;
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4dac225b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
index 3a33498..d4983ca 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
@@ -30,9 +30,7 @@ import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.Group;
import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMemento;
import org.apache.brooklyn.api.mgmt.rebind.mementos.CatalogItemMemento;
import org.apache.brooklyn.api.mgmt.rebind.mementos.EnricherMemento;
import org.apache.brooklyn.api.mgmt.rebind.mementos.EntityMemento;
@@ -60,7 +58,6 @@ import org.apache.brooklyn.core.location.internal.LocationInternal;
import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
import org.apache.brooklyn.core.mgmt.persist.OsgiClassPrefixer;
import org.apache.brooklyn.core.mgmt.rebind.AbstractBrooklynObjectRebindSupport;
-import org.apache.brooklyn.core.mgmt.rebind.TreeUtils;
import org.apache.brooklyn.core.objs.BrooklynTypes;
import org.apache.brooklyn.core.policy.AbstractPolicy;
import org.apache.brooklyn.util.collections.MutableMap;
@@ -114,42 +111,6 @@ public class MementosGenerators {
}
/**
- * Walks the contents of a ManagementContext, to create a corresponding memento.
- *
- * @deprecated since 0.7.0; will be moved to test code; generate each entity/location memento separately
- */
- @Deprecated
- public static BrooklynMemento newBrooklynMemento(ManagementContext managementContext) {
- BrooklynMementoImpl.Builder builder = BrooklynMementoImpl.builder();
-
- for (Application app : managementContext.getApplications()) {
- builder.applicationIds.add(app.getId());
- }
- for (Entity entity : managementContext.getEntityManager().getEntities()) {
- builder.entities.put(entity.getId(), ((EntityInternal)entity).getRebindSupport().getMemento());
-
- for (Location location : entity.getLocations()) {
- if (!builder.locations.containsKey(location.getId())) {
- for (Location locationInHierarchy : TreeUtils.findLocationsInHierarchy(location)) {
- if (!builder.locations.containsKey(locationInHierarchy.getId())) {
- builder.locations.put(locationInHierarchy.getId(), ((LocationInternal)locationInHierarchy).getRebindSupport().getMemento());
- }
- }
- }
- }
- }
- for (LocationMemento memento : builder.locations.values()) {
- if (memento.getParent() == null) {
- builder.topLevelLocationIds.add(memento.getId());
- }
- }
-
- BrooklynMemento result = builder.build();
- MementoValidators.validateMemento(result);
- return result;
- }
-
- /**
* Inspects an entity to create a corresponding memento.
*/
private static EntityMemento newEntityMemento(Entity entityRaw) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4dac225b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
index 537ff8c..912f7ef 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
@@ -40,7 +40,9 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister;
import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
import org.apache.brooklyn.api.objs.BrooklynObjectType;
import org.apache.brooklyn.api.objs.Identifiable;
+import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.location.internal.LocationInternal;
import org.apache.brooklyn.core.mgmt.ha.ManagementPlaneSyncRecordPersisterToObjectStore;
import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
@@ -49,7 +51,8 @@ import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
import org.apache.brooklyn.core.mgmt.persist.PersistMode;
import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
import org.apache.brooklyn.core.mgmt.rebind.Dumpers.Pointer;
-import org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators;
+import org.apache.brooklyn.core.mgmt.rebind.dto.BrooklynMementoImpl;
+import org.apache.brooklyn.core.mgmt.rebind.dto.MementoValidators;
import org.apache.brooklyn.core.server.BrooklynServerConfig;
import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
import org.apache.brooklyn.util.io.FileUtil;
@@ -114,7 +117,7 @@ public class RebindTestUtils {
}
public static void checkMementoSerializable(Application app) throws Exception {
- BrooklynMemento memento = MementosGenerators.newBrooklynMemento(app.getManagementContext());
+ BrooklynMemento memento = newBrooklynMemento(app.getManagementContext());
checkMementoSerializable(memento);
}
@@ -530,7 +533,7 @@ public class RebindTestUtils {
}
public static void checkCurrentMementoSerializable(ManagementContext mgmt) throws Exception {
- BrooklynMemento memento = MementosGenerators.newBrooklynMemento(mgmt);
+ BrooklynMemento memento = newBrooklynMemento(mgmt);
serializeAndDeserialize(memento);
}
@@ -567,4 +570,28 @@ public class RebindTestUtils {
mgmt.terminate();
}
}
+
+ /**
+ * Walks the contents of a ManagementContext, to create a corresponding memento.
+ */
+ protected static BrooklynMemento newBrooklynMemento(ManagementContext managementContext) {
+ BrooklynMementoImpl.Builder builder = BrooklynMementoImpl.builder();
+
+ for (Application app : managementContext.getApplications()) {
+ builder.applicationId(app.getId());
+ }
+ for (Entity entity : managementContext.getEntityManager().getEntities()) {
+ builder.entity(((EntityInternal)entity).getRebindSupport().getMemento());
+ }
+ for (Location location : managementContext.getLocationManager().getLocations()) {
+ builder.location(((LocationInternal)location).getRebindSupport().getMemento());
+ if (location.getParent() == null) {
+ builder.topLevelLocationId(location.getId());
+ }
+ }
+
+ BrooklynMemento result = builder.build();
+ MementoValidators.validateMemento(result);
+ return result;
+ }
}