From 226b74913134af6e541001159519cc2fcfc1ec21 Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Tue, 21 Jan 2014 14:35:48 +0530 Subject: [PATCH] CLOUDSTACK-5915. [AWSAPI] Instance launch is inconsistent if there are deleted service offerings Use CS API listServiceOfferingsCmd to retrieve appropriate service offerings --- .../com/cloud/bridge/service/core/ec2/EC2Engine.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java index 60f974a5e1d..ef7539f7350 100644 --- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java @@ -66,6 +66,7 @@ import com.cloud.stack.models.CloudStackPasswordData; import com.cloud.stack.models.CloudStackResourceLimit; import com.cloud.stack.models.CloudStackResourceTag; import com.cloud.stack.models.CloudStackSecurityGroup; +import com.cloud.stack.models.CloudStackServiceOffering; import com.cloud.stack.models.CloudStackSnapshot; import com.cloud.stack.models.CloudStackTemplate; import com.cloud.stack.models.CloudStackTemplatePermission; @@ -1414,7 +1415,7 @@ public class EC2Engine extends ManagerBase { if (request.getInstanceType() != null) { instanceType = request.getInstanceType(); } - CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType); + CloudStackServiceOffering svcOffering = getCSServiceOfferingId(instanceType); if (svcOffering == null) { logger.info("No ServiceOffering found to be defined by name, please contact the administrator " + instanceType); throw new Exception("instanceType not found"); @@ -1609,7 +1610,7 @@ public class EC2Engine extends ManagerBase { if (request.getInstanceType() != null) { String instanceType = request.getInstanceType(); - CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType); + CloudStackServiceOffering svcOffering = getCSServiceOfferingId(instanceType); if (svcOffering == null) throw new Exception("instanceType not found"); CloudStackUserVm userVm = getApi().changeServiceForVirtualMachine(instanceId, svcOffering.getId()); @@ -1783,11 +1784,12 @@ public class EC2Engine extends ManagerBase { * */ - private CloudStackServiceOfferingVO getCSServiceOfferingId(String instanceType) throws Exception { + private CloudStackServiceOffering getCSServiceOfferingId(String instanceType) throws Exception { try { if (instanceType == null) instanceType = "m1.small"; // default value - return scvoDao.getSvcOfferingByName(instanceType); + List serviceOfferings = getApi().listServiceOfferings(null, null, false, null, instanceType, null, null); + return serviceOfferings.get(0); } catch (Exception e) { logger.error("Error while retrieving ServiceOffering information by name - ", e); throw new Exception("No ServiceOffering found to be defined by name");