Java tutorial
/** * * Copyright (c) Microsoft and contributors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * limitations under the License. * */ // Warning: This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if the // code is regenerated. package com.microsoft.windowsazure.management.compute; import com.microsoft.windowsazure.core.OperationResponse; import com.microsoft.windowsazure.core.OperationStatus; import com.microsoft.windowsazure.core.OperationStatusResponse; import com.microsoft.windowsazure.core.ServiceOperations; import com.microsoft.windowsazure.core.pipeline.apache.CustomHttpDelete; import com.microsoft.windowsazure.exception.CloudError; import com.microsoft.windowsazure.exception.ServiceException; import com.microsoft.windowsazure.management.compute.models.LoadBalancerCreateParameters; import com.microsoft.windowsazure.management.compute.models.LoadBalancerUpdateParameters; import com.microsoft.windowsazure.tracing.ClientRequestTrackingHandler; import com.microsoft.windowsazure.tracing.CloudTracing; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.StringEntity; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.IOException; import java.io.StringWriter; import java.net.URISyntaxException; import java.net.URLEncoder; import java.util.HashMap; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; /** * The Compute Management API includes operations for managing the load * balancers for your subscription. */ public class LoadBalancerOperationsImpl implements ServiceOperations<ComputeManagementClientImpl>, LoadBalancerOperations { /** * Initializes a new instance of the LoadBalancerOperationsImpl class. * * @param client Reference to the service client. */ LoadBalancerOperationsImpl(ComputeManagementClientImpl client) { this.client = client; } private ComputeManagementClientImpl client; /** * Gets a reference to the * microsoft.windowsazure.management.compute.ComputeManagementClientImpl. * @return The Client value. */ public ComputeManagementClientImpl getClient() { return this.client; } /** * Add an internal load balancer to a an existing deployment. When used by * an input endpoint, the internal load balancer will provide an additional * private VIP that can be used for load balancing to the roles in this * deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param parameters Required. Parameters supplied to the Create Load * Balancer operation. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public Future<OperationStatusResponse> beginCreatingAsync(final String serviceName, final String deploymentName, final LoadBalancerCreateParameters parameters) { return this.getClient().getExecutorService().submit(new Callable<OperationStatusResponse>() { @Override public OperationStatusResponse call() throws Exception { return beginCreating(serviceName, deploymentName, parameters); } }); } /** * Add an internal load balancer to a an existing deployment. When used by * an input endpoint, the internal load balancer will provide an additional * private VIP that can be used for load balancing to the roles in this * deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param parameters Required. Parameters supplied to the Create Load * Balancer operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @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. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public OperationStatusResponse beginCreating(String serviceName, String deploymentName, LoadBalancerCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/loadbalancers"; String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPost httpRequest = new HttpPost(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2015-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element loadBalancerElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancer"); requestDoc.appendChild(loadBalancerElement); if (parameters.getName() != null) { Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); loadBalancerElement.appendChild(nameElement); } if (parameters.getFrontendIPConfiguration() != null) { Element frontendIpConfigurationElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "FrontendIpConfiguration"); loadBalancerElement.appendChild(frontendIpConfigurationElement); if (parameters.getFrontendIPConfiguration().getType() != null) { Element typeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Type"); typeElement .appendChild(requestDoc.createTextNode(parameters.getFrontendIPConfiguration().getType())); frontendIpConfigurationElement.appendChild(typeElement); } if (parameters.getFrontendIPConfiguration().getSubnetName() != null) { Element subnetNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement.appendChild( requestDoc.createTextNode(parameters.getFrontendIPConfiguration().getSubnetName())); frontendIpConfigurationElement.appendChild(subnetNameElement); } if (parameters.getFrontendIPConfiguration().getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement.appendChild(requestDoc.createTextNode(parameters .getFrontendIPConfiguration().getStaticVirtualNetworkIPAddress().getHostAddress())); frontendIpConfigurationElement.appendChild(staticVirtualNetworkIPAddressElement); } } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationStatusResponse result = null; // Deserialize Response result = new OperationStatusResponse(); 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; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } } /** * Delete an internal load balancer from the deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the load balancer. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public Future<OperationStatusResponse> beginDeletingAsync(final String serviceName, final String deploymentName, final String loadBalancerName) { return this.getClient().getExecutorService().submit(new Callable<OperationStatusResponse>() { @Override public OperationStatusResponse call() throws Exception { return beginDeleting(serviceName, deploymentName, loadBalancerName); } }); } /** * Delete an internal load balancer from the deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the load balancer. * @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. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public OperationStatusResponse beginDeleting(String serviceName, String deploymentName, String loadBalancerName) throws IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (loadBalancerName == null) { throw new NullPointerException("loadBalancerName"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("loadBalancerName", loadBalancerName); CloudTracing.enter(invocationId, this, "beginDeletingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/loadbalancers/"; url = url + URLEncoder.encode(loadBalancerName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects CustomHttpDelete httpRequest = new CustomHttpDelete(url); // Set Headers httpRequest.setHeader("x-ms-version", "2015-04-01"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationStatusResponse result = null; // Deserialize Response result = new OperationStatusResponse(); 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; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } } /** * Updates an internal load balancer associated with an existing deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the loadBalancer. * @param parameters Required. Parameters supplied to the Update Load * Balancer operation. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public Future<OperationStatusResponse> beginUpdatingAsync(final String serviceName, final String deploymentName, final String loadBalancerName, final LoadBalancerUpdateParameters parameters) { return this.getClient().getExecutorService().submit(new Callable<OperationStatusResponse>() { @Override public OperationStatusResponse call() throws Exception { return beginUpdating(serviceName, deploymentName, loadBalancerName, parameters); } }); } /** * Updates an internal load balancer associated with an existing deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the loadBalancer. * @param parameters Required. Parameters supplied to the Update Load * Balancer operation. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @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. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public OperationStatusResponse beginUpdating(String serviceName, String deploymentName, String loadBalancerName, LoadBalancerUpdateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serviceName == null) { throw new NullPointerException("serviceName"); } if (deploymentName == null) { throw new NullPointerException("deploymentName"); } if (loadBalancerName == null) { throw new NullPointerException("loadBalancerName"); } if (parameters == null) { throw new NullPointerException("parameters"); } // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("loadBalancerName", loadBalancerName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginUpdatingAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/services/hostedservices/"; url = url + URLEncoder.encode(serviceName, "UTF-8"); url = url + "/deployments/"; url = url + URLEncoder.encode(deploymentName, "UTF-8"); url = url + "/loadbalancers/"; url = url + URLEncoder.encode(loadBalancerName, "UTF-8"); String baseUrl = this.getClient().getBaseUri().toString(); // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl.charAt(baseUrl.length() - 1) == '/') { baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0); } if (url.charAt(0) == '/') { url = url.substring(1); } url = baseUrl + "/" + url; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpPut httpRequest = new HttpPut(url); // Set Headers httpRequest.setHeader("Content-Type", "application/xml"); httpRequest.setHeader("x-ms-version", "2015-04-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element loadBalancerElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "LoadBalancer"); requestDoc.appendChild(loadBalancerElement); if (parameters.getName() != null) { Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); loadBalancerElement.appendChild(nameElement); } if (parameters.getFrontendIPConfiguration() != null) { Element frontendIpConfigurationElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "FrontendIpConfiguration"); loadBalancerElement.appendChild(frontendIpConfigurationElement); if (parameters.getFrontendIPConfiguration().getType() != null) { Element typeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Type"); typeElement .appendChild(requestDoc.createTextNode(parameters.getFrontendIPConfiguration().getType())); frontendIpConfigurationElement.appendChild(typeElement); } if (parameters.getFrontendIPConfiguration().getSubnetName() != null) { Element subnetNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SubnetName"); subnetNameElement.appendChild( requestDoc.createTextNode(parameters.getFrontendIPConfiguration().getSubnetName())); frontendIpConfigurationElement.appendChild(subnetNameElement); } if (parameters.getFrontendIPConfiguration().getStaticVirtualNetworkIPAddress() != null) { Element staticVirtualNetworkIPAddressElement = requestDoc.createElementNS( "http://schemas.microsoft.com/windowsazure", "StaticVirtualNetworkIPAddress"); staticVirtualNetworkIPAddressElement.appendChild(requestDoc.createTextNode(parameters .getFrontendIPConfiguration().getStaticVirtualNetworkIPAddress().getHostAddress())); frontendIpConfigurationElement.appendChild(staticVirtualNetworkIPAddressElement); } } DOMSource domSource = new DOMSource(requestDoc); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.transform(domSource, streamResult); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/xml"); // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { CloudTracing.sendRequest(invocationId, httpRequest); } httpResponse = this.getClient().getHttpClient().execute(httpRequest); if (shouldTrace) { CloudTracing.receiveResponse(invocationId, httpResponse); } int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationStatusResponse result = null; // Deserialize Response result = new OperationStatusResponse(); 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; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } } /** * Add an internal load balancer to a an existing deployment. When used by * an input endpoint, the internal load balancer will provide an additional * private VIP that can be used for load balancing to the roles in this * deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param parameters Required. Parameters supplied to the Create Load * Balancer operation. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public Future<OperationStatusResponse> createAsync(final String serviceName, final String deploymentName, final LoadBalancerCreateParameters parameters) { return this.getClient().getExecutorService().submit(new Callable<OperationStatusResponse>() { @Override public OperationStatusResponse call() throws Exception { return create(serviceName, deploymentName, parameters); } }); } /** * Add an internal load balancer to a an existing deployment. When used by * an input endpoint, the internal load balancer will provide an additional * private VIP that can be used for load balancing to the roles in this * deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param parameters Required. Parameters supplied to the Create Load * Balancer operation. * @throws InterruptedException Thrown when a thread is waiting, sleeping, * or otherwise occupied, and the thread is interrupted, either before or * during the activity. Occasionally a method may wish to test whether the * current thread has been interrupted, and if so, to immediately throw * this exception. The following code can be used to achieve this effect: * @throws ExecutionException Thrown when attempting to retrieve the result * of a task that aborted by throwing an exception. This exception can be * inspected using the Throwable.getCause() method. * @throws ServiceException Thrown if the server returned an error for the * request. * @throws IOException Thrown if there was an error setting up tracing for * the request. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the 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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public OperationStatusResponse create(String serviceName, String deploymentName, LoadBalancerCreateParameters parameters) throws InterruptedException, ExecutionException, ServiceException, IOException, ParserConfigurationException, SAXException, TransformerException, URISyntaxException { ComputeManagementClient client2 = this.getClient(); boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", tracingParameters); } try { if (shouldTrace) { client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)) .withResponseFilterLast(new ClientRequestTrackingHandler(invocationId)); } OperationStatusResponse response = client2.getLoadBalancersOperations() .beginCreatingAsync(serviceName, deploymentName, parameters).get(); if (response.getStatus() == OperationStatus.Succeeded) { return response; } OperationStatusResponse result = client2.getOperationStatusAsync(response.getRequestId()).get(); int delayInSeconds = 30; if (client2.getLongRunningOperationInitialTimeout() >= 0) { delayInSeconds = client2.getLongRunningOperationInitialTimeout(); } while (result.getStatus() != null && result.getStatus().equals(OperationStatus.InProgress)) { Thread.sleep(delayInSeconds * 1000); result = client2.getOperationStatusAsync(response.getRequestId()).get(); delayInSeconds = 30; if (client2.getLongRunningOperationRetryTimeout() >= 0) { delayInSeconds = client2.getLongRunningOperationRetryTimeout(); } } if (shouldTrace) { CloudTracing.exit(invocationId, result); } if (result.getStatus() != OperationStatus.Succeeded) { if (result.getError() != null) { ServiceException ex = new ServiceException( result.getError().getCode() + " : " + result.getError().getMessage()); ex.setError(new CloudError()); ex.getError().setCode(result.getError().getCode()); ex.getError().setMessage(result.getError().getMessage()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } else { ServiceException ex = new ServiceException(""); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } } return result; } finally { if (client2 != null && shouldTrace) { client2.close(); } } } /** * Delete an internal load balancer from the deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the load balancer. * @return A standard service response including an HTTP status code and * request ID. */ @Override public Future<OperationResponse> deleteAsync(final String serviceName, final String deploymentName, final String loadBalancerName) { return this.getClient().getExecutorService().submit(new Callable<OperationResponse>() { @Override public OperationResponse call() throws Exception { return delete(serviceName, deploymentName, loadBalancerName); } }); } /** * Delete an internal load balancer from the deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the load balancer. * @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 InterruptedException Thrown when a thread is waiting, sleeping, * or otherwise occupied, and the thread is interrupted, either before or * during the activity. Occasionally a method may wish to test whether the * current thread has been interrupted, and if so, to immediately throw * this exception. The following code can be used to achieve this effect: * @throws ExecutionException Thrown when attempting to retrieve the result * of a task that aborted by throwing an exception. This exception can be * inspected using the Throwable.getCause() method. * @throws ServiceException Thrown if the server returned an error for the * request. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse delete(String serviceName, String deploymentName, String loadBalancerName) throws IOException, ServiceException, InterruptedException, ExecutionException { ComputeManagementClient client2 = this.getClient(); boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("loadBalancerName", loadBalancerName); CloudTracing.enter(invocationId, this, "deleteAsync", tracingParameters); } try { if (shouldTrace) { client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)) .withResponseFilterLast(new ClientRequestTrackingHandler(invocationId)); } OperationStatusResponse response = client2.getLoadBalancersOperations() .beginDeletingAsync(serviceName, deploymentName, loadBalancerName).get(); OperationStatusResponse result = client2.getOperationStatusAsync(response.getRequestId()).get(); int delayInSeconds = 30; if (client2.getLongRunningOperationInitialTimeout() >= 0) { delayInSeconds = client2.getLongRunningOperationInitialTimeout(); } while (result.getStatus() != null && result.getStatus().equals(OperationStatus.InProgress)) { Thread.sleep(delayInSeconds * 1000); result = client2.getOperationStatusAsync(response.getRequestId()).get(); delayInSeconds = 30; if (client2.getLongRunningOperationRetryTimeout() >= 0) { delayInSeconds = client2.getLongRunningOperationRetryTimeout(); } } if (shouldTrace) { CloudTracing.exit(invocationId, result); } if (result.getStatus() != OperationStatus.Succeeded) { if (result.getError() != null) { ServiceException ex = new ServiceException( result.getError().getCode() + " : " + result.getError().getMessage()); ex.setError(new CloudError()); ex.getError().setCode(result.getError().getCode()); ex.getError().setMessage(result.getError().getMessage()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } else { ServiceException ex = new ServiceException(""); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } } return result; } finally { if (client2 != null && shouldTrace) { client2.close(); } } } /** * Updates an internal load balancer associated with an existing deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the loadBalancer. * @param parameters Required. Parameters supplied to the Update Load * Balancer operation. * @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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public Future<OperationStatusResponse> updateAsync(final String serviceName, final String deploymentName, final String loadBalancerName, final LoadBalancerUpdateParameters parameters) { return this.getClient().getExecutorService().submit(new Callable<OperationStatusResponse>() { @Override public OperationStatusResponse call() throws Exception { return update(serviceName, deploymentName, loadBalancerName, parameters); } }); } /** * Updates an internal load balancer associated with an existing deployment. * * @param serviceName Required. The name of the service. * @param deploymentName Required. The name of the deployment. * @param loadBalancerName Required. The name of the loadBalancer. * @param parameters Required. Parameters supplied to the Update Load * Balancer operation. * @throws InterruptedException Thrown when a thread is waiting, sleeping, * or otherwise occupied, and the thread is interrupted, either before or * during the activity. Occasionally a method may wish to test whether the * current thread has been interrupted, and if so, to immediately throw * this exception. The following code can be used to achieve this effect: * @throws ExecutionException Thrown when attempting to retrieve the result * of a task that aborted by throwing an exception. This exception can be * inspected using the Throwable.getCause() method. * @throws ServiceException Thrown if the server returned an error for the * request. * @throws IOException Thrown if there was an error setting up tracing for * the request. * @throws ParserConfigurationException Thrown if there was an error * configuring the parser for the response body. * @throws SAXException Thrown if there was an error parsing the response * body. * @throws TransformerException Thrown if there was an error creating the * DOM transformer. * @throws ServiceException Thrown if an unexpected response is found. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the 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 * HTTP status code returned for the Get Operation Status operation itself. * If the asynchronous operation succeeded, the response body includes the * HTTP status code for the successful request. If the asynchronous * operation failed, the response body includes the HTTP status code for * the failed request and error information regarding the failure. */ @Override public OperationStatusResponse update(String serviceName, String deploymentName, String loadBalancerName, LoadBalancerUpdateParameters parameters) throws InterruptedException, ExecutionException, ServiceException, IOException, ParserConfigurationException, SAXException, TransformerException, URISyntaxException { ComputeManagementClient client2 = this.getClient(); boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); tracingParameters.put("serviceName", serviceName); tracingParameters.put("deploymentName", deploymentName); tracingParameters.put("loadBalancerName", loadBalancerName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", tracingParameters); } try { if (shouldTrace) { client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)) .withResponseFilterLast(new ClientRequestTrackingHandler(invocationId)); } OperationStatusResponse response = client2.getLoadBalancersOperations() .beginUpdatingAsync(serviceName, deploymentName, loadBalancerName, parameters).get(); if (response.getStatus() == OperationStatus.Succeeded) { return response; } OperationStatusResponse result = client2.getOperationStatusAsync(response.getRequestId()).get(); int delayInSeconds = 30; if (client2.getLongRunningOperationInitialTimeout() >= 0) { delayInSeconds = client2.getLongRunningOperationInitialTimeout(); } while (result.getStatus() != null && result.getStatus().equals(OperationStatus.InProgress)) { Thread.sleep(delayInSeconds * 1000); result = client2.getOperationStatusAsync(response.getRequestId()).get(); delayInSeconds = 30; if (client2.getLongRunningOperationRetryTimeout() >= 0) { delayInSeconds = client2.getLongRunningOperationRetryTimeout(); } } if (shouldTrace) { CloudTracing.exit(invocationId, result); } if (result.getStatus() != OperationStatus.Succeeded) { if (result.getError() != null) { ServiceException ex = new ServiceException( result.getError().getCode() + " : " + result.getError().getMessage()); ex.setError(new CloudError()); ex.getError().setCode(result.getError().getCode()); ex.getError().setMessage(result.getError().getMessage()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } else { ServiceException ex = new ServiceException(""); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } } return result; } finally { if (client2 != null && shouldTrace) { client2.close(); } } } }