CS-15771. ec2-run-instances fails with error "Unable to find service offering by id".

Add a check in EC2Engine to verify if the service offering returned by CloudStack
has not been deleted.
Reviewed by: Prachi
This commit is contained in:
Likitha Shetty 2012-08-01 14:15:18 +05:30
parent 52bbf4a185
commit 5b4b596023
4 changed files with 25 additions and 7 deletions

View File

@ -15,10 +15,10 @@
*/
package com.cloud.bridge.persist.dao;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.bridge.persist.EntityDao;
import com.cloud.stack.models.CloudStackConfiguration;
import com.cloud.stack.models.CloudStackServiceOffering;
@ -29,10 +29,9 @@ public class CloudStackSvcOfferingDao extends EntityDao<CloudStackServiceOfferin
super(CloudStackServiceOffering.class, true);
}
public CloudStackServiceOffering getSvcOfferingByName( String name ){
return queryEntity("from CloudStackServiceOffering where name=?", new Object[] {name});
}
public List<CloudStackServiceOffering> getSvcOfferingByName( String name ){
return queryEntities("from CloudStackServiceOffering where name=?", new Object[] {name});
}
public CloudStackServiceOffering getSvcOfferingById( String id ){
return queryEntity("from CloudStackServiceOffering where id=?", new Object[] {id});

View File

@ -1775,8 +1775,12 @@ public class EC2Engine {
if (null == instanceType) instanceType = "m1.small";
CloudStackSvcOfferingDao dao = new CloudStackSvcOfferingDao();
return dao.getSvcOfferingByName(instanceType);
List<CloudStackServiceOffering> svcOfferingList = dao.getSvcOfferingByName(instanceType);
for (CloudStackServiceOffering svcOffering : svcOfferingList) {
if (svcOffering.getRemoved() == null)
return svcOffering;
}
return null;
} catch(Exception e) {
logger.error( "Error while retrieving ServiceOffering information by name - ", e);
throw new EC2ServiceException(ServerError.InternalError, e.getMessage());

View File

@ -11,6 +11,9 @@
<property name="domainId">
<column name="domain_id" />
</property>
<property name="removed">
<column name="removed" />
</property>
</class>
</hibernate-mapping>

View File

@ -57,6 +57,8 @@ public class CloudStackServiceOffering {
private String systemVmType;
@SerializedName(ApiConstants.TAGS)
private String tags;
@SerializedName(ApiConstants.REMOVED)
private String removed;
/**
*
@ -196,4 +198,14 @@ public class CloudStackServiceOffering {
return tags;
}
/**
* @return the removed
*/
public String getRemoved() {
return removed;
}
public void setRemoved(String removed) {
this.removed = removed;
}
}