CLOUDSTACK-2623. Provide appropriate AWS EC2 error codes in error thrown by CS AWSAPI. Since CS has very few generic errorcode groups, in AWSAPI parse the response message and translate the CS error to AWS EC2 error code.

Provide support for the following error codes -
AuthFailure, DependencyViolation, IncorrectState, InvalidAMIID.NotFound, InvalidAttachment.NotFound, InvalidDevice.InUse, InvalidFilter, InvalidGroup.Duplicate, InvalidGroup.InUse, InvalidGroup.NotFound
InvalidInstanceID.NotFound, InvalidKeyPair.Duplicate, InvalidKeyPair.Format, InvalidKeyPair.NotFound, InvalidParameterCombinatio, InvalidParameterValue, InvalidPermission.Duplicate, InvalidPermission.Malformed
InvalidSnapshot.NotFound, InvalidVolume.NotFound, InvalidVolumeID.Duplicate, InvalidZone.NotFound, MissingParameter, UnsupportedOperation, SignatureDoesNotMatch, InternalError, AddressLimitExceeded, InstanceLimitExceeded
VolumeLimitExceeded, Unavailable, ResourceLimitExceeded

CLOUDSTACK-2624. Support ModifyInstanceAttribute API in AWSAPI.
2 AWS instance attributes will be supported, 'InstanceType' and 'UserData'
As per AWS EC2, to modify both the attributes, the instance must be stopped. If not throw 'IncorrectInstanceState' error
This commit is contained in:
Likitha Shetty 2013-05-22 16:33:08 +05:30
parent 85ff507094
commit 9a33fd181f
17 changed files with 928 additions and 504 deletions

View File

