mirror of https://github.com/apache/jclouds.git
Issue 428 cannot delete instances outside ec2 east
This commit is contained in:
parent
b4ed57b142
commit
e235427b5f
|
@ -126,6 +126,7 @@ public class EC2ComputeService extends BaseComputeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
} catch (HttpResponseException e) {
|
} catch (HttpResponseException e) {
|
||||||
// Eucalyptus does not support placement groups yet.
|
// Eucalyptus does not support placement groups yet.
|
||||||
if (!(e.getResponse().getStatusCode() == 400 && context.getProviderSpecificContext().getProvider()
|
if (!(e.getResponse().getStatusCode() == 400 && context.getProviderSpecificContext().getProvider()
|
||||||
|
|
|
@ -90,6 +90,9 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
response.getStatusLine());
|
response.getStatusLine());
|
||||||
switch (response.getStatusCode()) {
|
switch (response.getStatusCode()) {
|
||||||
case 400:
|
case 400:
|
||||||
|
if (error != null && error.getCode() != null
|
||||||
|
&& (error.getCode().equals("UnsupportedOperation")))
|
||||||
|
exception = new UnsupportedOperationException(message, exception);
|
||||||
if (error != null && error.getCode() != null
|
if (error != null && error.getCode() != null
|
||||||
&& (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown")))
|
&& (error.getCode().endsWith(".NotFound") || error.getCode().endsWith(".Unknown")))
|
||||||
exception = new ResourceNotFoundException(message, exception);
|
exception = new ResourceNotFoundException(message, exception);
|
||||||
|
|
|
@ -19,162 +19,68 @@
|
||||||
|
|
||||||
package org.jclouds.aws.ec2.compute;
|
package org.jclouds.aws.ec2.compute;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
import static org.easymock.classextension.EasyMock.replay;
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
import static org.easymock.classextension.EasyMock.verify;
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_large;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_small;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_xlarge;
|
|
||||||
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.t1_micro;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.aws.ec2.EC2Client;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.aws.ec2.services.PlacementGroupClient;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.ImageBuilder;
|
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
||||||
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.compute.util.ComputeUtils;
|
||||||
import org.jclouds.domain.LocationScope;
|
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests compute service specifically to EC2.
|
* @author Adrian Cole
|
||||||
*
|
|
||||||
* These tests are designed to verify the local functionality of jclouds, rather than the
|
|
||||||
* interaction with Amazon Web Services.
|
|
||||||
*
|
|
||||||
* @see EC2ComputeServiceLiveTest
|
|
||||||
*
|
|
||||||
* @author Oleksiy Yarmula
|
|
||||||
*/
|
*/
|
||||||
|
@Test(groups = "unit")
|
||||||
public class EC2ComputeServiceTest {
|
public class EC2ComputeServiceTest {
|
||||||
private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
|
|
||||||
|
|
||||||
public static final Hardware CC1_4XLARGE = cc1_4xlarge().location(location).supportsImageIds("us-east-1/cc-image")
|
@SuppressWarnings({ "unchecked" })
|
||||||
.build();
|
public void testUnsupportedOperationOkForPlacementGroups() {
|
||||||
|
EC2Client client = createMock(EC2Client.class);
|
||||||
|
EC2ComputeService service = new EC2ComputeService(createMock(ComputeServiceContext.class), createMock(Map.class),
|
||||||
|
createMock(Supplier.class), createMock(Supplier.class), createMock(Supplier.class),
|
||||||
|
createMock(ListNodesStrategy.class), createMock(GetNodeMetadataStrategy.class),
|
||||||
|
createMock(RunNodesAndAddToSetStrategy.class), createMock(RebootNodeStrategy.class),
|
||||||
|
createMock(DestroyNodeStrategy.class), createMock(ResumeNodeStrategy.class),
|
||||||
|
createMock(SuspendNodeStrategy.class), createMock(Provider.class), createMock(Provider.class),
|
||||||
|
createMock(Predicate.class), createMock(Predicate.class), createMock(Predicate.class),
|
||||||
|
createMock(ComputeUtils.class), createMock(Timeouts.class), createMock(ExecutorService.class), client,
|
||||||
|
createMock(Map.class), createMock(Map.class), createMock(Map.class), createMock(Predicate.class));
|
||||||
|
|
||||||
/**
|
PlacementGroupClient placementClient = createMock(PlacementGroupClient.class);
|
||||||
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
|
||||||
* on {@link org.jclouds.compute.domain.Hardware} from {@link EC2Hardware}.
|
// setup expectations
|
||||||
*
|
expect(client.getPlacementGroupServices()).andReturn(placementClient).atLeastOnce();
|
||||||
* Expected size: m2.xlarge
|
expect(placementClient.describePlacementGroupsInRegion("us-west-1", "jclouds#tag#us-west-1")).andThrow(
|
||||||
*/
|
new UnsupportedOperationException());
|
||||||
@Test
|
|
||||||
public void testTemplateChoiceForInstanceByhardwareId() throws Exception {
|
// replay mocks
|
||||||
Template template = newTemplateBuilder().os64Bit(true).hardwareId("m2.xlarge").locationId("us-east-1").build();
|
replay(client);
|
||||||
|
replay(placementClient);
|
||||||
|
// run
|
||||||
|
service.deletePlacementGroup("us-west-1", "tag");
|
||||||
|
|
||||||
|
// verify mocks
|
||||||
|
verify(client);
|
||||||
|
verify(placementClient);
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
|
||||||
// assert m2_xlarge().build().equals(template.getHardware()) : format(
|
|
||||||
// "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
|
|
||||||
// String.valueOf(template.getHardware()));
|
|
||||||
assertEquals(m2_xlarge().build(), template.getHardware());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTemplateChoiceForInstanceByCChardwareId() throws Exception {
|
|
||||||
Template template = newTemplateBuilder().fastest().build();
|
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
|
||||||
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
|
||||||
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String
|
|
||||||
.valueOf(template.getHardware()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
|
||||||
* on physical attributes (# of cores, ram, etc).
|
|
||||||
*
|
|
||||||
* Expected size: m2.xlarge
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
|
|
||||||
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId(
|
|
||||||
"us-east-1").build();
|
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
|
||||||
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
|
||||||
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, String
|
|
||||||
.valueOf(template.getHardware()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}.
|
|
||||||
*
|
|
||||||
* Verifies that {@link TemplateBuilderImpl} would not choose the insufficient size of the
|
|
||||||
* instance, based on physical attributes (# of cores, ram, etc).
|
|
||||||
*
|
|
||||||
* Expected size: anything but m2.xlarge
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
|
|
||||||
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().locationId(
|
|
||||||
"us-east-1").build();
|
|
||||||
|
|
||||||
assert template != null : "The returned template was null, but it should have a value.";
|
|
||||||
assert !m2_xlarge().build().equals(template.getHardware()) : format(
|
|
||||||
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String
|
|
||||||
.valueOf(template.getHardware()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private TemplateBuilder newTemplateBuilder() {
|
|
||||||
|
|
||||||
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
|
||||||
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
|
||||||
|
|
||||||
Image image = new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location)
|
|
||||||
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true)).description(
|
|
||||||
"description").version("1.0").defaultCredentials(new Credentials("root", null)).build();
|
|
||||||
replay(optionsProvider);
|
|
||||||
replay(templateBuilderProvider);
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
|
||||||
.<Location> of(location));
|
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
|
||||||
.<Image> of(image));
|
|
||||||
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
|
||||||
.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(),
|
|
||||||
m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(),
|
|
||||||
m2_4xlarge().build(), CC1_4XLARGE));
|
|
||||||
|
|
||||||
return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider,
|
|
||||||
templateBuilderProvider) {
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Function<ComputeMetadata, String> indexer() {
|
|
||||||
return new Function<ComputeMetadata, String>() {
|
|
||||||
@Override
|
|
||||||
public String apply(ComputeMetadata from) {
|
|
||||||
return from.getProviderId();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.jclouds.aws.ec2.compute;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.c1_xlarge;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.cc1_4xlarge;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_large;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_small;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m1_xlarge;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_2xlarge;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_4xlarge;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.m2_xlarge;
|
||||||
|
import static org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder.t1_micro;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
|
import org.jclouds.compute.domain.Hardware;
|
||||||
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.ImageBuilder;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
|
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
||||||
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
|
import org.jclouds.domain.Credentials;
|
||||||
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LocationScope;
|
||||||
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests compute service specifically to EC2.
|
||||||
|
*
|
||||||
|
* These tests are designed to verify the local functionality of jclouds, rather than the
|
||||||
|
* interaction with Amazon Web Services.
|
||||||
|
*
|
||||||
|
* @see EC2ComputeServiceLiveTest
|
||||||
|
*
|
||||||
|
* @author Oleksiy Yarmula
|
||||||
|
*/
|
||||||
|
public class EC2TemplateBuilderTest {
|
||||||
|
private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
|
||||||
|
|
||||||
|
public static final Hardware CC1_4XLARGE = cc1_4xlarge().location(location).supportsImageIds("us-east-1/cc-image")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
||||||
|
* on {@link org.jclouds.compute.domain.Hardware} from {@link EC2Hardware}.
|
||||||
|
*
|
||||||
|
* Expected size: m2.xlarge
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testTemplateChoiceForInstanceByhardwareId() throws Exception {
|
||||||
|
Template template = newTemplateBuilder().os64Bit(true).hardwareId("m2.xlarge").locationId("us-east-1").build();
|
||||||
|
|
||||||
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
|
// assert m2_xlarge().build().equals(template.getHardware()) : format(
|
||||||
|
// "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
|
||||||
|
// String.valueOf(template.getHardware()));
|
||||||
|
assertEquals(m2_xlarge().build(), template.getHardware());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTemplateChoiceForInstanceByCChardwareId() throws Exception {
|
||||||
|
Template template = newTemplateBuilder().fastest().build();
|
||||||
|
|
||||||
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
|
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
||||||
|
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String
|
||||||
|
.valueOf(template.getHardware()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
|
||||||
|
* on physical attributes (# of cores, ram, etc).
|
||||||
|
*
|
||||||
|
* Expected size: m2.xlarge
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
|
||||||
|
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId(
|
||||||
|
"us-east-1").build();
|
||||||
|
|
||||||
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
|
assert CC1_4XLARGE.equals(template.getHardware()) : format(
|
||||||
|
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, String
|
||||||
|
.valueOf(template.getHardware()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}.
|
||||||
|
*
|
||||||
|
* Verifies that {@link TemplateBuilderImpl} would not choose the insufficient size of the
|
||||||
|
* instance, based on physical attributes (# of cores, ram, etc).
|
||||||
|
*
|
||||||
|
* Expected size: anything but m2.xlarge
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
|
||||||
|
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().locationId(
|
||||||
|
"us-east-1").build();
|
||||||
|
|
||||||
|
assert template != null : "The returned template was null, but it should have a value.";
|
||||||
|
assert !m2_xlarge().build().equals(template.getHardware()) : format(
|
||||||
|
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String
|
||||||
|
.valueOf(template.getHardware()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private TemplateBuilder newTemplateBuilder() {
|
||||||
|
|
||||||
|
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
|
||||||
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
|
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||||
|
|
||||||
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
|
Image image = new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location)
|
||||||
|
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true)).description(
|
||||||
|
"description").version("1.0").defaultCredentials(new Credentials("root", null)).build();
|
||||||
|
replay(optionsProvider);
|
||||||
|
replay(templateBuilderProvider);
|
||||||
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
|
.<Location> of(location));
|
||||||
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
|
.<Image> of(image));
|
||||||
|
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(),
|
||||||
|
m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(),
|
||||||
|
m2_4xlarge().build(), CC1_4XLARGE));
|
||||||
|
|
||||||
|
return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider,
|
||||||
|
templateBuilderProvider) {
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Function<ComputeMetadata, String> indexer() {
|
||||||
|
return new Function<ComputeMetadata, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(ComputeMetadata from) {
|
||||||
|
return from.getProviderId();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.aws.ec2.compute.EC2ComputeServiceTest;
|
import org.jclouds.aws.ec2.compute.EC2TemplateBuilderTest;
|
||||||
import org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder;
|
import org.jclouds.aws.ec2.compute.domain.EC2HardwareBuilder;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
import org.jclouds.aws.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
|
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
|
||||||
|
@ -118,7 +118,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
||||||
// setup constants
|
// setup constants
|
||||||
String region = Region.US_EAST_1;
|
String region = Region.US_EAST_1;
|
||||||
String tag = "tag";
|
String tag = "tag";
|
||||||
Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
|
Hardware size = EC2TemplateBuilderTest.CC1_4XLARGE;
|
||||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||||
String generatedGroup = "group";
|
String generatedGroup = "group";
|
||||||
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
||||||
|
@ -177,7 +177,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
||||||
// setup constants
|
// setup constants
|
||||||
String region = Region.US_EAST_1;
|
String region = Region.US_EAST_1;
|
||||||
String tag = "tag";
|
String tag = "tag";
|
||||||
Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
|
Hardware size = EC2TemplateBuilderTest.CC1_4XLARGE;
|
||||||
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
|
||||||
String generatedGroup = "group";
|
String generatedGroup = "group";
|
||||||
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
|
||||||
|
|
|
@ -54,70 +54,81 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
@Test
|
@Test
|
||||||
public void test400WithNotFoundSetsResourceNotFoundException() {
|
public void test400WithNotFoundSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
||||||
"<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>Monster.NotFound</Code></Error>", ResourceNotFoundException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test400WithUnsupportedCodeMakesUnsupportedOperationException() {
|
||||||
|
assertCodeMakes("POST", URI.create("https://ec2.us-west-1.amazonaws.com/"), 400, "",
|
||||||
|
"<Error><Code>UnsupportedOperation</Code></Error>", UnsupportedOperationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithUnknownSetsResourceNotFoundException() {
|
public void test400WithUnknownSetsResourceNotFoundException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
||||||
"<Error><Code>InvalidPlacementGroup.Unknown</Code></Error>", ResourceNotFoundException.class);
|
"<Error><Code>InvalidPlacementGroup.Unknown</Code></Error>", ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithIncorrectStateSetsIllegalStateException() {
|
public void test400WithIncorrectStateSetsIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
||||||
"<Error><Code>IncorrectState</Code></Error>", IllegalStateException.class);
|
"<Error><Code>IncorrectState</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test409SetsIllegalStateException() {
|
public void test409SetsIllegalStateException() {
|
||||||
assertCodeMakes("PUT", URI.create("https://adriancole-blobstore011.s3.amazonaws.com/"), 409, "",
|
assertCodeMakes(
|
||||||
"<Error><Code>OperationAborted</Code><Message>A conflicting conditional operation is currently in progress against this resource. Please try again.</Message><RequestId>F716E81C3D814E59</RequestId><HostId>SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO</HostId></Error>", IllegalStateException.class);
|
"PUT",
|
||||||
|
URI.create("https://adriancole-blobstore011.s3.amazonaws.com/"),
|
||||||
|
409,
|
||||||
|
"",
|
||||||
|
"<Error><Code>OperationAborted</Code><Message>A conflicting conditional operation is currently in progress against this resource. Please try again.</Message><RequestId>F716E81C3D814E59</RequestId><HostId>SDprHxWzG/YXzanVnV7VTz/wP+6fRt1dS+q00kH1rz248YOOSddkFiTXF04XtqNO</HostId></Error>",
|
||||||
|
IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInvalidGroupDuplicateIllegalStateException() {
|
public void test400WithInvalidGroupDuplicateIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400,"Bad Request", "application/unknown",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "application/unknown",
|
||||||
"<Error><Code>InvalidGroup.Duplicate</Code></Error>", IllegalStateException.class);
|
"<Error><Code>InvalidGroup.Duplicate</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInvalidKeyPairGroupDuplicateIllegalStateException() {
|
public void test400WithInvalidKeyPairGroupDuplicateIllegalStateException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400,"Bad Request", "application/unknown",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "application/unknown",
|
||||||
"<Error><Code>InvalidKeyPair.Duplicate</Code></Error>", IllegalStateException.class);
|
"<Error><Code>InvalidKeyPair.Duplicate</Code></Error>", IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithTextPlainIllegalArgumentException() {
|
public void test400WithTextPlainIllegalArgumentException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "text/plain",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "Bad Request", "text/plain",
|
||||||
"Failure: 400 Bad Request\nFailed to bind the following fields\nMonitoring.Enabled = true\n\n\n",
|
"Failure: 400 Bad Request\nFailed to bind the following fields\nMonitoring.Enabled = true\n\n\n",
|
||||||
IllegalArgumentException.class);
|
IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithGroupAlreadyExistsEucalyptusIllegalStateException() {
|
public void test400WithGroupAlreadyExistsEucalyptusIllegalStateException() {
|
||||||
assertCodeMakes(
|
assertCodeMakes(
|
||||||
"GET",
|
"GET",
|
||||||
URI.create("https://amazonaws.com/foo"),
|
URI.create("https://amazonaws.com/foo"),
|
||||||
400,
|
400,
|
||||||
"",
|
"",
|
||||||
"<?xml version=\"1.0\"?><Response><Errors><Error><Code>Groups</Code><Message>\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists</Message></Error></Errors><RequestID>e0133975-3bc5-456d-9753-1d61b27e07e9</RequestID></Response>",
|
"<?xml version=\"1.0\"?><Response><Errors><Error><Code>Groups</Code><Message>\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists\nError adding network group: group named jclouds#eucrun#Eucalyptus already exists</Message></Error></Errors><RequestID>e0133975-3bc5-456d-9753-1d61b27e07e9</RequestID></Response>",
|
||||||
IllegalStateException.class);
|
IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithAuthFailureSetsAuthorizationException() {
|
public void test400WithAuthFailureSetsAuthorizationException() {
|
||||||
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
assertCodeMakes("GET", URI.create("https://amazonaws.com/foo"), 400, "",
|
||||||
"<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class);
|
"<Error><Code>AuthFailure</Code></Error>", AuthorizationException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||||
Class<? extends Exception> expected) {
|
Class<? extends Exception> expected) {
|
||||||
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||||
String content, Class<? extends Exception> expected) {
|
String content, Class<? extends Exception> expected) {
|
||||||
|
|
||||||
ParseAWSErrorFromXmlContent function = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
|
ParseAWSErrorFromXmlContent function = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
|
||||||
|
|
||||||
|
@ -132,7 +143,7 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
HttpCommand command = createMock(HttpCommand.class);
|
HttpCommand command = createMock(HttpCommand.class);
|
||||||
HttpRequest request = new HttpRequest(method, uri);
|
HttpRequest request = new HttpRequest(method, uri);
|
||||||
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils
|
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Utils
|
||||||
.toInputStream(content)));
|
.toInputStream(content)));
|
||||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||||
|
|
||||||
expect(command.getRequest()).andReturn(request).atLeastOnce();
|
expect(command.getRequest()).andReturn(request).atLeastOnce();
|
||||||
|
|
Loading…
Reference in New Issue