Repository: brooklyn-server Updated Branches: refs/heads/master c68cbaffe -> ce453ca1d
BROOKLYN-554: fix jclouds loc upgrade+rebind Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/98101fb6 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/98101fb6 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/98101fb6 Branch: refs/heads/master Commit: 98101fb6cb7ff25d630047504277c14580c6ca66 Parents: c68cbaf Author: Aled Sage <[email protected]> Authored: Fri Nov 10 13:19:31 2017 +0000 Committer: Aled Sage <[email protected]> Committed: Fri Nov 10 13:21:17 2017 +0000 ---------------------------------------------------------------------- .../location/jclouds/JcloudsLocation.java | 24 +++++ .../jclouds/JcloudsRebindStubUnitTest.java | 25 +++++ ...ted-no-semaphores-stubbed-machine-l27nwbyisk | 101 +++++++++++++++++++ ...sted-no-semaphores-stubbed-parent-afy79330h5 | 95 +++++++++++++++++ 4 files changed, 245 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/98101fb6/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java index 80e289a..06bcd4d 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java @@ -271,6 +271,30 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im } @Override + public void rebind() { + super.rebind(); + + // Fix for https://issues.apache.org/jira/browse/BROOKLYN-554: + // Historic persisted state will not have done the init checks to ensure these are non-null. + if (getConfig(MACHINE_CREATION_SEMAPHORE) == null) { + Integer maxConcurrent = getConfig(MAX_CONCURRENT_MACHINE_CREATIONS); + if (maxConcurrent == null || maxConcurrent < 1) { + LOG.warn(MAX_CONCURRENT_MACHINE_CREATIONS.getName()+" must be >= 1, but was "+maxConcurrent+", overwriting with "+Integer.MAX_VALUE); + maxConcurrent = Integer.MAX_VALUE; + } + config().set(MACHINE_CREATION_SEMAPHORE, new Semaphore(maxConcurrent, true)); + } + + if (getConfig(MACHINE_DELETION_SEMAPHORE) == null) { + Integer maxConcurrent = getConfig(MAX_CONCURRENT_MACHINE_DELETIONS); + if (maxConcurrent == null || maxConcurrent < 1) { + LOG.warn(MAX_CONCURRENT_MACHINE_DELETIONS.getName()+" must be >= 1, but was "+maxConcurrent+", overwriting with "+Integer.MAX_VALUE); + } + config().set(MACHINE_DELETION_SEMAPHORE, new Semaphore(maxConcurrent, true)); + } + } + + @Override public JcloudsLocation newSubLocation(Map<?,?> newFlags) { return newSubLocation(getClass(), newFlags); } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/98101fb6/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java index 5201932..c5cdba3 100644 --- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java +++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRebindStubUnitTest.java @@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; +import java.io.File; import java.util.List; import java.util.Map; @@ -34,9 +35,11 @@ import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.BasicN import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.NodeCreator; import org.apache.brooklyn.location.ssh.SshMachineLocation; import org.apache.brooklyn.location.winrm.WinRmMachineLocation; +import org.apache.brooklyn.util.core.ResourceUtils; import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool; import org.apache.brooklyn.util.core.internal.winrm.RecordingWinRmTool; import org.apache.brooklyn.util.exceptions.CompoundRuntimeException; +import org.apache.commons.io.FileUtils; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; import org.slf4j.Logger; @@ -174,6 +177,28 @@ public class JcloudsRebindStubUnitTest extends RebindTestFixtureWithApp { assertFalse(newTemplate.isPresent(), "newTemplate="+newTemplate); assertEquals(newJcloudsLoc.getProvider(), origJcloudsLoc.getProvider()); + + // Release the machine + newJcloudsLoc.release(newMachine); + } + + // See https://issues.apache.org/jira/browse/BROOKLYN-554, and fix in JcloudsLocation.rebind() + @Test + public void testHistoricLocationWithoutSemaphoresStops() throws Exception { + ResourceUtils resourceUtils = ResourceUtils.create(this); + FileUtils.write( + new File(mementoDir, "locations/afy79330h5"), + resourceUtils.getResourceAsString("classpath://org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-parent-afy79330h5")); + FileUtils.write( + new File(mementoDir, "locations/l27nwbyisk"), + resourceUtils.getResourceAsString("classpath://org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-machine-l27nwbyisk")); + + rebind(); + + JcloudsLocation jcloudsLoc = (JcloudsLocation) mgmt().getLocationManager().getLocation("afy79330h5"); + JcloudsSshMachineLocation machine = (JcloudsSshMachineLocation) mgmt().getLocationManager().getLocation("l27nwbyisk"); + + jcloudsLoc.release(machine); } protected JcloudsMachineLocation obtainMachine(JcloudsLocation jcloudsLoc, Map<?,?> props) throws Exception { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/98101fb6/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-machine-l27nwbyisk ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-machine-l27nwbyisk b/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-machine-l27nwbyisk new file mode 100644 index 0000000..b8f9c3f --- /dev/null +++ b/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-machine-l27nwbyisk @@ -0,0 +1,101 @@ +<!-- + 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. +--> + +<location> + <brooklynVersion>1.0.0-SNAPSHOT</brooklynVersion> + <type>org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation</type> + <id>l27nwbyisk</id> + <displayName>173.194.32.1</displayName> + <searchPath class="ImmutableList"/> + <parent>afy79330h5</parent> + <locationConfig> + <sshToolClass>org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool</sshToolClass> + <spec.original>jclouds:aws-ec2:us-east-1</spec.original> + <spec.named.name>jclouds:aws-ec2:us-east-1</spec.named.name> + <spec.final>jclouds:aws-ec2:us-east-1</spec.final> + <displayName>173.194.32.1</displayName> + <address> + <java.net.Inet4Address>173.194.32.1/173.194.32.1</java.net.Inet4Address> + </address> + <user>aledsage</user> + <password> + <null/> + </password> + <jcloudsParent> + <locationProxy>afy79330h5</locationProxy> + </jcloudsParent> + <brooklyn.ssh.config.port type="int">22</brooklyn.ssh.config.port> + <region>us-east-1</region> + <callerContext> + <null/> + </callerContext> + <detectMachineDetails type="boolean">true</detectMachineDetails> + <portforwarding.enabled type="boolean">false</portforwarding.enabled> + <privateAddresses> + <com.google.common.collect.SingletonImmutableSet> + <string>172.168.10.1</string> + </com.google.common.collect.SingletonImmutableSet> + </privateAddresses> + <node> + <null/> + </node> + <template> + <null/> + </template> + <nodeId>mynodeid1</nodeId> + <imageId> + <null/> + </imageId> + <publicAddresses> + <com.google.common.collect.SingletonImmutableSet> + <string>173.194.32.1</string> + </com.google.common.collect.SingletonImmutableSet> + </publicAddresses> + <hostname> + <null/> + </hostname> + <privateHostname> + <null/> + </privateHostname> + <usedPorts> + <set/> + </usedPorts> + <tags> + <set/> + </tags> + </locationConfig> + <locationConfigUnused> + <string>sshToolClass</string> + <string>privateKeyData</string> + <string>spec.original</string> + <string>spec.named.name</string> + <string>spec.final</string> + <string>displayName</string> + <string>address</string> + <string>user</string> + <string>password</string> + <string>jcloudsParent</string> + <string>brooklyn.ssh.config.port</string> + <string>region</string> + <string>callerContext</string> + <string>detectMachineDetails</string> + <string>portforwarding.enabled</string> + <string>privateAddresses</string> + </locationConfigUnused> +</location> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/98101fb6/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-parent-afy79330h5 ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-parent-afy79330h5 b/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-parent-afy79330h5 new file mode 100644 index 0000000..2567ebc --- /dev/null +++ b/locations/jclouds/src/test/resources/org/apache/brooklyn/location/jclouds/persisted-no-semaphores-stubbed-parent-afy79330h5 @@ -0,0 +1,95 @@ +<!-- + 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. +--> + +<location> + <brooklynVersion>1.0.0-SNAPSHOT</brooklynVersion> + <type>org.apache.brooklyn.location.jclouds.JcloudsLocation</type> + <id>afy79330h5</id> + <displayName>aws-ec2:us-east-1</displayName> + <searchPath class="ImmutableList"/> + <children> + <string>l27nwbyisk</string> + </children> + <locationConfig> + <provider>aws-ec2</provider> + <region>us-east-1</region> + <spec.final>jclouds:aws-ec2:us-east-1</spec.final> + <spec.original>jclouds:aws-ec2:us-east-1</spec.original> + <jclouds.computeServiceRegistry> + <org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry> + <nodeCreator class="org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry$BasicNodeCreator"> + <created class="java.util.concurrent.CopyOnWriteArrayList" serialization="custom"> + <java.util.concurrent.CopyOnWriteArrayList> + <default/> + <int>1</int> + <org.jclouds.compute.domain.internal.NodeMetadataImpl> + <id>mynodeid1</id> + </org.jclouds.compute.domain.internal.NodeMetadataImpl> + </java.util.concurrent.CopyOnWriteArrayList> + </created> + <destroyed class="java.util.concurrent.CopyOnWriteArrayList" serialization="custom"> + <java.util.concurrent.CopyOnWriteArrayList> + <default/> + <int>0</int> + </java.util.concurrent.CopyOnWriteArrayList> + </destroyed> + <counter> + <value>2</value> + </counter> + </nodeCreator> + <allowCloudQueries>false</allowCloudQueries> + </org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry> + </jclouds.computeServiceRegistry> + <identity>stub-identity</identity> + <credential>stub-credential</credential> + <sshToolClass>org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool</sshToolClass> + <winrmToolClass>org.apache.brooklyn.util.core.internal.winrm.RecordingWinRmTool</winrmToolClass> + <pollForFirstReachableAddress.predicate> + <com.google.common.base.Predicates_-ObjectPredicate>ALWAYS_TRUE</com.google.common.base.Predicates_-ObjectPredicate> + </pollForFirstReachableAddress.predicate> + <lookupAwsHostname type="boolean">false</lookupAwsHostname> + <spec.named.name>jclouds:aws-ec2:us-east-1</spec.named.name> + <vmInstanceIds> + <map> + <entry> + <locationProxy>l27nwbyisk</locationProxy> + <string>mynodeid1</string> + </entry> + </map> + </vmInstanceIds> + <tags> + <set/> + </tags> + </locationConfig> + <locationConfigUnused> + <string>provider</string> + <string>region</string> + <string>spec.final</string> + <string>spec.original</string> + <string>jclouds.computeServiceRegistry</string> + <string>templateBuilder</string> + <string>identity</string> + <string>credential</string> + <string>sshToolClass</string> + <string>winrmToolClass</string> + <string>pollForFirstReachableAddress.predicate</string> + <string>lookupAwsHostname</string> + <string>spec.named.name</string> + </locationConfigUnused> +</location>
