You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by m4...@apache.org on 2017/05/19 17:04:20 UTC

[01/12] brooklyn-server git commit: Delete deprecated EntityType.getEffector(name, parameterTypes…)

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 3d7a35f90 -> d4d5966c1


Delete deprecated EntityType.getEffector(name, parameterTypes…)

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

Branch: refs/heads/master
Commit: f665e57aa63132e0930c237d86425c9fe595bdc2
Parents: 7350fd6
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:24:25 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:46:35 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/api/entity/EntityType.java  | 12 ---------
 .../core/entity/EntityTypeSnapshot.java         | 26 --------------------
 2 files changed, 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f665e57a/api/src/main/java/org/apache/brooklyn/api/entity/EntityType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/EntityType.java b/api/src/main/java/org/apache/brooklyn/api/entity/EntityType.java
index 1c3f7b5..ccadb87 100644
--- a/api/src/main/java/org/apache/brooklyn/api/entity/EntityType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/entity/EntityType.java
@@ -18,7 +18,6 @@
  */
 package org.apache.brooklyn.api.entity;
 
-import java.util.NoSuchElementException;
 import java.util.Set;
 
 import org.apache.brooklyn.api.effector.Effector;
@@ -51,17 +50,6 @@ public interface EntityType extends BrooklynType {
     public Maybe<Effector<?>> getEffectorByName(String name);
         
     /**
-     * @return the matching effector on this entity
-     * @throws NoSuchElementException If there is no exact match for this signature
-     * <p>
-     * @deprecated since 0.7.0 use {@link #getEffectorByName(String)};
-     * use of multiple effectors with the same name is not supported by the EntityDynamicType implementation,
-     * so should be discouraged.  overloading can be achieved by inspecting the parameters map. 
-     */
-    @Deprecated
-    Effector<?> getEffector(String name, Class<?>... parameterTypes);
-
-    /**
      * The Sensor with the given name, or null if not found.
      */
     Sensor<?> getSensor(String name);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f665e57a/core/src/main/java/org/apache/brooklyn/core/entity/EntityTypeSnapshot.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/EntityTypeSnapshot.java b/core/src/main/java/org/apache/brooklyn/core/entity/EntityTypeSnapshot.java
index 25223f8..956221c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/EntityTypeSnapshot.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/EntityTypeSnapshot.java
@@ -19,20 +19,16 @@
 package org.apache.brooklyn.core.entity;
 
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
-import java.util.NoSuchElementException;
 import java.util.Set;
 
 import org.apache.brooklyn.api.effector.Effector;
-import org.apache.brooklyn.api.effector.ParameterType;
 import org.apache.brooklyn.api.entity.EntityType;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.objs.BrooklynTypeSnapshot;
 import org.apache.brooklyn.util.guava.Maybe;
 
-import com.google.common.base.Joiner;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableMap;
@@ -74,28 +70,6 @@ public class EntityTypeSnapshot extends BrooklynTypeSnapshot implements EntityTy
     }
     
     @Override
-    public Effector<?> getEffector(String name, Class<?>... parameterTypes) {
-        // TODO Could index for more efficient lookup (e.g. by name in a MultiMap, or using name+parameterTypes as a key)
-        // TODO Looks for exact match; could go for what would be valid to call (i.e. if parameterType is sub-class of ParameterType.getParameterClass then ok)
-        // TODO Could take into account ParameterType.getDefaultValue() for what can be omitted
-        
-        effectorLoop : for (Effector<?> contender : effectors) {
-            if (name.equals(contender.getName())) {
-                List<ParameterType<?>> contenderParameters = contender.getParameters();
-                if (parameterTypes.length == contenderParameters.size()) {
-                    for (int i = 0; i < parameterTypes.length; i++) {
-                        if (parameterTypes[i] != contenderParameters.get(i).getParameterClass()) {
-                            continue effectorLoop;
-                        }
-                    }
-                    return contender;
-                }
-            }
-        }
-        throw new NoSuchElementException("No matching effector "+name+"("+Joiner.on(", ").join(parameterTypes)+") on entity "+getName());
-    }
-
-    @Override
     public Sensor<?> getSensor(String name) {
         return sensors.get(name);
     }


[08/12] brooklyn-server git commit: AbstractManagementContext.runAtEntity protected, instead of public

Posted by m4...@apache.org.
AbstractManagementContext.runAtEntity protected, instead of public

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

Branch: refs/heads/master
Commit: 24236966d2e1a06e251a2d971c7c4f7fb55479df
Parents: e372291
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 17:09:57 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 13:27:04 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/core/mgmt/internal/AbstractManagementContext.java     | 2 +-
 .../apache/brooklyn/core/mgmt/internal/LocalManagementContext.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/24236966/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index c009437..850477c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -328,7 +328,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte
      * (Callable with Map flags is too open-ended, bothersome to support, and not used much) 
      */
     @Deprecated
