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:40 UTC

[1/4] brooklyn-server git commit: Delete `MutableBrooklynMemento`

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 6597908a2 -> 8a7d243c3


Delete `MutableBrooklynMemento`


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/3b41560c
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/3b41560c
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/3b41560c

Branch: refs/heads/master
Commit: 3b41560c64705b0f06d16254927b03f07a9f0d4f
Parents: 4dac225
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:16:15 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:47:26 2017 +0100

----------------------------------------------------------------------
 .../core/mgmt/persist/XmlMementoSerializer.java |   1 -
 .../mgmt/rebind/dto/MutableBrooklynMemento.java | 331 -------------------
 2 files changed, 332 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3b41560c/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
index 7f38611..2218c56 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
@@ -59,7 +59,6 @@ import org.apache.brooklyn.core.mgmt.rebind.dto.BasicFeedMemento;
 import org.apache.brooklyn.core.mgmt.rebind.dto.BasicLocationMemento;
 import org.apache.brooklyn.core.mgmt.rebind.dto.BasicManagedBundleMemento;
 import org.apache.brooklyn.core.mgmt.rebind.dto.BasicPolicyMemento;
-import org.apache.brooklyn.core.mgmt.rebind.dto.MutableBrooklynMemento;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
 import org.apache.brooklyn.util.core.ClassLoaderUtils;
 import org.apache.brooklyn.util.core.xstream.XmlSerializer;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3b41560c/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MutableBrooklynMemento.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MutableBrooklynMemento.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MutableBrooklynMemento.java