@ -94,7 +94,7 @@ public class EC2MainServlet extends HttpServlet{
if(!isEC2APIEnabled){
//response.sendError(404, "EC2 API is disabled.");
response.setStatus(404);
faultResponse(response, "404" , "EC2 API is disabled.");
faultResponse(response, "Unavailable" , "EC2 API is disabled");
return;
}

View File

@ -39,7 +39,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import javax.inject.Inject;
@ -92,10 +91,9 @@ import com.amazon.ec2.DescribeVolumesResponse;
import com.amazon.ec2.DetachVolumeResponse;
import com.amazon.ec2.DisassociateAddressResponse;
import com.amazon.ec2.GetPasswordDataResponse;
import com.amazon.ec2.GroupItemType;
import com.amazon.ec2.ImportKeyPairResponse;
import com.amazon.ec2.LaunchPermissionItemType;
import com.amazon.ec2.ModifyImageAttributeResponse;
import com.amazon.ec2.ModifyInstanceAttributeResponse;
import com.amazon.ec2.RebootInstancesResponse;
import com.amazon.ec2.RegisterImageResponse;
import com.amazon.ec2.ReleaseAddressResponse;
@ -105,9 +103,7 @@ import com.amazon.ec2.RunInstancesResponse;
import com.amazon.ec2.StartInstancesResponse;
import com.amazon.ec2.StopInstancesResponse;
import com.amazon.ec2.TerminateInstancesResponse;
import com.cloud.bridge.model.CloudStackUserVO;
import com.cloud.bridge.model.UserCredentialsVO;
import com.cloud.bridge.persist.dao.CloudStackConfigurationDao;
import com.cloud.bridge.persist.dao.CloudStackUserDaoImpl;
import com.cloud.bridge.persist.dao.OfferingDaoImpl;
import com.cloud.bridge.persist.dao.UserCredentialsDaoImpl;
@ -143,6 +139,7 @@ import com.cloud.bridge.service.core.ec2.EC2InstanceFilterSet;
import com.cloud.bridge.service.core.ec2.EC2IpPermission;
import com.cloud.bridge.service.core.ec2.EC2KeyPairFilterSet;
import com.cloud.bridge.service.core.ec2.EC2ModifyImageAttribute;
import com.cloud.bridge.service.core.ec2.EC2ModifyInstanceAttribute;
import com.cloud.bridge.service.core.ec2.EC2RebootInstances;
import com.cloud.bridge.service.core.ec2.EC2RegisterImage;
import com.cloud.bridge.service.core.ec2.EC2ReleaseAddress;
@ -151,8 +148,6 @@ import com.cloud.bridge.service.core.ec2.EC2SecurityGroup;
import com.cloud.bridge.service.core.ec2.EC2SnapshotFilterSet;
import com.cloud.bridge.service.core.ec2.EC2StartInstances;
import com.cloud.bridge.service.core.ec2.EC2StopInstances;
import com.cloud.bridge.service.core.ec2.EC2TagKeyValue;
import com.cloud.bridge.service.core.ec2.EC2TagTypeId;
import com.cloud.bridge.service.core.ec2.EC2Tags;
import com.cloud.bridge.service.core.ec2.EC2TagsFilterSet;
import com.cloud.bridge.service.core.ec2.EC2Volume;
@ -289,6 +284,7 @@ public class EC2RestServlet extends HttpServlet {
else if (action.equalsIgnoreCase( "DetachVolume" )) detachVolume(request, response);
else if (action.equalsIgnoreCase( "DisassociateAddress" )) disassociateAddress(request, response);
else if (action.equalsIgnoreCase( "ModifyImageAttribute" )) modifyImageAttribute(request, response);
else if (action.equalsIgnoreCase( "ModifyInstanceAttribute" )) modifyInstanceAttribute(request, response);
else if (action.equalsIgnoreCase( "RebootInstances" )) rebootInstances(request, response);
else if (action.equalsIgnoreCase( "RegisterImage" )) registerImage(request, response);
else if (action.equalsIgnoreCase( "ReleaseAddress" )) releaseAddress(request, response);
@ -318,8 +314,14 @@ public class EC2RestServlet extends HttpServlet {
} catch( EC2ServiceException e ) {
response.setStatus(e.getErrorCode());
if (e.getCause() != null && e.getCause() instanceof AxisFault)
faultResponse(response, ((AxisFault)e.getCause()).getFaultCode().getLocalPart(), e.getMessage());
if (e.getCause() != null && e.getCause() instanceof AxisFault) {
String errorCode = ((AxisFault)e.getCause()).getFaultCode().getLocalPart();
if (errorCode.startsWith("Client.")) // only in a SOAP API client error code is prefixed with Client.
errorCode = errorCode.split("Client.")[1];
else if (errorCode.startsWith("Server.")) // only in a SOAP API server error code is prefixed with Server.
errorCode = errorCode.split("Server.")[1];
faultResponse(response, errorCode, e.getMessage());
}
else {
logger.error("EC2ServiceException: " + e.getMessage(), e);
endResponse(response, e.toString());
@ -395,11 +397,6 @@ public class EC2RestServlet extends HttpServlet {
endResponse(response, "SetUserKeys exception " + e.getMessage());
return;
}
// prime UserContext here
// logger.debug("initializing context");
UserContext context = UserContext.current();
try {
txn = Transaction.open(Transaction.AWSAPI_DB);
// -> use the keys to see if the account actually exists
@ -681,17 +678,23 @@ public class EC2RestServlet extends HttpServlet {
String[] volumeId = request.getParameterValues( "VolumeId" );
if ( null != volumeId && 0 < volumeId.length )
EC2request.setId( volumeId[0] );
else { response.sendError(530, "Missing VolumeId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - VolumeId");
}
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( null != instanceId && 0 < instanceId.length )
EC2request.setInstanceId( instanceId[0] );
else { response.sendError(530, "Missing InstanceId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
String[] device = request.getParameterValues( "Device" );
if ( null != device && 0 < device.length )
EC2request.setDevice( device[0] );
else { response.sendError(530, "Missing Device parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Device");
}
// -> execute the request
AttachVolumeResponse EC2response = EC2SoapServiceImpl.toAttachVolumeResponse( ServiceProvider.getInstance().getEC2Engine().attachVolume( EC2request ));
@ -709,7 +712,9 @@ public class EC2RestServlet extends HttpServlet {
String[] groupName = request.getParameterValues( "GroupName" );
if ( null != groupName && 0 < groupName.length )
EC2request.setName( groupName[0] );
else { response.sendError(530, "Missing GroupName parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - GroupName");
}
// -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
int nCount = 1, mCount;
@ -772,8 +777,7 @@ public class EC2RestServlet extends HttpServlet {
} while( true );
if (1 == nCount) {
response.sendError(530, "At least one IpPermissions required" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - IpPermissions");
}
// -> execute the request
@ -790,7 +794,9 @@ public class EC2RestServlet extends HttpServlet {
String[] groupName = request.getParameterValues( "GroupName" );
if ( null != groupName && 0 < groupName.length )
EC2request.setName( groupName[0] );
else { response.sendError(530, "Missing GroupName parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter 'Groupname'");
}
// -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
int nCount = 1;
@ -852,8 +858,9 @@ public class EC2RestServlet extends HttpServlet {
} while( true );
if (1 == nCount) { response.sendError(530, "At least one IpPermissions required" ); return; }
if (1 == nCount) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - IpPermissions");
}
// -> execute the request
AuthorizeSecurityGroupIngressResponse EC2response = EC2SoapServiceImpl.toAuthorizeSecurityGroupIngressResponse(
@ -868,7 +875,9 @@ public class EC2RestServlet extends HttpServlet {
String[] volumeId = request.getParameterValues( "VolumeId" );
if ( null != volumeId && 0 < volumeId.length )
EC2request.setId(volumeId[0]);
else { response.sendError(530, "Missing VolumeId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter 'VolumeId'");
}
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( null != instanceId && 0 < instanceId.length )
@ -890,7 +899,9 @@ public class EC2RestServlet extends HttpServlet {
String[] volumeId = request.getParameterValues( "VolumeId" );
if ( null != volumeId && 0 < volumeId.length )
EC2request.setId(volumeId[0]);
else { response.sendError(530, "Missing VolumeId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - VolumeId");
}
// -> execute the request
DeleteVolumeResponse EC2response = EC2SoapServiceImpl.toDeleteVolumeResponse( ServiceProvider.getInstance().getEC2Engine().deleteVolume( EC2request ));
@ -904,7 +915,9 @@ public class EC2RestServlet extends HttpServlet {
String[] zoneName = request.getParameterValues( "AvailabilityZone" );
if ( null != zoneName && 0 < zoneName.length )
EC2request.setZoneName( zoneName[0] );
else { response.sendError(530, "Missing AvailabilityZone parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing parameter - AvailabilityZone");
}
String[] size = request.getParameterValues( "Size" );
String[] snapshotId = request.getParameterValues("SnapshotId");
@ -922,9 +935,9 @@ public class EC2RestServlet extends HttpServlet {
} else if (useSnapshot && !useSize) {
EC2request.setSnapshotId(snapshotId[0]);
} else if (useSize && useSnapshot) {
response.sendError(530, "Size and SnapshotId parameters are mutually exclusive" ); return;
throw new EC2ServiceException( ClientError.InvalidParameterCombination, "Parameters 'Size' and 'SnapshotId' are mutually exclusive");
} else {
response.sendError(530, "Size or SnapshotId has to be specified" ); return;
throw new EC2ServiceException( ClientError.MissingParamter, "Parameter 'Size' or 'SnapshotId' has to be specified");
}
@ -941,12 +954,15 @@ public class EC2RestServlet extends HttpServlet {
String[] name = request.getParameterValues( "GroupName" );
if ( null != name && 0 < name.length )
groupName = name[0];
else { response.sendError(530, "Missing GroupName parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - GroupName");
}
String[] desc = request.getParameterValues( "GroupDescription" );
if ( null != desc && 0 < desc.length )
groupDescription = desc[0];
else { response.sendError(530, "Missing GroupDescription parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - GroupDescription");
}
// -> execute the request
CreateSecurityGroupResponse EC2response = EC2SoapServiceImpl.toCreateSecurityGroupResponse( ServiceProvider.getInstance().getEC2Engine().createSecurityGroup( groupName, groupDescription ));
@ -960,7 +976,9 @@ public class EC2RestServlet extends HttpServlet {
String[] name = request.getParameterValues( "GroupName" );
if ( null != name && 0 < name.length )
groupName = name[0];
else { response.sendError(530, "Missing GroupName parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - GroupName");
}
// -> execute the request
DeleteSecurityGroupResponse EC2response = EC2SoapServiceImpl.toDeleteSecurityGroupResponse( ServiceProvider.getInstance().getEC2Engine().deleteSecurityGroup( groupName ));
@ -974,7 +992,9 @@ public class EC2RestServlet extends HttpServlet {
String[] snapSet = request.getParameterValues( "SnapshotId" );
if ( null != snapSet && 0 < snapSet.length )
snapshotId = snapSet[0];
else { response.sendError(530, "Missing SnapshotId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - SnapshotId");
}
// -> execute the request
DeleteSnapshotResponse EC2response = EC2SoapServiceImpl.toDeleteSnapshotResponse( ServiceProvider.getInstance().getEC2Engine().deleteSnapshot( snapshotId ));
@ -988,7 +1008,9 @@ public class EC2RestServlet extends HttpServlet {
String[] volSet = request.getParameterValues( "VolumeId" );
if ( null != volSet && 0 < volSet.length )
volumeId = volSet[0];
else { response.sendError(530, "Missing VolumeId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - VolumeId");
}
// -> execute the request
EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
@ -1003,7 +1025,9 @@ public class EC2RestServlet extends HttpServlet {
String[] imageId = request.getParameterValues( "ImageId" );
if ( null != imageId && 0 < imageId.length )
image.setId( imageId[0] );
else { response.sendError(530, "Missing ImageId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
}
// -> execute the request
DeregisterImageResponse EC2response = EC2SoapServiceImpl.toDeregisterImageResponse( ServiceProvider.getInstance().getEC2Engine().deregisterImage( image ));
@ -1017,16 +1041,25 @@ public class EC2RestServlet extends HttpServlet {
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( null != instanceId && 0 < instanceId.length )
EC2request.setInstanceId( instanceId[0] );
else { response.sendError(530, "Missing InstanceId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
String[] name = request.getParameterValues( "Name" );
if ( null != name && 0 < name.length )
EC2request.setName( name[0] );
else { response.sendError(530, "Missing Name parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Name");
}
String[] description = request.getParameterValues( "Description" );
if ( null != description && 0 < description.length )
if ( null != description && 0 < description.length ) {
if (description[0].length() > 255)
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Length of the value of parameter Description should be less than 255");
EC2request.setDescription( description[0] );
}
// -> execute the request
CreateImageResponse EC2response = EC2SoapServiceImpl.toCreateImageResponse( ServiceProvider.getInstance().getEC2Engine().createImage( EC2request ));
@ -1040,16 +1073,23 @@ public class EC2RestServlet extends HttpServlet {
String[] location = request.getParameterValues( "ImageLocation" );
if ( null != location && 0 < location.length )
EC2request.setLocation( location[0] );
else { response.sendError(530, "Missing ImageLocation parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing parameter - ImageLocation");
}
String[] cloudRedfined = request.getParameterValues( "Architecture" );
if ( null != cloudRedfined && 0 < cloudRedfined.length )
EC2request.setArchitecture( cloudRedfined[0] );
else { response.sendError(530, "Missing Architecture parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Architecture");
}
String[] name = request.getParameterValues( "Name" );
if ( null != name && 0 < name.length )
EC2request.setName( name[0] );
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Name");
}
String[] description = request.getParameterValues( "Description" );
if ( null != description && 0 < description.length )
@ -1068,9 +1108,8 @@ public class EC2RestServlet extends HttpServlet {
if ( imageId != null && imageId.length > 0 )
ec2request.setImageId( imageId[0]);
else {
response.sendError(530, "Missing ImageId parameter" );
return;
}
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
}
String[] description = request.getParameterValues( "Description.Value" );
if ( description != null && description.length > 0 ) {
@ -1082,8 +1121,8 @@ public class EC2RestServlet extends HttpServlet {
if (ec2request.getLaunchPermissionSet().length > 0)
ec2request.setAttribute(ImageAttribute.launchPermission);
else {
response.sendError(530, "Missing Attribute parameter - Description/LaunchPermission should be provided" );
return;
throw new EC2ServiceException( ClientError.MissingParamter,
"Missing required parameter - Description/LaunchPermission should be provided");
}
}
@ -1135,8 +1174,7 @@ public class EC2RestServlet extends HttpServlet {
if ( imageId != null && imageId.length > 0)
ec2request.setImageId(imageId[0]);
else {
response.sendError(530, "Missing ImageId parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
}
String[] attribute = request.getParameterValues( "Attribute" );
@ -1144,12 +1182,11 @@ public class EC2RestServlet extends HttpServlet {
if (attribute[0].equalsIgnoreCase("launchPermission"))
ec2request.setAttribute(ImageAttribute.launchPermission);
else {
response.sendError(501, "Unsupported Attribute - only launchPermission supported" );
return;
throw new EC2ServiceException( ClientError.MissingParamter,
"Missing required parameter - Description/LaunchPermission should be provided");
}
} else {
response.sendError(530, "Missing Attribute parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Attribute");
}
EC2ImageLaunchPermission launchPermission = new EC2ImageLaunchPermission();
@ -1170,12 +1207,13 @@ public class EC2RestServlet extends HttpServlet {
String[] imageId = request.getParameterValues( "ImageId" );
if ( null != imageId && 0 < imageId.length )
EC2request.setTemplateId( imageId[0] );
else { response.sendError(530, "Missing ImageId parameter" ); return; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
}
String[] minCount = request.getParameterValues( "MinCount" );
if ( minCount == null || minCount.length < 1) {
response.sendError(530, "Missing MinCount parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - MinCount");
} else if ( Integer.parseInt(minCount[0]) < 1) {
throw new EC2ServiceException(ClientError.InvalidParameterValue,
"Value of parameter MinCount should be greater than 0");
@ -1185,8 +1223,7 @@ public class EC2RestServlet extends HttpServlet {
String[] maxCount = request.getParameterValues( "MaxCount" );
if ( maxCount == null || maxCount.length < 1) {
response.sendError(530, "Missing MaxCount parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - MaxCount");
} else if ( Integer.parseInt(maxCount[0]) < 1) {
throw new EC2ServiceException(ClientError.InvalidParameterValue,
"Value of parameter MaxCount should be greater than 0");
@ -1250,7 +1287,9 @@ public class EC2RestServlet extends HttpServlet {
}
}
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
if (0 == count) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
// -> execute the request
RebootInstancesResponse EC2response = EC2SoapServiceImpl.toRebootInstancesResponse( ServiceProvider.getInstance().getEC2Engine().rebootInstances(EC2request));
@ -1274,7 +1313,9 @@ public class EC2RestServlet extends HttpServlet {
}
}
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
if (0 == count) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
// -> execute the request
StartInstancesResponse EC2response = EC2SoapServiceImpl.toStartInstancesResponse( ServiceProvider.getInstance().getEC2Engine().startInstances(EC2request));
@ -1298,7 +1339,9 @@ public class EC2RestServlet extends HttpServlet {
}
}
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
if (0 == count) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
String[] force = request.getParameterValues("Force");
if ( force != null) {
@ -1327,7 +1370,9 @@ public class EC2RestServlet extends HttpServlet {
}
}
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
if (0 == count) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
// -> execute the request
EC2request.setDestroyInstances( true );
@ -1364,7 +1409,8 @@ public class EC2RestServlet extends HttpServlet {
}
// -> execute the request
DescribeAvailabilityZonesResponse EC2response = EC2SoapServiceImpl.toDescribeAvailabilityZonesResponse( ServiceProvider.getInstance().getEC2Engine().handleRequest( EC2request ));
DescribeAvailabilityZonesResponse EC2response = EC2SoapServiceImpl.toDescribeAvailabilityZonesResponse(
ServiceProvider.getInstance().getEC2Engine().describeAvailabilityZones( EC2request ));
serializeResponse(response, EC2response);
}
@ -1404,8 +1450,7 @@ public class EC2RestServlet extends HttpServlet {
if (imageId != null && imageId.length > 0)
ec2request.setImageId(imageId[0]);
else {
response.sendError(530, "Missing ImageId parameter");
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
}
String[] attribute = request.getParameterValues( "Attribute" );
@ -1415,12 +1460,11 @@ public class EC2RestServlet extends HttpServlet {
else if (attribute[0].equalsIgnoreCase("launchPermission"))
ec2request.setAttribute(ImageAttribute.launchPermission);
else {
response.sendError(501, "Unsupported Attribute - description and launchPermission supported" );
return;
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Only values supported for paramter Attribute are - Description/LaunchPermission");
}
} else {
response.sendError(530, "Missing Attribute parameter");
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Attribute");
}
DescribeImageAttributeResponse EC2response = EC2SoapServiceImpl.toDescribeImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().describeImageAttribute( ec2request ));
@ -1501,9 +1545,8 @@ public class EC2RestServlet extends HttpServlet {
EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
String publicIp = request.getParameter( "PublicIp" );
if (publicIp == null) {
response.sendError(530, "Missing PublicIp parameter");
return;
if (publicIp == null) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - PublicIp");
}
EC2ReleaseAddress ec2Request = new EC2ReleaseAddress();
@ -1522,13 +1565,11 @@ public class EC2RestServlet extends HttpServlet {
String publicIp = request.getParameter( "PublicIp" );
if (null == publicIp) {
response.sendError(530, "Missing PublicIp parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - PublicIp");
}
String instanceId = request.getParameter( "InstanceId" );
if (null == instanceId) {
response.sendError(530, "Missing InstanceId parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
EC2AssociateAddress ec2Request = new EC2AssociateAddress();
@ -1548,8 +1589,7 @@ public class EC2RestServlet extends HttpServlet {
String publicIp = request.getParameter( "PublicIp" );
if (null == publicIp) {
response.sendError(530, "Missing PublicIp parameter" );
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - PublicIp");
}
EC2DisassociateAddress ec2Request = new EC2DisassociateAddress();
@ -1597,27 +1637,20 @@ public class EC2RestServlet extends HttpServlet {
private void describeInstanceAttribute( HttpServletRequest request, HttpServletResponse response )
throws ADBException, XMLStreamException, IOException {
EC2DescribeInstances EC2request = new EC2DescribeInstances();
String instanceType = null;
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( instanceId != null && instanceId.length > 0)
EC2request.addInstanceId( instanceId[0] );
else
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
// -> we are only handling queries about the "Attribute=instanceType"
Enumeration<?> names = request.getParameterNames();
while( names.hasMoreElements()) {
String key = (String)names.nextElement();
if (key.startsWith("Attribute")) {
String[] value = request.getParameterValues( key );
if (null != value && 0 < value.length && value[0].equalsIgnoreCase( "instanceType" )) {
instanceType = value[0];
break;
}
String[] attribute = request.getParameterValues( "Attribute" );
if (attribute != null && attribute.length > 0) {
if ( !attribute[0].equalsIgnoreCase("instanceType") ) {
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Only value supported for paramter Attribute is 'instanceType'");
}
}
if ( null != instanceType ) {
String[] value = request.getParameterValues( "InstanceId" );
EC2request.addInstanceId( value[0] );
}
else {
response.sendError(501, "Unsupported - only instanceType supported" );
return;
} else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Attribute");
}
// -> execute the request
@ -1625,6 +1658,38 @@ public class EC2RestServlet extends HttpServlet {
serializeResponse(response, EC2response);
}
private void modifyInstanceAttribute(HttpServletRequest request, HttpServletResponse response)
throws ADBException, XMLStreamException, IOException {
EC2ModifyInstanceAttribute ec2Request = new EC2ModifyInstanceAttribute();
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( instanceId != null && instanceId.length > 0 )
ec2Request.setInstanceId(instanceId[0]);
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
String[] instanceType = request.getParameterValues( "InstanceType.Value" );
String[] userData = request.getParameterValues( "UserData.Value" );
if ( instanceType != null && userData != null ) {
throw new EC2ServiceException( ClientError.InvalidParameterCombination, "Only one attribute can be" +
" specified at a time");
}
if ( instanceType != null && instanceType.length > 0 ) {
ec2Request.setInstanceType(instanceType[0]);
} else if ( userData != null && userData.length > 0 ) {
ec2Request.setUserData(userData[0]);
} else {
throw new EC2ServiceException( ClientError.MissingParamter,
"Missing parameter - InstanceType/UserData should be provided");
}
// -> execute the request
ModifyInstanceAttributeResponse EC2response = EC2SoapServiceImpl.toModifyInstanceAttributeResponse(
ServiceProvider.getInstance().getEC2Engine().modifyInstanceAttribute( ec2Request ));
serializeResponse(response, EC2response);
}
private void describeSnapshots( HttpServletRequest request, HttpServletResponse response )
throws ADBException, XMLStreamException, IOException
@ -1653,7 +1718,8 @@ public class EC2RestServlet extends HttpServlet {
// -> execute the request
EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
DescribeSnapshotsResponse EC2response = EC2SoapServiceImpl.toDescribeSnapshotsResponse( engine.handleRequest( EC2request ));
DescribeSnapshotsResponse EC2response = EC2SoapServiceImpl.toDescribeSnapshotsResponse(
engine.describeSnapshots( EC2request ));
serializeResponse(response, EC2response);
}
@ -1685,7 +1751,9 @@ public class EC2RestServlet extends HttpServlet {
}
// -> execute the request
DescribeVolumesResponse EC2response = EC2SoapServiceImpl.toDescribeVolumesResponse( ServiceProvider.getInstance().getEC2Engine().handleRequest( EC2request ));
EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
DescribeVolumesResponse EC2response = EC2SoapServiceImpl.toDescribeVolumesResponse(
ServiceProvider.getInstance().getEC2Engine().describeVolumes( EC2request ), engine);
serializeResponse(response, EC2response);
}
@ -1779,10 +1847,13 @@ public class EC2RestServlet extends HttpServlet {
throws ADBException, XMLStreamException, IOException {
String keyName = request.getParameter("KeyName");
if ( keyName == null ) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - KeyName");
}
String publicKeyMaterial = request.getParameter("PublicKeyMaterial");
if (keyName==null && publicKeyMaterial==null) {
response.sendError(530, "Missing parameter");
return;
if ( publicKeyMaterial == null ) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - PublicKeyMaterial");
}
if (!publicKeyMaterial.contains(" "))
@ -1804,9 +1875,8 @@ public class EC2RestServlet extends HttpServlet {
private void createKeyPair(HttpServletRequest request, HttpServletResponse response)
throws ADBException, XMLStreamException, IOException {
String keyName = request.getParameter("KeyName");
if (keyName==null) {
response.sendError(530, "Missing KeyName parameter");
return;
if (keyName==null) {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - KeyName");
}
EC2CreateKeyPair ec2Request = new EC2CreateKeyPair();
@ -1823,8 +1893,7 @@ public class EC2RestServlet extends HttpServlet {
throws ADBException, XMLStreamException, IOException {
String keyName = request.getParameter("KeyName");
if (keyName==null) {
response.sendError(530, "Missing KeyName parameter");
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - KeyName");
}
EC2DeleteKeyPair ec2Request = new EC2DeleteKeyPair();
@ -1839,8 +1908,7 @@ public class EC2RestServlet extends HttpServlet {
throws ADBException, XMLStreamException, IOException {
String instanceId = request.getParameter("InstanceId");
if (instanceId==null) {
response.sendError(530, "Missing InstanceId parameter");
return;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - InstanceId");
}
GetPasswordDataResponse EC2Response = EC2SoapServiceImpl.toGetPasswordData(
@ -1881,8 +1949,7 @@ public class EC2RestServlet extends HttpServlet {
nCount++;
} while (true);
if ( resourceIdList.isEmpty() ) {
response.sendError(530, "At least one Resource is required" );
return null;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ResourceId");
}
ec2Request = EC2SoapServiceImpl.toResourceTypeAndIds(ec2Request, resourceIdList);
@ -1899,8 +1966,7 @@ public class EC2RestServlet extends HttpServlet {
nCount++;
} while (true);
if ( resourceTagList.isEmpty() ) {
response.sendError(530, "At least one Tag is required" );
return null;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ResourceTag");
}
ec2Request = EC2SoapServiceImpl.toResourceTag(ec2Request, resourceTagList);
@ -1944,69 +2010,76 @@ public class EC2RestServlet extends HttpServlet {
String[] awsAccess = request.getParameterValues( "AWSAccessKeyId" );
if ( null != awsAccess && 0 < awsAccess.length )
cloudAccessKey = awsAccess[0];
else { response.sendError(530, "Missing AWSAccessKeyId parameter" ); return false; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - AWSAccessKeyId");
}
String[] clientSig = request.getParameterValues( "Signature" );
if ( null != clientSig && 0 < clientSig.length )
signature = clientSig[0];
else { response.sendError(530, "Missing Signature parameter" ); return false; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Signature");
}
String[] method = request.getParameterValues( "SignatureMethod" );
if ( null != method && 0 < method.length )
{
sigMethod = method[0];
if (!sigMethod.equals( "HmacSHA256" ) && !sigMethod.equals( "HmacSHA1" )) {
response.sendError(531, "Unsupported SignatureMethod value: " + sigMethod + " expecting: HmacSHA256 or HmacSHA1" );
return false;
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Unsupported SignatureMethod value: " + sigMethod + " expecting: HmacSHA256 or HmacSHA1");
}
} else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - SignatureMethod");
}
else { response.sendError(530, "Missing SignatureMethod parameter" ); return false; }
String[] version = request.getParameterValues( "Version" );
if ( null != version && 0 < version.length )
{
if (!version[0].equals( wsdlVersion )) {
response.sendError(531, "Unsupported Version value: " + version[0] + " expecting: " + wsdlVersion );
return false;
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Unsupported Version value: " + version[0] + " expecting: " + wsdlVersion);
}
} else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - Version");
}
else { response.sendError(530, "Missing Version parameter" ); return false; }
String[] sigVersion = request.getParameterValues( "SignatureVersion" );
if ( null != sigVersion && 0 < sigVersion.length )
{
if (!sigVersion[0].equals( "2" )) {
response.sendError(531, "Unsupported SignatureVersion value: " + sigVersion[0] + " expecting: 2" );
return false;
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Unsupported SignatureVersion value: " + sigVersion[0] + " expecting: 2");
}
}
else { response.sendError(530, "Missing SignatureVersion parameter" ); return false; }
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - SignatureVersion");
}
// -> can have only one but not both { Expires | Timestamp } headers
String[] expires = request.getParameterValues( "Expires" );
if ( null != expires && 0 < expires.length )
{
// -> contains the date and time at which the signature included in the request EXPIRES
if (hasSignatureExpired( expires[0] )) {
response.sendError(531, "Expires parameter indicates signature has expired: " + expires[0] );
return false;
if (hasSignatureExpired( expires[0] )) { //InvalidSecurity.RequestHasExpired
throw new EC2ServiceException( ClientError.InvalidSecurity_RequestHasExpired,
"Expires parameter indicates signature has expired: " + expires[0]);
}
}
else
{ // -> contains the date and time at which the request is SIGNED
String[] time = request.getParameterValues( "Timestamp" );
if ( null == time || 0 == time.length ) {
response.sendError(530, "Missing Timestamp and Expires parameter, one is required" );
return false;
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter -" +
" Timestamp/Expires");
}
}
// [B] Use the access key to get the users secret key from the cloud DB
cloudSecretKey = userDao.getSecretKeyByAccessKey( cloudAccessKey );
if ( cloudSecretKey == null ) {
logger.debug("No Secret key found for Access key '" + cloudAccessKey + "' in the the EC2 service");
throw new EC2ServiceException( ClientError.AuthFailure, "No Secret key found for Access key '" + cloudAccessKey +
"' in the the EC2 service" );
logger.debug( "Access key '" + cloudAccessKey + "' not found in the the EC2 service ");
throw new EC2ServiceException( ClientError.AuthFailure, "Access key '" + cloudAccessKey + "' not found in the the EC2 service ");
}
// [C] Verify the signature
@ -2050,8 +2123,9 @@ public class EC2RestServlet extends HttpServlet {
UserContext.current().initContext( cloudAccessKey, cloudSecretKey, cloudAccessKey, "REST request", null );
return true;
}
else throw new PermissionDeniedException("Invalid signature");
}
else throw new EC2ServiceException( ClientError.SignatureDoesNotMatch,
"The request signature calculated does not match the signature provided by the user.");
}
/**
* We check this to reduce replay attacks.

View File

@ -53,6 +53,7 @@ import com.cloud.bridge.service.core.ec2.EC2DescribeKeyPairs;
import com.cloud.bridge.service.core.ec2.EC2DescribeKeyPairsResponse;
import com.cloud.bridge.service.core.ec2.EC2ImageFilterSet;
import com.cloud.bridge.service.core.ec2.EC2ImageLaunchPermission;
import com.cloud.bridge.service.core.ec2.EC2ModifyInstanceAttribute;
import com.cloud.bridge.service.core.ec2.EC2ResourceTag;
import com.cloud.bridge.service.core.ec2.EC2DescribeSecurityGroups;
import com.cloud.bridge.service.core.ec2.EC2DescribeSecurityGroupsResponse;
@ -96,7 +97,6 @@ import com.cloud.bridge.service.core.ec2.EC2Volume;
import com.cloud.bridge.service.core.ec2.EC2VolumeFilterSet;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
import com.cloud.bridge.service.exception.EC2ServiceException.ServerError;
import com.cloud.bridge.util.EC2RestAuth;
@ -273,8 +273,8 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
List<String> resourceTypeList = new ArrayList<String>();
for (String resourceId : resourceIdList) {
if (!resourceId.contains(":") || resourceId.split(":").length != 2) {
throw new EC2ServiceException( ClientError.InvalidResourceId_Format,
"Invalid Format. ResourceId format is resource-type:resource-uuid");
throw new EC2ServiceException( ClientError.InvalidParameterValue,
"Invalid usage. ResourceId format is resource-type:resource-uuid");
}
String resourceType = resourceId.split(":")[0];
if (resourceTypeList.isEmpty())
@ -356,7 +356,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
request.setFilterSet( toAvailabiltyZonesFilterSet(fst));
}
return toDescribeAvailabilityZonesResponse( engine.handleRequest( request ));
return toDescribeAvailabilityZonesResponse( engine.describeAvailabilityZones( request ));
}
/**
@ -422,11 +422,11 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
EmptyElementType instanceType = diag.getInstanceType();
// -> toEC2DescribeInstances
if (null != instanceType) {
request.addInstanceId( diat.getInstanceId());
if (null != instanceType) {
request.addInstanceId( diat.getInstanceId());
return toDescribeInstanceAttributeResponse( engine.describeInstances( request ));
}
throw new EC2ServiceException( ClientError.Unsupported, "Unsupported - only instanceType supported");
throw new EC2ServiceException( ClientError.Unsupported, "Unsupported - only instanceType supported");
}
@ -549,7 +549,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
request = toSnapshotFilterSet( request, fst, timeFilters );
}
return toDescribeSnapshotsResponse(engine.handleRequest(request));
return toDescribeSnapshotsResponse(engine.describeSnapshots(request));
}
public DescribeTagsResponse describeTags(DescribeTags decsribeTags) {
@ -588,7 +588,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
request = toVolumeFilterSet( request, fst, timeFilters );
}
return toDescribeVolumesResponse( engine.handleRequest( request ));
return toDescribeVolumesResponse( engine.describeVolumes( request ), engine);
}
public DetachVolumeResponse detachVolume(DetachVolume detachVolume) {
@ -629,6 +629,26 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
throw new EC2ServiceException( ClientError.Unsupported, "Unsupported - can only modify image description or launchPermission");
}
public ModifyInstanceAttributeResponse modifyInstanceAttribute(ModifyInstanceAttribute modifyInstanceAttribute) {
EC2ModifyInstanceAttribute request = new EC2ModifyInstanceAttribute();
ModifyInstanceAttributeType modifyInstanceAttribute2 = modifyInstanceAttribute.getModifyInstanceAttribute();
ModifyInstanceAttributeTypeChoice_type0 mia = modifyInstanceAttribute2.getModifyInstanceAttributeTypeChoice_type0();
request.setInstanceId(modifyInstanceAttribute2.getInstanceId());
// we only support instanceType and userData
if (mia.getInstanceType() != null) {
request.setInstanceType(mia.getInstanceType().getValue());
} else if (mia.getUserData() != null) {
request.setUserData(mia.getUserData().getValue());
} else {
throw new EC2ServiceException( ClientError.MissingParamter,
"Missing required parameter - InstanceType/UserData should be provided");
}
return toModifyInstanceAttributeResponse(engine.modifyInstanceAttribute(request));
}
private void setAccountOrGroupList(LaunchPermissionItemType[] items, EC2ModifyImageAttribute request, String operation){
EC2ImageLaunchPermission launchPermission = new EC2ImageLaunchPermission();
@ -858,26 +878,20 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
response.setUnmonitorInstancesResponse( param1 );
return response;
}
public static DescribeImageAttributeResponse toDescribeImageAttributeResponse(EC2DescribeImagesResponse engineResponse) {
DescribeImageAttributeResponse response = new DescribeImageAttributeResponse();
DescribeImageAttributeResponseType param1 = new DescribeImageAttributeResponseType();
EC2Image[] imageSet = engineResponse.getImageSet();
if ( 0 < imageSet.length ) {
DescribeImageAttributeResponseTypeChoice_type0 param2 = new DescribeImageAttributeResponseTypeChoice_type0();
NullableAttributeValueType param3 = new NullableAttributeValueType();
param3.setValue( imageSet[0].getDescription());
param2.setDescription( param3 );
param1.setDescribeImageAttributeResponseTypeChoice_type0( param2 );
param1.setImageId( imageSet[0].getId());
}
param1.setRequestId( UUID.randomUUID().toString());
response.setDescribeImageAttributeResponse( param1 );
return response;
}
/**
* @param modifyInstanceAttribute
* @return
*/
public static ModifyInstanceAttributeResponse toModifyInstanceAttributeResponse(Boolean status) {
ModifyInstanceAttributeResponse miat = new ModifyInstanceAttributeResponse();
ModifyInstanceAttributeResponseType param = new ModifyInstanceAttributeResponseType();
param.set_return(status);
param.setRequestId(UUID.randomUUID().toString());
miat.setModifyInstanceAttributeResponse(param);
return miat;
}
public static DescribeImageAttributeResponse toDescribeImageAttributeResponse(EC2ImageAttributes engineResponse) {
DescribeImageAttributeResponse response = new DescribeImageAttributeResponse();
@ -1311,7 +1325,7 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
}
// toMethods
public static DescribeVolumesResponse toDescribeVolumesResponse( EC2DescribeVolumesResponse engineResponse )
public static DescribeVolumesResponse toDescribeVolumesResponse( EC2DescribeVolumesResponse engineResponse, EC2Engine engine )
{
DescribeVolumesResponse response = new DescribeVolumesResponse();
DescribeVolumesResponseType param1 = new DescribeVolumesResponseType();
@ -1342,8 +1356,8 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
AttachmentSetItemResponseType param5 = new AttachmentSetItemResponseType();
param5.setVolumeId(vol.getId().toString());
param5.setInstanceId(vol.getInstanceId().toString());
String devicePath = engine.cloudDeviceIdToDevicePath( vol.getHypervisor(), vol.getDeviceId());
param5.setDevice( devicePath );
String devicePath = engine.cloudDeviceIdToDevicePath( vol.getHypervisor(), vol.getDeviceId());
param5.setDevice( devicePath );
param5.setStatus(vol.getAttachmentState());
if (vol.getAttached() == null) {
param5.setAttachTime( cal );
@ -1876,7 +1890,10 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
param1.setVolumeId( engineResponse.getId().toString());
Long volSize = new Long( engineResponse.getSize());
param1.setSize( volSize.toString());
param1.setSnapshotId( "" );
if (engineResponse.getSnapshotId() != null)
param1.setSnapshotId( engineResponse.getSnapshotId() );
else
param1.setSnapshotId( "" );
param1.setAvailabilityZone( engineResponse.getZoneName());
if ( null != engineResponse.getState())
param1.setStatus( engineResponse.getState());
@ -2503,10 +2520,6 @@ public class EC2SoapServiceImpl implements AmazonEC2SkeletonInterface {
public ImportVolumeResponse importVolume(ImportVolume importVolume) {
throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");
}
public ModifyInstanceAttributeResponse modifyInstanceAttribute(ModifyInstanceAttribute modifyInstanceAttribute) {
throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");
}
public ModifySnapshotAttributeResponse modifySnapshotAttribute(ModifySnapshotAttribute modifySnapshotAttribute) {
throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");

View File

@ -26,6 +26,9 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2AddressFilterSet {
protected final static Logger logger = Logger.getLogger(EC2KeyPairFilterSet.class);
@ -43,16 +46,9 @@ public class EC2AddressFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value) {
// Changing this to silently ignore
logger.error("Unsupported filter [" + filterName + "] - 1");
return;
}
if (null != value && value.equalsIgnoreCase( "null" )) {
logger.error("Unsupported filter [" + filterName + "] - 2");
return;
}
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
// ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
filterSet.add( param );

View File

@ -26,6 +26,7 @@ import java.util.Map;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2AvailabilityZonesFilterSet {
@ -43,11 +44,9 @@ public class EC2AvailabilityZonesFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "]", 501 );
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "]", 501 );
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
filterSet.add( param );
}

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2GroupFilterSet {
@ -52,11 +53,9 @@ public class EC2GroupFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 1", 501 );
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 2", 501 );
if ( value == null || value.equalsIgnoreCase("null")) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
// ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
filterSet.add( param );

View File

@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2ImageFilterSet {
protected final static Logger logger = Logger.getLogger(EC2ImageFilterSet.class);
@ -51,10 +52,9 @@ public class EC2ImageFilterSet {
String filterName = param.getName();
if ( !filterName.startsWith("tag:") ) {
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 1", 501 );
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 2", 501 );
if ( value == null || value.equalsIgnoreCase("null")) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
}
filterSet.add( param );

View File

@ -24,6 +24,7 @@ import java.util.Map;
import com.cloud.bridge.service.EC2SoapServiceImpl;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2InstanceFilterSet {
@ -59,11 +60,10 @@ public class EC2InstanceFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "]", 501 );
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "]", 501 );
// ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
filterSet.add( param );
}

View File

@ -25,6 +25,9 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2KeyPairFilterSet {
protected final static Logger logger = Logger.getLogger(EC2KeyPairFilterSet.class);
@ -42,16 +45,9 @@ public class EC2KeyPairFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value) {
// Changing this to silently ignore
logger.error("Unsupported filter [" + filterName + "] - 1");
return;
}
if (null != value && value.equalsIgnoreCase( "null" )) {
logger.error("Unsupported filter [" + filterName + "] - 2");
return;
}
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
// ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
filterSet.add( param );

View File

@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.bridge.service.core.ec2;
public class EC2ModifyInstanceAttribute {
private String instanceId;
private String instanceType;
private String userData;
/**
* @return instanceId
*/
public String getInstanceId() {
return instanceId;
}
/**
* @param instanceId to set
*/
public void setInstanceId(String instanceId) {
this.instanceId = instanceId;
}
/**
* @return instanceType
*/
public String getInstanceType() {
return instanceType;
}
/**
* @param instanceType to set
*/
public void setInstanceType(String instanceType) {
this.instanceType = instanceType;
}
/**
* @return userData
*/
public String getUserData() {
return userData;
}
public void setUserData(String userData) {
this.userData = userData;
}
}

View File

@ -72,7 +72,7 @@ public class EC2RegisterImage {
if (null != param) {
if (!param.contains(":") || param.split(":").length < 4) {
throw new EC2ServiceException( ClientError.InvalidParameterValue, "Supported format for " +
"'architecture' is format:zonename:ostypename:hypervisor" );
"parameter 'architecture' is format:zonename:ostypename:hypervisor" );
}
String parts[] = param.split( ":" );
format = parts[0];
@ -80,9 +80,6 @@ public class EC2RegisterImage {
osTypeName = parts[2];
hypervisor = parts[3];
}
else {
throw new EC2ServiceException(ClientError.Unsupported, "Missing Parameter -" + " architecture");
}
}
public String getFormat() {

View File

@ -27,6 +27,7 @@ import java.util.TimeZone;
import com.cloud.bridge.service.UserContext;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
import com.cloud.bridge.util.DateHelper;
import com.cloud.bridge.util.EC2RestAuth;
@ -56,12 +57,9 @@ public class EC2SnapshotFilterSet {
String filterName = param.getName();
if (!filterName.startsWith("tag:")) {
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 1", 501 );
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 2", 501 );
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
}
// ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
filterSet.add( param );

View File

@ -26,6 +26,7 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
public class EC2TagsFilterSet {
protected final static Logger logger = Logger.getLogger(EC2TagsFilterSet.class);
@ -45,11 +46,9 @@ public class EC2TagsFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 1", 501 );
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 2", 501 );
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
filterSet.add( param );
}

View File

@ -26,6 +26,7 @@ import java.util.TimeZone;
import java.util.Date;
import com.cloud.bridge.service.exception.EC2ServiceException;
import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
import com.cloud.bridge.util.EC2RestAuth;
@ -61,11 +62,9 @@ public class EC2VolumeFilterSet {
String filterName = param.getName();
String value = (String) filterTypes.get( filterName );
if (null == value)
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 1", 501 );
if (null != value && value.equalsIgnoreCase( "null" ))
throw new EC2ServiceException( "Unsupported filter [" + filterName + "] - 2", 501 );
if ( value == null || value.equalsIgnoreCase("null") ) {
throw new EC2ServiceException( ClientError.InvalidFilter, "Filter '" + filterName + "' is invalid");
}
// ToDo we could add checks to make sure the type of a filters value is correct (e.g., an integer)
filterSet.add( param );
}

View File

@ -26,11 +26,11 @@ public class EC2ServiceException extends RuntimeException {
// ServerError & ClientError are correct as of schema version 2010-08-31
public static enum ServerError {
InsufficientAddressCapacity("Server.InsufficientAddressCapacity", 500),
InsufficientInstanceCapacity("Server.InsufficientInstanceCapacity", 500),
InsufficientReservedInstanceCapacity("Server.InsufficientReservedInstanceCapacity", 500),
InternalError("Server.InternalError", 500),
Unavailable("Server.Unavailable", 501);
InsufficientAddressCapacity("Server.InsufficientAddressCapacity", 500),
InsufficientInstanceCapacity("Server.InsufficientInstanceCapacity", 500),
InsufficientReservedInstanceCapacity("Server.InsufficientReservedInstanceCapacity", 500),
InternalError("Server.InternalError", 500),
Unavailable("Server.Unavailable", 501);
private String errorString;
private int httpErrorCode;
@ -45,58 +45,64 @@ public class EC2ServiceException extends RuntimeException {
}
public static enum ClientError {
AddressLimitExceeded("Client.AddressLimitExceeded", 400),
AttachmentLimitExceeded("Client.AttachmentLimitExceeded", 400),
AuthFailure("Client.AuthFailure", 400),
Blocked("Client.Blocked", 400),
FilterLimitExceeded("Client.FilterLimitExceeded", 400),
IdempotentParameterMismatch("Client.IdempotentParameterMismatch", 400),
IncorrectState("Client.IncorrectState", 400),
InstanceLimitExceeded("Client.InstanceLimitExceeded", 400),
InsufficientInstanceCapacity("Client.InsufficientInstanceCapacity", 400),
InsufficientReservedInstancesCapacity("Client.InsufficientReservedInstancesCapacity", 400),
InvalidAMIAttributeItemValue("Client.InvalidAMIAttributeItemValue", 400),
InvalidAMIID_Malformed("Client.InvalidAMIID.Malformed", 400),
InvalidAMIID_NotFound("Client.InvalidAMIID.NotFound", 400),
InvalidAMIID_Unavailable("Client.InvalidAMIID.Unavailable", 400),
InvalidAttachment_NotFound("Client.InvalidAttachment.NotFound", 400),
InvalidDevice_InUse("Client.InvalidDevice.InUse", 400),
InvalidGroup_Duplicate("Client.InvalidGroup.Duplicate", 400),
InvalidGroup_InUse("Client.InvalidGroup.InUse", 400),
InvalidGroup_NotFound("Client.InvalidGroup.NotFound", 400),
InvalidGroup_Reserved("Client.InvalidGroup.Reserved", 400),
InvalidInstanceID_Malformed("Client.InvalidInstanceID.Malformed", 400),
InvalidInstanceID_NotFound("Client.InvalidInstanceID.NotFound", 400),
InvalidIPAddress_InUse("Client.InvalidIPAddress.InUse", 400),
InvalidKeyPair_Duplicate("Client.InvalidKeyPair.Duplicate", 400),
InvalidKeyPair_Format("Client.InvalidKeyPair.Format", 400),
InvalidKeyPair_NotFound("Client.InvalidKeyPair.NotFound", 400),
InvalidManifest("Client.InvalidManifest", 400),
InvalidParameterCombination("Client.InvalidParameterCombination", 400),
InvalidParameterValue("Client.InvalidParameterValue", 400),
InvalidPermission_Duplicate("Client.InvalidPermission.Duplicate", 400),
InvalidPermission_Malformed("Client.InvalidPermission.Malformed", 400),
InvalidReservationID_Malformed("Client.InvalidReservationID.Malformed", 400),
InvalidReservationID_NotFound("Client.InvalidReservationID.NotFound", 400),
InvalidResourceId_Format("Client.InvalidResourceId.Format", 400),
InvalidSnapshotID_Malformed("Client.InvalidSnapshotID.Malformed", 400),
InvalidSnapshot_NotFound("Client.InvalidSnapshot.NotFound", 400),
InvalidUserID_Malformed("Client.InvalidUserID.Malformed", 400),
InvalidReservedInstancesId("Client.InvalidReservedInstancesId", 400),
InvalidReservedInstancesOfferingId("Client.InvalidReservedInstancesOfferingId", 400),
InvalidVolumeID_Duplicate("Client.InvalidVolumeID.Duplicate", 400),
InvalidVolumeID_Malformed("Client.InvalidVolumeID.Malformed", 400),
InvalidVolume_NotFound("Client.InvalidVolume.NotFound", 400),
InvalidVolumeID_ZoneMismatch("Client.InvalidVolumeID.ZoneMismatch", 400),
InvalidZone_NotFound("Client.InvalidZone.NotFound", 400),
NonEBSInstance("Client.NonEBSInstance", 400),
PendingVerification("Client.PendingVerification", 400),
PendingSnapshotLimitExceeded("Client.PendingSnapshotLimitExceeded", 400),
ReservedInstancesLimitExceeded("Client.ReservedInstancesLimitExceeded", 400),
SnapshotLimitExceeded("Client.SnapshotLimitExceeded", 400),
UnknownParameter("Client.UnknownParameter", 400),
Unsupported("Client.Unsupported", 400),
VolumeLimitExceeded("Client.VolumeLimitExceeded", 400);
AddressLimitExceeded("Client.AddressLimitExceeded", 400),
AttachmentLimitExceeded("Client.AttachmentLimitExceeded", 400),
AuthFailure("Client.AuthFailure", 400),
Blocked("Client.Blocked", 400),
DependencyViolation("Client.DependencyViolation", 400),
FilterLimitExceeded("Client.FilterLimitExceeded", 400),
IdempotentParameterMismatch("Client.IdempotentParameterMismatch", 400),
IncorrectState("Client.IncorrectState", 400),
IncorrectInstanceState("Client.IncorrectInstanceState", 400),
InstanceLimitExceeded("Client.InstanceLimitExceeded", 400),
InsufficientInstanceCapacity("Client.InsufficientInstanceCapacity", 400),
InsufficientReservedInstancesCapacity("Client.InsufficientReservedInstancesCapacity", 400),
InvalidAMIAttributeItemValue("Client.InvalidAMIAttributeItemValue", 400),
InvalidAMIID_Malformed("Client.InvalidAMIID.Malformed", 400),
InvalidAMIID_NotFound("Client.InvalidAMIID.NotFound", 400),
InvalidAMIID_Unavailable("Client.InvalidAMIID.Unavailable", 400),
InvalidAttachment_NotFound("Client.InvalidAttachment.NotFound", 400),
InvalidDevice_InUse("Client.InvalidDevice.InUse", 400),
InvalidFilter("Client.InvalidFilter", 400),
InvalidGroup_Duplicate("Client.InvalidGroup.Duplicate", 400),
InvalidGroup_InUse("Client.InvalidGroup.InUse", 400),
InvalidGroup_NotFound("Client.InvalidGroup.NotFound", 400),
InvalidGroup_Reserved("Client.InvalidGroup.Reserved", 400),
InvalidInstanceID_Malformed("Client.InvalidInstanceID.Malformed", 400),
InvalidInstanceID_NotFound("Client.InvalidInstanceID.NotFound", 400),
InvalidIPAddress_InUse("Client.InvalidIPAddress.InUse", 400),
InvalidKeyPair_Duplicate("Client.InvalidKeyPair.Duplicate", 400),
InvalidKeyPair_Format("Client.InvalidKeyPair.Format", 400),
InvalidKeyPair_NotFound("Client.InvalidKeyPair.NotFound", 400),
InvalidManifest("Client.InvalidManifest", 400),
InvalidParameterCombination("Client.InvalidParameterCombination", 400),
InvalidParameterValue("Client.InvalidParameterValue", 400),
InvalidPermission_Duplicate("Client.InvalidPermission.Duplicate", 400),
InvalidPermission_Malformed("Client.InvalidPermission.Malformed", 400),
InvalidReservationID_Malformed("Client.InvalidReservationID.Malformed", 400),
InvalidReservationID_NotFound("Client.InvalidReservationID.NotFound", 400),
InvalidSecurity_RequestHasExpired("Client.InvalidSecurity.RequestHasExpired", 400),
InvalidSnapshotID_Malformed("Client.InvalidSnapshotID.Malformed", 400),
InvalidSnapshot_NotFound("Client.InvalidSnapshot.NotFound", 400),
InvalidUserID_Malformed("Client.InvalidUserID.Malformed", 400),
InvalidReservedInstancesId("Client.InvalidReservedInstancesId", 400),
InvalidReservedInstancesOfferingId("Client.InvalidReservedInstancesOfferingId", 400),
InvalidVolumeID_Duplicate("Client.InvalidVolumeID.Duplicate", 400),
InvalidVolumeID_Malformed("Client.InvalidVolumeID.Malformed", 400),
InvalidVolume_NotFound("Client.InvalidVolume.NotFound", 400),
InvalidVolumeID_ZoneMismatch("Client.InvalidVolumeID.ZoneMismatch", 400),
InvalidZone_NotFound("Client.InvalidZone.NotFound", 400),
MissingParamter("Client.MissingParamter", 400),
NonEBSInstance("Client.NonEBSInstance", 400),
PendingVerification("Client.PendingVerification", 400),
PendingSnapshotLimitExceeded("Client.PendingSnapshotLimitExceeded", 400),
SignatureDoesNotMatch("Client.SignatureDoesNotMatch", 400),
ReservedInstancesLimitExceeded("Client.ReservedInstancesLimitExceeded", 400),
ResourceLimitExceeded("Client.ResourceLimitExceeded", 400),
SnapshotLimitExceeded("Client.SnapshotLimitExceeded", 400),
UnknownParameter("Client.UnknownParameter", 400),
Unsupported("Client.UnsupportedOperation", 400),
VolumeLimitExceeded("Client.VolumeLimitExceeded", 400);
private String errorString;
private int httpErrorCode;

View File

@ -103,8 +103,8 @@ public class CloudStackClient {
int jobStatus = queryAsyncJobResponse.getAsInt("queryasyncjobresultresponse.jobstatus");
switch(jobStatus) {
case 2:
throw new Exception(queryAsyncJobResponse.getAsString("queryasyncjobresultresponse.jobresult.errorcode") + " " +
queryAsyncJobResponse.getAsString("queryasyncjobresultresponse.jobresult.errortext"));
throw new Exception(queryAsyncJobResponse.getAsString("queryasyncjobresultresponse.jobresult.errortext") + " Error Code - " +
queryAsyncJobResponse.getAsString("queryasyncjobresultresponse.jobresult.errorcode") );
case 0 :
try {
@ -179,6 +179,7 @@ public class CloudStackClient {
if(errorMessage == null){
errorMessage = "CloudStack API call HTTP response error, HTTP status code: " + statusCode;
}
errorMessage = errorMessage.concat(" Error Code - " + Integer.toString(statusCode));
throw new IOException(errorMessage);
}