-    public abstract <T> Task<T> runAtEntity(@SuppressWarnings("rawtypes") Map flags, Entity entity, Callable<T> c);
+    protected abstract <T> Task<T> runAtEntity(@SuppressWarnings("rawtypes") Map flags, Entity entity, Callable<T> c);
 
     /** Runs the given effector in the right place for the given entity.
      * The task is immediately submitted in the background, but also recorded in the queueing context (if present)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/24236966/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
index 3e3b776..7d82c52 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
@@ -359,7 +359,7 @@ public class LocalManagementContext extends AbstractManagementContext {
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public <T> Task<T> runAtEntity(Map flags, Entity entity, Callable<T> c) {
+    protected <T> Task<T> runAtEntity(Map flags, Entity entity, Callable<T> c) {
         manageIfNecessary(entity, elvis(Arrays.asList(flags.get("displayName"), flags.get("description"), flags, c)));
         return runAtEntity(entity, Tasks.<T>builder().dynamic(true).body(c).flags(flags).build());
     }


[10/12] brooklyn-server git commit: Delete deprecated LocationConfigUtils methods

Posted by m4...@apache.org.
Delete deprecated LocationConfigUtils methods

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

Branch: refs/heads/master
Commit: 90e8fec418fc67f8da9095725ad77ae2d3d1a1d2
Parents: ed60d6f
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:52:41 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 13:27:04 2017 +0100

----------------------------------------------------------------------
 .../core/location/LocationConfigUtils.java      | 102 -------------------
 1 file changed, 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/90e8fec4/core/src/main/java/org/apache/brooklyn/core/location/LocationConfigUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/LocationConfigUtils.java b/core/src/main/java/org/apache/brooklyn/core/location/LocationConfigUtils.java
index 2ed7e1a..73607af 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/LocationConfigUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/LocationConfigUtils.java
@@ -44,15 +44,11 @@ import org.apache.brooklyn.util.core.crypto.SecureKeys.PassphraseProblem;
 import org.apache.brooklyn.util.crypto.AuthorizedKeysParser;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.text.StringFunctions;
 import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
 public class LocationConfigUtils {
@@ -367,40 +363,6 @@ public class LocationConfigUtils {
         }
     }
 
-    /** @deprecated since 0.7.0, use #getOsCredential(ConfigBag) */ @Deprecated
-    public static String getPrivateKeyData(ConfigBag config) {
-        return getKeyData(config, LocationConfigKeys.PRIVATE_KEY_DATA, LocationConfigKeys.PRIVATE_KEY_FILE);
-    }
-    
-    /** @deprecated since 0.7.0, use #getOsCredential(ConfigBag) */ @Deprecated
-    public static String getPublicKeyData(ConfigBag config) {
-        String data = getKeyData(config, LocationConfigKeys.PUBLIC_KEY_DATA, LocationConfigKeys.PUBLIC_KEY_FILE);
-        if (groovyTruth(data)) return data;
-        
-        String privateKeyFile = config.get(LocationConfigKeys.PRIVATE_KEY_FILE);
-        if (groovyTruth(privateKeyFile)) {
-            List<String> privateKeyFiles = Arrays.asList(privateKeyFile.split(File.pathSeparator));
-            List<String> publicKeyFiles = ImmutableList.copyOf(Iterables.transform(privateKeyFiles, StringFunctions.append(".pub")));
-            List<String> publicKeyFilesTidied = tidyFilePaths(publicKeyFiles);
-            
-            String fileData = getFileContents(publicKeyFilesTidied);
-            if (groovyTruth(fileData)) {
-                if (log.isDebugEnabled()) log.debug("Loaded "+LocationConfigKeys.PUBLIC_KEY_DATA.getName()+" from inferred files, based on "+LocationConfigKeys.PRIVATE_KEY_FILE.getName() + ": used " + publicKeyFilesTidied + " for "+config.getDescription());
-                config.put(LocationConfigKeys.PUBLIC_KEY_DATA, fileData);
-                return fileData;
-            } else {
-                log.info("Not able to load "+LocationConfigKeys.PUBLIC_KEY_DATA.getName()+" from inferred files, based on "+LocationConfigKeys.PRIVATE_KEY_FILE.getName() + ": tried " + publicKeyFilesTidied + " for "+config.getDescription());
-            }
-        }
-        
-        return null;
-    }
-
-    /** @deprecated since 0.7.0, use #getOsCredential(ConfigBag) */ @Deprecated
-    public static String getKeyData(ConfigBag config, ConfigKey<String> dataKey, ConfigKey<String> fileKey) {
-        return getKeyDataFromDataKeyOrFileKey(config, dataKey, fileKey);
-    }
-    
     private static String getKeyDataFromDataKeyOrFileKey(ConfigBag config, ConfigKey<String> dataKey, ConfigKey<String> fileKey) {
         boolean unused = config.isUnused(dataKey);
         String data = config.get(dataKey);
@@ -463,70 +425,6 @@ public class LocationConfigUtils {
         return result;
     }
 
-    /** @deprecated since 0.6.0 use configBag.getWithDeprecation */
-    @Deprecated
-    @SuppressWarnings("unchecked")
-    public static <T> T getConfigCheckingDeprecatedAlternatives(ConfigBag configBag, ConfigKey<T> preferredKey,
-            ConfigKey<?> ...deprecatedKeys) {
-        T value1 = (T) configBag.getWithDeprecation(preferredKey, deprecatedKeys);
-        T value2 = getConfigCheckingDeprecatedAlternativesInternal(configBag, preferredKey, deprecatedKeys);
-        if (!Objects.equal(value1, value2)) {
-            // points to a bug in one of the get-with-deprecation methods
-            log.warn("Deprecated getConfig with deprecated keys "+Arrays.toString(deprecatedKeys)+" gets different value with " +
-                    "new strategy "+preferredKey+" ("+value1+") and old ("+value2+"); preferring old value for now, but this behaviour will change");
-            return value2;
-        }
-        return value1;
-    }
-    
-    @SuppressWarnings("unchecked")
-    private static <T> T getConfigCheckingDeprecatedAlternativesInternal(ConfigBag configBag, ConfigKey<T> preferredKey,
-            ConfigKey<?> ...deprecatedKeys) {
-        ConfigKey<?> keyProvidingValue = null;
-        T value = null;
-        boolean found = false;
-        if (configBag.containsKey(preferredKey)) {
-            value = configBag.get(preferredKey);
-            found = true;
-            keyProvidingValue = preferredKey;
-        }
-        
-        for (ConfigKey<?> deprecatedKey: deprecatedKeys) {
-            T altValue = null;
-            boolean altFound = false;
-            if (configBag.containsKey(deprecatedKey)) {
-                altValue = (T) configBag.get(deprecatedKey);
-                altFound = true;
-                
-                if (altFound) {
-                    if (found) {
-                        if (Objects.equal(value, altValue)) {
-                            // fine -- nothing
-                        } else {
-                            log.warn("Detected deprecated key "+deprecatedKey+" with value "+altValue+" used in addition to "+keyProvidingValue+" " +
-                                    "with value "+value+" for "+configBag.getDescription()+"; ignoring");
-                            configBag.remove(deprecatedKey);
-                        }
-                    } else {
-                        log.warn("Detected deprecated key "+deprecatedKey+" with value "+altValue+" used instead of recommended "+preferredKey+"; " +
-                                "promoting to preferred key status; will not be supported in future versions");
-                        configBag.put(preferredKey, altValue);
-                        configBag.remove(deprecatedKey);
-                        value = altValue;
-                        found = true;
-                        keyProvidingValue = deprecatedKey;
-                    }
-                }
-            }
-        }
-        
-        if (found) {
-            return value;
-        } else {
-            return configBag.get(preferredKey); // get the default
-        }
-    }
-
     public static Map<ConfigKey<String>,String> finalAndOriginalSpecs(String finalSpec, Object ...sourcesForOriginalSpec) {
         // yuck!: TODO should clean up how these things get passed around
         Map<ConfigKey<String>,String> result = MutableMap.of();


[06/12] brooklyn-server git commit: Delete deprecated LocationSpec.id()

Posted by m4...@apache.org.
Delete deprecated LocationSpec.id()


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

Branch: refs/heads/master
Commit: 55eb11fa91e9091447d56bb45116ccc3dc6009df
Parents: f665e57
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:39:35 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 13:27:03 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/api/location/LocationSpec.java     | 21 -------------
 .../objs/proxy/InternalLocationFactory.java     | 11 -------
 .../core/location/AbstractLocationTest.java     | 33 ++++++++++++++------
 3 files changed, 23 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/55eb11fa/api/src/main/java/org/apache/brooklyn/api/location/LocationSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/location/LocationSpec.java b/api/src/main/java/org/apache/brooklyn/api/location/LocationSpec.java
index 6f84403..e72b8a2 100644
--- a/api/src/main/java/org/apache/brooklyn/api/location/LocationSpec.java
+++ b/api/src/main/java/org/apache/brooklyn/api/location/LocationSpec.java
@@ -78,7 +78,6 @@ public class LocationSpec<T extends Location> extends AbstractBrooklynObjectSpec
         return create(exactType).copyFrom(spec);
     }
 
-    private String id;
     private Location parent;
     private final Map<Class<?>, Object> extensions = Maps.newLinkedHashMap();
 
@@ -90,7 +89,6 @@ public class LocationSpec<T extends Location> extends AbstractBrooklynObjectSpec
     protected LocationSpec<T> copyFrom(LocationSpec<T> otherSpec) {
         LocationSpec<T> result = super.copyFrom(otherSpec).extensions(otherSpec.getExtensions());
         if (otherSpec.getParent() != null) result.parent(otherSpec.getParent());
-        if (otherSpec.getId() != null) result.id(otherSpec.getId());
         return result;
     }
     
@@ -100,15 +98,6 @@ public class LocationSpec<T extends Location> extends AbstractBrooklynObjectSpec
         checkIsNewStyleImplementation(type);
     }
 
-    /**
-     * @deprecated since 0.7.0; instead let the management context pick a random+unique id
-     */
-    @Deprecated
-    public LocationSpec<T> id(String val) {
-        id = val;
-        return this;
-    }
-
     public LocationSpec<T> parent(Location val) {
         parent = checkNotNull(val, "parent");
         return this;
@@ -128,16 +117,6 @@ public class LocationSpec<T extends Location> extends AbstractBrooklynObjectSpec
     }
     
     /**
-     * @return The id of the location to be created, or null if brooklyn can auto-generate an id
-     * 
-     * @deprecated since 0.7.0; instead let the management context pick a random+unique id
-     */
-    @Deprecated
-    public String getId() {
-        return id;
-    }
-    
-    /**
      * @return The location's parent
      */
     public Location getParent() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/55eb11fa/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
index b15863d..ffe3e21 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalLocationFactory.java
@@ -29,16 +29,12 @@ import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.location.AbstractLocation;
 import org.apache.brooklyn.core.location.Locations;
 import org.apache.brooklyn.core.location.internal.LocationInternal;