deleted file mode 100644
index a7dcbe9..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MutableBrooklynMemento.java
+++ /dev/null
@@ -1,331 +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.brooklyn.core.mgmt.rebind.dto;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-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;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.FeedMemento;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.LocationMemento;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.ManagedBundleMemento;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.PolicyMemento;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-
-/**
- * @deprecated since 0.7.0; this code will move to src/tests/java
- */
-@Deprecated
-@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
-public class MutableBrooklynMemento implements BrooklynMemento {
-
-    // TODO Is this class pulling its weight? Do we really need it?
-    // (shouldn't be used anymore -- have added logging April 2017 to ensure not used)
-
-    private static final Logger log = LoggerFactory.getLogger(MutableBrooklynMemento.class);
-    
-    private static final long serialVersionUID = -442895028005849060L;
-    
-    private String planeId;
-    private final Collection<String> applicationIds = Sets.newLinkedHashSet();
-    private final Collection<String> topLevelLocationIds = Sets.newLinkedHashSet();
-    private final Map<String, EntityMemento> entities = Maps.newLinkedHashMap();
-    private final Map<String, LocationMemento> locations = Maps.newLinkedHashMap();
-    private final Map<String, PolicyMemento> policies = Maps.newLinkedHashMap();
-    private final Map<String, EnricherMemento> enrichers = Maps.newLinkedHashMap();
-    private final Map<String, FeedMemento> feeds = Maps.newLinkedHashMap();
-    private final Map<String, CatalogItemMemento> catalogItems = Maps.newLinkedHashMap();
-    private final Map<String, ManagedBundleMemento> bundles = Maps.newLinkedHashMap();
-
-    {
-        log.warn("Using legacy "+this, new Exception("location of use of legacy "+this));
-    }
-    
-    public MutableBrooklynMemento() {
-    }
-    
-    public MutableBrooklynMemento(BrooklynMemento memento) {
-        reset(memento);
-    }
-    
-    public void reset(BrooklynMemento memento) {
-        planeId = memento.getPlaneId();
-        applicationIds.addAll(memento.getApplicationIds());
-        topLevelLocationIds.addAll(memento.getTopLevelLocationIds());
-        for (String entityId : memento.getEntityIds()) {
-            entities.put(entityId, checkNotNull(memento.getEntityMemento(entityId), entityId));
-        }
-        for (String locationId : memento.getLocationIds()) {
-            locations.put(locationId, checkNotNull(memento.getLocationMemento(locationId), locationId));
-        }
-    }
-
-    public void setPlaneId(String planeId) {
-        this.planeId = planeId;
-    }
-
-    public void updateEntityMemento(EntityMemento memento) {
-        updateEntityMementos(ImmutableSet.of(memento));
-    }
-    
-    public void updateLocationMemento(LocationMemento memento) {
-        updateLocationMementos(ImmutableSet.of(memento));
-    }
-    
-    public void updatePolicyMemento(PolicyMemento memento) {
-        updatePolicyMementos(ImmutableSet.of(memento));
-    }
-    
-    public void updateEnricherMemento(EnricherMemento memento) {
-        updateEnricherMementos(ImmutableSet.of(memento));
-    }
-    
-    public void updateFeedMemento(FeedMemento memento) {
-        updateFeedMementos(ImmutableSet.of(memento));
-    }
-
-    public void updateCatalogItemMemento(CatalogItemMemento memento) {
-        updateCatalogItemMementos(ImmutableSet.of(memento));
-    }
-    
-    public void updateEntityMementos(Collection<EntityMemento> mementos) {
-        for (EntityMemento memento : mementos) {
-            entities.put(memento.getId(), memento);
-            
-            if (memento.isTopLevelApp()) {
-                applicationIds.add(memento.getId());
-            }
-        }
-    }
-    
-    public void updateLocationMementos(Collection<LocationMemento> mementos) {
-        for (LocationMemento locationMemento : mementos) {
-            locations.put(locationMemento.getId(), locationMemento);
-            
-            if (locationMemento.getParent() == null) {
-                topLevelLocationIds.add(locationMemento.getId());
-            }
-        }
-    }
-    
-    public void updatePolicyMementos(Collection<PolicyMemento> mementos) {
-        for (PolicyMemento memento : mementos) {
-            policies.put(memento.getId(), memento);
-        }
-    }
-    
-    public void updateEnricherMementos(Collection<EnricherMemento> mementos) {
-        for (EnricherMemento memento : mementos) {
-            enrichers.put(memento.getId(), memento);
-        }
-    }
-    
-    public void updateFeedMementos(Collection<FeedMemento> mementos) {
-        for (FeedMemento memento : mementos) {
-            feeds.put(memento.getId(), memento);
-        }
-    }
-    
-    public void updateCatalogItemMementos(Collection<CatalogItemMemento> mementos) {
-        for (CatalogItemMemento memento : mementos) {
-            catalogItems.put(memento.getId(), memento);
-        }
-    }
-
-    /**
-     * Removes the entities with the given ids.
-     */
-    public void removeEntities(Collection<String> ids) {
-        entities.keySet().removeAll(ids);
-        applicationIds.removeAll(ids);
-    }
-    
-    /**
-     * Removes the locations with the given ids.
-     */
-    public void removeLocations(Collection<String> ids) {
-        locations.keySet().removeAll(ids);
-        topLevelLocationIds.removeAll(ids);
-    }
-
-    /**
-     * Removes the policies with the given ids.
-     */
-    public void removePolicies(Collection<String> ids) {
-        policies.keySet().removeAll(ids);
-    }
-
-    /**
-     * Removes the enrichers with the given ids.
-     */
-    public void removeEnrichers(Collection<String> ids) {
-        enrichers.keySet().removeAll(ids);
-    }
-
-    /**
-     * Removes the feeds with the given ids.
-     */
-    public void removeFeeds(Collection<String> ids) {
-        feeds.keySet().removeAll(ids);
-    }
-
-    /**
-     * Removes the catalog items with the given ids.
-     */
-    public void removeCatalogItems(Collection<String> ids) {
-        catalogItems.keySet().removeAll(ids);
-    }
-    
-    @Override
-    public String getPlaneId() {
-        return planeId;
-    }
-
-    @Override
-    public EntityMemento getEntityMemento(String id) {
-        return entities.get(id);
-    }
-
-    @Override
-    public LocationMemento getLocationMemento(String id) {
-        return locations.get(id);
-    }
-    
-    @Override
-    public PolicyMemento getPolicyMemento(String id) {
-        return policies.get(id);
-    }
-
-    @Override
-    public EnricherMemento getEnricherMemento(String id) {
-            return enrichers.get(id);
-        }
-    
-    @Override
-    public FeedMemento getFeedMemento(String id) {
-        return feeds.get(id);
-    }
-
-    @Override
-    public CatalogItemMemento getCatalogItemMemento(String id) {
-        return catalogItems.get(id);
-    }
-    
-    @Override
-    public Collection<String> getApplicationIds() {
-        return ImmutableList.copyOf(applicationIds);
-    }
-
-    @Override
-    public Collection<String> getEntityIds() {
-        // TODO Return immutable copy? Synchronize while making copy?
-        return Collections.unmodifiableSet(entities.keySet());
-    }
-    
-    @Override
-    public Collection<String> getLocationIds() {
-        return Collections.unmodifiableSet(locations.keySet());
-    }
-    
-    @Override
-    public Collection<String> getPolicyIds() {
-        return Collections.unmodifiableSet(policies.keySet());
-    }
-    
-    @Override
-    public Collection<String> getEnricherIds() {
-        return Collections.unmodifiableSet(enrichers.keySet());
-    }
-
-    @Override
-    public Collection<String> getFeedIds() {
-        return Collections.unmodifiableSet(feeds.keySet());
-    }
-    
-    @Override
-    public Collection<String> getCatalogItemIds() {
-        return Collections.unmodifiableSet(catalogItems.keySet());
-    }
-
-    @Override
-    public Collection<String> getTopLevelLocationIds() {
-        return Collections.unmodifiableCollection(topLevelLocationIds);
-    }
-
-    @Override
-    public Map<String, EntityMemento> getEntityMementos() {
-        return ImmutableMap.copyOf(entities);
-    }
-
-    @Override
-    public Map<String, LocationMemento> getLocationMementos() {
-        return ImmutableMap.copyOf(locations);
-    }
-
-    @Override
-    public Map<String, PolicyMemento> getPolicyMementos() {
-        return ImmutableMap.copyOf(policies);
-    }
-
-    @Override
-    public Map<String, EnricherMemento> getEnricherMementos() {
-        return ImmutableMap.copyOf(enrichers);
-    }
-    
-    @Override
-    public Map<String, FeedMemento> getFeedMementos() {
-        return ImmutableMap.copyOf(feeds);
-    }
-
-    @Override
-    public Map<String, CatalogItemMemento> getCatalogItemMementos() {
-        return ImmutableMap.copyOf(catalogItems);
-    }
-
-    @Override
-    public ManagedBundleMemento getManagedBundleMemento(String id) {
-        return null;
-    }
-
-    @Override
-    public Collection<String> getManagedBundleIds() {
-        return MutableList.of();
-    }
-
-    @Override
-    public Map<String, ManagedBundleMemento> getManagedBundleMementos() {
-        return bundles;
-    }
-}


