Further FindBugs fixes

This commit is contained in:
Andrew Gaul 2014-08-27 10:16:53 -07:00
parent 34cfdbe266
commit 8f8b6dd7ce
3 changed files with 10 additions and 15 deletions

View File

@ -147,17 +147,15 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions {
// base EC2 driver currently does not support key import
protected String createOrImportKeyPair(String region, String group, TemplateOptions options) {
RegionAndName regionAndGroup = new RegionAndName(region, group);
KeyPair keyPair;
KeyPair keyPair = makeKeyPair.apply(new RegionAndName(region, group));
// make sure that we don't request multiple keys simultaneously
synchronized (credentialsMap) {
// if there is already a keypair for the group specified, use it
if (credentialsMap.containsKey(regionAndGroup))
return credentialsMap.get(regionAndGroup).getKeyName();
// otherwise create a new keypair and key it under the group and also the regular keyname
keyPair = makeKeyPair.apply(new RegionAndName(region, group));
credentialsMap.put(regionAndGroup, keyPair);
KeyPair origValue = credentialsMap.putIfAbsent(regionAndGroup, keyPair);
if (origValue != null) {
return origValue.getKeyName();
}
credentialsMap.put(new RegionAndName(region, keyPair.getKeyName()), keyPair);
return keyPair.getKeyName();
}

View File

@ -17,6 +17,7 @@
package org.jclouds.ec2.compute.strategy;
import static com.google.common.io.BaseEncoding.base64;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
@ -356,8 +357,7 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest {
expect(options.getKeyPair()).andReturn(userSuppliedKeyPair);
expect(options.shouldAutomaticallyCreateKeyPair()).andReturn(shouldAutomaticallyCreateKeyPair);
expect(keyPair.getKeyName()).andReturn(systemGeneratedKeyPairName).atLeastOnce();
expect(strategy.credentialsMap.containsKey(new RegionAndName(region, group))).andReturn(true);
expect(strategy.credentialsMap.get(new RegionAndName(region, group))).andReturn(keyPair);
expect(strategy.credentialsMap.putIfAbsent(anyObject(RegionAndName.class), anyObject(KeyPair.class))).andReturn(keyPair);
expect(options.getRunScript()).andReturn(null);
// replay mocks
@ -557,6 +557,7 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest {
LoadingCache<RegionAndName, String> securityGroupMap = createMock(LoadingCache.class);
GroupNamingConvention.Factory namingConventionFactory = createMock(GroupNamingConvention.Factory.class);
GroupNamingConvention namingConvention = createMock(GroupNamingConvention.class);
expect(makeKeyPair.apply(anyObject(RegionAndName.class))).andReturn(null).anyTimes();
expect(namingConventionFactory.create()).andReturn(namingConvention).anyTimes();
expect(namingConvention.sharedNameForGroup("group")).andReturn("jclouds#group").anyTimes();
replay(namingConventionFactory);

View File

@ -52,10 +52,6 @@ public class GoGridTemplateOptions extends TemplateOptions implements Cloneable
@Override
public void copyTo(TemplateOptions to) {
super.copyTo(to);
if (to instanceof GoGridTemplateOptions) {
@SuppressWarnings("unused")
GoGridTemplateOptions eTo = GoGridTemplateOptions.class.cast(to);
}
}
public static final GoGridTemplateOptions NONE = new GoGridTemplateOptions();