You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/03/28 12:13:17 UTC
[1/5] brooklyn-server git commit: Add location customizer to ensure
SoftLayer VMs use the same VLAN
Repository: brooklyn-server
Updated Branches:
refs/heads/master 52e0c4e19 -> f66d1ad44
Add location customizer to ensure SoftLayer VMs use the same VLAN
- Use CountDownLatch for locking
- Keep state in ConfigKey on Location
- Record VLAN details on Entity as Sensor
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4e047763
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4e047763
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4e047763
Branch: refs/heads/master
Commit: 4e04776310a5c816774462731425a1ae16c1a3b6
Parents: 3c051ad
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Tue Mar 8 11:46:29 2016 -0500
Committer: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Committed: Thu Mar 24 19:37:05 2016 +0000
----------------------------------------------------------------------
.../SoftLayerSameVlanLocationCustomizer.java | 398 +++++++++++++++++++
1 file changed, 398 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e047763/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
new file mode 100644
index 0000000..4c980d8
--- /dev/null
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
@@ -0,0 +1,398 @@
+/*
+ * 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.location.jclouds.softlayer;
+
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.reflect.TypeToken;
+import com.google.common.util.concurrent.Uninterruptibles;
+
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.softlayer.SoftLayerApi;
+import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
+import org.jclouds.softlayer.domain.VirtualGuest;
+import org.jclouds.softlayer.features.VirtualGuestApi;
+import org.jclouds.softlayer.reference.SoftLayerConstants;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.location.LocationConfigKeys;
+import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.location.jclouds.BasicJcloudsLocationCustomizer;
+import org.apache.brooklyn.location.jclouds.JcloudsLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsLocationCustomizer;
+import org.apache.brooklyn.location.jclouds.JcloudsMachineLocation;
+import org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.flags.SetFromFlag;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.text.Strings;
+import org.apache.brooklyn.util.time.Duration;
+
+/**
+ * Customizes {@link JcloudsSshMachineLocation machines} in SoftLayer to use
+ * the same VLANs across an application, or other named scope
+ * <p>
+ * Define the scope by setting the {@link #SCOPE_UID scopeUid} ({@code softlayer.vlan.scopeUid})
+ * option. Set {@link #SCOPE_TIMEOUT scopeTimeout} ({@code softlayer.vlan.timeout}) to change
+ * the length of time the customizer will wait for VLAN information; normally 15 minutes.
+ * <p>
+ * The VLAN IDs and latches are stored as {@link ConfigKey configuration} on
+ * the {@link JcloudsLocation location} provisioning the VMs, in a map keyed
+ * on the scope.
+ */
+@ThreadSafe
+public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCustomizer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SoftLayerSameVlanLocationCustomizer.class);
+
+ @SetFromFlag("scopeUid")
+ public static final ConfigKey<String> SCOPE_UID = ConfigKeys.newStringConfigKey(
+ "softlayer.vlan.scopeUid",
+ "The unique identifier for a Softlayer location scope that will have VMs created in the same VLAN");
+
+ @SetFromFlag("scopeTimeout")
+ public static final ConfigKey<Duration> SCOPE_TIMEOUT = ConfigKeys.newDurationConfigKey(
+ "softlayer.vlan.timeout",
+ "The length of time to wait for a Softlayer VLAN ID",
+ Duration.minutes(15));
+
+ public static final ConfigKey<Map<String, CountDownLatch>> COUNTDOWN_LATCH_MAP = ConfigKeys.newConfigKey(
+ new TypeToken<Map<String, CountDownLatch>>() { },
+ "softLayerSameVlanLocationCustomizer.map.latches",
+ "A mapping from scope identifiers to CountDownLatches; used to synchronize threads");
+ public static final ConfigKey<Map<String, Integer>> PUBLIC_VLAN_ID_MAP = ConfigKeys.newConfigKey(
+ new TypeToken<Map<String, Integer>>() { },
+ "softLayerSameVlanLocationCustomizer.map.publicVlanIds",
+ "A mapping from scope identifiers to public VLAN numbers");
+ public static final ConfigKey<Map<String, Integer>> PRIVATE_VLAN_ID_MAP = ConfigKeys.newConfigKey(
+ new TypeToken<Map<String, Integer>>() { },
+ "softLayerSameVlanLocationCustomizer.map.privateVlanIds",
+ "A mapping from scope identifiers to private VLAN numbers");
+
+ public static final AttributeSensor<Integer> PUBLIC_VLAN_ID = Sensors.newIntegerSensor(
+ "softLayer.vlan.publicId", "The public VLAN ID for this entity");
+ public static final AttributeSensor<Integer> PRIVATE_VLAN_ID = Sensors.newIntegerSensor(
+ "softLayer.vlan.privateId", "The private VLAN ID for this entity");
+
+ /* Flags passed in on object creation. */
+ private final Map<String, ?> flags;
+
+ /* Lock object for global critical sections accessing shared state maps. */
+ private static final transient Object lock = new Object[0];
+
+ /** Convenience creation method. */
+ public static SoftLayerSameVlanLocationCustomizer forScope(String scopeUid) {
+ SoftLayerSameVlanLocationCustomizer customizer = new SoftLayerSameVlanLocationCustomizer(ImmutableMap.of(SCOPE_UID.getName(), scopeUid));
+ return customizer;
+ }
+
+ public SoftLayerSameVlanLocationCustomizer() {
+ this(ImmutableMap.<String, Object>of());
+ }
+
+ public SoftLayerSameVlanLocationCustomizer(Map<String, ?> flags) {
+ this.flags = ImmutableMap.copyOf(flags);
+ }
+
+ /**
+ * Used to obtain the VLANs being used by the first created {@link JcloudsMachineLocation}.
+ *
+ * @see {@link JcloudsLocationCustomizer#customize(JcloudsLocation, ComputeService, JcloudsMachineLocation)}
+ */
+ @Override
+ public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) {
+ // Check we are customising a SoftLayer location
+ String provider = location.getProvider();
+ if (!(provider.equals(SoftLayerConstants.SOFTLAYER_PROVIDER_NAME))) {
+ String message = String.format("Invalid location provider: %s", provider);
+ LOG.warn(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ // Lookup the latch for this scope
+ String scopeUid = getScopeUid(location);
+ CountDownLatch latch = null;
+ synchronized (lock) {
+ latch = lookupCountDownLatch(location, scopeUid);
+ if (latch == null) {
+ throw new IllegalStateException("No latch available for scope: " + scopeUid);
+ }
+ }
+
+ try {
+ // Check if VLAN IDs have been set for this scope
+ LOG.debug("Looking up saved VLAN details {}", scopeUid);
+ Integer publicVlanId = lookupPublicVlanId(location, scopeUid);
+ Integer privateVlanId = lookupPrivateVlanId(location, scopeUid);
+ if (privateVlanId != null && publicVlanId != null) {
+ LOG.debug("SoftLayer VLANs private {} and public {} already configured for scope: {}",
+ new Object[] { privateVlanId, publicVlanId, scopeUid });
+ saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
+ return;
+ }
+
+ // No VLAN info yet known, we are probably the first VM and we should
+ // set the VLAN info for others to then learn about.
+
+ // Ask SoftLayer API for the VLAN details for this VM
+ LOG.debug("Requesting VLAN details from API for scope: {}", scopeUid);
+ VirtualGuestApi api = computeService.getContext().unwrapApi(SoftLayerApi.class).getVirtualGuestApi();
+ Long serverId = Long.parseLong(machine.getJcloudsId());
+ VirtualGuest guest = api.getVirtualGuestFiltered(serverId,
+ "primaryNetworkComponent;" +
+ "primaryNetworkComponent.networkVlan;" +
+ "primaryBackendNetworkComponent;" +
+ "primaryBackendNetworkComponent.networkVlan");
+ publicVlanId = guest.getPrimaryNetworkComponent().getNetworkVlan().getId();
+ privateVlanId = guest.getPrimaryBackendNetworkComponent().getNetworkVlan().getId();
+
+ // Save the VLAN ids
+ LOG.debug("Saving VLAN details private {} and public {} for scope: {}",
+ new Object[] { privateVlanId, publicVlanId, scopeUid });
+ savePublicVlanId(location, scopeUid, publicVlanId);
+ savePrivateVlanId(location, scopeUid, privateVlanId);
+ saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
+ } finally {
+ // Release the latch
+ latch.countDown();
+ }
+ }
+
+ /* Save the VLAN IDs as sensor data on the entity and set tag. */
+ private void saveVlanDetails(JcloudsMachineLocation machine, String scopeUid, Integer privateVlanId, Integer publicVlanId) {
+ Object context = flags.get(LocationConfigKeys.CALLER_CONTEXT.getName());
+ if (context == null) {
+ context = machine.config().get(LocationConfigKeys.CALLER_CONTEXT);
+ }
+ if (!(context instanceof Entity)) {
+ throw new IllegalStateException("Invalid location context: " + context);
+ }
+ Entity entity = (Entity) context;
+ entity.sensors().set(PUBLIC_VLAN_ID, publicVlanId);
+ entity.sensors().set(PRIVATE_VLAN_ID, privateVlanId);
+ entity.tags().addTag("softlayer-vlan-scopeUid-" + scopeUid);
+ }
+
+ /**
+ * Update the {@link org.jclouds.compute.options.TemplateOptions} that will
+ * be used by {@link JcloudsLocation} to obtain machines. Uses the VLAN
+ * numbers configured on an existing machine, as saved in the configuration
+ * maps for {@link #PUBLIC_VLAN_ID_MAP public} and {@link #PRIVATE_VLAN_ID_MAP private}
+ * VLAN numbers.
+ *
+ * @see {@link JcloudsLocationCustomizer#customize(JcloudsLocation, ComputeService, TemplateOptions)}
+ */
+ @Override
+ public void customize(JcloudsLocation location, ComputeService computeService, TemplateOptions templateOptions) {
+ // Check we are customising a SoftLayer location
+ String provider = location.getProvider();
+ if (!(provider.equals(SoftLayerConstants.SOFTLAYER_PROVIDER_NAME) &&
+ templateOptions instanceof SoftLayerTemplateOptions)) {
+ String message = String.format("Invalid location provider or template options: %s/%s",
+ provider, templateOptions.getClass().getSimpleName());
+ LOG.warn(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ // Check template options for VLAN configuration and return if already set
+ String scopeUid = getScopeUid(location);
+ SoftLayerTemplateOptions softLayerOptions = (SoftLayerTemplateOptions) templateOptions;
+ Integer publicVlanId = softLayerOptions.getPrimaryNetworkComponentNetworkVlanId();
+ Integer privateVlanId = softLayerOptions.getPrimaryBackendNetworkComponentNetworkVlanId();
+ if (publicVlanId != null && privateVlanId != null) {
+ LOG.debug("SoftLayer VLANs private {} and public {} already configured in template options for scope: {}",
+ new Object[] { privateVlanId, publicVlanId, scopeUid });
+ return;
+ }
+
+ // Create a new latch if we are first
+ CountDownLatch latch = null;
+ synchronized (lock) {
+ latch = lookupCountDownLatch(location, scopeUid);
+ if (latch == null) {
+ // We are first to try obtaining a VM; create a latch and return
+ LOG.debug("Creating new latch for scope: {}", scopeUid);
+ latch = createCountDownLatch(location, scopeUid);
+ return;
+ }
+ }
+
+ // Try and acquire the latch, or time out
+ Duration timeout = getTimeout(location);
+ Tasks.setBlockingDetails("Waiting for VLAN details");
+ try {
+ LOG.debug("Waiting for VLAN details for scope: {}", scopeUid);
+ if (!Uninterruptibles.awaitUninterruptibly(latch, timeout.toMilliseconds(), TimeUnit.MILLISECONDS)) {
+ // Release the latch and throw an exception to prevent others blocking forever
+ latch.countDown();
+ throw new IllegalStateException("Timeout acquiring latch for scope: " + scopeUid);
+ }
+ } finally {
+ Tasks.resetBlockingDetails();
+ }
+
+ // Looking up saved VLAN details
+ LOG.debug("Looking up saved VLAN details {}", scopeUid);
+ publicVlanId = lookupPublicVlanId(location, scopeUid);
+ privateVlanId = lookupPrivateVlanId(location, scopeUid);
+ if (privateVlanId == null && publicVlanId == null) {
+ // Saved VLAN IDs not found; something went wrong so remove the latch to try again
+ removeCountDownLatch(location, scopeUid);
+ String message = String.format("Saved VLAN configuration not found for scope: %s", scopeUid);
+ LOG.warn(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ // Setting VLAN template options
+ LOG.debug("Setting VLAN template options private {} and public {} for scope: {}",
+ new Object[] { privateVlanId, publicVlanId, scopeUid });
+ softLayerOptions.primaryNetworkComponentNetworkVlanId(publicVlanId);
+ softLayerOptions.primaryBackendNetworkComponentNetworkVlanId(privateVlanId);
+ }
+
+ /**
+ * Get the {@link #SCOPE_TIMEOUT timeout} {@link Duration duration} from the
+ * location flags, or the location itself.
+ */
+ private Duration getTimeout(JcloudsLocation location) {
+ Duration timeout = (Duration) flags.get(SCOPE_TIMEOUT.getName());
+ if (timeout == null) {
+ timeout = location.config().get(SCOPE_TIMEOUT);
+ }
+ return timeout;
+ }
+
+ /**
+ * Get the {@link #SCOPE_UID scope} UID from the location flags, or the
+ * location itself.
+ */
+ private String getScopeUid(JcloudsLocation location) {
+ String scopeUid = (String) flags.get(SCOPE_UID.getName());
+ if (Strings.isEmpty(scopeUid)) {
+ scopeUid = location.config().get(SCOPE_UID);
+ }
+ return Preconditions.checkNotNull(scopeUid, "scopeUid");
+ }
+
+ // Methods to manage the configuration maps
+
+ /**
+ * Look up the {@link CountDownLatch} object for a scope.
+ *
+ * @return {@code null} if the latch has not been created yet
+ */
+ protected CountDownLatch lookupCountDownLatch(JcloudsLocation location, String scopeUid) {
+ synchronized (lock) {
+ Map<String, CountDownLatch> map = location.config().get(COUNTDOWN_LATCH_MAP);
+ return (map != null) ? map.get(scopeUid) : null;
+ }
+ }
+
+ /**
+ * Create a new {@link CountDownLatch} and optionally the {@link #COUNTDOWN_LATCH_MAP map}
+ * for a scope.
+ *
+ * @return The latch for the scope that is stored in the map.
+ */
+ protected CountDownLatch createCountDownLatch(JcloudsLocation location, String scopeUid) {
+ synchronized (lock) {
+ Map<String, CountDownLatch> map = location.config().get(COUNTDOWN_LATCH_MAP);
+ if (map == null) { map = MutableMap.of(); }
+
+ if (!map.containsKey(scopeUid)) {
+ map.put(scopeUid, new CountDownLatch(1));
+ }
+ CountDownLatch latch = map.get(scopeUid);
+ location.config().set(COUNTDOWN_LATCH_MAP, map);
+
+ return latch;
+ }
+ }
+
+ /**
+ * Remove the {@link CountDownLatch} object for a scope.
+ */
+ protected void removeCountDownLatch(JcloudsLocation location, String scopeUid) {
+ synchronized (lock) {
+ Map<String, CountDownLatch> map = location.config().get(COUNTDOWN_LATCH_MAP);
+ if (map != null) {
+ map.remove(scopeUid);
+ }
+ }
+ }
+
+ /** Return the public VLAN number for a scope. */
+ protected Integer lookupPublicVlanId(JcloudsLocation location, String scopeUid) {
+ synchronized (SoftLayerSameVlanLocationCustomizer.class) {
+ Map<String, Integer> map = location.config().get(PUBLIC_VLAN_ID_MAP);
+ if (map == null) {
+ map = MutableMap.of();
+ location.config().set(PUBLIC_VLAN_ID_MAP, map);
+ }
+ return map.get(scopeUid);
+ }
+ }
+
+ /** Save the public VLAN number for a scope. */
+ protected void savePublicVlanId(JcloudsLocation location, String scopeUid, Integer publicVlanId) {
+ synchronized (lock) {
+ Map<String, Integer> map = location.config().get(PUBLIC_VLAN_ID_MAP);
+ if (map == null) { map = MutableMap.of(); }
+
+ map.put(scopeUid, publicVlanId);
+ location.config().set(PUBLIC_VLAN_ID_MAP, map);
+ }
+ }
+
+ /** Return the private VLAN number for a scope. */
+ protected Integer lookupPrivateVlanId(JcloudsLocation location, String scopeUid) {
+ synchronized (lock) {
+ Map<String, Integer> map = location.config().get(PRIVATE_VLAN_ID_MAP);
+ if (map == null) {
+ map = MutableMap.of();
+ location.config().set(PRIVATE_VLAN_ID_MAP, map);
+ }
+ return map.get(scopeUid);
+ }
+ }
+
+ /** Save the private VLAN number for a scope. */
+ protected void savePrivateVlanId(JcloudsLocation location, String scopeUid, Integer privateVlanId) {
+ synchronized (lock) {
+ Map<String, Integer> map = location.config().get(PRIVATE_VLAN_ID_MAP);
+ if (map == null) { map = MutableMap.of(); }
+
+ map.put(scopeUid, privateVlanId);
+ location.config().set(PRIVATE_VLAN_ID_MAP, map);
+ }
+ }
+}
\ No newline at end of file
[2/5] brooklyn-server git commit: Force perist after mutating the
location configuration maps
Posted by he...@apache.org.
Force perist after mutating the location configuration maps
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/84c21a87
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/84c21a87
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/84c21a87
Branch: refs/heads/master
Commit: 84c21a8758944ff21664a0688cf4a970f7105af9
Parents: 4e04776
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Authored: Thu Mar 24 15:31:11 2016 +0000
Committer: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Committed: Thu Mar 24 20:03:12 2016 +0000
----------------------------------------------------------------------
.../SoftLayerSameVlanLocationCustomizer.java | 53 ++++++++++++--------
1 file changed, 31 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/84c21a87/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
index 4c980d8..720657c 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
@@ -325,14 +325,15 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
*/
protected CountDownLatch createCountDownLatch(JcloudsLocation location, String scopeUid) {
synchronized (lock) {
- Map<String, CountDownLatch> map = location.config().get(COUNTDOWN_LATCH_MAP);
- if (map == null) { map = MutableMap.of(); }
+ Map<String, CountDownLatch> map = MutableMap.copyOf(location.config().get(COUNTDOWN_LATCH_MAP));
if (!map.containsKey(scopeUid)) {
map.put(scopeUid, new CountDownLatch(1));
}
CountDownLatch latch = map.get(scopeUid);
- location.config().set(COUNTDOWN_LATCH_MAP, map);
+
+ location.config().set(COUNTDOWN_LATCH_MAP, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
return latch;
}
@@ -343,21 +344,25 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
*/
protected void removeCountDownLatch(JcloudsLocation location, String scopeUid) {
synchronized (lock) {
- Map<String, CountDownLatch> map = location.config().get(COUNTDOWN_LATCH_MAP);
- if (map != null) {
- map.remove(scopeUid);
- }
+ Map<String, CountDownLatch> map = MutableMap.copyOf(location.config().get(COUNTDOWN_LATCH_MAP));
+
+ map.remove(scopeUid);
+
+ location.config().set(COUNTDOWN_LATCH_MAP, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
}
}
/** Return the public VLAN number for a scope. */
protected Integer lookupPublicVlanId(JcloudsLocation location, String scopeUid) {
- synchronized (SoftLayerSameVlanLocationCustomizer.class) {
- Map<String, Integer> map = location.config().get(PUBLIC_VLAN_ID_MAP);
- if (map == null) {
- map = MutableMap.of();
- location.config().set(PUBLIC_VLAN_ID_MAP, map);
+ synchronized (lock) {
+ Map<String, Integer> map = MutableMap.copyOf(location.config().get(PUBLIC_VLAN_ID_MAP));
+
+ if (map.isEmpty()) {
+ location.config().set(PUBLIC_VLAN_ID_MAP, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
}
+
return map.get(scopeUid);
}
}
@@ -365,22 +370,25 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
/** Save the public VLAN number for a scope. */
protected void savePublicVlanId(JcloudsLocation location, String scopeUid, Integer publicVlanId) {
synchronized (lock) {
- Map<String, Integer> map = location.config().get(PUBLIC_VLAN_ID_MAP);
- if (map == null) { map = MutableMap.of(); }
+ Map<String, Integer> map = MutableMap.copyOf(location.config().get(PUBLIC_VLAN_ID_MAP));
map.put(scopeUid, publicVlanId);
- location.config().set(PUBLIC_VLAN_ID_MAP, map);
+
+ location.config().set(PUBLIC_VLAN_ID_MAP, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
}
}
/** Return the private VLAN number for a scope. */
protected Integer lookupPrivateVlanId(JcloudsLocation location, String scopeUid) {
synchronized (lock) {
- Map<String, Integer> map = location.config().get(PRIVATE_VLAN_ID_MAP);
- if (map == null) {
- map = MutableMap.of();
- location.config().set(PRIVATE_VLAN_ID_MAP, map);
+ Map<String, Integer> map = MutableMap.copyOf(location.config().get(PRIVATE_VLAN_ID_MAP));
+
+ if (map.isEmpty()) {
+ location.config().set(PRIVATE_VLAN_ID_MAP, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
}
+
return map.get(scopeUid);
}
}
@@ -388,11 +396,12 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
/** Save the private VLAN number for a scope. */
protected void savePrivateVlanId(JcloudsLocation location, String scopeUid, Integer privateVlanId) {
synchronized (lock) {
- Map<String, Integer> map = location.config().get(PRIVATE_VLAN_ID_MAP);
- if (map == null) { map = MutableMap.of(); }
+ Map<String, Integer> map = MutableMap.copyOf(location.config().get(PRIVATE_VLAN_ID_MAP));
map.put(scopeUid, privateVlanId);
- location.config().set(PRIVATE_VLAN_ID_MAP, map);
+
+ location.config().set(PRIVATE_VLAN_ID_MAP, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
}
}
}
\ No newline at end of file
[5/5] brooklyn-server git commit: reorder softlayer vlan so template
options set first, then location callback impl follows that
Posted by he...@apache.org.
reorder softlayer vlan so template options set first, then location callback impl follows that
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f66d1ad4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f66d1ad4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f66d1ad4
Branch: refs/heads/master
Commit: f66d1ad4418cdf7ec4af373f3964e6cfb180a891
Parents: cc9be55
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Mar 28 11:12:35 2016 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Mar 28 11:12:35 2016 +0100
----------------------------------------------------------------------
.../SoftLayerSameVlanLocationCustomizer.java | 218 +++++++++----------
1 file changed, 107 insertions(+), 111 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f66d1ad4/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
index 2c8eca6..d8af21a 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
@@ -126,91 +126,13 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
}
/**
- * Used to obtain the VLANs being used by the first created {@link JcloudsMachineLocation}.
- *
- * @see {@link JcloudsLocationCustomizer#customize(JcloudsLocation, ComputeService, JcloudsMachineLocation)}
- */
- @Override
- public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) {
- // Check we are customising a SoftLayer location
- String provider = location.getProvider();
- if (!(provider.equals(SoftLayerConstants.SOFTLAYER_PROVIDER_NAME))) {
- String message = String.format("Invalid location provider: %s", provider);
- LOG.warn(message);
- throw new IllegalArgumentException(message);
- }
-
- // Lookup the latch for this scope
- String scopeUid = getScopeUid(location);
- CountDownLatch latch = null;
- synchronized (lock) {
- latch = lookupCountDownLatch(location, scopeUid);
- if (latch == null) {
- throw new IllegalStateException("No latch available for scope: " + scopeUid);
- }
- }
-
- try {
- // Check if VLAN IDs have been set for this scope
- LOG.debug("Looking up saved VLAN details {}", scopeUid);
- Integer publicVlanId = lookupPublicVlanId(location, scopeUid);
- Integer privateVlanId = lookupPrivateVlanId(location, scopeUid);
- if (privateVlanId != null && publicVlanId != null) {
- LOG.warn("SoftLayer VLANs private {} and public {} already configured for location {} scope {}",
- new Object[] { privateVlanId, publicVlanId, location, scopeUid });
- saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
- // TODO if there were a failure and race this machine might have different details to what we've recorded
- return;
- }
-
- // No VLAN info yet known, we are probably the first VM and we should
- // set the VLAN info for others to then learn about.
-
- // Ask SoftLayer API for the VLAN details for this VM
- LOG.debug("Requesting VLAN details from API for scope: {}", scopeUid);
- VirtualGuestApi api = computeService.getContext().unwrapApi(SoftLayerApi.class).getVirtualGuestApi();
- Long serverId = Long.parseLong(machine.getJcloudsId());
- VirtualGuest guest = api.getVirtualGuestFiltered(serverId,
- "primaryNetworkComponent;" +
- "primaryNetworkComponent.networkVlan;" +
- "primaryBackendNetworkComponent;" +
- "primaryBackendNetworkComponent.networkVlan");
- publicVlanId = guest.getPrimaryNetworkComponent().getNetworkVlan().getId();
- privateVlanId = guest.getPrimaryBackendNetworkComponent().getNetworkVlan().getId();
-
- // Save the VLAN ids
- LOG.debug("Saving VLAN details private {} and public {} for location {} scope {}",
- new Object[] { privateVlanId, publicVlanId, location, scopeUid });
- savePublicVlanId(location, scopeUid, publicVlanId);
- savePrivateVlanId(location, scopeUid, privateVlanId);
- saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
- } finally {
- // Release the latch
- latch.countDown();
- }
- }
-
- /* Save the VLAN IDs as sensor data on the entity and set tag. */
- private void saveVlanDetails(JcloudsMachineLocation machine, String scopeUid, Integer privateVlanId, Integer publicVlanId) {
- Object context = flags.get(LocationConfigKeys.CALLER_CONTEXT.getName());
- if (context == null) {
- context = machine.config().get(LocationConfigKeys.CALLER_CONTEXT);
- }
- if (!(context instanceof Entity)) {
- throw new IllegalStateException("Invalid location context: " + context);
- }
- Entity entity = (Entity) context;
- entity.sensors().set(PUBLIC_VLAN_ID, publicVlanId);
- entity.sensors().set(PRIVATE_VLAN_ID, privateVlanId);
- entity.tags().addTag("softlayer-vlan-scopeUid-" + scopeUid);
- }
-
- /**
* Update the {@link org.jclouds.compute.options.TemplateOptions} that will
* be used by {@link JcloudsLocation} to obtain machines. Uses the VLAN
* numbers configured on an existing machine, as saved in the configuration
* maps for {@link #PUBLIC_VLAN_ID_MAP public} and {@link #PRIVATE_VLAN_ID_MAP private}
* VLAN numbers.
+ * <p>
+ * If no such numbers, this either returns (if no one else is creating) or blocks (waiting on someone else who is creating).
*
* @see {@link JcloudsLocationCustomizer#customize(JcloudsLocation, ComputeService, TemplateOptions)}
*/
@@ -242,7 +164,7 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
publicVlanId = lookupPublicVlanId(location, scopeUid);
privateVlanId = lookupPrivateVlanId(location, scopeUid);
if (publicVlanId==null && privateVlanId!=null) {
- saveVlanOptions(scopeUid, softLayerOptions, publicVlanId, privateVlanId);
+ saveVlanTemplateOptions(scopeUid, softLayerOptions, publicVlanId, privateVlanId);
return;
}
@@ -288,17 +210,98 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
throw new IllegalArgumentException(message);
}
- saveVlanOptions(scopeUid, softLayerOptions, publicVlanId, privateVlanId);
+ saveVlanTemplateOptions(scopeUid, softLayerOptions, publicVlanId, privateVlanId);
}
- private void saveVlanOptions(String scopeUid, SoftLayerTemplateOptions softLayerOptions, Integer publicVlanId, Integer privateVlanId) {
+ private void saveVlanTemplateOptions(String scopeUid, SoftLayerTemplateOptions softLayerOptions, Integer publicVlanId, Integer privateVlanId) {
LOG.debug("Setting VLAN template options private {} and public {} for scope: {}",
- new Object[] { privateVlanId, publicVlanId, scopeUid });
+ new Object[] { privateVlanId, publicVlanId, scopeUid });
softLayerOptions.primaryNetworkComponentNetworkVlanId(publicVlanId);
softLayerOptions.primaryBackendNetworkComponentNetworkVlanId(privateVlanId);
}
/**
+ * After provisioning, if it's the first created {@link JcloudsMachineLocation} then get and cache the VLAN info
+ *
+ * @see {@link JcloudsLocationCustomizer#customize(JcloudsLocation, ComputeService, JcloudsMachineLocation)}
+ */
+ @Override
+ public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) {
+ // Check we are customising a SoftLayer location
+ String provider = location.getProvider();
+ if (!(provider.equals(SoftLayerConstants.SOFTLAYER_PROVIDER_NAME))) {
+ String message = String.format("Invalid location provider: %s", provider);
+ LOG.warn(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ // Lookup the latch for this scope
+ String scopeUid = getScopeUid(location);
+ CountDownLatch latch = null;
+ synchronized (lock) {
+ latch = lookupCountDownLatch(location, scopeUid);
+ if (latch == null) {
+ throw new IllegalStateException("No latch available for scope: " + scopeUid);
+ }
+ }
+
+ try {
+ // Check if VLAN IDs have been set for this scope
+ LOG.debug("Looking up saved VLAN details {}", scopeUid);
+ Integer publicVlanId = lookupPublicVlanId(location, scopeUid);
+ Integer privateVlanId = lookupPrivateVlanId(location, scopeUid);
+ if (privateVlanId != null && publicVlanId != null) {
+ LOG.warn("SoftLayer VLANs private {} and public {} already configured for location {} scope {}",
+ new Object[] { privateVlanId, publicVlanId, location, scopeUid });
+ saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
+ // TODO if there were a failure and race this machine might have different details to what we've recorded
+ return;
+ }
+
+ // No VLAN info yet known, we are probably the first VM and we should
+ // set the VLAN info for others to then learn about.
+
+ // Ask SoftLayer API for the VLAN details for this VM
+ LOG.debug("Requesting VLAN details from API for scope: {}", scopeUid);
+ VirtualGuestApi api = computeService.getContext().unwrapApi(SoftLayerApi.class).getVirtualGuestApi();
+ Long serverId = Long.parseLong(machine.getJcloudsId());
+ VirtualGuest guest = api.getVirtualGuestFiltered(serverId,
+ "primaryNetworkComponent;" +
+ "primaryNetworkComponent.networkVlan;" +
+ "primaryBackendNetworkComponent;" +
+ "primaryBackendNetworkComponent.networkVlan");
+ publicVlanId = guest.getPrimaryNetworkComponent().getNetworkVlan().getId();
+ privateVlanId = guest.getPrimaryBackendNetworkComponent().getNetworkVlan().getId();
+
+ // Save the VLAN ids
+ LOG.debug("Saving VLAN details private {} and public {} for location {} scope {}",
+ new Object[] { privateVlanId, publicVlanId, location, scopeUid });
+ savePublicVlanId(location, scopeUid, publicVlanId);
+ savePrivateVlanId(location, scopeUid, privateVlanId);
+ saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
+ } finally {
+ // Release the latch
+ latch.countDown();
+ }
+ }
+
+ /* Save the VLAN IDs as sensor data on the entity and set tag. */
+ private void saveVlanDetails(JcloudsMachineLocation machine, String scopeUid, Integer privateVlanId, Integer publicVlanId) {
+ Object context = flags.get(LocationConfigKeys.CALLER_CONTEXT.getName());
+ if (context == null) {
+ context = machine.config().get(LocationConfigKeys.CALLER_CONTEXT);
+ }
+ if (!(context instanceof Entity)) {
+ throw new IllegalStateException("Invalid location context: " + context);
+ }
+ Entity entity = (Entity) context;
+ entity.sensors().set(PUBLIC_VLAN_ID, publicVlanId);
+ entity.sensors().set(PRIVATE_VLAN_ID, privateVlanId);
+ entity.tags().addTag("softlayer-vlan-scopeUid-" + scopeUid);
+ }
+
+
+ /**
* Get the {@link #SCOPE_TIMEOUT timeout} {@link Duration duration} from the
* location flags, or the location itself.
*/
@@ -345,16 +348,11 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
protected CountDownLatch createCountDownLatch(JcloudsLocation location, String scopeUid) {
synchronized (lock) {
Map<String, CountDownLatch> map = MutableMap.copyOf(location.config().get(COUNTDOWN_LATCH_MAP));
-
if (!map.containsKey(scopeUid)) {
map.put(scopeUid, new CountDownLatch(1));
+ saveAndPersist(location, COUNTDOWN_LATCH_MAP, map);
}
- CountDownLatch latch = map.get(scopeUid);
-
- location.config().set(COUNTDOWN_LATCH_MAP, ImmutableMap.copyOf(map));
- location.getManagementContext().getRebindManager().forcePersistNow(false, null);
-
- return latch;
+ return map.get(scopeUid);
}
}
@@ -367,21 +365,23 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
map.remove(scopeUid);
- location.config().set(COUNTDOWN_LATCH_MAP, ImmutableMap.copyOf(map));
- location.getManagementContext().getRebindManager().forcePersistNow(false, null);
+ saveAndPersist(location, COUNTDOWN_LATCH_MAP, map);
}
}
+ private <T> void saveAndPersist(JcloudsLocation location, ConfigKey<Map<String, T>> key, Map<String, T> map) {
+ location.config().set(key, ImmutableMap.copyOf(map));
+ location.getManagementContext().getRebindManager().forcePersistNow(false, null);
+ }
+
/** Return the public VLAN number for a scope. */
protected Integer lookupPublicVlanId(JcloudsLocation location, String scopeUid) {
synchronized (lock) {
- Map<String, Integer> map = MutableMap.copyOf(location.config().get(PUBLIC_VLAN_ID_MAP));
-
- if (map.isEmpty()) {
- location.config().set(PUBLIC_VLAN_ID_MAP, ImmutableMap.copyOf(map));
- location.getManagementContext().getRebindManager().forcePersistNow(false, null);
+ Map<String, Integer> map = location.config().get(PUBLIC_VLAN_ID_MAP);
+ if (map == null) {
+ map = MutableMap.copyOf(map);
+ saveAndPersist(location, PUBLIC_VLAN_ID_MAP, map);
}
-
return map.get(scopeUid);
}
}
@@ -390,24 +390,21 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
protected void savePublicVlanId(JcloudsLocation location, String scopeUid, Integer publicVlanId) {
synchronized (lock) {
Map<String, Integer> map = MutableMap.copyOf(location.config().get(PUBLIC_VLAN_ID_MAP));
-
+
map.put(scopeUid, publicVlanId);
-
- location.config().set(PUBLIC_VLAN_ID_MAP, ImmutableMap.copyOf(map));
- location.getManagementContext().getRebindManager().forcePersistNow(false, null);
+
+ saveAndPersist(location, PUBLIC_VLAN_ID_MAP, map);
}
}
/** Return the private VLAN number for a scope. */
protected Integer lookupPrivateVlanId(JcloudsLocation location, String scopeUid) {
synchronized (lock) {
- Map<String, Integer> map = MutableMap.copyOf(location.config().get(PRIVATE_VLAN_ID_MAP));
-
- if (map.isEmpty()) {
- location.config().set(PRIVATE_VLAN_ID_MAP, ImmutableMap.copyOf(map));
- location.getManagementContext().getRebindManager().forcePersistNow(false, null);
+ Map<String, Integer> map = location.config().get(PRIVATE_VLAN_ID_MAP);
+ if (map == null) {
+ map = MutableMap.copyOf(map);
+ saveAndPersist(location, PRIVATE_VLAN_ID_MAP, map);
}
-
return map.get(scopeUid);
}
}
@@ -419,8 +416,7 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
map.put(scopeUid, privateVlanId);
- location.config().set(PRIVATE_VLAN_ID_MAP, ImmutableMap.copyOf(map));
- location.getManagementContext().getRebindManager().forcePersistNow(false, null);
+ saveAndPersist(location, PRIVATE_VLAN_ID_MAP, map);
}
}
}
\ No newline at end of file
[4/5] brooklyn-server git commit: minor tidy of softlayer vlan
customizer
Posted by he...@apache.org.
minor tidy of softlayer vlan customizer
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/cc9be55e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/cc9be55e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/cc9be55e
Branch: refs/heads/master
Commit: cc9be55e2dce419539e6ab24db59dad370dc249c
Parents: 8e24512
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Mar 28 11:05:31 2016 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Mar 28 11:05:31 2016 +0100
----------------------------------------------------------------------
.../SoftLayerSameVlanLocationCustomizer.java | 47 ++++++++++++++------
1 file changed, 33 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cc9be55e/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
index 720657c..2c8eca6 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/softlayer/SoftLayerSameVlanLocationCustomizer.java
@@ -39,7 +39,6 @@ import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.jclouds.softlayer.features.VirtualGuestApi;
import org.jclouds.softlayer.reference.SoftLayerConstants;
-
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.config.ConfigKey;
@@ -85,14 +84,17 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
"The length of time to wait for a Softlayer VLAN ID",
Duration.minutes(15));
+ @SuppressWarnings("serial")
public static final ConfigKey<Map<String, CountDownLatch>> COUNTDOWN_LATCH_MAP = ConfigKeys.newConfigKey(
new TypeToken<Map<String, CountDownLatch>>() { },
"softLayerSameVlanLocationCustomizer.map.latches",
"A mapping from scope identifiers to CountDownLatches; used to synchronize threads");
+ @SuppressWarnings("serial")
public static final ConfigKey<Map<String, Integer>> PUBLIC_VLAN_ID_MAP = ConfigKeys.newConfigKey(
new TypeToken<Map<String, Integer>>() { },
"softLayerSameVlanLocationCustomizer.map.publicVlanIds",
"A mapping from scope identifiers to public VLAN numbers");
+ @SuppressWarnings("serial")
public static final ConfigKey<Map<String, Integer>> PRIVATE_VLAN_ID_MAP = ConfigKeys.newConfigKey(
new TypeToken<Map<String, Integer>>() { },
"softLayerSameVlanLocationCustomizer.map.privateVlanIds",
@@ -154,9 +156,10 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
Integer publicVlanId = lookupPublicVlanId(location, scopeUid);
Integer privateVlanId = lookupPrivateVlanId(location, scopeUid);
if (privateVlanId != null && publicVlanId != null) {
- LOG.debug("SoftLayer VLANs private {} and public {} already configured for scope: {}",
- new Object[] { privateVlanId, publicVlanId, scopeUid });
+ LOG.warn("SoftLayer VLANs private {} and public {} already configured for location {} scope {}",
+ new Object[] { privateVlanId, publicVlanId, location, scopeUid });
saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
+ // TODO if there were a failure and race this machine might have different details to what we've recorded
return;
}
@@ -176,8 +179,8 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
privateVlanId = guest.getPrimaryBackendNetworkComponent().getNetworkVlan().getId();
// Save the VLAN ids
- LOG.debug("Saving VLAN details private {} and public {} for scope: {}",
- new Object[] { privateVlanId, publicVlanId, scopeUid });
+ LOG.debug("Saving VLAN details private {} and public {} for location {} scope {}",
+ new Object[] { privateVlanId, publicVlanId, location, scopeUid });
savePublicVlanId(location, scopeUid, publicVlanId);
savePrivateVlanId(location, scopeUid, privateVlanId);
saveVlanDetails(machine, scopeUid, privateVlanId, publicVlanId);
@@ -234,27 +237,39 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
return;
}
- // Create a new latch if we are first
+ // if vlan details already available then don't even bother looking at the latch
+ LOG.debug("Looking up saved VLAN details {}", scopeUid);
+ publicVlanId = lookupPublicVlanId(location, scopeUid);
+ privateVlanId = lookupPrivateVlanId(location, scopeUid);
+ if (publicVlanId==null && privateVlanId!=null) {
+ saveVlanOptions(scopeUid, softLayerOptions, publicVlanId, privateVlanId);
+ return;
+ }
+
+ // vlan details need to be created; should we do it?
CountDownLatch latch = null;
synchronized (lock) {
latch = lookupCountDownLatch(location, scopeUid);
if (latch == null) {
- // We are first to try obtaining a VM; create a latch and return
+ // we are the first -- create a latch to block others
LOG.debug("Creating new latch for scope: {}", scopeUid);
latch = createCountDownLatch(location, scopeUid);
return;
}
}
- // Try and acquire the latch, or time out
+ // someone else is/has created. block on the latch.
Duration timeout = getTimeout(location);
Tasks.setBlockingDetails("Waiting for VLAN details");
try {
LOG.debug("Waiting for VLAN details for scope: {}", scopeUid);
if (!Uninterruptibles.awaitUninterruptibly(latch, timeout.toMilliseconds(), TimeUnit.MILLISECONDS)) {
- // Release the latch and throw an exception to prevent others blocking forever
+ // timeout -- release the latch to trigger others to unblock;
+ // remove the recorded latch so the next fresh attempt will try to create again;
+ // and throw because this location is not able to be provisioned with right vlan info
latch.countDown();
- throw new IllegalStateException("Timeout acquiring latch for scope: " + scopeUid);
+ removeCountDownLatch(location, scopeUid);
+ throw new IllegalStateException("Timeout waiting on VLAN info in " + location + " for scope: " + scopeUid);
}
} finally {
Tasks.resetBlockingDetails();
@@ -265,14 +280,18 @@ public class SoftLayerSameVlanLocationCustomizer extends BasicJcloudsLocationCus
publicVlanId = lookupPublicVlanId(location, scopeUid);
privateVlanId = lookupPrivateVlanId(location, scopeUid);
if (privateVlanId == null && publicVlanId == null) {
- // Saved VLAN IDs not found; something went wrong so remove the latch to try again
- removeCountDownLatch(location, scopeUid);
- String message = String.format("Saved VLAN configuration not found for scope: %s", scopeUid);
+ // Saved VLAN IDs not found; something went wrong!
+ // throw because this location is not able to be provisioned with right vlan info
+ // NB: if either public or private is set, we will live with that (not sure if that happens and if so what it would mean...)
+ String message = String.format("Saved VLAN configuration not available for location %s scope %s", location, scopeUid);
LOG.warn(message);
throw new IllegalArgumentException(message);
}
- // Setting VLAN template options
+ saveVlanOptions(scopeUid, softLayerOptions, publicVlanId, privateVlanId);
+ }
+
+ private void saveVlanOptions(String scopeUid, SoftLayerTemplateOptions softLayerOptions, Integer publicVlanId, Integer privateVlanId) {
LOG.debug("Setting VLAN template options private {} and public {} for scope: {}",
new Object[] { privateVlanId, publicVlanId, scopeUid });
softLayerOptions.primaryNetworkComponentNetworkVlanId(publicVlanId);
[3/5] brooklyn-server git commit: This closes #53
Posted by he...@apache.org.
This closes #53
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/8e24512f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/8e24512f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/8e24512f
Branch: refs/heads/master
Commit: 8e24512f1bd31172715cdbbbd8412c433f254f3c
Parents: 52e0c4e 84c21a8
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Mar 28 10:27:18 2016 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Mon Mar 28 10:27:18 2016 +0100
----------------------------------------------------------------------
.../SoftLayerSameVlanLocationCustomizer.java | 407 +++++++++++++++++++
1 file changed, 407 insertions(+)
----------------------------------------------------------------------