Delete deprecated MachinePool and BrooklynMachinePool
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/7d072fde Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/7d072fde Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/7d072fde Branch: refs/heads/master Commit: 7d072fded80e796a6afe9820bf821e4dce1dd976 Parents: b132249 Author: Aled Sage <[email protected]> Authored: Wed Aug 19 18:49:07 2015 +0100 Committer: Aled Sage <[email protected]> Committed: Thu Aug 20 12:04:13 2015 +0100 ---------------------------------------------------------------------- .../location/jclouds/BrooklynMachinePool.java | 218 ---------- .../location/jclouds/pool/MachinePool.java | 395 ------------------- .../jclouds/BrooklynMachinePoolLiveTest.java | 102 ----- .../pool/JcloudsMachinePoolLiveTest.java | 120 ------ 4 files changed, 835 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d072fde/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java deleted file mode 100644 index 3b53139..0000000 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePool.java +++ /dev/null @@ -1,218 +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.location.jclouds; - -import static org.apache.brooklyn.location.jclouds.pool.MachinePoolPredicates.matching; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.location.MachineLocation; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.core.entity.trait.Startable; -import org.jclouds.compute.domain.NodeMetadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.brooklyn.location.jclouds.pool.MachinePool; -import org.apache.brooklyn.location.jclouds.pool.MachineSet; -import org.apache.brooklyn.location.jclouds.pool.ReusableMachineTemplate; -import org.apache.brooklyn.location.ssh.SshMachineLocation; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.task.BasicExecutionContext; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; - -/** - * @deprecated since 0.6.0; never used in production setting, and thus of dubious value; best avoided as unlikely to be supported in future versions - */ -@Deprecated -public class BrooklynMachinePool extends MachinePool { - - private static final Logger log = LoggerFactory.getLogger(BrooklynMachinePool.class); - - protected final JcloudsLocation location; - final List<Task<?>> activeTasks = new ArrayList<Task<?>>(); - final String providerLocationId; - - public BrooklynMachinePool(JcloudsLocation l) { - super(l.getComputeService()); - providerLocationId = l.getRegion(); - this.location = l; - } - - /** claims a machine with the indicated spec, creating if necessary */ - public SshMachineLocation obtain(ReusableMachineTemplate t) { - MachineSet previous = unclaimed(matching(t)); - - while (true) { - NodeMetadata m = claim(1, t).iterator().next(); - // TODO ideally shouldn't have to rebind - SshMachineLocation result = null; - try { - result = toSshMachineLocation( m ); - } catch (Exception e) { - if (previous.contains(m)) { - log.debug("attempt to bind to previous existing machine "+m+" failed (will blacklist and retry another): "+e); - } else { - log.warn("attempt to bind to machine "+m+" failed: "+e); - throw Throwables.propagate(e); - } - } - if (result!=null) return result; - if (previous.contains(m)) { - log.debug("could not bind to previous existing machine "+m+"; blacklisting and trying a new one"); - addToBlacklist(new MachineSet(m)); - } else { - throw new IllegalStateException("cannot bind/connect to newly created machine; error in configuration"); - } - } - } - - protected MachineSet filterForAllowedMachines(MachineSet input) { - MachineSet result = super.filterForAllowedMachines(input); - if (providerLocationId!=null) { - result = result.filtered(matching( new ReusableMachineTemplate().locationId(providerLocationId).strict(false) )); - } - return result; - } - - /** returns an SshMachineLocation, if one can be created and accessed; returns null if it cannot be created */ - protected SshMachineLocation toSshMachineLocation(NodeMetadata m) { - try { - JcloudsSshMachineLocation sshM = location.rebindMachine(m); - if (sshM.execCommands("check-reachable", Arrays.asList("whoami")) != 0) { - log.warn("cannot bind to machine "+m); - return null; - } - return sshM; - } catch (Exception e) { - throw Throwables.propagate(e); - } - } - - @Override - public MachineSet create(int count, ReusableMachineTemplate template) { - List<NodeMetadata> nodes = new ArrayList<NodeMetadata>(); - for (int i=0; i<count; i++) { - // TODO this in parallel - JcloudsSshMachineLocation m; - try { - MachineLocation machineLocation = location.obtain(MutableMap.of("callerContext", ""+this+"("+template+")"), template); - // Class has been deprecated since 0.6.0, and prior to that, obtain would have returned a JcloudsSshMachineLocation - if (machineLocation instanceof JcloudsSshMachineLocation) { - m = (JcloudsSshMachineLocation) machineLocation; - } else { - throw new UnsupportedOperationException("Cannot create WinRmMachineLocation"); - } - } catch (Exception e) { - throw Throwables.propagate(e); - } - nodes.add(m.getNode()); - } - MachineSet result = new MachineSet(nodes); - registerNewNodes(result, template); - return result; - } - - public boolean unclaim(SshMachineLocation location) { - init(); - if (location instanceof JcloudsSshMachineLocation) - return unclaim(new MachineSet( ((JcloudsSshMachineLocation)location).getNode()) ) > 0; - return false; - } - public boolean destroy(SshMachineLocation location) { - init(); - if (location instanceof JcloudsSshMachineLocation) - return destroy(new MachineSet( ((JcloudsSshMachineLocation)location).getNode()) ) > 0; - return false; - } - - // TODO we need to remove stale tasks somewhere - protected <T> Task<T> addTask(Task<T> t) { - synchronized (activeTasks) { activeTasks.add(t); } - return t; - } - - public List<Task<?>> getActiveTasks() { - List<Task<?>> result; - synchronized (activeTasks) { result = ImmutableList.<Task<?>>copyOf(activeTasks); } - return result; - } - - public void blockUntilTasksEnded() { - while (true) { - boolean allDone = true; - List<Task<?>> tt = getActiveTasks(); - for (Task<?> t: tt) { - if (!t.isDone()) { - allDone = false; - if (log.isDebugEnabled()) log.debug("Pool "+this+", blocking for completion of: "+t); - t.blockUntilEnded(); - } - } - synchronized (activeTasks) { - List<Task> newTT = new ArrayList<Task>(getActiveTasks()); - newTT.removeAll(tt); - if (allDone && tt.isEmpty()) { - //task list has stabilized, and there are no active tasks; clear and exit - if (log.isDebugEnabled()) log.debug("Pool "+this+", all known tasks have completed, clearing list"); - activeTasks.clear(); - break; - } - if (log.isDebugEnabled()) log.debug("Pool "+this+", all previously known tasks have completed, but there are new tasks ("+newTT+") checking them"); - } - } - } - - /** starts the given template; for use only within a task (e.g. application's start effector). - * returns a child task of the current task. - * <p> - * throws exception if not in a task. (you will have to claim, then invoke the effectors manually.) */ - public Task<?> start(final ReusableMachineTemplate template, final List<? extends Startable> entities) { - BasicExecutionContext ctx = BasicExecutionContext.getCurrentExecutionContext(); - if (ctx==null) throw new IllegalStateException("Pool.start is only permitted within a task (effector)"); - final AtomicReference<Task<?>> t = new AtomicReference<Task<?>>(); - synchronized (t) { - t.set(ctx.submit(new Runnable() { - public void run() { - synchronized (t) { - if (log.isDebugEnabled()) log.debug("Pool "+this+", task "+t.get()+" claiming a "+template); - SshMachineLocation m = obtain(template); - if (log.isDebugEnabled()) log.debug("Pool "+this+", task "+t.get()+" got "+m+"; starting "+entities); - for (Startable entity: entities) - addTask( ((Entity)entity).invoke(Startable.START, MutableMap.of("locations", Arrays.asList(m))) ); - } - } - })); - } - addTask(t.get()); - return t.get(); - } - - /** @see #start(ReusableMachineTemplate, List) */ - public Task<?> start(ReusableMachineTemplate template, Startable ...entities) { - return start(template, Arrays.asList(entities)); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d072fde/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/pool/MachinePool.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/pool/MachinePool.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/pool/MachinePool.java deleted file mode 100644 index 79a3dc8..0000000 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/pool/MachinePool.java +++ /dev/null @@ -1,395 +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.location.jclouds.pool; - -import static org.apache.brooklyn.location.jclouds.pool.MachinePoolPredicates.compose; -import static org.apache.brooklyn.location.jclouds.pool.MachinePoolPredicates.matching; - -import java.util.ArrayList; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.RunNodesException; -import org.jclouds.compute.domain.ComputeMetadata; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Template; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Predicate; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -/** - * Contains details of machines detected at a given cloud (ComputeService), - * and records claims made against those machines via this pool. - * <p> - * Machine instances themselves are persisted and rescanned as new instances of this class are created. - * Claims however are specific to this instance of the class, i.e. <b>not</b> persisted. - * <p> - * This class is believed to be thread-safe. - * Refreshes to the remote detected machines are synchronized on the pool instance. - * Details of detected and claimed machines are also synchronized on the pool instance. - * (If it is necessary to claim machines whilst the pool is being rescanned, - * we can investigate a more sophisticated threading model. - * Access to some fields is clearly independent and uses a tighter synchonization - * strategy, e.g. templates. - * Synchronization of fields within a synch block on the class instance - * is permitted, but not the other way round, - * and synching on multiple fields is also not permitted.) - * <p> - * Callers wishing to guarantee results of e.g. ensureUnclaimed remaining available - * can synchronize on this class for the duration that they wish to have that guarantee - * (at the cost, of course, of any other threads being able to access this pool). - * <p> - * If underlying provisioning/destroying operations fail, the pool - * currently may be in an unknown state, currently. - * If more robustness is needed this can be added. - * - * @deprecated since 0.6.0; never used in production setting, and thus of dubious value; best avoided as unlikely to be supported in future versions - */ -@Deprecated -public class MachinePool { - - private static final Logger log = LoggerFactory.getLogger(MachinePool.class); - - protected final ComputeService computeService; - final AtomicBoolean refreshNeeded = new AtomicBoolean(true); - final List<ReusableMachineTemplate> templates = new ArrayList<ReusableMachineTemplate>(); - String poolName = null; - - /** all machines detected, less those in the black list */ - volatile MachineSet detectedMachines = new MachineSet(); - volatile MachineSet matchedMachines = new MachineSet(); - volatile MachineSet claimedMachines = new MachineSet(); - volatile MachineSet blacklistedMachines = new MachineSet(); - - public MachinePool(ComputeService computeService) { - this.computeService = computeService; - } - - protected synchronized void init() { - if (!refreshNeeded.get()) return; - refresh(); - } - - public void setPoolName(String poolName) { - if (poolName!=null) - log.warn("Changing pool name of "+this+" (from "+this.poolName+" to "+poolName+") is discouraged."); - this.poolName = poolName; - } - /** pool name is used as a group/label by jclouds, for convenience only; - * it has no special properties for detecting matching instances - * (use explicit tags on the templates, for that). - * defaults to name of pool class and user name. - * callers should set pool name before getting, if using a custom name. */ - public synchronized String getPoolName() { - if (poolName==null) - poolName = getClass().getSimpleName()+"-"+System.getProperty("user.name"); - return poolName; - } - - /** refreshes the pool of machines from the server (finding all instances matching the registered templates) */ - public synchronized void refresh() { - refreshNeeded.set(false); - Set<? extends ComputeMetadata> computes = computeService.listNodes(); - Set<NodeMetadata> nodes = new LinkedHashSet<NodeMetadata>(); - for (ComputeMetadata c: computes) { - if (c instanceof NodeMetadata) { - nodes.add((NodeMetadata)c); - } else { - // TODO should we try to fetch more info? - log.warn("MachinePool "+this+" ignoring non-Node record for remote machine: "+c); - } - } - - MachineSet allNewDetectedMachines = new MachineSet(nodes); - MachineSet newDetectedMachines = filterForAllowedMachines(allNewDetectedMachines); - MachineSet oldDetectedMachines = detectedMachines; - MachineSet newMatchedMachines = new MachineSet(); - detectedMachines = newDetectedMachines; - - MachineSet appearedMachinesIncludingBlacklist = allNewDetectedMachines.removed(oldDetectedMachines); - MachineSet appearedMachines = filterForAllowedMachines(appearedMachinesIncludingBlacklist); - if (appearedMachinesIncludingBlacklist.size()>appearedMachines.size()) - if (log.isDebugEnabled()) log.debug("Pool "+this+", ignoring "+(appearedMachinesIncludingBlacklist.size()-appearedMachines.size())+" disallowed"); - int matchedAppeared = 0; - for (NodeMetadata m: appearedMachines) { - if (m.getStatus() != NodeMetadata.Status.RUNNING) { - if (log.isDebugEnabled()) - log.debug("Pool "+this+", newly detected machine "+m+", not running ("+m.getStatus()+")"); - } else { - Set<ReusableMachineTemplate> ts = getTemplatesMatchingInstance(m); - if (!ts.isEmpty()) { - matchedAppeared++; - newMatchedMachines = newMatchedMachines.added(new MachineSet(m)); - if (log.isDebugEnabled()) - log.debug("Pool "+this+", newly detected machine "+m+", matches pool templates "+ts); - } else { - if (log.isDebugEnabled()) - log.debug("Pool "+this+", newly detected machine "+m+", does not match any pool templates"); - } - } - } - if (matchedAppeared>0) { - log.info("Pool "+this+" discovered "+matchedAppeared+" matching machines (of "+appearedMachines.size()+" total new; "+newDetectedMachines.size()+" total including claimed and unmatched)"); - } else { - if (log.isDebugEnabled()) - log.debug("Pool "+this+" discovered "+matchedAppeared+" matching machines (of "+appearedMachines.size()+" total new; "+newDetectedMachines.size()+" total including claimed and unmatched)"); - } - matchedMachines = newMatchedMachines; - } - - protected MachineSet filterForAllowedMachines(MachineSet input) { - return input.removed(blacklistedMachines); - } - - // TODO template registry and claiming from a template could be a separate responsibility - - protected ReusableMachineTemplate registerTemplate(ReusableMachineTemplate template) { - registerTemplates(template); - return template; - } - protected void registerTemplates(ReusableMachineTemplate ...templatesToReg) { - synchronized (templates) { - for (ReusableMachineTemplate template: templatesToReg) - templates.add(template); - } - } - - protected ReusableMachineTemplate newTemplate(String name) { - return registerTemplate(new ReusableMachineTemplate(name)); - } - - - public List<ReusableMachineTemplate> getTemplates() { - List<ReusableMachineTemplate> result; - synchronized (templates) { result = ImmutableList.copyOf(templates); } - return result; - } - - /** all machines matching any templates */ - public MachineSet all() { - init(); - return matchedMachines; - } - - /** machines matching any templates which have not been claimed */ - public MachineSet unclaimed() { - init(); - synchronized (this) { - return matchedMachines.removed(claimedMachines); - } - } - - /** returns all machines matching the given criteria (may be claimed) */ - @SuppressWarnings("unchecked") - public MachineSet all(Predicate<NodeMetadata> criterion) { - // To avoid generics complaints in callers caused by varargs, overload here - return all(new Predicate[] {criterion}); - } - - /** returns all machines matching the given criteria (may be claimed) */ - public MachineSet all(Predicate<NodeMetadata> ...ops) { - return new MachineSet(Iterables.filter(all(), compose(ops))); - } - - /** returns unclaimed machines matching the given criteria */ - @SuppressWarnings("unchecked") - public MachineSet unclaimed(Predicate<NodeMetadata> criterion) { - // To avoid generics complaints in callers caused by varargs, overload here - return unclaimed(new Predicate[] {criterion}); - } - - /** returns unclaimed machines matching the given criteria */ - public MachineSet unclaimed(Predicate<NodeMetadata> ...criteria) { - return new MachineSet(Iterables.filter(unclaimed(), compose(criteria))); - } - - /** creates machines if necessary so that this spec exists (may already be claimed however) - * returns a set of all matching machines, guaranteed non-empty - * (but possibly some are already claimed) */ - public MachineSet ensureExists(ReusableMachineTemplate template) { - return ensureExists(1, template); - } - - public synchronized void addToBlacklist(MachineSet newToBlacklist) { - setBlacklist(blacklistedMachines.added(newToBlacklist)); - } - - /** replaces the blacklist set; callers should generally perform a refresh() - * afterwards, to trigger re-detection of blacklisted machines - */ - public synchronized void setBlacklist(MachineSet newBlacklist) { - blacklistedMachines = newBlacklist; - detectedMachines = detectedMachines.removed(blacklistedMachines); - matchedMachines = matchedMachines.removed(blacklistedMachines); - } - - /** creates machines if necessary so that this spec exists (may already be claimed however); - * returns a set of all matching machines, of size at least count (but possibly some are already claimed). - * (the pool can change at any point, so this set is a best-effort but may be out of date. - * see javadoc comments on this class.) */ - public MachineSet ensureExists(int count, ReusableMachineTemplate template) { - MachineSet current; - current = all(matching(template)); - if (current.size() >= count) - return current; - //have to create more - MachineSet moreNeeded = create(count-current.size(), template); - return current.added(moreNeeded); - } - - /** creates machines if necessary so that this spec can subsequently be claimed; - * returns all such unclaimed machines, guaranteed to be non-empty. - * (the pool can change at any point, so this set is a best-effort but may be out of date. - * see javadoc comments on this class.) */ - public MachineSet ensureUnclaimed(ReusableMachineTemplate template) { - return ensureUnclaimed(1, template); - } - - /** creates machines if necessary so that this spec can subsequently be claimed; - * returns a set of at least count unclaimed machines */ - public MachineSet ensureUnclaimed(int count, ReusableMachineTemplate template) { - MachineSet current; - current = unclaimed(matching(template)); - if (current.size() >= count) - return current; - //have to create more - MachineSet moreNeeded = create(count-current.size(), template); - return current.added(moreNeeded); - } - - public Set<ReusableMachineTemplate> getTemplatesMatchingInstance(NodeMetadata nm) { - Set<ReusableMachineTemplate> result = new LinkedHashSet<ReusableMachineTemplate>(); - for (ReusableMachineTemplate t: getTemplates()) { - if (matching(t).apply(nm)) { - result.add(t); - } - } - return result; - } - - /** creates the given number of machines of the indicated template */ - public MachineSet create(int count, ReusableMachineTemplate template) { - Set<? extends NodeMetadata> nodes; - try { - Template t = template.newJcloudsTemplate(computeService); - if (log.isDebugEnabled()) log.debug("Creating "+count+" new instances of "+t); - nodes = computeService.createNodesInGroup(getPoolName(), count, t); - } catch (RunNodesException e) { - throw Throwables.propagate(e); - } - MachineSet result = new MachineSet(nodes); - registerNewNodes(result, template); - return result; - } - protected void registerNewNodes(MachineSet result, ReusableMachineTemplate template) { - for (NodeMetadata m: result) { - Set<ReusableMachineTemplate> ts = getTemplatesMatchingInstance(m); - if (ts.isEmpty()) { - log.error("Pool "+this+", created machine "+m+" from template "+template+", but no pool templates match!"); - } else { - if (log.isDebugEnabled()) - log.debug("Pool "+this+", created machine "+m+" from template "+template+", matching templates "+ts); - } - } - synchronized (this) { - detectedMachines = detectedMachines.added(result); - matchedMachines = matchedMachines.added(result); - } - } - - /** claims the indicated number of machines with the indicated spec, creating if necessary */ - public MachineSet claim(int count, ReusableMachineTemplate t) { - init(); - Set<NodeMetadata> claiming = new LinkedHashSet<NodeMetadata>(); - while (claiming.size() < count) { - MachineSet mm = ensureUnclaimed(count - claiming.size(), t); - for (NodeMetadata m : mm) { - synchronized (this) { - if (claiming.size() < count && !claimedMachines.contains(m)) { - claiming.add(m); - claimedMachines = claimedMachines.added(new MachineSet(m)); - } - } - } - } - MachineSet result = new MachineSet(claiming); - return result; - } - - - /** claims the indicated set of machines; - * throws exception if cannot all be claimed; - * returns the set passed in if successful */ - public MachineSet claim(MachineSet set) { - init(); - synchronized (this) { - MachineSet originalClaimed = claimedMachines; - claimedMachines = claimedMachines.added(set); - MachineSet newlyClaimed = claimedMachines.removed(originalClaimed); - if (newlyClaimed.size() != set.size()) { - //did not claim all; unclaim and fail - claimedMachines = originalClaimed; - MachineSet unavailable = set.removed(newlyClaimed); - throw new IllegalArgumentException("Could not claim all requested machines; failed to claim "+unavailable); - } - return newlyClaimed; - } - } - - public int unclaim(MachineSet set) { - init(); - synchronized (this) { - MachineSet originalClaimed = claimedMachines; - claimedMachines = claimedMachines.removed(set); - return originalClaimed.size() - claimedMachines.size(); - } - } - - - public int destroy(final MachineSet set) { - init(); - synchronized (this) { - detectedMachines = detectedMachines.removed(set); - matchedMachines = matchedMachines.removed(set); - claimedMachines = claimedMachines.removed(set); - } - Set<? extends NodeMetadata> destroyed = computeService.destroyNodesMatching(new Predicate<NodeMetadata>() { - @Override - public boolean apply(NodeMetadata input) { - return set.contains(input); - } - }); - synchronized (this) { - //in case a rescan happened while we were destroying - detectedMachines = detectedMachines.removed(set); - matchedMachines = matchedMachines.removed(set); - claimedMachines = claimedMachines.removed(set); - } - return destroyed.size(); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d072fde/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java deleted file mode 100644 index 2f6afcb..0000000 --- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java +++ /dev/null @@ -1,102 +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.location.jclouds; - -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.location.jclouds.pool.MachineSet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.apache.brooklyn.location.jclouds.pool.MachinePoolPredicates; -import org.apache.brooklyn.location.jclouds.pool.ReusableMachineTemplate; -import org.apache.brooklyn.location.ssh.SshMachineLocation; - -public class BrooklynMachinePoolLiveTest { - - public static final Logger log = LoggerFactory.getLogger(BrooklynMachinePoolLiveTest.class); - - public static class SamplePool extends BrooklynMachinePool { - public SamplePool(JcloudsLocation l) { - super(l); - } - - public final static ReusableMachineTemplate - USUAL_VM = - new ReusableMachineTemplate("usual").templateOwnedByMe(). - tagOptional("tagForUsualVm"). - metadataOptional("metadataForUsualVm", "12345"). - minRam(1024).minCores(2); - - public final static ReusableMachineTemplate - ANYONE_NOT_TINY_VM = - new ReusableMachineTemplate("anyone"). - minRam(512).minCores(1).strict(false); - - public static final ReusableMachineTemplate - VM_LARGE1 = - new ReusableMachineTemplate("vm.large1").templateOwnedByMe(). - minRam(16384).minCores(4), - VM_SMALL1 = - new ReusableMachineTemplate("vm.small1").templateOwnedByMe().smallest(); - - { registerTemplates(USUAL_VM, ANYONE_NOT_TINY_VM, VM_LARGE1, VM_SMALL1); } - } - - - private LocalManagementContext managementContext; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - managementContext = new LocalManagementContext(); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (managementContext != null) managementContext.terminate(); - } - - @Test(groups="Live") - public void buildClaimAndDestroy() { - SamplePool p = new SamplePool(resolve("aws-ec2:us-west-1")); - log.info("buildClaimAndDestroy: created pool"); - p.refresh(); - log.info("buildClaimAndDestroy: refreshed pool"); - p.ensureExists(2, SamplePool.USUAL_VM); - log.info("buildClaimAndDestroy: ensure have 2"); - SshMachineLocation l = p.obtain(SamplePool.USUAL_VM); - Assert.assertNotNull(l); - log.info("buildClaimAndDestroy: claimed 1"); - MachineSet unclaimedUsual = p.unclaimed(MachinePoolPredicates.matching(SamplePool.USUAL_VM)); - log.info("buildClaimAndDestroy: unclaimed now "+unclaimedUsual); - Assert.assertTrue(!unclaimedUsual.isEmpty(), "should have been unclaimed machines (can fail if there are some we cannot connect to, ie blacklisted)"); - p.destroy(unclaimedUsual); - p.destroy(l); - unclaimedUsual = p.unclaimed(MachinePoolPredicates.matching(SamplePool.USUAL_VM)); - log.info("buildClaimAndDestroy: destroyed, unclaimed now "+unclaimedUsual); - log.info("end"); - } - - - private JcloudsLocation resolve(String spec) { - return (JcloudsLocation) managementContext.getLocationRegistry().resolve(new JcloudsLocationResolver().getPrefix() + ":" + spec); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d072fde/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java deleted file mode 100644 index 4d30c80..0000000 --- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/pool/JcloudsMachinePoolLiveTest.java +++ /dev/null @@ -1,120 +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.location.jclouds.pool; - -import java.util.Arrays; - -import org.apache.brooklyn.location.jclouds.AbstractJcloudsLiveTest; -import org.jclouds.ContextBuilder; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import org.apache.brooklyn.location.jclouds.JcloudsLocation; - -public class JcloudsMachinePoolLiveTest extends AbstractJcloudsLiveTest { - - public static final Logger log = LoggerFactory.getLogger(JcloudsMachinePoolLiveTest.class); - - private static final String PROVIDER = AWS_EC2_PROVIDER; - private static final String LOCATION_SPEC = PROVIDER + ":" + AWS_EC2_EUWEST_REGION_NAME; - - public static class SamplePool extends MachinePool { - public SamplePool(ComputeService svc) { - super(svc); - } - - public final static ReusableMachineTemplate - USUAL_VM = - new ReusableMachineTemplate("usual").templateOwnedByMe(). - tagOptional("tagForUsualVm"). - metadataOptional("metadataForUsualVm", "12345"). - minRam(1024).minCores(2); - - public final static ReusableMachineTemplate - ANYONE_NOT_TINY_VM = - new ReusableMachineTemplate("anyone"). - minRam(512).minCores(1).strict(false); - - public static final ReusableMachineTemplate - VM_LARGE1 = - new ReusableMachineTemplate("vm.large1").templateOwnedByMe(). - minRam(16384).minCores(4), - VM_SMALL1 = - new ReusableMachineTemplate("vm.small1").templateOwnedByMe().smallest(); - - { registerTemplates(USUAL_VM, ANYONE_NOT_TINY_VM, VM_LARGE1, VM_SMALL1); } - } - - private ComputeServiceContext context; - - @BeforeMethod(alwaysRun=true) - @Override - public void setUp() throws Exception { - super.setUp(); - - jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(LOCATION_SPEC); - - context = ContextBuilder.newBuilder(PROVIDER) - .modules(Arrays.asList(new SshjSshClientModule(), new SLF4JLoggingModule())) - .credentials(jcloudsLocation.getIdentity(), jcloudsLocation.getCredential()) - .build(ComputeServiceContext.class); - } - - @AfterMethod(alwaysRun=true) - @Override - public void tearDown() throws Exception { - try { - super.tearDown(); - } finally { - if (context != null) context.close(); - } - } - - @Test(groups={"Live","WIP"}) - public void buildClaimAndDestroy() { - ComputeService svc = context.getComputeService(); - SamplePool p = new SamplePool(svc); - log.info("buildClaimAndDestroy: created pool"); - p.refresh(); - log.info("buildClaimAndDestroy: refreshed pool"); - p.ensureExists(2, SamplePool.USUAL_VM); - log.info("buildClaimAndDestroy: ensure have 2"); - MachineSet l = p.claim(1, SamplePool.USUAL_VM); - Assert.assertEquals(l.size(), 1); - log.info("buildClaimAndDestroy: claimed 1"); - MachineSet unclaimedUsual = p.unclaimed(MachinePoolPredicates.matching(SamplePool.USUAL_VM)); - log.info("buildClaimAndDestroy: unclaimed now "+unclaimedUsual); - Assert.assertTrue(!unclaimedUsual.isEmpty()); - p.destroy(unclaimedUsual); - unclaimedUsual = p.unclaimed(MachinePoolPredicates.matching(SamplePool.USUAL_VM)); - log.info("buildClaimAndDestroy: destroyed, unclaimed now "+unclaimedUsual); - log.info("end"); - } - - - -}
