You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/01/15 03:04:54 UTC
[41/44] Revert "Merge remote-tracking branch 'origin/javelin' into
javelin"
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/110465b5/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
index 4f74873..8309bfd 100644
--- a/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
+++ b/awsapi/src/com/cloud/bridge/service/EC2RestServlet.java
@@ -39,6 +39,7 @@ import java.util.List;
import java.util.Properties;
import java.util.UUID;
+import javax.inject.Inject;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -132,184 +133,183 @@ import com.cloud.bridge.service.core.ec2.EC2StopInstances;
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.NoSuchObjectException;
import com.cloud.bridge.service.exception.PermissionDeniedException;
-import com.cloud.bridge.service.exception.EC2ServiceException.ClientError;
import com.cloud.bridge.util.AuthenticationUtils;
import com.cloud.bridge.util.ConfigurationHelper;
import com.cloud.bridge.util.EC2RestAuth;
import com.cloud.stack.models.CloudStackAccount;
-import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.Transaction;
public class EC2RestServlet extends HttpServlet {
- private static final long serialVersionUID = -6168996266762804888L;
- protected final UserCredentialsDaoImpl ucDao = ComponentLocator.inject(UserCredentialsDaoImpl.class);
- protected final OfferingDaoImpl ofDao = ComponentLocator.inject(OfferingDaoImpl.class);
-
- public static final Logger logger = Logger.getLogger(EC2RestServlet.class);
-
- private OMFactory factory = OMAbstractFactory.getOMFactory();
- private XMLOutputFactory xmlOutFactory = XMLOutputFactory.newInstance();
-
- private String pathToKeystore = null;
- private String keystorePassword = null;
- private String wsdlVersion = null;
- private String version = null;
-
- boolean debug=true;
-
-
- /**
- * We build the path to where the keystore holding the WS-Security X509 certificates
- * are stored.
- */
- @Override
- public void init( ServletConfig config ) throws ServletException {
- File propertiesFile = ConfigurationHelper.findConfigurationFile("ec2-service.properties");
- Properties EC2Prop = null;
-
- if (null != propertiesFile) {
- logger.info("Use EC2 properties file: " + propertiesFile.getAbsolutePath());
- EC2Prop = new Properties();
- try {
- EC2Prop.load( new FileInputStream( propertiesFile ));
- } catch (FileNotFoundException e) {
- logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
- } catch (IOException e) {
- logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
- }
- String keystore = EC2Prop.getProperty( "keystore" );
- keystorePassword = EC2Prop.getProperty( "keystorePass" );
- wsdlVersion = EC2Prop.getProperty( "WSDLVersion", "2010-11-15" );
- version = EC2Prop.getProperty( "cloudbridgeVersion", "UNKNOWN VERSION" );
-
- String installedPath = System.getenv("CATALINA_HOME");
- if (installedPath == null) installedPath = System.getenv("CATALINA_BASE");
- if (installedPath == null) installedPath = System.getProperty("catalina.home");
- String webappPath = config.getServletContext().getRealPath("/");
- //pathToKeystore = new String( installedPath + File.separator + "webapps" + File.separator + webappName + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + keystore );
- pathToKeystore = new String( webappPath + "WEB-INF" + File.separator + "classes" + File.separator + keystore );
- }
+ private static final long serialVersionUID = -6168996266762804888L;
+ @Inject UserCredentialsDaoImpl ucDao;
+ @Inject OfferingDaoImpl ofDao;
+
+ public static final Logger logger = Logger.getLogger(EC2RestServlet.class);
+
+ private final OMFactory factory = OMAbstractFactory.getOMFactory();
+ private final XMLOutputFactory xmlOutFactory = XMLOutputFactory.newInstance();
+
+ private String pathToKeystore = null;
+ private String keystorePassword = null;
+ private String wsdlVersion = null;
+ private String version = null;
+
+ boolean debug=true;
+
+
+ /**
+ * We build the path to where the keystore holding the WS-Security X509 certificates
+ * are stored.
+ */
+ @Override
+ public void init( ServletConfig config ) throws ServletException {
+ File propertiesFile = ConfigurationHelper.findConfigurationFile("ec2-service.properties");
+ Properties EC2Prop = null;
+
+ if (null != propertiesFile) {
+ logger.info("Use EC2 properties file: " + propertiesFile.getAbsolutePath());
+ EC2Prop = new Properties();
+ try {
+ EC2Prop.load( new FileInputStream( propertiesFile ));
+ } catch (FileNotFoundException e) {
+ logger.warn("Unable to open properties file: " + propertiesFile.getAbsolutePath(), e);
+ } catch (IOException e) {
+ logger.warn("Unable to read properties file: " + propertiesFile.getAbsolutePath(), e);
+ }
+ String keystore = EC2Prop.getProperty( "keystore" );
+ keystorePassword = EC2Prop.getProperty( "keystorePass" );
+ wsdlVersion = EC2Prop.getProperty( "WSDLVersion", "2010-11-15" );
+ version = EC2Prop.getProperty( "cloudbridgeVersion", "UNKNOWN VERSION" );
+
+ String installedPath = System.getenv("CATALINA_HOME");
+ if (installedPath == null) installedPath = System.getenv("CATALINA_BASE");
+ if (installedPath == null) installedPath = System.getProperty("catalina.home");
+ String webappPath = config.getServletContext().getRealPath("/");
+ //pathToKeystore = new String( installedPath + File.separator + "webapps" + File.separator + webappName + File.separator + "WEB-INF" + File.separator + "classes" + File.separator + keystore );
+ pathToKeystore = new String( webappPath + "WEB-INF" + File.separator + "classes" + File.separator + keystore );
+ }
}
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
- doGetOrPost(req, resp);
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
+ doGetOrPost(req, resp);
}
-
+
@Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
- doGetOrPost(req, resp);
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
+ doGetOrPost(req, resp);
}
protected void doGetOrPost(HttpServletRequest request, HttpServletResponse response) {
-
- if(debug){
- System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.request_uri: "+request.getAttribute("javax.servlet.forward.request_uri"));
- System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.context_path: "+request.getAttribute("javax.servlet.forward.context_path"));
- System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.servlet_path: "+request.getAttribute("javax.servlet.forward.servlet_path"));
- System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.path_info: "+request.getAttribute("javax.servlet.forward.path_info"));
- System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.query_string: "+request.getAttribute("javax.servlet.forward.query_string"));
-
- }
-
-
- String action = request.getParameter( "Action" );
- logRequest(request);
-
- // -> unauthenticated calls, should still be done over HTTPS
- if (action.equalsIgnoreCase( "SetUserKeys" )) {
- setUserKeys(request, response);
- return;
- }
-
- if (action.equalsIgnoreCase( "CloudEC2Version" )) {
- cloudEC2Version(request, response);
- return;
- }
-
- // -> authenticated calls
+
+ if(debug){
+ System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.request_uri: "+request.getAttribute("javax.servlet.forward.request_uri"));
+ System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.context_path: "+request.getAttribute("javax.servlet.forward.context_path"));
+ System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.servlet_path: "+request.getAttribute("javax.servlet.forward.servlet_path"));
+ System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.path_info: "+request.getAttribute("javax.servlet.forward.path_info"));
+ System.out.println("EC2RestServlet.doGetOrPost: javax.servlet.forward.query_string: "+request.getAttribute("javax.servlet.forward.query_string"));
+
+ }
+
+
+ String action = request.getParameter( "Action" );
+ logRequest(request);
+
+ // -> unauthenticated calls, should still be done over HTTPS
+ if (action.equalsIgnoreCase( "SetUserKeys" )) {
+ setUserKeys(request, response);
+ return;
+ }
+
+ if (action.equalsIgnoreCase( "CloudEC2Version" )) {
+ cloudEC2Version(request, response);
+ return;
+ }
+
+ // -> authenticated calls
try {
- if (!authenticateRequest( request, response )) return;
-
- if (action.equalsIgnoreCase( "AllocateAddress" )) allocateAddress(request, response);
- else if (action.equalsIgnoreCase( "AssociateAddress" )) associateAddress(request, response);
- else if (action.equalsIgnoreCase( "AttachVolume" )) attachVolume(request, response );
- else if (action.equalsIgnoreCase( "AuthorizeSecurityGroupIngress" )) authorizeSecurityGroupIngress(request, response);
- else if (action.equalsIgnoreCase( "CreateImage" )) createImage(request, response);
- else if (action.equalsIgnoreCase( "CreateSecurityGroup" )) createSecurityGroup(request, response);
- else if (action.equalsIgnoreCase( "CreateSnapshot" )) createSnapshot(request, response);
- else if (action.equalsIgnoreCase( "CreateVolume" )) createVolume(request, response);
- else if (action.equalsIgnoreCase( "DeleteSecurityGroup" )) deleteSecurityGroup(request, response);
- else if (action.equalsIgnoreCase( "DeleteSnapshot" )) deleteSnapshot(request, response);
- else if (action.equalsIgnoreCase( "DeleteVolume" )) deleteVolume(request, response);
- else if (action.equalsIgnoreCase( "DeregisterImage" )) deregisterImage(request, response);
- else if (action.equalsIgnoreCase( "DescribeAddresses" )) describeAddresses(request, response);
- else if (action.equalsIgnoreCase( "DescribeAvailabilityZones" )) describeAvailabilityZones(request, response);
- else if (action.equalsIgnoreCase( "DescribeImageAttribute" )) describeImageAttribute(request, response);
- else if (action.equalsIgnoreCase( "DescribeImages" )) describeImages(request, response);
- else if (action.equalsIgnoreCase( "DescribeInstanceAttribute" )) describeInstanceAttribute(request, response);
- else if (action.equalsIgnoreCase( "DescribeInstances" )) describeInstances(request, response);
- else if (action.equalsIgnoreCase( "DescribeSecurityGroups" )) describeSecurityGroups(request, response);
- else if (action.equalsIgnoreCase( "DescribeSnapshots" )) describeSnapshots(request, response);
- else if (action.equalsIgnoreCase( "DescribeVolumes" )) describeVolumes(request, response);
- 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( "RebootInstances" )) rebootInstances(request, response);
- else if (action.equalsIgnoreCase( "RegisterImage" )) registerImage(request, response);
- else if (action.equalsIgnoreCase( "ReleaseAddress" )) releaseAddress(request, response);
- else if (action.equalsIgnoreCase( "ResetImageAttribute" )) resetImageAttribute(request, response);
- else if (action.equalsIgnoreCase( "RevokeSecurityGroupIngress")) revokeSecurityGroupIngress(request, response);
- else if (action.equalsIgnoreCase( "RunInstances" )) runInstances(request, response);
- else if (action.equalsIgnoreCase( "StartInstances" )) startInstances(request, response);
- else if (action.equalsIgnoreCase( "StopInstances" )) stopInstances(request, response);
- else if (action.equalsIgnoreCase( "TerminateInstances" )) terminateInstances(request, response);
- else if (action.equalsIgnoreCase( "SetCertificate" )) setCertificate(request, response);
- else if (action.equalsIgnoreCase( "DeleteCertificate" )) deleteCertificate(request, response);
- else if (action.equalsIgnoreCase( "SetOfferMapping" )) setOfferMapping(request, response);
- else if (action.equalsIgnoreCase( "DeleteOfferMapping" )) deleteOfferMapping(request, response);
- else if (action.equalsIgnoreCase( "CreateKeyPair" )) createKeyPair(request, response);
- else if (action.equalsIgnoreCase( "ImportKeyPair" )) importKeyPair(request, response);
- else if (action.equalsIgnoreCase( "DeleteKeyPair" )) deleteKeyPair(request, response);
- else if (action.equalsIgnoreCase( "DescribeKeyPairs" )) describeKeyPairs(request, response);
- else if (action.equalsIgnoreCase( "GetPasswordData" )) getPasswordData(request, response);
- else {
- logger.error("Unsupported action " + action);
- throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");
- }
-
+ if (!authenticateRequest( request, response )) return;
+
+ if (action.equalsIgnoreCase( "AllocateAddress" )) allocateAddress(request, response);
+ else if (action.equalsIgnoreCase( "AssociateAddress" )) associateAddress(request, response);
+ else if (action.equalsIgnoreCase( "AttachVolume" )) attachVolume(request, response );
+ else if (action.equalsIgnoreCase( "AuthorizeSecurityGroupIngress" )) authorizeSecurityGroupIngress(request, response);
+ else if (action.equalsIgnoreCase( "CreateImage" )) createImage(request, response);
+ else if (action.equalsIgnoreCase( "CreateSecurityGroup" )) createSecurityGroup(request, response);
+ else if (action.equalsIgnoreCase( "CreateSnapshot" )) createSnapshot(request, response);
+ else if (action.equalsIgnoreCase( "CreateVolume" )) createVolume(request, response);
+ else if (action.equalsIgnoreCase( "DeleteSecurityGroup" )) deleteSecurityGroup(request, response);
+ else if (action.equalsIgnoreCase( "DeleteSnapshot" )) deleteSnapshot(request, response);
+ else if (action.equalsIgnoreCase( "DeleteVolume" )) deleteVolume(request, response);
+ else if (action.equalsIgnoreCase( "DeregisterImage" )) deregisterImage(request, response);
+ else if (action.equalsIgnoreCase( "DescribeAddresses" )) describeAddresses(request, response);
+ else if (action.equalsIgnoreCase( "DescribeAvailabilityZones" )) describeAvailabilityZones(request, response);
+ else if (action.equalsIgnoreCase( "DescribeImageAttribute" )) describeImageAttribute(request, response);
+ else if (action.equalsIgnoreCase( "DescribeImages" )) describeImages(request, response);
+ else if (action.equalsIgnoreCase( "DescribeInstanceAttribute" )) describeInstanceAttribute(request, response);
+ else if (action.equalsIgnoreCase( "DescribeInstances" )) describeInstances(request, response);
+ else if (action.equalsIgnoreCase( "DescribeSecurityGroups" )) describeSecurityGroups(request, response);
+ else if (action.equalsIgnoreCase( "DescribeSnapshots" )) describeSnapshots(request, response);
+ else if (action.equalsIgnoreCase( "DescribeVolumes" )) describeVolumes(request, response);
+ 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( "RebootInstances" )) rebootInstances(request, response);
+ else if (action.equalsIgnoreCase( "RegisterImage" )) registerImage(request, response);
+ else if (action.equalsIgnoreCase( "ReleaseAddress" )) releaseAddress(request, response);
+ else if (action.equalsIgnoreCase( "ResetImageAttribute" )) resetImageAttribute(request, response);
+ else if (action.equalsIgnoreCase( "RevokeSecurityGroupIngress")) revokeSecurityGroupIngress(request, response);
+ else if (action.equalsIgnoreCase( "RunInstances" )) runInstances(request, response);
+ else if (action.equalsIgnoreCase( "StartInstances" )) startInstances(request, response);
+ else if (action.equalsIgnoreCase( "StopInstances" )) stopInstances(request, response);
+ else if (action.equalsIgnoreCase( "TerminateInstances" )) terminateInstances(request, response);
+ else if (action.equalsIgnoreCase( "SetCertificate" )) setCertificate(request, response);
+ else if (action.equalsIgnoreCase( "DeleteCertificate" )) deleteCertificate(request, response);
+ else if (action.equalsIgnoreCase( "SetOfferMapping" )) setOfferMapping(request, response);
+ else if (action.equalsIgnoreCase( "DeleteOfferMapping" )) deleteOfferMapping(request, response);
+ else if (action.equalsIgnoreCase( "CreateKeyPair" )) createKeyPair(request, response);
+ else if (action.equalsIgnoreCase( "ImportKeyPair" )) importKeyPair(request, response);
+ else if (action.equalsIgnoreCase( "DeleteKeyPair" )) deleteKeyPair(request, response);
+ else if (action.equalsIgnoreCase( "DescribeKeyPairs" )) describeKeyPairs(request, response);
+ else if (action.equalsIgnoreCase( "GetPasswordData" )) getPasswordData(request, response);
+ else {
+ logger.error("Unsupported action " + action);
+ throw new EC2ServiceException(ClientError.Unsupported, "This operation is not available");
+ }
+
} catch( EC2ServiceException e ) {
- response.setStatus(e.getErrorCode());
-
- if (e.getCause() != null && e.getCause() instanceof AxisFault)
- faultResponse(response, ((AxisFault)e.getCause()).getFaultCode().getLocalPart(), e.getMessage());
- else {
- logger.error("EC2ServiceException: " + e.getMessage(), e);
- endResponse(response, e.toString());
- }
+ response.setStatus(e.getErrorCode());
+
+ if (e.getCause() != null && e.getCause() instanceof AxisFault)
+ faultResponse(response, ((AxisFault)e.getCause()).getFaultCode().getLocalPart(), e.getMessage());
+ else {
+ logger.error("EC2ServiceException: " + e.getMessage(), e);
+ endResponse(response, e.toString());
+ }
} catch( PermissionDeniedException e ) {
- logger.error("Unexpected exception: " + e.getMessage(), e);
- response.setStatus(403);
- endResponse(response, "Access denied");
-
+ logger.error("Unexpected exception: " + e.getMessage(), e);
+ response.setStatus(403);
+ endResponse(response, "Access denied");
+
} catch( Exception e ) {
- logger.error("Unexpected exception: " + e.getMessage(), e);
- response.setStatus(500);
- endResponse(response, e.toString());
-
+ logger.error("Unexpected exception: " + e.getMessage(), e);
+ response.setStatus(500);
+ endResponse(response, e.toString());
+
} finally {
- try {
- response.flushBuffer();
- } catch (IOException e) {
- logger.error("Unexpected exception " + e.getMessage(), e);
- }
+ try {
+ response.flushBuffer();
+ } catch (IOException e) {
+ logger.error("Unexpected exception " + e.getMessage(), e);
+ }
}
}
-
+
/**
* Provide an easy way to determine the version of the implementation running.
*
@@ -320,7 +320,7 @@ public class EC2RestServlet extends HttpServlet {
response.setStatus(200);
endResponse(response, version_response);
}
-
+
/**
* This request registers the Cloud.com account holder to the EC2 service. The Cloud.com
* account holder saves his API access and secret keys with the EC2 service so that
@@ -340,54 +340,54 @@ public class EC2RestServlet extends HttpServlet {
* As with all REST calls HTTPS should be used to ensure their security.
*/
private void setUserKeys( HttpServletRequest request, HttpServletResponse response ) {
- String[] accessKey = null;
- String[] secretKey = null;
- Transaction txn = null;
- try {
- // -> all these parameters are required
+ String[] accessKey = null;
+ String[] secretKey = null;
+ Transaction txn = null;
+ try {
+ // -> all these parameters are required
accessKey = request.getParameterValues( "accesskey" );
- if ( null == accessKey || 0 == accessKey.length ) {
- response.sendError(530, "Missing accesskey parameter" );
- return;
- }
+ if ( null == accessKey || 0 == accessKey.length ) {
+ response.sendError(530, "Missing accesskey parameter" );
+ return;
+ }
secretKey = request.getParameterValues( "secretkey" );
if ( null == secretKey || 0 == secretKey.length ) {
- response.sendError(530, "Missing secretkey parameter" );
- return;
+ response.sendError(530, "Missing secretkey parameter" );
+ return;
}
} catch( Exception e ) {
- logger.error("SetUserKeys exception " + e.getMessage(), e);
- response.setStatus(500);
- endResponse(response, "SetUserKeys exception " + e.getMessage());
- return;
+ logger.error("SetUserKeys exception " + e.getMessage(), e);
+ response.setStatus(500);
+ endResponse(response, "SetUserKeys exception " + e.getMessage());
+ return;
}
-
- // prime UserContext here
+
+ // prime UserContext here
// logger.debug("initializing context");
- UserContext context = UserContext.current();
+ UserContext context = UserContext.current();
try {
txn = Transaction.open(Transaction.AWSAPI_DB);
// -> use the keys to see if the account actually exists
- ServiceProvider.getInstance().getEC2Engine().validateAccount( accessKey[0], secretKey[0] );
-/* UserCredentialsDao credentialDao = new UserCredentialsDao();
+ ServiceProvider.getInstance().getEC2Engine().validateAccount( accessKey[0], secretKey[0] );
+ /* UserCredentialsDao credentialDao = new UserCredentialsDao();
credentialDao.setUserKeys( );
-*/ UserCredentialsVO user = new UserCredentialsVO(accessKey[0], secretKey[0]);
- ucDao.persist(user);
- txn.commit();
-
+ */ UserCredentialsVO user = new UserCredentialsVO(accessKey[0], secretKey[0]);
+ ucDao.persist(user);
+ txn.commit();
+
} catch( Exception e ) {
- logger.error("SetUserKeys " + e.getMessage(), e);
- response.setStatus(401);
- endResponse(response, e.toString());
- txn.close();
- return;
+ logger.error("SetUserKeys " + e.getMessage(), e);
+ response.setStatus(401);
+ endResponse(response, e.toString());
+ txn.close();
+ return;
}
- response.setStatus(200);
+ response.setStatus(200);
endResponse(response, "User keys set successfully");
}
-
+
/**
* The SOAP API for EC2 uses WS-Security to sign all client requests. This requires that
* the client have a public/private key pair and the public key defined by a X509 certificate.
@@ -405,46 +405,46 @@ public class EC2RestServlet extends HttpServlet {
* simply over writes any previously stored value.
*/
private void setCertificate( HttpServletRequest request, HttpServletResponse response )
- throws Exception {
+ throws Exception {
Transaction txn = null;
- try {
- // [A] Pull the cert and cloud AccessKey from the request
+ try {
+ // [A] Pull the cert and cloud AccessKey from the request
String[] certificate = request.getParameterValues( "cert" );
- if (null == certificate || 0 == certificate.length) {
- response.sendError(530, "Missing cert parameter" );
- return;
- }
+ if (null == certificate || 0 == certificate.length) {
+ response.sendError(530, "Missing cert parameter" );
+ return;
+ }
// logger.debug( "SetCertificate cert: [" + certificate[0] + "]" );
-
+
String [] accessKey = request.getParameterValues( "AWSAccessKeyId" );
- if ( null == accessKey || 0 == accessKey.length ) {
- response.sendError(530, "Missing AWSAccessKeyId parameter" );
- return;
- }
-
- // [B] Open our keystore
- FileInputStream fsIn = new FileInputStream( pathToKeystore );
- KeyStore certStore = KeyStore.getInstance( "JKS" );
- certStore.load( fsIn, keystorePassword.toCharArray());
-
- // -> use the Cloud API key to save the cert in the keystore
- // -> write the cert into the keystore on disk
- Certificate userCert = null;
- CertificateFactory cf = CertificateFactory.getInstance( "X.509" );
-
- ByteArrayInputStream bs = new ByteArrayInputStream( certificate[0].getBytes());
- while (bs.available() > 0) userCert = cf.generateCertificate(bs);
- certStore.setCertificateEntry( accessKey[0], userCert );
-
- FileOutputStream fsOut = new FileOutputStream( pathToKeystore );
- certStore.store( fsOut, keystorePassword.toCharArray());
-
- // [C] Associate the cert's uniqueId with the Cloud API keys
+ if ( null == accessKey || 0 == accessKey.length ) {
+ response.sendError(530, "Missing AWSAccessKeyId parameter" );
+ return;
+ }
+
+ // [B] Open our keystore
+ FileInputStream fsIn = new FileInputStream( pathToKeystore );
+ KeyStore certStore = KeyStore.getInstance( "JKS" );
+ certStore.load( fsIn, keystorePassword.toCharArray());
+
+ // -> use the Cloud API key to save the cert in the keystore
+ // -> write the cert into the keystore on disk
+ Certificate userCert = null;
+ CertificateFactory cf = CertificateFactory.getInstance( "X.509" );
+
+ ByteArrayInputStream bs = new ByteArrayInputStream( certificate[0].getBytes());
+ while (bs.available() > 0) userCert = cf.generateCertificate(bs);
+ certStore.setCertificateEntry( accessKey[0], userCert );
+
+ FileOutputStream fsOut = new FileOutputStream( pathToKeystore );
+ certStore.store( fsOut, keystorePassword.toCharArray());
+
+ // [C] Associate the cert's uniqueId with the Cloud API keys
String uniqueId = AuthenticationUtils.X509CertUniqueId( userCert );
logger.debug( "SetCertificate, uniqueId: " + uniqueId );
-/* UserCredentialsDao credentialDao = new UserCredentialsDao();
+ /* UserCredentialsDao credentialDao = new UserCredentialsDao();
credentialDao.setCertificateId( accessKey[0], uniqueId );
-*/
+ */
txn = Transaction.open(Transaction.AWSAPI_DB);
UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
user.setCertUniqueId(uniqueId);
@@ -452,20 +452,20 @@ public class EC2RestServlet extends HttpServlet {
response.setStatus(200);
endResponse(response, "User certificate set successfully");
txn.commit();
-
- } catch( NoSuchObjectException e ) {
- logger.error("SetCertificate exception " + e.getMessage(), e);
- response.sendError(404, "SetCertificate exception " + e.getMessage());
-
+
+ } catch( NoSuchObjectException e ) {
+ logger.error("SetCertificate exception " + e.getMessage(), e);
+ response.sendError(404, "SetCertificate exception " + e.getMessage());
+
} catch( Exception e ) {
- logger.error("SetCertificate exception " + e.getMessage(), e);
- response.sendError(500, "SetCertificate exception " + e.getMessage());
+ logger.error("SetCertificate exception " + e.getMessage(), e);
+ response.sendError(500, "SetCertificate exception " + e.getMessage());
} finally {
txn.close();
}
-
+
}
-
+
/**
* The SOAP API for EC2 uses WS-Security to sign all client requests. This requires that
* the client have a public/private key pair and the public key defined by a X509 certificate.
@@ -478,133 +478,133 @@ public class EC2RestServlet extends HttpServlet {
* algorithm.
*/
private void deleteCertificate( HttpServletRequest request, HttpServletResponse response )
- throws Exception {
+ throws Exception {
Transaction txn = null;
- try {
+ try {
String [] accessKey = request.getParameterValues( "AWSAccessKeyId" );
- if ( null == accessKey || 0 == accessKey.length ) {
- response.sendError(530, "Missing AWSAccessKeyId parameter" );
- return;
- }
-
- // -> delete the specified entry and save back to disk
- FileInputStream fsIn = new FileInputStream( pathToKeystore );
- KeyStore certStore = KeyStore.getInstance( "JKS" );
- certStore.load( fsIn, keystorePassword.toCharArray());
-
- if ( certStore.containsAlias( accessKey[0] )) {
- certStore.deleteEntry( accessKey[0] );
- FileOutputStream fsOut = new FileOutputStream( pathToKeystore );
- certStore.store( fsOut, keystorePassword.toCharArray());
-
- // -> dis-associate the cert's uniqueId with the Cloud API keys
-/* UserCredentialsDao credentialDao = new UserCredentialsDao();
+ if ( null == accessKey || 0 == accessKey.length ) {
+ response.sendError(530, "Missing AWSAccessKeyId parameter" );
+ return;
+ }
+
+ // -> delete the specified entry and save back to disk
+ FileInputStream fsIn = new FileInputStream( pathToKeystore );
+ KeyStore certStore = KeyStore.getInstance( "JKS" );
+ certStore.load( fsIn, keystorePassword.toCharArray());
+
+ if ( certStore.containsAlias( accessKey[0] )) {
+ certStore.deleteEntry( accessKey[0] );
+ FileOutputStream fsOut = new FileOutputStream( pathToKeystore );
+ certStore.store( fsOut, keystorePassword.toCharArray());
+
+ // -> dis-associate the cert's uniqueId with the Cloud API keys
+ /* UserCredentialsDao credentialDao = new UserCredentialsDao();
credentialDao.setCertificateId( accessKey[0], null );
-
-*/ txn = Transaction.open(Transaction.AWSAPI_DB);
- UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
- user.setCertUniqueId(null);
- ucDao.update(user.getId(), user);
- response.setStatus(200);
- endResponse(response, "User certificate deleted successfully");
- txn.commit();
- }
- else response.setStatus(404);
-
- } catch( NoSuchObjectException e ) {
- logger.error("SetCertificate exception " + e.getMessage(), e);
- response.sendError(404, "SetCertificate exception " + e.getMessage());
+
+ */ txn = Transaction.open(Transaction.AWSAPI_DB);
+ UserCredentialsVO user = ucDao.getByAccessKey(accessKey[0]);
+ user.setCertUniqueId(null);
+ ucDao.update(user.getId(), user);
+ response.setStatus(200);
+ endResponse(response, "User certificate deleted successfully");
+ txn.commit();
+ }
+ else response.setStatus(404);
+
+ } catch( NoSuchObjectException e ) {
+ logger.error("SetCertificate exception " + e.getMessage(), e);
+ response.sendError(404, "SetCertificate exception " + e.getMessage());
} catch( Exception e ) {
- logger.error("DeleteCertificate exception " + e.getMessage(), e);
- response.sendError(500, "DeleteCertificate exception " + e.getMessage());
+ logger.error("DeleteCertificate exception " + e.getMessage(), e);
+ response.sendError(500, "DeleteCertificate exception " + e.getMessage());
} finally {
txn.close();
}
}
-
+
/**
* Allow the caller to define the mapping between the Amazon instance type strings
* (e.g., m1.small, cc1.4xlarge) and the cloudstack service offering ids. Setting
* an existing mapping just over writes the prevous values.
*/
private void setOfferMapping( HttpServletRequest request, HttpServletResponse response ) {
- String amazonOffer = null;
- String cloudOffer = null;
-
- try {
- // -> all these parameters are required
+ String amazonOffer = null;
+ String cloudOffer = null;
+
+ try {
+ // -> all these parameters are required
amazonOffer = request.getParameter( "amazonoffer" );
- if ( null == amazonOffer ) {
- response.sendError(530, "Missing amazonoffer parameter" );
- return;
- }
+ if ( null == amazonOffer ) {
+ response.sendError(530, "Missing amazonoffer parameter" );
+ return;
+ }
cloudOffer = request.getParameter( "cloudoffer" );
if ( null == cloudOffer ) {
- response.sendError(530, "Missing cloudoffer parameter" );
- return;
+ response.sendError(530, "Missing cloudoffer parameter" );
+ return;
}
} catch( Exception e ) {
- logger.error("SetOfferMapping exception " + e.getMessage(), e);
- response.setStatus(500);
- endResponse(response, "SetOfferMapping exception " + e.getMessage());
- return;
+ logger.error("SetOfferMapping exception " + e.getMessage(), e);
+ response.setStatus(500);
+ endResponse(response, "SetOfferMapping exception " + e.getMessage());
+ return;
+ }
+
+ // validate account is admin level
+ try {
+ CloudStackAccount currentAccount = ServiceProvider.getInstance().getEC2Engine().getCurrentAccount();
+
+ if (currentAccount.getAccountType() != 1) {
+ logger.debug("SetOfferMapping called by non-admin user!");
+ response.setStatus(500);
+ endResponse(response, "Permission denied for non-admin user to setOfferMapping!");
+ return;
+ }
+ } catch (Exception e) {
+ logger.error("SetOfferMapping " + e.getMessage(), e);
+ response.setStatus(401);
+ endResponse(response, e.toString());
+ return;
}
-
- // validate account is admin level
- try {
- CloudStackAccount currentAccount = ServiceProvider.getInstance().getEC2Engine().getCurrentAccount();
-
- if (currentAccount.getAccountType() != 1) {
- logger.debug("SetOfferMapping called by non-admin user!");
- response.setStatus(500);
- endResponse(response, "Permission denied for non-admin user to setOfferMapping!");
- return;
- }
- } catch (Exception e) {
- logger.error("SetOfferMapping " + e.getMessage(), e);
- response.setStatus(401);
- endResponse(response, e.toString());
- return;
- }
try {
-
- ofDao.setOfferMapping( amazonOffer, cloudOffer );
-
+
+ ofDao.setOfferMapping( amazonOffer, cloudOffer );
+
} catch( Exception e ) {
- logger.error("SetOfferMapping " + e.getMessage(), e);
- response.setStatus(401);
- endResponse(response, e.toString());
- return;
+ logger.error("SetOfferMapping " + e.getMessage(), e);
+ response.setStatus(401);
+ endResponse(response, e.toString());
+ return;
}
- response.setStatus(200);
+ response.setStatus(200);
endResponse(response, "offering mapping set successfully");
}
private void deleteOfferMapping( HttpServletRequest request, HttpServletResponse response ) {
- String amazonOffer = null;
-
- try {
- // -> all these parameters are required
+ String amazonOffer = null;
+
+ try {
+ // -> all these parameters are required
amazonOffer = request.getParameter( "amazonoffer" );
- if ( null == amazonOffer ) {
- response.sendError(530, "Missing amazonoffer parameter" );
- return;
- }
+ if ( null == amazonOffer ) {
+ response.sendError(530, "Missing amazonoffer parameter" );
+ return;
+ }
} catch( Exception e ) {
- logger.error("DeleteOfferMapping exception " + e.getMessage(), e);
- response.setStatus(500);
- endResponse(response, "DeleteOfferMapping exception " + e.getMessage());
- return;
+ logger.error("DeleteOfferMapping exception " + e.getMessage(), e);
+ response.setStatus(500);
+ endResponse(response, "DeleteOfferMapping exception " + e.getMessage());
+ return;
}
-
- // validate account is admin level
- try {
+
+ // validate account is admin level
+ try {
CloudStackAccount currentAccount = ServiceProvider.getInstance().getEC2Engine().getCurrentAccount();
-
+
if (currentAccount.getAccountType() != 1) {
logger.debug("deleteOfferMapping called by non-admin user!");
response.setStatus(500);
@@ -619,14 +619,14 @@ public class EC2RestServlet extends HttpServlet {
}
try {
- ofDao.deleteOfferMapping( amazonOffer );
+ ofDao.deleteOfferMapping( amazonOffer );
} catch( Exception e ) {
- logger.error("DeleteOfferMapping " + e.getMessage(), e);
- response.setStatus(401);
- endResponse(response, e.toString());
- return;
+ logger.error("DeleteOfferMapping " + e.getMessage(), e);
+ response.setStatus(401);
+ endResponse(response, e.toString());
+ return;
}
- response.setStatus(200);
+ response.setStatus(200);
endResponse(response, "offering mapping deleted successfully");
}
@@ -641,257 +641,257 @@ public class EC2RestServlet extends HttpServlet {
* response XML.
*/
private void attachVolume( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2Volume EC2request = new EC2Volume();
-
- // -> all these parameters are required
+ throws ADBException, XMLStreamException, IOException {
+ EC2Volume EC2request = new EC2Volume();
+
+ // -> all these parameters are required
String[] volumeId = request.getParameterValues( "VolumeId" );
- if ( null != volumeId && 0 < volumeId.length )
- EC2request.setId( volumeId[0] );
- else { response.sendError(530, "Missing VolumeId parameter" ); return; }
+ if ( null != volumeId && 0 < volumeId.length )
+ EC2request.setId( volumeId[0] );
+ else { response.sendError(530, "Missing VolumeId parameter" ); return; }
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( null != instanceId && 0 < instanceId.length )
- EC2request.setInstanceId( instanceId[0] );
- else { response.sendError(530, "Missing InstanceId parameter" ); return; }
+ EC2request.setInstanceId( instanceId[0] );
+ else { response.sendError(530, "Missing InstanceId parameter" ); return; }
String[] device = request.getParameterValues( "Device" );
if ( null != device && 0 < device.length )
- EC2request.setDevice( device[0] );
- else { response.sendError(530, "Missing Device parameter" ); return; }
-
- // -> execute the request
- AttachVolumeResponse EC2response = EC2SoapServiceImpl.toAttachVolumeResponse( ServiceProvider.getInstance().getEC2Engine().attachVolume( EC2request ));
- serializeResponse(response, EC2response);
+ EC2request.setDevice( device[0] );
+ else { response.sendError(530, "Missing Device parameter" ); return; }
+
+ // -> execute the request
+ AttachVolumeResponse EC2response = EC2SoapServiceImpl.toAttachVolumeResponse( ServiceProvider.getInstance().getEC2Engine().attachVolume( EC2request ));
+ serializeResponse(response, EC2response);
}
-
+
/**
* The SOAP equivalent of this function appears to allow multiple permissions per request, yet
* in the REST API documentation only one permission is allowed.
*/
private void revokeSecurityGroupIngress( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
+ throws ADBException, XMLStreamException, IOException {
EC2AuthorizeRevokeSecurityGroup EC2request = new EC2AuthorizeRevokeSecurityGroup();
String[] groupName = request.getParameterValues( "GroupName" );
- if ( null != groupName && 0 < groupName.length )
- EC2request.setName( groupName[0] );
- else { response.sendError(530, "Missing GroupName parameter" ); return; }
+ if ( null != groupName && 0 < groupName.length )
+ EC2request.setName( groupName[0] );
+ else { response.sendError(530, "Missing GroupName parameter" ); return; }
- EC2IpPermission perm = new EC2IpPermission();
+ EC2IpPermission perm = new EC2IpPermission();
String[] protocol = request.getParameterValues( "IpProtocol" );
- if ( null != protocol && 0 < protocol.length )
- perm.setProtocol( protocol[0] );
- else { response.sendError(530, "Missing IpProtocol parameter" ); return; }
+ if ( null != protocol && 0 < protocol.length )
+ perm.setProtocol( protocol[0] );
+ else { response.sendError(530, "Missing IpProtocol parameter" ); return; }
String[] fromPort = request.getParameterValues( "FromPort" );
- if ( null != fromPort && 0 < fromPort.length )
- perm.setProtocol( fromPort[0] );
- else { response.sendError(530, "Missing FromPort parameter" ); return; }
+ if ( null != fromPort && 0 < fromPort.length )
+ perm.setProtocol( fromPort[0] );
+ else { response.sendError(530, "Missing FromPort parameter" ); return; }
String[] toPort = request.getParameterValues( "ToPort" );
- if ( null != toPort && 0 < toPort.length )
- perm.setProtocol( toPort[0] );
- else { response.sendError(530, "Missing ToPort parameter" ); return; }
-
- String[] ranges = request.getParameterValues( "CidrIp" );
- if ( null != ranges && 0 < ranges.length)
- perm.addIpRange( ranges[0] );
- else { response.sendError(530, "Missing CidrIp parameter" ); return; }
-
- String[] user = request.getParameterValues( "SourceSecurityGroupOwnerId" );
- if ( null == user || 0 == user.length) {
- response.sendError(530, "Missing SourceSecurityGroupOwnerId parameter" );
- return;
- }
-
- String[] name = request.getParameterValues( "SourceSecurityGroupName" );
- if ( null == name || 0 == name.length) {
- response.sendError(530, "Missing SourceSecurityGroupName parameter" );
- return;
- }
-
- EC2SecurityGroup group = new EC2SecurityGroup();
- group.setAccount( user[0] );
- group.setName( name[0] );
- perm.addUser( group );
- EC2request.addIpPermission( perm );
-
- // -> execute the request
+ if ( null != toPort && 0 < toPort.length )
+ perm.setProtocol( toPort[0] );
+ else { response.sendError(530, "Missing ToPort parameter" ); return; }
+
+ String[] ranges = request.getParameterValues( "CidrIp" );
+ if ( null != ranges && 0 < ranges.length)
+ perm.addIpRange( ranges[0] );
+ else { response.sendError(530, "Missing CidrIp parameter" ); return; }
+
+ String[] user = request.getParameterValues( "SourceSecurityGroupOwnerId" );
+ if ( null == user || 0 == user.length) {
+ response.sendError(530, "Missing SourceSecurityGroupOwnerId parameter" );
+ return;
+ }
+
+ String[] name = request.getParameterValues( "SourceSecurityGroupName" );
+ if ( null == name || 0 == name.length) {
+ response.sendError(530, "Missing SourceSecurityGroupName parameter" );
+ return;
+ }
+
+ EC2SecurityGroup group = new EC2SecurityGroup();
+ group.setAccount( user[0] );
+ group.setName( name[0] );
+ perm.addUser( group );
+ EC2request.addIpPermission( perm );
+
+ // -> execute the request
RevokeSecurityGroupIngressResponse EC2response = EC2SoapServiceImpl.toRevokeSecurityGroupIngressResponse(
- ServiceProvider.getInstance().getEC2Engine().revokeSecurityGroup( EC2request ));
+ ServiceProvider.getInstance().getEC2Engine().revokeSecurityGroup( EC2request ));
serializeResponse(response, EC2response);
}
- private void authorizeSecurityGroupIngress( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- // -> parse the complicated paramters into our standard object
+ private void authorizeSecurityGroupIngress( HttpServletRequest request, HttpServletResponse response )
+ throws ADBException, XMLStreamException, IOException {
+ // -> parse the complicated paramters into our standard object
EC2AuthorizeRevokeSecurityGroup EC2request = new EC2AuthorizeRevokeSecurityGroup();
String[] groupName = request.getParameterValues( "GroupName" );
- if ( null != groupName && 0 < groupName.length )
- EC2request.setName( groupName[0] );
- else { response.sendError(530, "Missing GroupName parameter" ); return; }
-
- // -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
- int nCount = 1;
- do
- { EC2IpPermission perm = new EC2IpPermission();
-
- String[] protocol = request.getParameterValues( "IpPermissions." + nCount + ".IpProtocol" );
- if ( null != protocol && 0 < protocol.length )
- perm.setProtocol( protocol[0] );
- else break;
-
- String[] fromPort = request.getParameterValues( "IpPermissions." + nCount + ".FromPort" );
- if (null != fromPort && 0 < fromPort.length) perm.setProtocol( fromPort[0] );
-
- String[] toPort = request.getParameterValues( "IpPermissions." + nCount + ".ToPort" );
- if (null != toPort && 0 < toPort.length) perm.setProtocol( toPort[0] );
-
- // -> list: IpPermissions.n.IpRanges.m.CidrIp
- int mCount = 1;
- do
- { String[] ranges = request.getParameterValues( "IpPermissions." + nCount + ".IpRanges." + mCount + ".CidrIp" );
- if ( null != ranges && 0 < ranges.length)
- perm.addIpRange( ranges[0] );
- else break;
- mCount++;
-
- } while( true );
-
- // -> list: IpPermissions.n.Groups.m.UserId and IpPermissions.n.Groups.m.GroupName
- mCount = 1;
- do
- { String[] user = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".UserId" );
- if ( null == user || 0 == user.length) break;
-
- String[] name = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".GroupName" );
- if ( null == name || 0 == name.length) break;
-
- EC2SecurityGroup group = new EC2SecurityGroup();
- group.setAccount( user[0] );
- group.setName( name[0] );
- perm.addUser( group );
- mCount++;
-
- } while( true );
-
- // -> multiple IP permissions can be specified per group name
- EC2request.addIpPermission( perm );
- nCount++;
-
- } while( true );
-
- if (1 == nCount) { response.sendError(530, "At least one IpPermissions required" ); return; }
-
-
- // -> execute the request
+ if ( null != groupName && 0 < groupName.length )
+ EC2request.setName( groupName[0] );
+ else { response.sendError(530, "Missing GroupName parameter" ); return; }
+
+ // -> not clear how many parameters there are until we fail to get IpPermissions.n.IpProtocol
+ int nCount = 1;
+ do
+ { EC2IpPermission perm = new EC2IpPermission();
+
+ String[] protocol = request.getParameterValues( "IpPermissions." + nCount + ".IpProtocol" );
+ if ( null != protocol && 0 < protocol.length )
+ perm.setProtocol( protocol[0] );
+ else break;
+
+ String[] fromPort = request.getParameterValues( "IpPermissions." + nCount + ".FromPort" );
+ if (null != fromPort && 0 < fromPort.length) perm.setProtocol( fromPort[0] );
+
+ String[] toPort = request.getParameterValues( "IpPermissions." + nCount + ".ToPort" );
+ if (null != toPort && 0 < toPort.length) perm.setProtocol( toPort[0] );
+
+ // -> list: IpPermissions.n.IpRanges.m.CidrIp
+ int mCount = 1;
+ do
+ { String[] ranges = request.getParameterValues( "IpPermissions." + nCount + ".IpRanges." + mCount + ".CidrIp" );
+ if ( null != ranges && 0 < ranges.length)
+ perm.addIpRange( ranges[0] );
+ else break;
+ mCount++;
+
+ } while( true );
+
+ // -> list: IpPermissions.n.Groups.m.UserId and IpPermissions.n.Groups.m.GroupName
+ mCount = 1;
+ do
+ { String[] user = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".UserId" );
+ if ( null == user || 0 == user.length) break;
+
+ String[] name = request.getParameterValues( "IpPermissions." + nCount + ".Groups." + mCount + ".GroupName" );
+ if ( null == name || 0 == name.length) break;
+
+ EC2SecurityGroup group = new EC2SecurityGroup();
+ group.setAccount( user[0] );
+ group.setName( name[0] );
+ perm.addUser( group );
+ mCount++;
+
+ } while( true );
+
+ // -> multiple IP permissions can be specified per group name
+ EC2request.addIpPermission( perm );
+ nCount++;
+
+ } while( true );
+
+ if (1 == nCount) { response.sendError(530, "At least one IpPermissions required" ); return; }
+
+
+ // -> execute the request
AuthorizeSecurityGroupIngressResponse EC2response = EC2SoapServiceImpl.toAuthorizeSecurityGroupIngressResponse(
- ServiceProvider.getInstance().getEC2Engine().authorizeSecurityGroup( EC2request ));
+ ServiceProvider.getInstance().getEC2Engine().authorizeSecurityGroup( EC2request ));
serializeResponse(response, EC2response);
}
-
+
private void detachVolume( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2Volume EC2request = new EC2Volume();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2Volume EC2request = new EC2Volume();
+
String[] volumeId = request.getParameterValues( "VolumeId" );
- if ( null != volumeId && 0 < volumeId.length )
- EC2request.setId(volumeId[0]);
- else { response.sendError(530, "Missing VolumeId parameter" ); return; }
+ if ( null != volumeId && 0 < volumeId.length )
+ EC2request.setId(volumeId[0]);
+ else { response.sendError(530, "Missing VolumeId parameter" ); return; }
String[] instanceId = request.getParameterValues( "InstanceId" );
if ( null != instanceId && 0 < instanceId.length )
- EC2request.setInstanceId(instanceId[0]);
+ EC2request.setInstanceId(instanceId[0]);
String[] device = request.getParameterValues( "Device" );
if ( null != device && 0 < device.length )
- EC2request.setDevice( device[0] );
-
- // -> execute the request
- DetachVolumeResponse EC2response = EC2SoapServiceImpl.toDetachVolumeResponse( ServiceProvider.getInstance().getEC2Engine().detachVolume( EC2request ));
- serializeResponse(response, EC2response);
+ EC2request.setDevice( device[0] );
+
+ // -> execute the request
+ DetachVolumeResponse EC2response = EC2SoapServiceImpl.toDetachVolumeResponse( ServiceProvider.getInstance().getEC2Engine().detachVolume( EC2request ));
+ serializeResponse(response, EC2response);
}
private void deleteVolume( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2Volume EC2request = new EC2Volume();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2Volume EC2request = new EC2Volume();
+
String[] volumeId = request.getParameterValues( "VolumeId" );
- if ( null != volumeId && 0 < volumeId.length )
- EC2request.setId(volumeId[0]);
- else { response.sendError(530, "Missing VolumeId parameter" ); return; }
+ if ( null != volumeId && 0 < volumeId.length )
+ EC2request.setId(volumeId[0]);
+ else { response.sendError(530, "Missing VolumeId parameter" ); return; }
- // -> execute the request
- DeleteVolumeResponse EC2response = EC2SoapServiceImpl.toDeleteVolumeResponse( ServiceProvider.getInstance().getEC2Engine().deleteVolume( EC2request ));
- serializeResponse(response, EC2response);
+ // -> execute the request
+ DeleteVolumeResponse EC2response = EC2SoapServiceImpl.toDeleteVolumeResponse( ServiceProvider.getInstance().getEC2Engine().deleteVolume( EC2request ));
+ serializeResponse(response, EC2response);
}
private void createVolume( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2CreateVolume EC2request = new EC2CreateVolume();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2CreateVolume EC2request = new EC2CreateVolume();
+
String[] zoneName = request.getParameterValues( "AvailabilityZone" );
if ( null != zoneName && 0 < zoneName.length )
- EC2request.setZoneName( zoneName[0] );
- else { response.sendError(530, "Missing AvailabilityZone parameter" ); return; }
-
+ EC2request.setZoneName( zoneName[0] );
+ else { response.sendError(530, "Missing AvailabilityZone parameter" ); return; }
+
String[] size = request.getParameterValues( "Size" );
String[] snapshotId = request.getParameterValues("SnapshotId");
boolean useSnapshot = false;
boolean useSize = false;
-
+
if (null != size && 0 < size.length)
- useSize = true;
-
+ useSize = true;
+
if (snapshotId != null && snapshotId.length != 0)
- useSnapshot = true;
-
- if (useSize && !useSnapshot) {
- EC2request.setSize( size[0] );
- } else if (useSnapshot && !useSize) {
- EC2request.setSnapshotId(snapshotId[0]);
+ useSnapshot = true;
+
+ if (useSize && !useSnapshot) {
+ EC2request.setSize( size[0] );
+ } else if (useSnapshot && !useSize) {
+ EC2request.setSnapshotId(snapshotId[0]);
} else if (useSize && useSnapshot) {
- response.sendError(530, "Size and SnapshotId parameters are mutually exclusive" ); return;
+ response.sendError(530, "Size and SnapshotId parameters are mutually exclusive" ); return;
} else {
- response.sendError(530, "Size or SnapshotId has to be specified" ); return;
+ response.sendError(530, "Size or SnapshotId has to be specified" ); return;
}
-
- // -> execute the request
- CreateVolumeResponse EC2response = EC2SoapServiceImpl.toCreateVolumeResponse( ServiceProvider.getInstance().getEC2Engine().createVolume( EC2request ));
- serializeResponse(response, EC2response);
+
+ // -> execute the request
+ CreateVolumeResponse EC2response = EC2SoapServiceImpl.toCreateVolumeResponse( ServiceProvider.getInstance().getEC2Engine().createVolume( EC2request ));
+ serializeResponse(response, EC2response);
}
private void createSecurityGroup( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
-
- String groupName, groupDescription = null;
-
+ throws ADBException, XMLStreamException, IOException {
+
+ String groupName, groupDescription = null;
+
String[] name = request.getParameterValues( "GroupName" );
- if ( null != name && 0 < name.length )
- groupName = name[0];
- else { response.sendError(530, "Missing GroupName parameter" ); return; }
-
+ if ( null != name && 0 < name.length )
+ groupName = name[0];
+ else { response.sendError(530, "Missing GroupName parameter" ); return; }
+
String[] desc = request.getParameterValues( "GroupDescription" );
if ( null != desc && 0 < desc.length )
- groupDescription = desc[0];
- else { response.sendError(530, "Missing GroupDescription parameter" ); return; }
+ groupDescription = desc[0];
+ else { response.sendError(530, "Missing GroupDescription parameter" ); return; }
- // -> execute the request
+ // -> execute the request
CreateSecurityGroupResponse EC2response = EC2SoapServiceImpl.toCreateSecurityGroupResponse( ServiceProvider.getInstance().getEC2Engine().createSecurityGroup( groupName, groupDescription ));
serializeResponse(response, EC2response);
}
private void deleteSecurityGroup( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- String groupName = null;
-
+ throws ADBException, XMLStreamException, IOException {
+ String groupName = null;
+
String[] name = request.getParameterValues( "GroupName" );
if ( null != name && 0 < name.length )
- groupName = name[0];
+ groupName = name[0];
else { response.sendError(530, "Missing GroupName parameter" ); return; }
// -> execute the request
@@ -900,217 +900,217 @@ public class EC2RestServlet extends HttpServlet {
}
private void deleteSnapshot( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- String snapshotId = null;
-
+ throws ADBException, XMLStreamException, IOException {
+ String snapshotId = null;
+
String[] snapSet = request.getParameterValues( "SnapshotId" );
- if ( null != snapSet && 0 < snapSet.length )
- snapshotId = snapSet[0];
- else { response.sendError(530, "Missing SnapshotId parameter" ); return; }
-
- // -> execute the request
- DeleteSnapshotResponse EC2response = EC2SoapServiceImpl.toDeleteSnapshotResponse( ServiceProvider.getInstance().getEC2Engine().deleteSnapshot( snapshotId ));
- serializeResponse(response, EC2response);
+ if ( null != snapSet && 0 < snapSet.length )
+ snapshotId = snapSet[0];
+ else { response.sendError(530, "Missing SnapshotId parameter" ); return; }
+
+ // -> execute the request
+ DeleteSnapshotResponse EC2response = EC2SoapServiceImpl.toDeleteSnapshotResponse( ServiceProvider.getInstance().getEC2Engine().deleteSnapshot( snapshotId ));
+ serializeResponse(response, EC2response);
}
private void createSnapshot( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- String volumeId = null;
-
+ throws ADBException, XMLStreamException, IOException {
+ String volumeId = null;
+
String[] volSet = request.getParameterValues( "VolumeId" );
- if ( null != volSet && 0 < volSet.length )
- volumeId = volSet[0];
- else { response.sendError(530, "Missing VolumeId parameter" ); return; }
-
- // -> execute the request
- EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
+ if ( null != volSet && 0 < volSet.length )
+ volumeId = volSet[0];
+ else { response.sendError(530, "Missing VolumeId parameter" ); return; }
+
+ // -> execute the request
+ EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
CreateSnapshotResponse EC2response = EC2SoapServiceImpl.toCreateSnapshotResponse( engine.createSnapshot( volumeId ), engine);
serializeResponse(response, EC2response);
}
-
+
private void deregisterImage( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2Image image = new EC2Image();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2Image image = new EC2Image();
+
String[] imageId = request.getParameterValues( "ImageId" );
- if ( null != imageId && 0 < imageId.length )
- image.setId( imageId[0] );
- else { response.sendError(530, "Missing ImageId parameter" ); return; }
-
- // -> execute the request
- DeregisterImageResponse EC2response = EC2SoapServiceImpl.toDeregisterImageResponse( ServiceProvider.getInstance().getEC2Engine().deregisterImage( image ));
- serializeResponse(response, EC2response);
+ if ( null != imageId && 0 < imageId.length )
+ image.setId( imageId[0] );
+ else { response.sendError(530, "Missing ImageId parameter" ); return; }
+
+ // -> execute the request
+ DeregisterImageResponse EC2response = EC2SoapServiceImpl.toDeregisterImageResponse( ServiceProvider.getInstance().getEC2Engine().deregisterImage( image ));
+ serializeResponse(response, EC2response);
}
-
+
private void createImage( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2CreateImage EC2request = new EC2CreateImage();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2CreateImage EC2request = new EC2CreateImage();
+
String[] instanceId = request.getParameterValues( "InstanceId" );
- if ( null != instanceId && 0 < instanceId.length )
- EC2request.setInstanceId( instanceId[0] );
- else { response.sendError(530, "Missing InstanceId parameter" ); return; }
-
+ if ( null != instanceId && 0 < instanceId.length )
+ EC2request.setInstanceId( instanceId[0] );
+ else { response.sendError(530, "Missing InstanceId parameter" ); return; }
+
String[] name = request.getParameterValues( "Name" );
if ( null != name && 0 < name.length )
- EC2request.setName( name[0] );
- else { response.sendError(530, "Missing Name parameter" ); return; }
+ EC2request.setName( name[0] );
+ else { response.sendError(530, "Missing Name parameter" ); return; }
String[] description = request.getParameterValues( "Description" );
if ( null != description && 0 < description.length )
- EC2request.setDescription( description[0] );
+ EC2request.setDescription( description[0] );
- // -> execute the request
+ // -> execute the request
CreateImageResponse EC2response = EC2SoapServiceImpl.toCreateImageResponse( ServiceProvider.getInstance().getEC2Engine().createImage( EC2request ));
serializeResponse(response, EC2response);
}
private void registerImage( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2RegisterImage EC2request = new EC2RegisterImage();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2RegisterImage EC2request = new EC2RegisterImage();
+
String[] location = request.getParameterValues( "ImageLocation" );
- if ( null != location && 0 < location.length )
- EC2request.setLocation( location[0] );
- else { response.sendError(530, "Missing ImageLocation parameter" ); return; }
+ if ( null != location && 0 < location.length )
+ EC2request.setLocation( location[0] );
+ else { response.sendError(530, "Missing ImageLocation parameter" ); return; }
String[] cloudRedfined = request.getParameterValues( "Architecture" );
- if ( null != cloudRedfined && 0 < cloudRedfined.length )
- EC2request.setArchitecture( cloudRedfined[0] );
- else { response.sendError(530, "Missing Architecture parameter" ); return; }
+ if ( null != cloudRedfined && 0 < cloudRedfined.length )
+ EC2request.setArchitecture( cloudRedfined[0] );
+ else { response.sendError(530, "Missing Architecture parameter" ); return; }
String[] name = request.getParameterValues( "Name" );
if ( null != name && 0 < name.length )
- EC2request.setName( name[0] );
+ EC2request.setName( name[0] );
String[] description = request.getParameterValues( "Description" );
if ( null != description && 0 < description.length )
- EC2request.setDescription( description[0] );
+ EC2request.setDescription( description[0] );
- // -> execute the request
+ // -> execute the request
RegisterImageResponse EC2response = EC2SoapServiceImpl.toRegisterImageResponse( ServiceProvider.getInstance().getEC2Engine().registerImage( EC2request ));
serializeResponse(response, EC2response);
}
private void modifyImageAttribute( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2Image image = new EC2Image();
-
- // -> its interesting to note that the SOAP API docs has description but the REST API docs do not
+ throws ADBException, XMLStreamException, IOException {
+ EC2Image image = new EC2Image();
+
+ // -> its interesting to note that the SOAP API docs has description but the REST API docs do not
String[] imageId = request.getParameterValues( "ImageId" );
- if ( null != imageId && 0 < imageId.length )
- image.setId( imageId[0] );
- else { response.sendError(530, "Missing ImageId parameter" ); return; }
+ if ( null != imageId && 0 < imageId.length )
+ image.setId( imageId[0] );
+ else { response.sendError(530, "Missing ImageId parameter" ); return; }
String[] description = request.getParameterValues( "Description" );
- if ( null != description && 0 < description.length )
- image.setDescription( description[0] );
- else { response.sendError(530, "Missing Description parameter" ); return; }
+ if ( null != description && 0 < description.length )
+ image.setDescription( description[0] );
+ else { response.sendError(530, "Missing Description parameter" ); return; }
- // -> execute the request
- ModifyImageAttributeResponse EC2response = EC2SoapServiceImpl.toModifyImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().modifyImageAttribute( image ));
- serializeResponse(response, EC2response);
+ // -> execute the request
+ ModifyImageAttributeResponse EC2response = EC2SoapServiceImpl.toModifyImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().modifyImageAttribute( image ));
+ serializeResponse(response, EC2response);
}
private void resetImageAttribute( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2Image image = new EC2Image();
-
+ throws ADBException, XMLStreamException, IOException {
+ EC2Image image = new EC2Image();
+
String[] imageId = request.getParameterValues( "ImageId" );
- if ( null != imageId && 0 < imageId.length )
- image.setId( imageId[0] );
- else { response.sendError(530, "Missing ImageId parameter" ); return; }
-
- // -> execute the request
- image.setDescription( "" );
- ResetImageAttributeResponse EC2response = EC2SoapServiceImpl.toResetImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().modifyImageAttribute( image ));
- serializeResponse(response, EC2response);
+ if ( null != imageId && 0 < imageId.length )
+ image.setId( imageId[0] );
+ else { response.sendError(530, "Missing ImageId parameter" ); return; }
+
+ // -> execute the request
+ image.setDescription( "" );
+ ResetImageAttributeResponse EC2response = EC2SoapServiceImpl.toResetImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().modifyImageAttribute( image ));
+ 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
+ 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 { response.sendError(530, "Missing ImageId parameter" ); return; }
+ if ( null != imageId && 0 < imageId.length )
+ EC2request.setTemplateId( imageId[0] );
+ else { response.sendError(530, "Missing ImageId parameter" ); return; }
String[] minCount = request.getParameterValues( "MinCount" );
- if ( null != minCount && 0 < minCount.length )
- EC2request.setMinCount( Integer.parseInt( minCount[0] ));
- else { response.sendError(530, "Missing MinCount parameter" ); return; }
+ if ( null != minCount && 0 < minCount.length )
+ EC2request.setMinCount( Integer.parseInt( minCount[0] ));
+ else { response.sendError(530, "Missing MinCount parameter" ); return; }
String[] maxCount = request.getParameterValues( "MaxCount" );
- if ( null != maxCount && 0 < maxCount.length )
- EC2request.setMaxCount( Integer.parseInt( maxCount[0] ));
- else { response.sendError(530, "Missing MaxCount parameter" ); return; }
+ if ( null != maxCount && 0 < maxCount.length )
+ EC2request.setMaxCount( Integer.parseInt( maxCount[0] ));
+ else { response.sendError(530, "Missing MaxCount parameter" ); return; }
String[] instanceType = request.getParameterValues( "InstanceType" );
- if ( null != instanceType && 0 < instanceType.length )
- EC2request.setInstanceType( instanceType[0] );
+ 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]);
- }
-
- // -> execute the request
- EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
- RunInstancesResponse EC2response = EC2SoapServiceImpl.toRunInstancesResponse( engine.runInstances( EC2request ), engine);
- serializeResponse(response, EC2response);
+ 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]);
+ }
+
+ // -> execute the request
+ EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
+ RunInstancesResponse EC2response = EC2SoapServiceImpl.toRunInstancesResponse( engine.runInstances( EC2request ), engine);
+ serializeResponse(response, EC2response);
}
private void rebootInstances( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
+ throws ADBException, XMLStreamException, IOException {
EC2RebootInstances EC2request = new EC2RebootInstances();
int count = 0;
// -> load in all the "InstanceId.n" parameters if any
- Enumeration<?> names = request.getParameterNames();
+ Enumeration<?> names = request.getParameterNames();
while( names.hasMoreElements()) {
String key = (String)names.nextElement();
if (key.startsWith("InstanceId")) {
String[] value = request.getParameterValues( key );
if (null != value && 0 < value.length) {
- EC2request.addInstanceId( value[0] );
- count++;
+ EC2request.addInstanceId( value[0] );
+ count++;
}
}
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
-
+
// -> execute the request
RebootInstancesResponse EC2response = EC2SoapServiceImpl.toRebootInstancesResponse( ServiceProvider.getInstance().getEC2Engine().rebootInstances(EC2request));
serializeResponse(response, EC2response);
}
private void startInstances( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
+ throws ADBException, XMLStreamException, IOException {
EC2StartInstances EC2request = new EC2StartInstances();
int count = 0;
// -> load in all the "InstanceId.n" parameters if any
- Enumeration<?> names = request.getParameterNames();
+ Enumeration<?> names = request.getParameterNames();
while( names.hasMoreElements()) {
- String key = (String)names.nextElement();
- if (key.startsWith("InstanceId")) {
- String[] value = request.getParameterValues( key );
- if (null != value && 0 < value.length) {
- EC2request.addInstanceId( value[0] );
- count++;
- }
- }
+ String key = (String)names.nextElement();
+ if (key.startsWith("InstanceId")) {
+ String[] value = request.getParameterValues( key );
+ if (null != value && 0 < value.length) {
+ EC2request.addInstanceId( value[0] );
+ count++;
+ }
+ }
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
@@ -1120,50 +1120,50 @@ public class EC2RestServlet extends HttpServlet {
}
private void stopInstances( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2StopInstances EC2request = new EC2StopInstances();
- int count = 0;
-
- // -> load in all the "InstanceId.n" parameters if any
- Enumeration<?> names = request.getParameterNames();
- while( names.hasMoreElements()) {
- String key = (String)names.nextElement();
- if (key.startsWith("InstanceId")) {
- String[] value = request.getParameterValues( key );
- if (null != value && 0 < value.length) {
- EC2request.addInstanceId( value[0] );
- count++;
- }
- }
- }
+ throws ADBException, XMLStreamException, IOException {
+ EC2StopInstances EC2request = new EC2StopInstances();
+ int count = 0;
+
+ // -> load in all the "InstanceId.n" parameters if any
+ Enumeration<?> names = request.getParameterNames();
+ while( names.hasMoreElements()) {
+ String key = (String)names.nextElement();
+ if (key.startsWith("InstanceId")) {
+ String[] value = request.getParameterValues( key );
+ if (null != value && 0 < value.length) {
+ EC2request.addInstanceId( value[0] );
+ count++;
+ }
+ }
+ }
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
- // -> execute the request
- StopInstancesResponse EC2response = EC2SoapServiceImpl.toStopInstancesResponse( ServiceProvider.getInstance().getEC2Engine().stopInstances( EC2request ));
- serializeResponse(response, EC2response);
+ // -> execute the request
+ StopInstancesResponse EC2response = EC2SoapServiceImpl.toStopInstancesResponse( ServiceProvider.getInstance().getEC2Engine().stopInstances( EC2request ));
+ serializeResponse(response, EC2response);
}
private void terminateInstances( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
+ throws ADBException, XMLStreamException, IOException {
EC2StopInstances EC2request = new EC2StopInstances();
int count = 0;
// -> load in all the "InstanceId.n" parameters if any
- Enumeration<?> names = request.getParameterNames();
+ Enumeration<?> names = request.getParameterNames();
while( names.hasMoreElements()) {
- String key = (String)names.nextElement();
- if (key.startsWith("InstanceId")) {
- String[] value = request.getParameterValues( key );
- if (null != value && 0 < value.length) {
- EC2request.addInstanceId( value[0] );
- count++;
- }
- }
+ String key = (String)names.nextElement();
+ if (key.startsWith("InstanceId")) {
+ String[] value = request.getParameterValues( key );
+ if (null != value && 0 < value.length) {
+ EC2request.addInstanceId( value[0] );
+ count++;
+ }
+ }
}
if (0 == count) { response.sendError(530, "Missing InstanceId parameter" ); return; }
// -> execute the request
- EC2request.setDestroyInstances( true );
+ EC2request.setDestroyInstances( true );
TerminateInstancesResponse EC2response = EC2SoapServiceImpl.toTermInstancesResponse( ServiceProvider.getInstance().getEC2Engine().stopInstances( EC2request ));
serializeResponse(response, EC2response);
}
@@ -1173,100 +1173,100 @@ public class EC2RestServlet extends HttpServlet {
* resulting EC2 Amazon object into XML to return to the client.
*/
private void describeAvailabilityZones( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2DescribeAvailabilityZones EC2request = new EC2DescribeAvailabilityZones();
-
- // -> load in all the "ZoneName.n" parameters if any
- Enumeration<?> names = request.getParameterNames();
- while( names.hasMoreElements()) {
- String key = (String)names.nextElement();
- if (key.startsWith("ZoneName")) {
- String[] value = request.getParameterValues( key );
- if (null != value && 0 < value.length) EC2request.addZone( value[0] );
- }
- }
- // -> execute the request
- DescribeAvailabilityZonesResponse EC2response = EC2SoapServiceImpl.toDescribeAvailabilityZonesResponse( ServiceProvider.getInstance().getEC2Engine().handleRequest( EC2request ));
- serializeResponse(response, EC2response);
+ throws ADBException, XMLStreamException, IOException {
+ EC2DescribeAvailabilityZones EC2request = new EC2DescribeAvailabilityZones();
+
+ // -> load in all the "ZoneName.n" parameters if any
+ Enumeration<?> names = request.getParameterNames();
+ while( names.hasMoreElements()) {
+ String key = (String)names.nextElement();
+ if (key.startsWith("ZoneName")) {
+ String[] value = request.getParameterValues( key );
+ if (null != value && 0 < value.length) EC2request.addZone( value[0] );
+ }
+ }
+ // -> execute the request
+ DescribeAvailabilityZonesResponse EC2response = EC2SoapServiceImpl.toDescribeAvailabilityZonesResponse( ServiceProvider.getInstance().getEC2Engine().handleRequest( EC2request ));
+ serializeResponse(response, EC2response);
}
private void describeImages( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2DescribeImages EC2request = new EC2DescribeImages();
-
- // -> load in all the "ImageId.n" parameters if any, and ignore all other parameters
- Enumeration<?> names = request.getParameterNames();
- while( names.hasMoreElements()) {
- String key = (String)names.nextElement();
- if (key.startsWith("ImageId")) {
- String[] value = request.getParameterValues( key );
- if (null != value && 0 < value.length) EC2request.addImageSet( value[0] );
- }
- }
- // -> execute the request
- EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
- DescribeImagesResponse EC2response = EC2SoapServiceImpl.toDescribeImagesResponse( engine.describeImages( EC2request ));
- serializeResponse(response, EC2response);
+ throws ADBException, XMLStreamException, IOException {
+ EC2DescribeImages EC2request = new EC2DescribeImages();
+
+ // -> load in all the "ImageId.n" parameters if any, and ignore all other parameters
+ Enumeration<?> names = request.getParameterNames();
+ while( names.hasMoreElements()) {
+ String key = (String)names.nextElement();
+ if (key.startsWith("ImageId")) {
+ String[] value = request.getParameterValues( key );
+ if (null != value && 0 < value.length) EC2request.addImageSet( value[0] );
+ }
+ }
+ // -> execute the request
+ EC2Engine engine = ServiceProvider.getInstance().getEC2Engine();
+ DescribeImagesResponse EC2response = EC2SoapServiceImpl.toDescribeImagesResponse( engine.describeImages( EC2request ));
+ serializeResponse(response, EC2response);
}
-
+
private void describeImageAttribute( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException {
- EC2DescribeImages EC2request = new EC2DescribeImages();
-
- // -> only works for queries about descriptions
+ throws ADBException, XMLStreamException, IOException {
+ EC2DescribeImages EC2request = new EC2DescribeImages();
+
+ // -> only works for queries about descriptions
String[] descriptions = request.getParameterValues( "Description" );
- if ( null != descriptions && 0 < descriptions.length ) {
- String[] value = request.getParameterValues( "ImageId" );
- EC2request.addImageSet( value[0] );
- }
- else {
- response.sendError(501, "Unsupported - only description supported" );
- return;
- }
-
- // -> execute the request
- DescribeImageAttributeResponse EC2response = EC2SoapServiceImpl.toDescribeImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().describeImages( EC2request ));
- serializeResponse(response, EC2response);
+ if ( null != descriptions && 0 < descriptions.length ) {
+ String[] value = request.getParameterValues( "ImageId" );
+ EC2request.addImageSet( value[0] );
+ }
+ else {
+ response.sendError(501, "Unsupported - only description supported" );
+ return;
+ }
+
+ // -> execute the request
+ DescribeImageAttributeResponse EC2response = EC2SoapServiceImpl.toDescribeImageAttributeResponse( ServiceProvider.getInstance().getEC2Engine().describeImages( EC2request ));
+ serializeResponse(response, EC2response);
}
-
+
private void describeInstances( HttpServletRequest request, HttpServletResponse response )
- throws ADBException, XMLStreamException, IOException
- {
- EC2DescribeInstances EC2request = new EC2DescribeInstances();
-
- // -> load in all the "InstanceId.n" parameters if any
- Enumeration<?> names = request.getParameterNames();
- while( names.hasMoreElements())
- {
- String key = (String)names.nextElement();
- if (key.startsWith("InstanceId")) {
- String[] value = request.getParameterValues( key );
- if (null != value && 0 < value.length) EC2request.addInstanceId( value[0] );
- }
- }
-
+ throws ADBException, XMLStreamException, IOException
+ {
+ EC2DescribeInstances EC2request = new EC2DescribeInstances();
+
+ // -> load in all the "InstanceId.n" parameters if any
+ Enumeration<?> names = request.getParameterNames();
+ while( names.hasMoreElements())
+ {
+ String key = (String)names.nextElement();
+ if (key.startsWith("InstanceId")) {
+ String[] value = request.getParameterValues( key );
+ if (null != value && 0 < value.length) EC2request.addInstanceId( value[0] );
+ }
+ }
+
// -> are there any filters with this request?
EC2Filter[] filterSet = extractFilters( request );
if (null != filterSet)
{
- EC2InstanceFilterSet ifs = new EC2InstanceFilterSet();
- for( int i=0; i < filterSet.length; i++ ) ifs.addFilter( filterSet[i] );
- EC2request.setFilterSet( ifs );
+
<TRUNCATED>