[3/4] brooklyn-server git commit: Delete deprecated persistence/rebind code

Posted by dr...@apache.org.
Delete deprecated persistence/rebind code


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/846314a7
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/846314a7
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/846314a7

Branch: refs/heads/master
Commit: 846314a7734b6a251f128047fb7fbb19ca1bb69d
Parents: 3c35a1e
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:01:20 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:47:26 2017 +0100

----------------------------------------------------------------------
 .../mgmt/rebind/BasicEntityRebindSupport.java   | 18 ----
 .../mgmt/rebind/dto/MementosGenerators.java     | 87 +-------------------
 .../core/mgmt/rebind/RebindEntityTest.java      | 35 --------
 .../mgmt/rebind/RebindManagerSorterTest.java    |  2 +-
 4 files changed, 4 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/846314a7/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
index f3e4b5b..aa3e7a8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
@@ -19,7 +19,6 @@ package org.apache.brooklyn.core.mgmt.rebind;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
-import java.util.Collections;
 import java.util.Map;
 
 import org.apache.brooklyn.api.effector.Effector;
@@ -41,7 +40,6 @@ import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
 import org.apache.brooklyn.core.feed.AbstractFeed;
 import org.apache.brooklyn.core.location.Machines;
-import org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators;
 import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
 import org.apache.brooklyn.core.policy.AbstractPolicy;
 import org.apache.brooklyn.entity.group.AbstractGroupImpl;
@@ -64,22 +62,6 @@ public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSuppor
         this.entity = checkNotNull(entity, "entity");
     }
     
-    // Can rely on super-type once the deprecated getMementoWithProperties is deleted
-    @Override
-    public EntityMemento getMemento() {
-        return getMementoWithProperties(Collections.<String,Object>emptyMap());
-    }
-
-    /**
-     * @deprecated since 0.7.0; use generic config/attributes rather than "custom fields", so use {@link #getMemento()}
-     */
-    @Deprecated
-    protected EntityMemento getMementoWithProperties(Map<String,?> props) {
-        EntityMemento memento = MementosGenerators.newEntityMementoBuilder(entity).customFields(props).build();
-        if (LOG.isTraceEnabled()) LOG.trace("Creating memento for entity: {}", memento.toVerboseString());
-        return memento;
-    }
-
     @Override
     @SuppressWarnings("unchecked")
     protected void addCustoms(RebindContext rebindContext, EntityMemento memento) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/846314a7/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 dce5c97..3a33498 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