-import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.core.flags.FlagUtils;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.ImmutableMap;
-
 /**
  * Creates locations of required types.
  * 
@@ -92,9 +88,6 @@ public class InternalLocationFactory extends InternalFactory {
         if (spec.getFlags().containsKey("id")) {
             throw new IllegalArgumentException("Spec's flags must not contain id; use spec.id() instead for "+spec);
         }
-        if (spec.getId() != null && ((LocalLocationManager)managementContext.getLocationManager()).isKnownLocationId(spec.getId())) {
-            throw new IllegalArgumentException("Entity with id "+spec.getId()+" already exists; cannot create new entity with this explicit id from spec "+spec);
-        }
 
         try {
             Class<? extends T> clazz = spec.getType();
@@ -108,10 +101,6 @@ public class InternalLocationFactory extends InternalFactory {
                 return loc;
             }
 
-            if (spec.getId() != null) {
-                FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", spec.getId()), loc);
-            }
-            
             managementContext.prePreManage(loc);
 
             final AbstractLocation location = (AbstractLocation) loc;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/55eb11fa/core/src/test/java/org/apache/brooklyn/core/location/AbstractLocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/location/AbstractLocationTest.java b/core/src/test/java/org/apache/brooklyn/core/location/AbstractLocationTest.java
index 93f74c2..960fa27 100644
--- a/core/src/test/java/org/apache/brooklyn/core/location/AbstractLocationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/location/AbstractLocationTest.java
@@ -30,7 +30,6 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.location.AbstractLocation;
 import org.apache.brooklyn.core.location.internal.LocationInternal;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.util.collections.MutableMap;
@@ -41,7 +40,6 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 
 public class AbstractLocationTest {
 
@@ -58,6 +56,18 @@ public class AbstractLocationTest {
         }
     }
 
+    public static class LocationWithOverriddenId extends ConcreteLocation {
+        @SetFromFlag
+        String overriddenId;
+        
+        public LocationWithOverriddenId() {
+        }
+
+        public String getId() {
+            return overriddenId;
+        }
+    }
+
     private ManagementContext mgmt;
 
     @BeforeMethod(alwaysRun=true)
@@ -74,18 +84,21 @@ public class AbstractLocationTest {
         return createConcrete(MutableMap.<String,Object>of());
     }
     private ConcreteLocation createConcrete(Map<String,?> flags) {
-        return createConcrete(null, flags);
-    }
-    @SuppressWarnings("deprecation")
-    private ConcreteLocation createConcrete(String id, Map<String,?> flags) {
-        return mgmt.getLocationManager().createLocation( LocationSpec.create(ConcreteLocation.class).id(id).configure(flags) );
+        return mgmt.getLocationManager().createLocation( LocationSpec.create(ConcreteLocation.class).configure(flags) );
     }
     
     @Test
     public void testEqualsUsesId() {
-        Location l1 = createConcrete("1", MutableMap.of("name", "bob"));
-        Location l1b = new ConcreteLocation(ImmutableMap.of("id", 1));
-        Location l2 = createConcrete("2", MutableMap.of("name", "frank"));
+        Location l1 = mgmt.getLocationManager().createLocation(LocationSpec.create(LocationWithOverriddenId.class)
+                .configure("overriddenId", "id1")
+                .configure("myfield", "bob"));
+        Location l1b = mgmt.getLocationManager().createLocation(LocationSpec.create(LocationWithOverriddenId.class)
+                .configure("overriddenId", "id1")
+                .configure("myfield", "frank"));
+        Location l2 = mgmt.getLocationManager().createLocation(LocationSpec.create(LocationWithOverriddenId.class)
+                .configure("overriddenId", "id2")
+                .configure("myfield", "bob"));
+        
         assertEquals(l1, l1b);
         assertNotEquals(l1, l2);
     }


[04/12] brooklyn-server git commit: Delete deprecated test util classes

Posted by m4...@apache.org.
Delete deprecated test util classes

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

Branch: refs/heads/master
Commit: 858fba4d49e1fd098e66f1faf96f1c0caa1963fc
Parents: 9911286
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 17 20:34:19 2017 +0200
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:46:35 2017 +0100

----------------------------------------------------------------------
 .../EntityPersistencePerformanceTest.java       |   2 +-
 .../ssh/SshMachineLocationPerformanceTest.java  |   2 +-
 .../apache/brooklyn/test/EntityTestUtils.java   | 192 -------------------
 .../brooklyn/test/PerformanceTestUtils.java     |  26 ---
 .../org/apache/brooklyn/test/TestUtils.java     |  83 --------
 5 files changed, 2 insertions(+), 303 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/858fba4d/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPersistencePerformanceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPersistencePerformanceTest.java b/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPersistencePerformanceTest.java
index a821107..513c0db 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPersistencePerformanceTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/qa/performance/EntityPersistencePerformanceTest.java
@@ -30,7 +30,7 @@ import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.core.test.policy.TestPolicy;
-import org.apache.brooklyn.test.PerformanceTestUtils;
+import org.apache.brooklyn.test.performance.PerformanceTestUtils;
 import org.apache.brooklyn.util.repeat.Repeater;
 import org.apache.brooklyn.util.time.Duration;
 import org.testng.annotations.Test;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/858fba4d/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationPerformanceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationPerformanceTest.java b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationPerformanceTest.java
index 95f2025..c4d7d7d 100644
--- a/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationPerformanceTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/ssh/SshMachineLocationPerformanceTest.java
@@ -26,7 +26,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.brooklyn.location.ssh.SshMachineLocation;
-import org.apache.brooklyn.test.PerformanceTestUtils;
+import org.apache.brooklyn.test.performance.PerformanceTestUtils;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.internal.ssh.SshTool;
 import org.apache.brooklyn.util.net.Networking;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/858fba4d/test-support/src/main/java/org/apache/brooklyn/test/EntityTestUtils.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/brooklyn/test/EntityTestUtils.java b/test-support/src/main/java/org/apache/brooklyn/test/EntityTestUtils.java
deleted file mode 100644
index 28d9f2c..0000000
--- a/test-support/src/main/java/org/apache/brooklyn/test/EntityTestUtils.java
+++ /dev/null
@@ -1,192 +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.test;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.Group;
-import org.apache.brooklyn.api.mgmt.SubscriptionHandle;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.api.sensor.SensorEvent;
-import org.apache.brooklyn.api.sensor.SensorEventListener;
-import org.apache.brooklyn.config.ConfigKey;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-/**
- * A utility class containing tests on Entities.
- *
- * @deprecated since 0.9.0. Prefer core assertions class org.apache.brooklyn.core.entity.EntityAsserts.
- */
-@Deprecated
-public class EntityTestUtils {
-
-//    public static LocalManagementContext newManagementContext() { return new LocalManagementContextForTests(); }
-    
-    // TODO Delete methods from TestUtils, to just have them here (or switch so TestUtils delegates here,
-    // and deprecate methods in TestUtils until deleted).
-    
-    public static <T> void assertAttributeEquals(Entity entity, AttributeSensor<T> attribute, T expected) {
-        assertEquals(entity.getAttribute(attribute), expected, "entity=" + entity + "; attribute=" + attribute);
-    }
-    
-    public static <T> void assertConfigEquals(Entity entity, ConfigKey<T> configKey, T expected) {
-        assertEquals(entity.getConfig(configKey), expected, "entity=" + entity + "; configKey=" + configKey);
-    }
-    
-    public static <T> void assertAttributeEqualsEventually(final Entity entity, final AttributeSensor<T> attribute, final T expected) {
-        assertAttributeEqualsEventually(Maps.newLinkedHashMap(), entity, attribute, expected);
-    }
-
-    public static <T> void assertAttributeEqualsEventually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final T expected) {
-        // Not using assertAttributeEventually(predicate) so get nicer error message
-        Asserts.succeedsEventually((Map) flags, new Runnable() {
-            @Override
-            public void run() {
-                assertAttributeEquals(entity, attribute, expected);
-            }
-        });
-    }
-
-    public static <T> T assertAttributeEventuallyNonNull(final Entity entity, final AttributeSensor<T> attribute) {
-        return assertAttributeEventuallyNonNull(Maps.newLinkedHashMap(), entity, attribute);
-    }
-
-    public static <T> T assertAttributeEventuallyNonNull(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute) {
-        return assertAttributeEventually(flags, entity, attribute, Predicates.notNull());
-    }
-
-    public static <T> T assertAttributeEventually(final Entity entity, final AttributeSensor<T> attribute, Predicate<? super T> predicate) {
-        return assertAttributeEventually(ImmutableMap.of(), entity, attribute, predicate);
-    }
-    
-    public static <T> T assertAttributeEventually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final Predicate<? super T> predicate) {
-        final AtomicReference<T> result = new AtomicReference<T>();
-        Asserts.succeedsEventually((Map)flags, new Runnable() {
-            @Override public void run() {
-                T val = entity.getAttribute(attribute);
-                assertTrue(predicate.apply(val), "val="+val);
-                result.set(val);
-            }});
-        return result.get();
-    }
-
-    public static <T> T assertAttribute(final Entity entity, final AttributeSensor<T> attribute, final Predicate<? super T> predicate) {
-        T val = entity.getAttribute(attribute);
-        assertTrue(predicate.apply(val), "val="+val);
-        return val;
-    }
-
-    public static <T extends Entity> void assertPredicateEventuallyTrue(final T entity, final Predicate<? super T> predicate) {
-        assertPredicateEventuallyTrue(Maps.newLinkedHashMap(), entity, predicate);
-    }
-
-    public static <T extends Entity> void assertPredicateEventuallyTrue(Map<?,?> flags, final T entity, final Predicate<? super T> predicate) {
-        Asserts.succeedsEventually((Map) flags, new Runnable() {
-            @Override
-            public void run() {
-                assertTrue(predicate.apply(entity));
-            }
-        });
-    }
-
-    public static <T> void assertAttributeEqualsContinually(final Entity entity, final AttributeSensor<T> attribute, final T expected) {
-        assertAttributeEqualsContinually(Maps.newLinkedHashMap(), entity, attribute, expected);
-    }
-    
-    public static <T> void assertAttributeEqualsContinually(Map<?,?> flags, final Entity entity, final AttributeSensor<T> attribute, final T expected) {
-        Asserts.succeedsContinually(flags, new Runnable() {
-            @Override
-            public void run() {
-                assertAttributeEquals(entity, attribute, expected);
-            }
-        });
-    }
-
-    public static void assertGroupSizeEqualsEventually(final Group group, int expected) {
-        assertGroupSizeEqualsEventually(ImmutableMap.of(), group, expected);
-    }
-    
-    public static void assertGroupSizeEqualsEventually(Map<?,?> flags, final Group group, final int expected) {
-        Asserts.succeedsEventually((Map) flags, new Runnable() {
-            @Override
-            public void run() {
-                Collection<Entity> members = group.getMembers();
-                assertEquals(members.size(), expected, "members=" + members);
-            }
-        });
-    }
-
-    /** checks that the entity's value for this attribute changes, by registering a subscription and checking the value */
-    public static void assertAttributeChangesEventually(final Entity entity, final AttributeSensor<?> attribute) {
-        final Object origValue = entity.getAttribute(attribute);
-        final AtomicBoolean changed = new AtomicBoolean();
-        SubscriptionHandle handle = entity.subscriptions().subscribe(entity, attribute, new SensorEventListener<Object>() {
-            @Override public void onEvent(SensorEvent<Object> event) {
-                if (!Objects.equal(origValue, event.getValue())) {
-                    changed.set(true);
-                }
-            }});
-        try {
-            Asserts.succeedsEventually(new Runnable() {
-                @Override public void run() {
-                    assertTrue(changed.get(), entity+" -> "+attribute+" not changed");
-                }});
-        } finally {
-            entity.subscriptions().unsubscribe(entity, handle);
-        }
-    }
-    
-    /** alternate version of {@link #assertAttributeChangesEventually(Entity, AttributeSensor)} not using subscriptions and 
-     * with simpler code, for comparison */
-    @Beta
-    public static <T> void assertAttributeChangesEventually2(final Entity entity, final AttributeSensor<T> attribute) {
-        assertAttributeEventually(entity, attribute,
-                Predicates.not(Predicates.equalTo(entity.getAttribute(attribute))));
-    }
-
-    @Beta
-    public static <T> void assertAttributeNever(final Entity entity, final AttributeSensor<T> attribute, T... disallowed) {
-        final Set<T> reject = Sets.newHashSet(disallowed);
-        Asserts.succeedsContinually(new Runnable() {
-            @Override
-            public void run() {
-                T val = entity.getAttribute(attribute);
-                assertFalse(reject.contains(val),
-                        "Attribute " + attribute + " on " + entity + " has disallowed value " + val);
-            }
-        });
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/858fba4d/test-support/src/main/java/org/apache/brooklyn/test/PerformanceTestUtils.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/brooklyn/test/PerformanceTestUtils.java b/test-support/src/main/java/org/apache/brooklyn/test/PerformanceTestUtils.java
deleted file mode 100644
index c0e9a71..0000000
--- a/test-support/src/main/java/org/apache/brooklyn/test/PerformanceTestUtils.java
+++ /dev/null
@@ -1,26 +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.test;
-
-/**
- * @deprecated since 0.9.0; see {@link org.apache.brooklyn.test.performance.PerformanceTestUtils}.
- */
-@Deprecated
-public class PerformanceTestUtils extends org.apache.brooklyn.test.performance.PerformanceTestUtils {
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/858fba4d/test-support/src/main/java/org/apache/brooklyn/test/TestUtils.java
----------------------------------------------------------------------
diff --git a/test-support/src/main/java/org/apache/brooklyn/test/TestUtils.java b/test-support/src/main/java/org/apache/brooklyn/test/TestUtils.java
deleted file mode 100644
index 40fd53f..0000000
--- a/test-support/src/main/java/org/apache/brooklyn/test/TestUtils.java
+++ /dev/null
@@ -1,83 +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.test;
-
-import static org.testng.Assert.fail;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-
-import org.codehaus.groovy.runtime.InvokerInvocationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Helper functions for tests of Tomcat, JBoss and others.
- * 
- * @deprecated Since 0.8. Methods moving to {@link Asserts}.
- */
-@Deprecated
-public class TestUtils {
-    private static final Logger log = LoggerFactory.getLogger(TestUtils.class);
-
-    private TestUtils() { }
-
-    /** @deprecated since 0.8; use Asserts.BooleanWithMessage */
-    @Deprecated
-    public static class BooleanWithMessage {
-        boolean value; String message;
-        public BooleanWithMessage(boolean value, String message) {
-            this.value = value; this.message = message;
-        }
-        public boolean asBoolean() {
-            return value;
-        }
-        @Override
-        public String toString() {
-            return message;
-        }
-    }
-    
-    /** @deprecated since 0.8; use Exceptions.getFirstInteresting */ 
-    @Deprecated
-    public static Throwable unwrapThrowable(Throwable t) {
-        if (t.getCause() == null) {
-            return t;
-        } else if (t instanceof ExecutionException) {
-            return unwrapThrowable(t.getCause());
-        } else if (t instanceof InvokerInvocationException) {
-            return unwrapThrowable(t.getCause());
-        } else {
-            return t;
-        }
-    }
-
-    /** @deprecated since 0.8; use Asserts.assertEqualsIgnoringOrder */
-    @Deprecated
-    public static void assertSetsEqual(Collection c1, Collection c2) {
-        Set s = new LinkedHashSet();
-        s.addAll(c1); s.removeAll(c2);
-        if (!s.isEmpty()) fail("First argument contains additional contents: "+s);
-        s.clear(); s.addAll(c2); s.removeAll(c1);
-        if (!s.isEmpty()) fail("Second argument contains additional contents: "+s);
-    }
-    
-}


[11/12] brooklyn-server git commit: Delete deprecated BrooklynTasks

Posted by m4...@apache.org.
Delete deprecated BrooklynTasks

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

Branch: refs/heads/master
Commit: e920c2687a159609ff17c1654ffb816204c52366
Parents: 90e8fec
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:54:16 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 13:27:04 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/core/mgmt/BrooklynTasks.java       | 25 --------------------
 1 file changed, 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e920c268/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTasks.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTasks.java
deleted file mode 100644
index e38c34f..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/BrooklynTasks.java
+++ /dev/null
@@ -1,25 +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;
-
-
-/** @deprecated since 0.7.0 use {@link BrooklynTaskTags} */
-@Deprecated
-public class BrooklynTasks extends BrooklynTaskTags {
-}


[02/12] brooklyn-server git commit: Delete ShellUtils (unused & deprecated since 0.7)

Posted by m4...@apache.org.
Delete ShellUtils (unused & deprecated since 0.7)

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

Branch: refs/heads/master
Commit: 093a8d1968d5c9adb8b6b2021ff7c3b40568dd70
Parents: 3c35a1e
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 17 20:25:56 2017 +0200
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:46:35 2017 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/util/ShellUtils.java    | 185 -------------------
 1 file changed, 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/093a8d19/utils/common/src/main/java/org/apache/brooklyn/util/ShellUtils.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/ShellUtils.java b/utils/common/src/main/java/org/apache/brooklyn/util/ShellUtils.java
deleted file mode 100644
index 792d8d6..0000000
--- a/utils/common/src/main/java/org/apache/brooklyn/util/ShellUtils.java
+++ /dev/null
@@ -1,185 +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.util;
-
-import groovy.io.GroovyPrintStream;
-import groovy.time.TimeDuration;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.stream.StreamGobbler;
-import org.apache.brooklyn.util.stream.Streams;
-import org.apache.brooklyn.util.text.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Maps;
-import com.google.common.io.Closer;
-
-/**
- * @deprecated since 0.7; does not return exit status, stderr, etc, so utility is of very limited use; and is not used in core brooklyn at all!;
- * use ProcessTool or SystemProcessTaskFactory.
- */
-@Deprecated
-public class ShellUtils {
-
-    private static final Logger LOG = LoggerFactory.getLogger(ShellUtils.class);
-
-    public static long TIMEOUT = 60*1000;
-
-    /**
-     * Executes the given command.
-     * <p>
-     * Uses {@code bash -l -c cmd} (to have a good PATH set), and defaults for other fields.
-     * <p>
-     * requires a logger and a context object (whose toString is used in the logger and in error messages)
-     * optionally takes a string to use as input to the command
-     *
-     * @see {@link #exec(String, String, Logger, Object)}
-     */
-    public static String[] exec(String cmd, Logger log, Object context) {
-        return exec(cmd, null, log, context);
-    }
-    /** @see {@link #exec(String[], String[], File, String, Logger, Object)} */
-    public static String[] exec(String cmd, String input, Logger log, Object context) {
-        return exec(new String[] { "bash", "-l", "-c", cmd }, null, null, input, log, context);
-    }
-    /** @see {@link #exec(Map, String[], String[], File, String, Logger, Object)} */
-    public static String[] exec(Map<?,?> flags, String cmd, Logger log, Object context) {
-        return exec(flags, new String[] { "bash", "-l", "-c", cmd }, null, null, null, log, context);
-    }
-    /** @see {@link #exec(Map, String[], String[], File, String, Logger, Object)} */
-    public static String[] exec(Map<?,?> flags, String cmd, String input, Logger log, Object context) {
-        return exec(flags, new String[] { "bash", "-l", "-c", cmd }, null, null, input, log, context);
-    }
-    /** @see {@link #exec(Map, String[], String[], File, String, Logger, Object)} */
-    public static String[] exec(String[] cmd, String[] envp, File dir, String input, Logger log, Object context) {
-        return exec(Maps.newLinkedHashMap(), cmd, envp, dir, input, log, context);
-    }
-
-    private static long getTimeoutMs(Map<?,?> flags) {
-        long timeout = TIMEOUT;
-
-        Object tf = flags.get("timeout");
-
-        if (tf instanceof Number) {
-            timeout = ((Number) tf).longValue();
-        } else if (tf instanceof TimeDuration) {
-            LOG.warn("Use of groovy.time.TimeuDuration is deprecated in ShellUtils, for configuring timeout");
-            timeout = ((TimeDuration) tf).toMilliseconds();
-        }
-
-        //if (tf != null) timeout = tf;
-
-        return timeout;
-    }
-
-    /**
-     * Executes the given command.
-     * <p>
-     * Uses the given environmnet (inherited if null) and cwd ({@literal .} if null),
-     * feeding it the given input stream (if not null) and logging I/O at debug (if not null).
-     * <p>
-     * flags:  timeout (Duration), 0 for forever; default 60 seconds
-     *
-     * @throws IllegalStateException if return code non-zero
-     * @return lines from stdout.
-     */
-    public static String[] exec(Map<?,?> flags, final String[] cmd, String[] envp, File dir, String input, final Logger log, final Object context) {
-        if (log.isDebugEnabled()) {
-            log.debug("Running local command: {}% {}", context, Strings.join(cmd, " "));
-        }
-        Closer closer = Closer.create();
-        try {
-            final Process proc = Runtime.getRuntime().exec(cmd, envp, dir); // Call *execute* on the string
-            ByteArrayOutputStream stdoutB = new ByteArrayOutputStream();
-            ByteArrayOutputStream stderrB = new ByteArrayOutputStream();
-            PrintStream stdoutP = new GroovyPrintStream(stdoutB);
-            PrintStream stderrP = new GroovyPrintStream(stderrB);
-            @SuppressWarnings("resource")
-            StreamGobbler stdoutG = new StreamGobbler(proc.getInputStream(), stdoutP, log).setLogPrefix("["+context+":stdout] ");
-            stdoutG.start();
-            closer.register(stdoutG);
-            @SuppressWarnings("resource")
-            StreamGobbler stderrG = new StreamGobbler(proc.getErrorStream(), stderrP, log).setLogPrefix("["+context+":stderr] ");
-            stderrG.start();
-            closer.register(stderrG);
-            if (input!=null && input.length()>0) {
-                proc.getOutputStream().write(input.getBytes());
-                proc.getOutputStream().flush();
-            }
-
-            final long timeout = getTimeoutMs(flags);
-            final AtomicBoolean ended = new AtomicBoolean(false);
-            final AtomicBoolean killed = new AtomicBoolean(false);
-
-            //if a timeout was specified, this thread will kill the process. This is a work around because the process.waitFor'
-            //doesn't accept a timeout.
-            Thread timeoutThread = new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    if (timeout <= 0) return;
-                    try { 
-                        Thread.sleep(timeout);
-                        if (!ended.get()) {
-                            if (log.isDebugEnabled()) {
-                                log.debug("Timeout exceeded for "+context+"% "+Strings.join(cmd, " "));
-                            }
-                            proc.destroy();
-                            killed.set(true);
-                        }
-                    } catch (Exception e) { }
-                }
-            });
-            if (timeout > 0) timeoutThread.start();
-            int exitCode = proc.waitFor();
-            ended.set(true);
-            if (timeout > 0) timeoutThread.interrupt();
-
-            stdoutG.blockUntilFinished();
-            stderrG.blockUntilFinished();
-            if (exitCode!=0 || killed.get()) {
-                String message = killed.get() ? "terminated after timeout" : "exit code "+exitCode;
-                if (log.isDebugEnabled()) {
-                    log.debug("Completed local command (problem, throwing): "+context+"% "+Strings.join(cmd, " ")+" - "+message);
-                }
-                String e = "Command failed ("+message+"): "+Strings.join(cmd, " ");
-                log.warn(e+"\n"+stdoutB+(stderrB.size()>0 ? "\n--\n"+stderrB : ""));
-                throw new IllegalStateException(e+" (details logged)");
-            }
-            if (log.isDebugEnabled()) {
-                log.debug("Completed local command: "+context+"% "+Strings.join(cmd, " ")+" - exit code 0");
-            }
-            return stdoutB.toString().split("\n");
-        } catch (IOException e) {
-            throw Exceptions.propagate(e);
-        } catch (InterruptedException e) {
-            throw Exceptions.propagate(e);
-        } finally {
-            Streams.closeQuietly(closer);
-        }
-    }
-
-}


