brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [4/8] git commit: call `parentLocation.release(child)` on unmanage, so that (in part) ports obtained for use on localhost are freed up for reuse; and clean up how the decision to `release` is made with new abstract ProvisioningLocation
Date Mon, 27 Oct 2014 14:56:09 GMT
call `parentLocation.release(child)` on unmanage, so that (in part) ports obtained for use
on localhost are freed up for reuse;
and clean up how the decision to `release` is made with new abstract ProvisioningLocation


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

Branch: refs/heads/master
Commit: f4d24b08765078cf87298de650d7af6399d0e1d4
Parents: d311ba1
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Oct 27 02:33:57 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Oct 27 07:51:41 2014 -0700

----------------------------------------------------------------------
 .../location/MachineProvisioningLocation.java   |  4 +-
 .../location/NoMachinesAvailableException.java  |  2 +-
 .../NoSuchLocationAvailableException.java       | 35 ++++++++++++++++
 .../brooklyn/location/ProvisioningLocation.java | 44 ++++++++++++++++++++
 .../internal/LocalLocationManager.java          | 12 ++++++
 .../location/jclouds/JcloudsLocation.java       |  3 +-
 6 files changed, 97 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f4d24b08/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java b/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java
index 65d296e..8553480 100644
--- a/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java
+++ b/api/src/main/java/brooklyn/location/MachineProvisioningLocation.java
@@ -26,7 +26,7 @@ import java.util.Map;
  *
  * This interface extends {@link Location} to add the ability to provision {@link MachineLocation}s
in this location.
  */
-public interface MachineProvisioningLocation<T extends MachineLocation> extends Location
{
+public interface MachineProvisioningLocation<T extends MachineLocation> extends ProvisioningLocation<T>
{
     /**
      * Obtain a machine in this location.
      * 
@@ -35,6 +35,7 @@ public interface MachineProvisioningLocation<T extends MachineLocation>
extends
      * @return a machine that is a child of this location.
      * @throws NoMachinesAvailableException if there are no machines available in this location
(or impls may return null, but that is discouraged)
      */
+    @Override
     T obtain(Map<?,?> flags) throws NoMachinesAvailableException;
 
     /**
@@ -52,6 +53,7 @@ public interface MachineProvisioningLocation<T extends MachineLocation>
extends
      * @param machine a {@link MachineLocation} previously obtained from a call to {@link
#obtain()}
      * @throws IllegalStateException if the machine did not come from a call to {@link #obtain()}
or it has already been released.
      */
+    @Override
     void release(T machine);
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f4d24b08/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java b/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java
index 03b3053..27b7ddf 100644
--- a/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java
+++ b/api/src/main/java/brooklyn/location/NoMachinesAvailableException.java
@@ -22,7 +22,7 @@ package brooklyn.location;
 /**
  * Indicates no machines are available in a given location.
  */
-public class NoMachinesAvailableException extends Exception {
+public class NoMachinesAvailableException extends NoSuchLocationAvailableException {
     private static final long serialVersionUID = 1079817235289265761L;
     
     public NoMachinesAvailableException(String s) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f4d24b08/api/src/main/java/brooklyn/location/NoSuchLocationAvailableException.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/NoSuchLocationAvailableException.java b/api/src/main/java/brooklyn/location/NoSuchLocationAvailableException.java
new file mode 100644
index 0000000..d719537
--- /dev/null
+++ b/api/src/main/java/brooklyn/location/NoSuchLocationAvailableException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.location;
+
+
+/**
+ * Indicates no machines are available in a given location.
+ */
+public class NoSuchLocationAvailableException extends Exception {
+    private static final long serialVersionUID = 1079817235289265761L;
+    
+    public NoSuchLocationAvailableException(String s) {
+        super(s);
+    }
+
+    public NoSuchLocationAvailableException(String s, Throwable throwable) {
+        super(s, throwable);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f4d24b08/api/src/main/java/brooklyn/location/ProvisioningLocation.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/ProvisioningLocation.java b/api/src/main/java/brooklyn/location/ProvisioningLocation.java
new file mode 100644
index 0000000..92cd26a
--- /dev/null
+++ b/api/src/main/java/brooklyn/location/ProvisioningLocation.java
@@ -0,0 +1,44 @@
+/*
+ * 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 brooklyn.location;
+
+import java.util.Map;
+
+/**
+ * A location that is able to provision new locations within it.
+ */
+public interface ProvisioningLocation<T extends Location> extends Location {
+    /**
+     * Obtain a new (sub)-location in the location represented by this class.
+     * 
+     * @param flags Constraints and details of the location to be provisioned
+     * @return the location provisioned
+     * @throws NoSuchLocationAvailableException if could not provision such a location
+     */
+    T obtain(Map<?,?> flags) throws NoSuchLocationAvailableException;
+
+    /**
+     * Release a previously-obtained location.
+     *
+     * @param location a location previously obtained
+     * @throws IllegalStateException if the machine did not come from a call to {@link #obtain()}
or it has already been released.
+     */
+    void release(T machine);
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f4d24b08/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java b/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
index de90390..bbb5c19 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalLocationManager.java
@@ -35,6 +35,7 @@ import brooklyn.entity.proxying.InternalLocationFactory;
 import brooklyn.internal.storage.BrooklynStorage;
 import brooklyn.location.Location;
 import brooklyn.location.LocationSpec;
+import brooklyn.location.ProvisioningLocation;
 import brooklyn.location.basic.AbstractLocation;
 import brooklyn.location.basic.LocationInternal;
 import brooklyn.management.AccessController;
@@ -372,9 +373,20 @@ public class LocalLocationManager implements LocationManagerInternal
{
         return true;
     }
 
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     private synchronized void unmanageNonRecursiveClearItsFields(Location loc, ManagementTransitionMode
mode) {
         if (mode==ManagementTransitionMode.DESTROYING) {
             ((AbstractLocation)loc).setParent(null, true);
+            
+            Location parent = ((AbstractLocation)loc).getParent();
+            if (parent instanceof ProvisioningLocation<?>) {
+                try {
+                    ((ProvisioningLocation)parent).release(loc);
+                } catch (Exception e) {
+                    Exceptions.propagateIfFatal(e);
+                    log.debug("Error releasing "+loc+" in its parent "+parent+": "+e);
+                }
+            }
         } else {
             // if not destroying, don't change the parent's children list
             ((AbstractLocation)loc).setParent(null, false);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f4d24b08/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index 5f8fbb7..2f732ec 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -1645,7 +1645,8 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
             computeService.destroyNode(instanceId);
         } finally {
         /*
-         //don't close, so can re-use...
+            // we don't close the compute service; this means if we provision add'l it is
fast;
+            // however it also means an explicit System.exit may be needed for termination
             if (computeService != null) {
                 try {
                     computeService.getContext().close();


Mime
View raw message