@@ -72,7 +72,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicates;
 import com.google.common.collect.Sets;
@@ -83,12 +82,6 @@ public class MementosGenerators {
 
     private static final Logger log = LoggerFactory.getLogger(MementosGenerators.class);
     
-    /** @deprecated since 0.7.0 use {@link #newBasicMemento(BrooklynObject)} */
-    @Deprecated
-    public static Memento newMemento(BrooklynObject instance) {
-        return newBasicMemento(instance);
-    }
-    
     /**
      * Inspects a brooklyn object to create a basic corresponding memento.
      * <p>
@@ -158,19 +151,8 @@ public class MementosGenerators {
     
     /**
      * Inspects an entity to create a corresponding memento.
-     * <p>
-     * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
-     */
-    @Deprecated
-    public static EntityMemento newEntityMemento(Entity entity) {
-        return newEntityMementoBuilder(entity).build();
-    }
-
-    /**
-     * @deprecated since 0.7.0; use {@link #newBasicMemento(BrooklynObject)} instead
      */
-    @Deprecated
-    public static BasicEntityMemento.Builder newEntityMementoBuilder(Entity entityRaw) {
+    private static EntityMemento newEntityMemento(Entity entityRaw) {
         EntityInternal entity = (EntityInternal) entityRaw;
         BasicEntityMemento.Builder builder = BasicEntityMemento.builder();
         populateBrooklynObjectMementoBuilder(entity, builder);
@@ -244,24 +226,10 @@ public class MementosGenerators {
             }
         }
 
-        return builder;
+        return builder.build();
     }
  
     /**
-     * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
-     */
-    @Deprecated
-    public static Function<Entity, EntityMemento> entityMementoFunction() {
-        return new Function<Entity,EntityMemento>() {
-            @Override
-            public EntityMemento apply(Entity input) {
-                return MementosGenerators.newEntityMemento(input);
-            }
-        };
-    }
-
-    
-    /**
      * Given a location, extracts its state for serialization.
      * 
      * For bits of state that are references to other locations, these are treated in a special way:
@@ -311,20 +279,6 @@ public class MementosGenerators {
     }
     
     /**
-     * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
-     */
-    @Deprecated
-    public static Function<Location, LocationMemento> locationMementoFunction() {
-        return new Function<Location,LocationMemento>() {
-            @Override
-            public LocationMemento apply(Location input) {
-                return MementosGenerators.newLocationMemento(input);
-            }
-        };
-    }
-
-    
-    /**
      * Given a policy, extracts its state for serialization.
      * 
      * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
@@ -356,19 +310,6 @@ public class MementosGenerators {
     }
     
     /**
-     * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
-     */
-    @Deprecated
-    public static Function<Policy, PolicyMemento> policyMementoFunction() {
-        return new Function<Policy,PolicyMemento>() {
-            @Override
-            public PolicyMemento apply(Policy input) {
-                return MementosGenerators.newPolicyMemento(input);
-            }
-        };
-    }
-
-    /**
      * Given an enricher, extracts its state for serialization.
      * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
      */
@@ -421,11 +362,7 @@ public class MementosGenerators {
         return builder.build();
     }
     
-    /**
-     * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
-     */
-    @Deprecated
-    public static CatalogItemMemento newCatalogItemMemento(CatalogItem<?, ?> catalogItem) {
+    private static CatalogItemMemento newCatalogItemMemento(CatalogItem<?, ?> catalogItem) {
         if (catalogItem instanceof CatalogItemDo<?,?>) {
             catalogItem = ((CatalogItemDo<?,?>)catalogItem).getDto();
         }
@@ -524,22 +461,4 @@ public class MementosGenerators {
         }
         return value;
     }
-    
-    public static Function<Enricher, EnricherMemento> enricherMementoFunction() {
-        return new Function<Enricher,EnricherMemento>() {
-            @Override
-            public EnricherMemento apply(Enricher input) {
-                return MementosGenerators.newEnricherMemento(input);
-            }
-        };
-    }
-
-    public static Function<Feed, FeedMemento> feedMementoFunction() {
-        return new Function<Feed,FeedMemento>() {
-            @Override
-            public FeedMemento apply(Feed input) {
-                return MementosGenerators.newFeedMemento(input);
-            }
-        };
-    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/846314a7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
index 32720b9..8c2e7b7 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
@@ -238,17 +238,6 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
     }
     
     @Test
-    public void testCanCustomizeRebind() throws Exception {
-        MyEntity2 origE = origApp.createAndManageChild(EntitySpec.create(MyEntity2.class).configure("myfield", "myval"));
-        
-        newApp = rebind();
-        
-        MyEntity2 newE = (MyEntity2) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity2.class));
-        assertEquals(newE.getMyfield(), "myval");
-        Assert.assertEquals(newE, origE);
-    }
-    
-    @Test
     public void testRebindsSubscriptions() throws Exception {
         MyEntity2 origE = origApp.createAndManageChild(EntitySpec.create(MyEntity2.class).configure("subscribe", true));
         
@@ -835,14 +824,9 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
                 Boolean.class, "test.subscribe", "Whether to do some subscriptions on re-bind", false);
         
         public List<String> getEvents();