[03/12] brooklyn-server git commit: Delete deprecated Repeater class

Posted by m4...@apache.org.
Delete deprecated Repeater class

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

Branch: refs/heads/master
Commit: 7350fd621d8b97ab5e98e20d1e7fa4aa399a4ec0
Parents: 858fba4
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 17 20:39:43 2017 +0200
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:46:35 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/util/core/internal/Repeater.java   | 367 -------------------
 .../util/core/internal/RepeaterTest.java        | 251 -------------
 2 files changed, 618 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7350fd62/core/src/main/java/org/apache/brooklyn/util/core/internal/Repeater.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/internal/Repeater.java b/core/src/main/java/org/apache/brooklyn/util/core/internal/Repeater.java
deleted file mode 100644
index 5f7973f..0000000
--- a/core/src/main/java/org/apache/brooklyn/util/core/internal/Repeater.java
+++ /dev/null
@@ -1,367 +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.util.core.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.brooklyn.util.JavaGroovyEquivalents;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.core.flags.FlagUtils;
-import org.apache.brooklyn.util.core.flags.SetFromFlag;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.time.Duration;
-import org.apache.brooklyn.util.time.Time;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Callables;
-
-/**
- * Simple DSL to repeat a fragment of code periodically until a condition is satisfied.
- *
- * In its simplest case, it is passed two {@link groovy.lang.Closure}s / {@link Callable} - 
- * the first is executed, then the second. If the second closure returns false, the loop
- * is repeated; if true, it finishes. Further customization can be applied to set the period 
- * between loops and place a maximum limit on how long the loop should run for.
- * <p>
- * It is configured in a <em>fluent</em> manner. For example, in Groovy:
- * <pre>
- * {@code
- * Repeater.create("Wait until the Frobnitzer is ready")
- *     .repeat {
- *         status = frobnitzer.getStatus()
- *     }
- *     .until {
- *         status == "Ready" || status == "Failed"
- *     }
- *     .limitIterationsTo(30)
- *     .run()
- * }
- * </pre>
- * 
- * Or in Java:
- * <pre>
- * {@code
- * Repeater.create("Wait until the Frobnitzer is ready")
- *     .until(new Callable<Boolean>() {
- *              public Boolean call() {
- *                  String status = frobnitzer.getStatus()
- *                  return "Ready".equals(status) || "Failed".equals(status);
- *              }})
- *     .limitIterationsTo(30)
- *     .run()
- * }
- * </pre>
- * 
- * @deprecated since 0.7.0, use {@link org.apache.brooklyn.util.repeat.Repeater} instead
- */
-@Deprecated
-public class Repeater {
-    
-    // TODO Was converted to Java, from groovy. Needs thorough review and improvements
-    // to use idiomatic java
-    
-    private static final Logger log = LoggerFactory.getLogger(Repeater.class);
-
-    @SetFromFlag
-    private String description;
-    private Callable<?> body = Callables.returning(null);
-    private Callable<Boolean> exitCondition;
-    @SetFromFlag
-    private Long period = null;
-    @SetFromFlag("timeout")
-    private Long durationLimit = null;
-    private int iterationLimit = 0;
-    private boolean rethrowException = false;
-    private boolean rethrowExceptionImmediately = false;
-    private boolean warnOnUnRethrownException = true;
-
-    public Repeater() {
-        this(MutableMap.of(), null);
-    }
-
-    public Repeater(Map<?,?> flags) {
-        this(flags, null);
-    }
-
-    public Repeater(String description) {
-        this(MutableMap.of(), description);
-    }
-    
-    /**
-     * Construct a new instance of Repeater.
-     *
-     * @param flags       can include period, timeout, description
-     * @param description a description of the operation that will appear in debug logs.
-     */
-    public Repeater(Map<?,?> flags, String description) {
-        setFromFlags(flags);
-        this.description = JavaGroovyEquivalents.elvis(description, this.description, "Repeater");
-    }
-
-    public void setFromFlags(Map<?,?> flags) {
-        FlagUtils.setFieldsFromFlags(flags, this);
-    }
-    
-    public static Repeater create() {
-        return create(MutableMap.of());
-    }
-    public static Repeater create(Map<?,?> flags) {
-        return create(flags, null);
-    }
-    public static Repeater create(String description) {
-        return create(MutableMap.of(), description);
-    }
-    public static Repeater create(Map<?,?> flags, String description) {
-        return new Repeater(flags, description);
-    }
-
-    /**
-     * Sets the main body of the loop to be a no-op.
-     * 
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater repeat() {
-        return repeat(Callables.returning(null));
-    }
-    
-    /**
-     * Sets the main body of the loop.
-     *
-     * @param body a closure or other Runnable that is executed in the main body of the loop.
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater repeat(Runnable body) {
-        checkNotNull(body, "body must not be null");
-        this.body = (body instanceof Callable) ? (Callable<?>)body : Executors.callable(body);
-        return this;
-    }
-    
-    /**
-     * Sets the main body of the loop.
-     *
-     * @param body a closure or other Callable that is executed in the main body of the loop.
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater repeat(Callable<?> body) {
-        checkNotNull(body, "body must not be null");
-        this.body = body;
-        return this;
-    }
-
-    /**
-     * Set how long to wait between loop iterations.
-     *
-     * @param period how long to wait between loop iterations.
-     * @param unit the unit of measurement of the period.
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater every(long period, TimeUnit unit) {
-        Preconditions.checkArgument(period > 0, "period must be positive: %s", period);
-        checkNotNull(unit, "unit must not be null");
-        this.period = unit.toMillis(period);
-        return this;
-    }
-
-    /**
-     * @see #every(long, TimeUnit)
-     */
-    public Repeater every(Duration duration) {
-        Preconditions.checkNotNull(duration, "duration must not be null");
-        Preconditions.checkArgument(duration.toMilliseconds()>0, "period must be positive: %s", duration);
-        this.period = duration.toMilliseconds();
-        return this;
-    }
-    
-    public Repeater every(groovy.time.Duration duration) {
-        return every(Duration.of(duration));
-    }
-
-    /**
-     * @see #every(long, TimeUnit)
-     * @deprecated specify unit
-     */
-    @Deprecated
-    public Repeater every(long duration) {
-        return every(duration, TimeUnit.MILLISECONDS);
-    }
-
-    /**
-     * Set code fragment that tests if the loop has completed.
-     *
-     * @param exitCondition a closure or other Callable that returns a boolean. If this code returns {@literal true} then the
-     * loop will stop executing.
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater until(Callable<Boolean> exitCondition) {
-        Preconditions.checkNotNull(exitCondition, "exitCondition must not be null");
-        this.exitCondition = exitCondition;
-        return this;
-    }
-
-    /**
-     * If the exit condition check throws an exception, it will be recorded and the last exception will be thrown on failure.
-     *
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater rethrowException() {
-        this.rethrowException = true;
-        return this;
-    }
-
-    /**
-     * If the repeated body or the exit condition check throws an exception, then propagate that exception immediately.
-     *
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater rethrowExceptionImmediately() {
-        this.rethrowExceptionImmediately = true;
-        return this;
-    }
-
-    public Repeater suppressWarnings() {
-        this.warnOnUnRethrownException = false;
-        return this;
-    }
-
-    /**
-     * Set the maximum number of iterations.
-     *
-     * The loop will exit if the condition has not been satisfied after this number of iterations.
-     *
-     * @param iterationLimit the maximum number of iterations.
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater limitIterationsTo(int iterationLimit) {
-        Preconditions.checkArgument(iterationLimit > 0, "iterationLimit must be positive: %s", iterationLimit);
-        this.iterationLimit = iterationLimit;
-        return this;
-    }
-
-    /**
-     * Set the amount of time to wait for the condition.
-     * The repeater will wait at least this long for the condition to be true,
-     * and will exit soon after even if the condition is false.
-     *
-     * @param deadline the time that the loop should wait.
-     * @param unit the unit of measurement of the period.
-     * @return {@literal this} to aid coding in a fluent style.
-     */
-    public Repeater limitTimeTo(long deadline, TimeUnit unit) {
-        Preconditions.checkArgument(deadline > 0, "deadline must be positive: %s", deadline);
-        Preconditions.checkNotNull(unit, "unit must not be null");
-        this.durationLimit = unit.toMillis(deadline);
-        return this;
-    }
-
-    /**
-     * @see #limitTimeTo(long, TimeUnit)
-     */
-    public Repeater limitTimeTo(Duration duration) {
-        Preconditions.checkNotNull(duration, "duration must not be null");
-        Preconditions.checkArgument(duration.toMilliseconds() > 0, "deadline must be positive: %s", duration);
-        this.durationLimit = duration.toMilliseconds();
-        return this;
-    }
-
-    /**
-     * Run the loop.
-     *
-     * @return true if the exit condition was satisfied; false if the loop terminated for any other reason.
-     */
-    public boolean run() {
-        Preconditions.checkState(body != null, "repeat() method has not been called to set the body");
-        Preconditions.checkState(exitCondition != null, "until() method has not been called to set the exit condition");
-        Preconditions.checkState(period != null, "every() method has not been called to set the loop period time units");
-
-        Throwable lastError = null;
-        int iterations = 0;
-        long endTime = -1;
-        if (durationLimit != null) {
-            endTime = System.currentTimeMillis() + durationLimit;
-        }
-
-        while (true) {
-            iterations++;
-
-            try {
-                body.call();
-            } catch (Exception e) {
-                log.warn(description, e);
-                if (rethrowExceptionImmediately) throw Exceptions.propagate(e);
-            }
-
-            boolean done = false;
-            try {
-                lastError = null;
-                done = exitCondition.call();
-            } catch (Exception e) {
-                if (log.isDebugEnabled()) log.debug(description, e);
-                lastError = e;
-                if (rethrowExceptionImmediately) throw Exceptions.propagate(e);
-            }
-            if (done) {
-                if (log.isDebugEnabled()) log.debug("{}: condition satisfied", description);
-                return true;
-            } else {
-                if (log.isDebugEnabled()) {
-                    String msg = String.format("%s: unsatisfied during iteration %s %s", description, iterations,
-                            (iterationLimit > 0 ? "(max "+iterationLimit+" attempts)" : "") + 
-                            (endTime > 0 ? "("+Time.makeTimeStringRounded(endTime - System.currentTimeMillis())+" remaining)" : ""));
-                    if (iterations == 1) {
-                        log.debug(msg);
-                    } else {
-                        log.trace(msg);
-                    }
-                }
-            }
-
-            if (iterationLimit > 0 && iterations == iterationLimit) {
-                if (log.isDebugEnabled()) log.debug("{}: condition not satisfied and exceeded iteration limit", description);
-                if (rethrowException && lastError != null) {
-                    log.warn("{}: error caught checking condition (rethrowing): {}", description, lastError.getMessage());
-                    throw Exceptions.propagate(lastError);
-                }
-                if (warnOnUnRethrownException && lastError != null)
-                    log.warn("{}: error caught checking condition: {}", description, lastError.getMessage());
-                return false;
-            }
-
-            if (endTime > 0) {
-                if (System.currentTimeMillis() > endTime) {
-                    if (log.isDebugEnabled()) log.debug("{}: condition not satisfied and deadline {} passed", 
-                            description, Time.makeTimeStringRounded(endTime - System.currentTimeMillis()));
-                    if (rethrowException && lastError != null) {
-                        log.error("{}: error caught checking condition: {}", description, lastError.getMessage());
-                        throw Exceptions.propagate(lastError);
-                    }
-                    return false;
-                }
-            }
-
-            Time.sleep(period);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7350fd62/core/src/test/java/org/apache/brooklyn/util/core/internal/RepeaterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/internal/RepeaterTest.java b/core/src/test/java/org/apache/brooklyn/util/core/internal/RepeaterTest.java
deleted file mode 100644
index de26857..0000000
--- a/core/src/test/java/org/apache/brooklyn/util/core/internal/RepeaterTest.java
+++ /dev/null
@@ -1,251 +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.util.core.internal;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.brooklyn.util.time.Duration;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Stopwatch;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.util.concurrent.Callables;
-
-@SuppressWarnings("deprecation")
-public class RepeaterTest {
-
-    @Test
-    public void sanityTest() {
-        new Repeater("Sanity test")
-            .repeat()
-            .until(Callables.returning(true))
-            .every(Duration.millis(10));
-    }
-
-    @Test
-    public void sanityTestDescription() {
-        new Repeater()
-            .repeat()
-            .until(Callables.returning(true))
-            .every(Duration.millis(10));
-    }
-
-    @Test
-    public void sanityTestBuilder() {
-        Repeater.create("Sanity test")
-            .repeat()
-            .until(Callables.returning(true))
-            .every(Duration.millis(10));
-    }
-
-    @Test
-    public void sanityTestBuilderDescription() {
-        Repeater.create()
-            .repeat()
-            .until(Callables.returning(true))
-            .every(Duration.millis(10));
-    }
-
-    @Test(expectedExceptions = NullPointerException.class)
-    public void repeatFailsIfClosureIsNull() {
-        new Repeater("repeatFailsIfClosureIsNull").repeat((Callable<?>)null);
-    }
-
-    @Test
-    public void repeatSucceedsIfClosureIsNonNull() {
-        new Repeater("repeatSucceedsIfClosureIsNonNull").repeat(Callables.returning(true));
-    }
-
-    @Test(expectedExceptions = NullPointerException.class)
-    public void untilFailsIfClosureIsNull() {
-        new Repeater("untilFailsIfClosureIsNull").until(null);
-    }
-
-    @Test
-    public void untilSucceedsIfClosureIsNonNull() {
-        new Repeater("untilSucceedsIfClosureIsNonNull").until(Callables.returning(true));
-    }
-
-    @Test(expectedExceptions = IllegalArgumentException.class)
-    public void everyFailsIfPeriodIsZero() {
-        new Repeater("everyFailsIfPeriodIsZero").every(Duration.ZERO);
-    }
-
-    @Test(expectedExceptions = IllegalArgumentException.class)
-    public void everyFailsIfPeriodIsNegative() {
-        new Repeater("everyFailsIfPeriodIsNegative").every(Duration.millis(-1));
-    }
-
-    @Test(expectedExceptions = NullPointerException.class)
-    public void everyFailsIfUnitsIsNull() {
-        new Repeater("everyFailsIfUnitsIsNull").every(10, null);
-    }
-
-    @Test
-    public void everySucceedsIfPeriodIsPositiveAndUnitsIsNonNull() {
-        new Repeater("repeatSucceedsIfClosureIsNonNull").every(Duration.millis(10));
-    }
-
-    @Test(expectedExceptions = IllegalArgumentException.class)
-    public void limitTimeToFailsIfPeriodIsZero() {
-        new Repeater("limitTimeToFailsIfPeriodIsZero").limitTimeTo(0, TimeUnit.MILLISECONDS);
-    }
-
-    @Test(expectedExceptions = IllegalArgumentException.class)
-    public void limitTimeToFailsIfPeriodIsNegative() {
-        new Repeater("limitTimeToFailsIfPeriodIsNegative").limitTimeTo(-1, TimeUnit.MILLISECONDS);
-    }
-
-    @Test(expectedExceptions = NullPointerException.class)
-    public void limitTimeToFailsIfUnitsIsNull() {
-        new Repeater("limitTimeToFailsIfUnitsIsNull").limitTimeTo(10, null);
-    }
-
-    @Test
-    public void limitTimeToSucceedsIfPeriodIsPositiveAndUnitsIsNonNull() {
-        new Repeater("limitTimeToSucceedsIfClosureIsNonNull").limitTimeTo(10, TimeUnit.MILLISECONDS);
-    }
-
-    @Test
-    public void everyAcceptsDuration() {
-        new Repeater("everyAcceptsDuration").every(Duration.ONE_SECOND);
-    }
-
-    @Test
-    public void everyAcceptsLong() {
-        new Repeater("everyAcceptsLong").every(1000L);
-    }
-
-    @Test
-    public void everyAcceptsTimeUnit() {
-        new Repeater("everyAcceptsTimeUnit").every(1000000L, TimeUnit.MICROSECONDS);
-    }
-
-    @Test
-    public void runReturnsTrueIfExitConditionIsTrue() {
-        assertTrue(new Repeater("runReturnsTrueIfExitConditionIsTrue")
-            .repeat()
-            .every(Duration.millis(1))
-            .until(Callables.returning(true))
-            .run());
-    }
-
-    @Test
-    public void runRespectsMaximumIterationLimitAndReturnsFalseIfReached() {
-        final AtomicInteger iterations = new AtomicInteger();
-        assertFalse(new Repeater("runRespectsMaximumIterationLimitAndReturnsFalseIfReached")
-            .repeat(new Runnable() {@Override public void run() {iterations.incrementAndGet();}})
-            .every(Duration.millis(1))
-            .until(Callables.returning(false))
-            .limitIterationsTo(5)
-            .run());
-        assertEquals(iterations.get(), 5);
-    }
-
-    /**
-     * Check that the {@link Repeater} will stop after a time limit.
-     *
-     * The repeater is configured to run every 100ms and never stop until the limit is reached.
-     * This is given as {@link Repeater#limitTimeTo(groovy.time.Duration)} and the execution time
-     * is then checked to ensure it is between 100% and 400% of the specified value. Due to scheduling
-     * delays and other factors in a non RTOS system it is expected that the repeater will take much
-     * longer to exit occasionally.
-     *
-     * @see #runRespectsMaximumIterationLimitAndReturnsFalseIfReached()
-     */
-    @Test(groups="Integration")
-    public void runRespectsTimeLimitAndReturnsFalseIfReached() {
-        final long LIMIT = 2000l;
-        Repeater repeater = new Repeater("runRespectsTimeLimitAndReturnsFalseIfReached")
-            .repeat()
-            .every(Duration.millis(100))
-            .until(Callables.returning(false))
-            .limitTimeTo(LIMIT, TimeUnit.MILLISECONDS);
-
-        Stopwatch stopwatch = Stopwatch.createStarted();
-        boolean result = repeater.run();
-        stopwatch.stop();
-
-        assertFalse(result);
-
-        long difference = stopwatch.elapsed(TimeUnit.MILLISECONDS);
-        assertTrue(difference >= LIMIT, "Difference was: " + difference);
-        assertTrue(difference < 4 * LIMIT, "Difference was: " + difference);
-    }
-
-    @Test(expectedExceptions = IllegalStateException.class)
-    public void runFailsIfUntilWasNotSet() {
-        new Repeater("runFailsIfUntilWasNotSet")
-            .repeat()
-            .every(Duration.millis(10))
-            .run();
-    }
-
-    @Test(expectedExceptions = IllegalStateException.class)
-    public void runFailsIfEveryWasNotSet() {
-        new Repeater("runFailsIfEveryWasNotSet")
-            .repeat()
-            .until(Callables.returning(true))
-            .run();
-    }
-
-    @Test(expectedExceptions = UnsupportedOperationException.class)
-    public void testRethrowsException() {
-        new Repeater("throwRuntimeException")
-            .repeat()
-            .every(Duration.millis(10))
-            .until(new Callable<Boolean>() {@Override public Boolean call() {throw new UnsupportedOperationException("fail"); }})
-            .rethrowException()
-            .limitIterationsTo(2)
-            .run();
-    }
-
-    @Test
-    public void testNoRethrowsException() {
-        try {
-            boolean result = new Repeater("throwRuntimeException")
-                .repeat()
-                .every(Duration.millis(10))
-                .until(new Callable<Boolean>() {@Override public Boolean call() {throw new UnsupportedOperationException("fail"); }})
-                .limitIterationsTo(2)
-                .run();
-            assertFalse(result);
-        } catch (RuntimeException re) {
-            fail("Exception should not have been thrown: " + re.getMessage(), re);
-        }
-    }
-    
-    public void testFlags() {
-        final AtomicInteger count = new AtomicInteger();
-        new Repeater(ImmutableMap.of("period", Duration.millis(5), "timeout", Duration.millis(100)))
-                .repeat(new Runnable() {@Override public void run() {count.incrementAndGet();}})
-                .until(new Callable<Boolean>() { @Override public Boolean call() {return count.get() > 0;}})
-                .run();
-        assertTrue(count.get()>10);
-        assertTrue(count.get()<30);
-    }
-    
-}


[12/12] brooklyn-server git commit: This closes #687

Posted by m4...@apache.org.
This closes #687


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

Branch: refs/heads/master
Commit: d4d5966c1d49187cd05a884c0a99e6af64494291
Parents: 3d7a35f 2423696
Author: Mark McKenna <m4...@gmail.com>
Authored: Fri May 19 18:02:49 2017 +0100
Committer: Mark McKenna <m4...@gmail.com>
Committed: Fri May 19 18:02:49 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/api/entity/EntityType.java  |  12 -
 .../brooklyn/api/location/LocationSpec.java     |  21 --
 .../apache/brooklyn/camp/util/yaml/Yamls.java   |  24 --
 .../core/entity/EntityTypeSnapshot.java         |  26 --
 .../apache/brooklyn/core/feed/AbstractFeed.java |  20 -
 .../core/location/LocationConfigUtils.java      | 102 ------
 .../brooklyn/core/mgmt/BrooklynTasks.java       |  25 --
 .../internal/AbstractManagementContext.java     |   2 +-
 .../core/mgmt/internal/EffectorUtils.java       |  34 --
 .../mgmt/internal/LocalManagementContext.java   |   2 +-
 .../objs/proxy/InternalLocationFactory.java     |  11 -
 .../brooklyn/util/core/internal/Repeater.java   | 367 -------------------
 .../core/location/AbstractLocationTest.java     |  33 +-
 .../EntityPersistencePerformanceTest.java       |   2 +-
 .../ssh/SshMachineLocationPerformanceTest.java  |   2 +-
 .../util/core/internal/RepeaterTest.java        | 251 -------------
 .../apache/brooklyn/test/EntityTestUtils.java   | 192 ----------
 .../brooklyn/test/PerformanceTestUtils.java     |  26 --
 .../org/apache/brooklyn/test/TestUtils.java     |  83 -----
 .../org/apache/brooklyn/util/ShellUtils.java    | 185 ----------
 20 files changed, 27 insertions(+), 1393 deletions(-)
----------------------------------------------------------------------



[09/12] brooklyn-server git commit: Delete deprecated AbstractFeed constructors

Posted by m4...@apache.org.
Delete deprecated AbstractFeed constructors

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

Branch: refs/heads/master
Commit: ed60d6f207360895f09b160e4a41884cb00d1f86
Parents: 55eb11f
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:48:38 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 13:27:04 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/core/feed/AbstractFeed.java | 20 --------------------
 1 file changed, 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ed60d6f2/core/src/main/java/org/apache/brooklyn/core/feed/AbstractFeed.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/feed/AbstractFeed.java b/core/src/main/java/org/apache/brooklyn/core/feed/AbstractFeed.java
index 675dc83..fba15ca 100644
--- a/core/src/main/java/org/apache/brooklyn/core/feed/AbstractFeed.java
+++ b/core/src/main/java/org/apache/brooklyn/core/feed/AbstractFeed.java
@@ -18,11 +18,8 @@
  */
 package org.apache.brooklyn.core.feed;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-
 import java.util.Collection;
 
-import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.FeedMemento;
@@ -57,23 +54,6 @@ public abstract class AbstractFeed extends AbstractEntityAdjunct implements Feed
     public AbstractFeed() {
     }
     
-    /**
-     * @deprecated since 0.7.0; use no-arg constructor; call {@link #setEntity(EntityLocal)}
-     */
-    @Deprecated
-    public AbstractFeed(Entity entity) {
-        this(entity, false);
-    }
-    
-    /**
-     * @deprecated since 0.7.0; use no-arg constructor; call {@link #setEntity(EntityLocal)} and {@code setConfig(ONLY_IF_SERVICE_UP, onlyIfServiceUp)}
-     */
-    @Deprecated
-    public AbstractFeed(Entity entity, boolean onlyIfServiceUp) {
-        this.entity = checkNotNull((EntityInternal)entity, "entity");
-        setConfig(ONLY_IF_SERVICE_UP, onlyIfServiceUp);
-    }
-
     // Ensure idempotent, as called in builders (in case not registered with entity), and also called
     // when registering with entity
     @Override


[05/12] brooklyn-server git commit: Delete deprecated Yamls class

Posted by m4...@apache.org.
Delete deprecated Yamls class

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

Branch: refs/heads/master
Commit: 9911286bcdd1402acab2b7319305bb6d8fcc7076
Parents: 093a8d1
Author: Aled Sage <al...@gmail.com>
Authored: Wed May 17 20:43:27 2017 +0200
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 10:46:35 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/camp/util/yaml/Yamls.java   | 24 --------------------
 1 file changed, 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9911286b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/util/yaml/Yamls.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/util/yaml/Yamls.java b/camp/camp-base/src/main/java/org/apache/brooklyn/camp/util/yaml/Yamls.java
deleted file mode 100644
index 1bfde6f..0000000
--- a/camp/camp-base/src/main/java/org/apache/brooklyn/camp/util/yaml/Yamls.java
+++ /dev/null
@@ -1,24 +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.camp.util.yaml;
-
-/** @deprecated since 0.7.0 use {@link org.apache.brooklyn.util.yaml.Yamls} */
-@Deprecated
-public class Yamls extends org.apache.brooklyn.util.yaml.Yamls {
-}


[07/12] brooklyn-server git commit: Delete deprecated EffectorUtils methods

Posted by m4...@apache.org.
Delete deprecated EffectorUtils methods

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

Branch: refs/heads/master
Commit: e37229168970bacef2555d6f6bbc8e6063fcad98
Parents: e920c26
Author: Aled Sage <al...@gmail.com>
Authored: Thu May 18 16:57:25 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri May 19 13:27:04 2017 +0100

----------------------------------------------------------------------
 .../core/mgmt/internal/EffectorUtils.java       | 34 --------------------
 1 file changed, 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e3722916/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
index bab9fc7..245c1c5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
@@ -20,14 +20,12 @@ package org.apache.brooklyn.core.mgmt.internal;
 
 import static org.apache.brooklyn.util.JavaGroovyEquivalents.groovyTruth;
 
-import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.Set;
 
 import org.apache.brooklyn.api.effector.Effector;
 import org.apache.brooklyn.api.effector.ParameterType;
@@ -348,32 +346,6 @@ public class EffectorUtils {
         }
     }
 
-    /** @deprecated since 0.7.0, not used */
-    @Deprecated
-    public static Effector<?> findEffectorMatching(Entity entity, Method method) {
-        outer: for (Effector<?> effector : entity.getEntityType().getEffectors()) {
-            if (!effector.getName().equals(entity)) continue;
-            if (effector.getParameters().size() != method.getParameterTypes().length) continue;
-            for (int i = 0; i < effector.getParameters().size(); i++) {
-                if (effector.getParameters().get(i).getParameterClass() != method.getParameterTypes()[i]) continue outer;
-            }
-            return effector;
-        }
-        return null;
-    }
-
-    /** @deprecated since 0.7.0, expects parameters but does not use them! */
-    @Deprecated
-    public static Effector<?> findEffectorMatching(Set<Effector<?>> effectors, String effectorName, Map<String, ?> parameters) {
-        // TODO Support overloading: check parameters as well
-        for (Effector<?> effector : effectors) {
-            if (effector.getName().equals(effectorName)) {
-                return effector;
-            }
-        }
-        return null;
-    }
-
     /** matches effectors by name only (not parameters) */
     public static Maybe<Effector<?>> findEffector(Collection<? extends Effector<?>> effectors, String effectorName) {
         for (Effector<?> effector : effectors) {
@@ -389,12 +361,6 @@ public class EffectorUtils {
         return findEffector(entity.getEntityType().getEffectors(), effectorName);
     }
 
-    /** @deprecated since 0.7.0 use {@link #getTaskFlagsForEffectorInvocation(Entity, Effector, ConfigBag)} */
-    @Deprecated
-    public static Map<Object,Object> getTaskFlagsForEffectorInvocation(Entity entity, Effector<?> effector) {
-        return getTaskFlagsForEffectorInvocation(entity, effector, null);
-    }
-    
     /** returns a (mutable) map of the standard flags which should be placed on an effector */
     public static Map<Object,Object> getTaskFlagsForEffectorInvocation(Entity entity, Effector<?> effector, ConfigBag parameters) {
         List<Object> tags = MutableList.of(