CS-15145. ec2-register: need better error handling for negative cases(AWSAPI).

This commit is contained in:
Likitha Shetty 2012-07-20 10:43:15 +05:30
parent 8f11a882e0
commit e43677c603
2 changed files with 19 additions and 12 deletions

View File

@ -1064,10 +1064,8 @@ public class EC2Engine {
{
try {
CloudStackAccount caller = getCurrentAccount();
if (null == request.getFormat() || null == request.getName() || null == request.getOsTypeName() ||
null == request.getLocation() || null == request.getZoneName())
throw new EC2ServiceException(ServerError.InternalError, "Missing parameter - location/architecture/name");
if (null == request.getName())
throw new EC2ServiceException(ClientError.Unsupported, "Missing parameter - name");
List<CloudStackTemplate> templates = getApi().registerTemplate((request.getDescription() == null ? request.getName() : request.getDescription()),
request.getFormat(), request.getHypervisor(), request.getName(), toOSTypeId(request.getOsTypeName()), request.getLocation(),
toZoneId(request.getZoneName(), null), null, null, null, null, null, null, null, null, null);

View File

@ -15,6 +15,9 @@
*/
package com.cloud.bridge.service.core.ec2;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2RegisterImage {
private String location;
@ -66,14 +69,20 @@ public class EC2RegisterImage {
*/
public void setArchitecture( String param ) {
if (null != param) {
String parts[] = param.split( ":" );
if (3 <= parts.length) {
format = parts[0];
zoneName = parts[1];
osTypeName = parts[2];
hypervisor = parts[3];
}
}
if (!param.contains(":") || param.split(":").length < 4) {
throw new EC2ServiceException( ClientError.InvalidParameterValue, "Supported format for " +
"'architecture' is format:zonename:ostypename:hypervisor" );
}
String parts[] = param.split( ":" );
format = parts[0];
zoneName = parts[1];
osTypeName = parts[2];
hypervisor = parts[3];
}
else {
throw new EC2ServiceException(ClientError.Unsupported, "Missing Parameter -" +
" architecture");
}
}
public String getFormat() {