mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 10:02:27 +01:00
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:
parent
b80c3dc9c6
commit
11f5bd25f8
@ -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(),
|
||||
|
||||
@ -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,14 +70,19 @@ 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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user