Skip to content

Commit

Permalink
Merge pull request #30 from andrerod/cloudservices
Browse files Browse the repository at this point in the history
Add Cloudservices wrapper
  • Loading branch information
André Rodrigues committed Jan 20, 2014
2 parents 93a5984 + 0cfcddf commit 294bd4e
Show file tree
Hide file tree
Showing 338 changed files with 39,900 additions and 24,130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
{
/**
* The URI used as the base for all Service Management requests.
* @return The BaseUri value.
*/
URI getBaseUri();

Expand All @@ -55,6 +56,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* Azure Service ManagementAPI use mutual authentication of management
* certificates over SSL to ensure that a request made to the service is
* secure. No anonymous requests are allowed.
* @return The Credentials value.
*/
SubscriptionCloudCredentials getCredentials();

Expand All @@ -63,6 +65,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* deployments beneath your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx for
* more information)
* @return The DeploymentsOperations value.
*/
DeploymentOperations getDeploymentsOperations();

Expand All @@ -71,6 +74,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* services beneath your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx for
* more information)
* @return The HostedServicesOperations value.
*/
HostedServiceOperations getHostedServicesOperations();

Expand All @@ -79,13 +83,15 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* Operating System on which your service is running. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ff684169.aspx for
* more information)
* @return The OperatingSystemsOperations value.
*/
OperatingSystemOperations getOperatingSystemsOperations();

/**
* Operations for managing service certificates for your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee795178.aspx for
* more information)
* @return The ServiceCertificatesOperations value.
*/
ServiceCertificateOperations getServiceCertificatesOperations();

Expand All @@ -94,6 +100,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157188.aspx for
* more information)
* @return The VirtualMachineDisksOperations value.
*/
VirtualMachineDiskOperations getVirtualMachineDisksOperations();

Expand All @@ -102,6 +109,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* in your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157175.aspx for
* more information)
* @return The VirtualMachineImagesOperations value.
*/
VirtualMachineImageOperations getVirtualMachineImagesOperations();

Expand All @@ -110,6 +118,7 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* machines in your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157206.aspx for
* more information)
* @return The VirtualMachinesOperations value.
*/
VirtualMachineOperations getVirtualMachinesOperations();

Expand All @@ -124,6 +133,14 @@ public interface ComputeManagementClient extends FilterableService<ComputeManage
* @param requestId The request ID for the request you wish to track. The
* request ID is returned in the x-ms-request-id response header for every
* request.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is
* inprogress, or has failed. Note that this status is distinct from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ComputeManagementClientImpl extends ServiceClient<ComputeManagement

