CS-15145: Summary: ec2-register: need better error handling for negative cases.

The negative cases for which the error handling is improved,
1. run ec2-register with incorrect field separator for architecture parameter.
2. run ec2-register without providing required parameters.
This commit is contained in:
Likitha Shetty 2012-07-23 15:44:30 -07:00 committed by prachi
parent b80c3dc9c6
commit 11f5bd25f8
2 changed files with 18 additions and 11 deletions

View File

@ -1068,9 +1068,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(),

View File

@ -16,6 +16,9 @@
// under the License.
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;
@ -67,13 +70,18 @@ public class EC2RegisterImage {
*/
public void setArchitecture( String param ) {
if (null != param) {
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( ":" );
if (3 <= parts.length) {
format = parts[0];
zoneName = parts[1];
osTypeName = parts[2];
hypervisor = parts[3];
}
else {
throw new EC2ServiceException(ClientError.Unsupported, "Missing Parameter -" + " architecture");
}
}