-        
-        public String getMyfield();
     }
     
     public static class MyEntity2Impl extends AbstractEntity implements MyEntity2 {
-        @SetFromFlag
-        String myfield;
-        
         final List<String> events = new CopyOnWriteArrayList<String>();
 
         @SuppressWarnings("unused")
@@ -857,11 +841,6 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
         }
 
         @Override
-        public String getMyfield() {
-            return myfield;
-        }
-        
-        @Override
         public void onManagementStarting() {
             if (getConfig(SUBSCRIBE)) {
                 subscriptions().subscribe(getApplication(), TestApplication.MY_ATTRIBUTE, new SensorEventListener<String>() {
@@ -871,20 +850,6 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
                 });
             }
         }
-        
-        @Override
-        public RebindSupport<EntityMemento> getRebindSupport() {
-            return new BasicEntityRebindSupport(this) {
-                @Override public EntityMemento getMemento() {
-                    // Note: using MutableMap so accepts nulls
-                    return getMementoWithProperties(MutableMap.<String,Object>of("myfield", myfield));
-                }
-                @Override protected void doReconstruct(RebindContext rebindContext, EntityMemento memento) {
-                    super.doReconstruct(rebindContext, memento);
-                    myfield = (String) memento.getCustomField("myfield");
-                }
-            };
-        }
     }
 
     @ImplementedBy(MyLatchingEntityImpl.class)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/846314a7/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerSorterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerSorterTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerSorterTest.java
index 6387b81..598c0d5 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerSorterTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindManagerSorterTest.java
@@ -140,7 +140,7 @@ public class RebindManagerSorterTest {
     private Map<String, EntityMemento> toMementos(Iterable<? extends Entity> entities) {
         Map<String, EntityMemento> result = Maps.newLinkedHashMap();
         for (Entity entity : entities) {
-            result.put(entity.getId(), MementosGenerators.newEntityMemento(Entities.deproxy(entity)));
+            result.put(entity.getId(), (EntityMemento) MementosGenerators.newBasicMemento(Entities.deproxy(entity)));
         }
         return result;
     }


[4/4] brooklyn-server git commit: This closes #688

Posted by dr...@apache.org.
This closes #688


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8a7d243c
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8a7d243c
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8a7d243c

Branch: refs/heads/master
Commit: 8a7d243c349c056bcf35a679a0a927ced338ab81
Parents: 6597908 3b41560
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Fri May 19 11:27:27 2017 +0100
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Fri May 19 11:27:27 2017 +0100

----------------------------------------------------------------------
 .../core/mgmt/persist/XmlMementoSerializer.java |   1 -
 .../mgmt/rebind/BasicEntityRebindSupport.java   |  18 -
 .../mgmt/rebind/dto/BrooklynMementoImpl.java    |   3 +
 .../mgmt/rebind/dto/MementosGenerators.java     | 126 +------
 .../mgmt/rebind/dto/MutableBrooklynMemento.java | 331 -------------------
 .../core/mgmt/rebind/RebindEntityTest.java      |  35 --
 .../mgmt/rebind/RebindManagerSorterTest.java    |   2 +-
 .../core/mgmt/rebind/RebindTestUtils.java       |  33 +-
 8 files changed, 37 insertions(+), 512 deletions(-)
----------------------------------------------------------------------



[2/4] brooklyn-server git commit: Move `newBrooklynMemento` to RebindTestUtils

Posted by dr...@apache.org.
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;
+    }
 }