/**
* The URI used as the base for all Service Management requests.
* @return The BaseUri value.
*/
public URI getBaseUri()
{
Expand All @@ -83,6 +84,7 @@ public URI getBaseUri()
* Azure Service ManagementAPI use mutual authentication of management
* certificates over SSL to ensure that a request made to the service is
* secure. No anonymous requests are allowed.
* @return The Credentials value.
*/
public SubscriptionCloudCredentials getCredentials()
{
Expand All @@ -96,6 +98,7 @@ public SubscriptionCloudCredentials getCredentials()
* deployments beneath your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx for
* more information)
* @return The DeploymentsOperations value.
*/
public DeploymentOperations getDeploymentsOperations()
{
Expand All @@ -109,6 +112,7 @@ public DeploymentOperations getDeploymentsOperations()
* services beneath your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee460812.aspx for
* more information)
* @return The HostedServicesOperations value.
*/
public HostedServiceOperations getHostedServicesOperations()
{
Expand All @@ -122,6 +126,7 @@ public HostedServiceOperations getHostedServicesOperations()
* Operating System on which your service is running. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ff684169.aspx for
* more information)
* @return The OperatingSystemsOperations value.
*/
public OperatingSystemOperations getOperatingSystemsOperations()
{
Expand All @@ -134,6 +139,7 @@ public OperatingSystemOperations getOperatingSystemsOperations()
* Operations for managing service certificates for your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/ee795178.aspx for
* more information)
* @return The ServiceCertificatesOperations value.
*/
public ServiceCertificateOperations getServiceCertificatesOperations()
{
Expand All @@ -147,6 +153,7 @@ public ServiceCertificateOperations getServiceCertificatesOperations()
* your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157188.aspx for
* more information)
* @return The VirtualMachineDisksOperations value.
*/
public VirtualMachineDiskOperations getVirtualMachineDisksOperations()
{
Expand All @@ -160,6 +167,7 @@ public VirtualMachineDiskOperations getVirtualMachineDisksOperations()
* in your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157175.aspx for
* more information)
* @return The VirtualMachineImagesOperations value.
*/
public VirtualMachineImageOperations getVirtualMachineImagesOperations()
{
Expand All @@ -173,6 +181,7 @@ public VirtualMachineImageOperations getVirtualMachineImagesOperations()
* machines in your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj157206.aspx for
* more information)
* @return The VirtualMachinesOperations value.
*/
public VirtualMachineOperations getVirtualMachinesOperations()
{
Expand Down Expand Up @@ -238,6 +247,8 @@ public ComputeManagementClientImpl(HttpClientBuilder httpBuilder, ExecutorServic
* The Windows Azure Service ManagementAPI use mutual authentication of
* management certificates over SSL to ensure that a request made to the
* service is secure. No anonymous requests are allowed.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
*/
@Inject
public ComputeManagementClientImpl(HttpClientBuilder httpBuilder, ExecutorService executorService, @Named(ManagementConfiguration.SUBSCRIPTION_CLOUD_CREDENTIALS) SubscriptionCloudCredentials credentials) throws java.net.URISyntaxException
Expand Down Expand Up @@ -305,6 +316,14 @@ public ComputeOperationStatusResponse call() throws Exception
* @param requestId The request ID for the request you wish to track. The
* request ID is returned in the x-ms-request-id response header for every
* request.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is
* inprogress, or has failed. Note that this status is distinct from the
Expand Down Expand Up @@ -346,104 +365,114 @@ public ComputeOperationStatusResponse getOperationStatus(String requestId) throw

// Send Request
HttpResponse httpResponse = null;
if (shouldTrace)
try
{
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getHttpClient().execute(httpRequest);
if (shouldTrace)
{
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK)
{
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace)
{
CloudTracing.error(invocationId, ex);
CloudTracing.sendRequest(invocationId, httpRequest);
}
throw ex;
}

// Create Result
ComputeOperationStatusResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new ComputeOperationStatusResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(responseContent);

NodeList elements = responseDoc.getElementsByTagName("Operation");
Element operationElement = elements.getLength() > 0 ? ((Element) elements.item(0)) : null;
if (operationElement != null)
{
NodeList elements2 = operationElement.getElementsByTagName("ID");
Element idElement = elements2.getLength() > 0 ? ((Element) elements2.item(0)) : null;
if (idElement != null)
httpResponse = this.getHttpClient().execute(httpRequest);
if (shouldTrace)
{
String idInstance;
idInstance = idElement.getTextContent();
result.setId(idInstance);
CloudTracing.receiveResponse(invocationId, httpResponse);
}

NodeList elements3 = operationElement.getElementsByTagName("Status");
Element statusElement = elements3.getLength() > 0 ? ((Element) elements3.item(0)) : null;
if (statusElement != null)
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK)
{
OperationStatus statusInstance;
statusInstance = OperationStatus.valueOf(statusElement.getTextContent());
result.setStatus(statusInstance);
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace)
{
CloudTracing.error(invocationId, ex);
}
throw ex;
}

NodeList elements4 = operationElement.getElementsByTagName("HttpStatusCode");
Element httpStatusCodeElement = elements4.getLength() > 0 ? ((Element) elements4.item(0)) : null;
if (httpStatusCodeElement != null)
{
Integer httpStatusCodeInstance;
httpStatusCodeInstance = Integer.valueOf(httpStatusCodeElement.getTextContent());
result.setHttpStatusCode(httpStatusCodeInstance);
}
// Create Result
ComputeOperationStatusResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new ComputeOperationStatusResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(responseContent);

NodeList elements5 = operationElement.getElementsByTagName("Error");
Element errorElement = elements5.getLength() > 0 ? ((Element) elements5.item(0)) : null;
if (errorElement != null)
NodeList elements = responseDoc.getElementsByTagName("Operation");
Element operationElement = elements.getLength() > 0 ? ((Element) elements.item(0)) : null;
if (operationElement != null)
{
ComputeOperationStatusResponse.ErrorDetails errorInstance = new ComputeOperationStatusResponse.ErrorDetails();
result.setError(errorInstance);
NodeList elements2 = operationElement.getElementsByTagName("ID");
Element idElement = elements2.getLength() > 0 ? ((Element) elements2.item(0)) : null;
if (idElement != null)
{
String idInstance;
idInstance = idElement.getTextContent();
result.setId(idInstance);
}

NodeList elements6 = errorElement.getElementsByTagName("Code");
Element codeElement = elements6.getLength() > 0 ? ((Element) elements6.item(0)) : null;
if (codeElement != null)
NodeList elements3 = operationElement.getElementsByTagName("Status");
Element statusElement = elements3.getLength() > 0 ? ((Element) elements3.item(0)) : null;
if (statusElement != null)
{
String codeInstance;
codeInstance = codeElement.getTextContent();
errorInstance.setCode(codeInstance);
OperationStatus statusInstance;
statusInstance = OperationStatus.valueOf(statusElement.getTextContent());
result.setStatus(statusInstance);
}

NodeList elements7 = errorElement.getElementsByTagName("Message");
Element messageElement = elements7.getLength() > 0 ? ((Element) elements7.item(0)) : null;
if (messageElement != null)
NodeList elements4 = operationElement.getElementsByTagName("HttpStatusCode");
Element httpStatusCodeElement = elements4.getLength() > 0 ? ((Element) elements4.item(0)) : null;
if (httpStatusCodeElement != null)
{
String messageInstance;
messageInstance = messageElement.getTextContent();
errorInstance.setMessage(messageInstance);
Integer httpStatusCodeInstance;
httpStatusCodeInstance = Integer.valueOf(httpStatusCodeElement.getTextContent());
result.setHttpStatusCode(httpStatusCodeInstance);
}

NodeList elements5 = operationElement.getElementsByTagName("Error");
Element errorElement = elements5.getLength() > 0 ? ((Element) elements5.item(0)) : null;
if (errorElement != null)
{
ComputeOperationStatusResponse.ErrorDetails errorInstance = new ComputeOperationStatusResponse.ErrorDetails();
result.setError(errorInstance);

NodeList elements6 = errorElement.getElementsByTagName("Code");
Element codeElement = elements6.getLength() > 0 ? ((Element) elements6.item(0)) : null;
if (codeElement != null)
{
String codeInstance;
codeInstance = codeElement.getTextContent();
errorInstance.setCode(codeInstance);
}

NodeList elements7 = errorElement.getElementsByTagName("Message");
Element messageElement = elements7.getLength() > 0 ? ((Element) elements7.item(0)) : null;
if (messageElement != null)
{
String messageInstance;
messageInstance = messageElement.getTextContent();
errorInstance.setMessage(messageInstance);
}
}
}

result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0)
{
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}

if (shouldTrace)
{
CloudTracing.exit(invocationId, result);
}
return result;
}

result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0)
{
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}

if (shouldTrace)
finally
{
CloudTracing.exit(invocationId, result);
if (httpResponse != null && httpResponse.getEntity() != null)
{
httpResponse.getEntity().getContent().close();
}
}
return result;
}

/**
Expand Down

0 comments on commit 294bd4e

Please sign in to comment.