serializeResponse(response, EC2response);
}
private void runInstances( HttpServletRequest request, HttpServletResponse response )
throws ADBException, XMLStreamException, IOException {
EC2RunInstances EC2request = new EC2RunInstances();
// -> so in the Amazon docs for this REST call there is no userData even though there is in the SOAP docs
String[] imageId = request.getParameterValues( "ImageId" );
if ( null != imageId && 0 < imageId.length )
EC2request.setTemplateId( imageId[0] );
else {
throw new EC2ServiceException( ClientError.MissingParamter, "Missing required parameter - ImageId");
}
String[] minCount = request.getParameterValues( "MinCount" );
if ( minCount == null || minCount.length < 1) {
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");
} else {
EC2request.setMinCount( Integer.parseInt( minCount[0]) );
}
String[] maxCount = request.getParameterValues( "MaxCount" );
if ( maxCount == null || maxCount.length < 1) {
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");
} else {
EC2request.setMaxCount( Integer.parseInt( maxCount[0]) );
}
String[] instanceType = request.getParameterValues( "InstanceType" );
if ( null != instanceType && 0 < instanceType.length )
EC2request.setInstanceType( instanceType[0] );
String[] zoneName = request.getParameterValues( "Placement.AvailabilityZone" );
if ( null != zoneName && 0 < zoneName.length )
EC2request.setZoneName( zoneName[0] );
String[] size = request.getParameterValues("size");
if (size != null) {
EC2request.setSize(Integer.valueOf(size[0]));
}
String[] keyName = request.getParameterValues("KeyName");
if (keyName != null) {
EC2request.setKeyName(keyName[0]);
}
String[] userData = request.getParameterValues("UserData");
if ( userData != null) {
EC2request.setUserData( userData[0]);
}
Enumeration<?> names = request.getParameterNames();
while( names.hasMoreElements()) {
String key = (String)names.nextElement();
if ( key.startsWith("SecurityGroup")) {
String[] value = request.getParameterValues(key);
if (null != value && 0 < value.length) {
if ( key.startsWith("SecurityGroupId"))
EC2request.addSecuritGroupId( value[0]);
else
EC2request.addSecuritGroupName( value[0]);
}
}
}
// -> execute the request