List of usage examples for javax.xml.bind DatatypeConverter parseDateTime
public static java.util.Calendar parseDateTime(String lexicalXSDDateTime)
Converts the string argument into a Calendar value.
From source file:com.microsoft.windowsazure.management.sql.RestoreDatabaseOperationsImpl.java
/** * Issues a restore request for an Azure SQL Database. * * @param sourceServerName Required. The name of the Azure SQL Database * Server where the source database is, or was, hosted. * @param parameters Required. Additional parameters for the Create Restore * Database Operation request.// w w w . ja v a 2s. c o m * @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 Contains the response to the Create Restore Database Operation * request. */ @Override public RestoreDatabaseOperationCreateResponse create(String sourceServerName, RestoreDatabaseOperationCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (sourceServerName == null) { throw new NullPointerException("sourceServerName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getSourceDatabaseName() == null) { throw new NullPointerException("parameters.SourceDatabaseName"); } if (parameters.getTargetDatabaseName() == null) { throw new NullPointerException("parameters.TargetDatabaseName"); } // 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("sourceServerName", sourceServerName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", 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/sqlservers/servers/"; url = url + URLEncoder.encode(sourceServerName, "UTF-8"); url = url + "/restoredatabaseoperations"; 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", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceResource"); requestDoc.appendChild(serviceResourceElement); Element sourceDatabaseNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SourceDatabaseName"); sourceDatabaseNameElement.appendChild(requestDoc.createTextNode(parameters.getSourceDatabaseName())); serviceResourceElement.appendChild(sourceDatabaseNameElement); if (parameters.getSourceDatabaseDeletionDate() != null) { Element sourceDatabaseDeletionDateElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "SourceDatabaseDeletionDate"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); sourceDatabaseDeletionDateElement.appendChild(requestDoc .createTextNode(simpleDateFormat.format(parameters.getSourceDatabaseDeletionDate().getTime()))); serviceResourceElement.appendChild(sourceDatabaseDeletionDateElement); } if (parameters.getTargetServerName() != null) { Element targetServerNameElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "TargetServerName"); targetServerNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetServerName())); serviceResourceElement.appendChild(targetServerNameElement); } Element targetDatabaseNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "TargetDatabaseName"); targetDatabaseNameElement.appendChild(requestDoc.createTextNode(parameters.getTargetDatabaseName())); serviceResourceElement.appendChild(targetDatabaseNameElement); if (parameters.getPointInTime() != null) { Element targetUtcPointInTimeElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "TargetUtcPointInTime"); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC")); targetUtcPointInTimeElement.appendChild( requestDoc.createTextNode(simpleDateFormat2.format(parameters.getPointInTime().getTime()))); serviceResourceElement.appendChild(targetUtcPointInTimeElement); } 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_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result RestoreDatabaseOperationCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new RestoreDatabaseOperationCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement2 != null) { RestoreDatabaseOperation serviceResourceInstance = new RestoreDatabaseOperation(); result.setOperation(serviceResourceInstance); Element requestIDElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "RequestID"); if (requestIDElement != null) { String requestIDInstance; requestIDInstance = requestIDElement.getTextContent(); serviceResourceInstance.setId(requestIDInstance); } Element sourceDatabaseNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SourceDatabaseName"); if (sourceDatabaseNameElement2 != null) { String sourceDatabaseNameInstance; sourceDatabaseNameInstance = sourceDatabaseNameElement2.getTextContent(); serviceResourceInstance.setSourceDatabaseName(sourceDatabaseNameInstance); } Element sourceDatabaseDeletionDateElement2 = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SourceDatabaseDeletionDate"); if (sourceDatabaseDeletionDateElement2 != null && sourceDatabaseDeletionDateElement2.getTextContent() != null && !sourceDatabaseDeletionDateElement2.getTextContent().isEmpty()) { Calendar sourceDatabaseDeletionDateInstance; sourceDatabaseDeletionDateInstance = DatatypeConverter .parseDateTime(sourceDatabaseDeletionDateElement2.getTextContent()); serviceResourceInstance.setSourceDatabaseDeletionDate(sourceDatabaseDeletionDateInstance); } Element targetServerNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "TargetServerName"); if (targetServerNameElement2 != null) { String targetServerNameInstance; targetServerNameInstance = targetServerNameElement2.getTextContent(); serviceResourceInstance.setTargetServerName(targetServerNameInstance); } Element targetDatabaseNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "TargetDatabaseName"); if (targetDatabaseNameElement2 != null) { String targetDatabaseNameInstance; targetDatabaseNameInstance = targetDatabaseNameElement2.getTextContent(); serviceResourceInstance.setTargetDatabaseName(targetDatabaseNameInstance); } Element targetUtcPointInTimeElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "TargetUtcPointInTime"); if (targetUtcPointInTimeElement2 != null) { Calendar targetUtcPointInTimeInstance; targetUtcPointInTimeInstance = DatatypeConverter .parseDateTime(targetUtcPointInTimeElement2.getTextContent()); serviceResourceInstance.setPointInTime(targetUtcPointInTimeInstance); } } } 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(); } } }
From source file:com.microsoft.azure.management.sql.ServerUpgradeOperationsImpl.java
/** * Returns information about Upgrade status of an Azure SQL Database Server. * * @param resourceGroupName Required. The name of the Resource Group to * which the server belongs.//from w ww. j a v a2 s . c o m * @param serverName Required. The name of the Azure SQL Database Server to * upgrade. * @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 Represents the response to a Get request for Upgrade status of an * Azure SQL Database Server. */ @Override public ServerUpgradeGetResponse get(String resourceGroupName, String serverName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (serverName == null) { throw new NullPointerException("serverName"); } // 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("resourceGroupName", resourceGroupName); tracingParameters.put("serverName", serverName); CloudTracing.enter(invocationId, this, "getAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Sql"; url = url + "/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/operationResults/versionUpgrade"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-04-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } 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 HttpGet httpRequest = new HttpGet(url); // Set Headers // 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_OK && statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ServerUpgradeGetResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ServerUpgradeGetResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode statusValue = responseDoc.get("status"); if (statusValue != null && statusValue instanceof NullNode == false) { String statusInstance; statusInstance = statusValue.getTextValue(); result.setStatus(statusInstance); } JsonNode scheduleUpgradeAfterTimeValue = responseDoc.get("scheduleUpgradeAfterTime"); if (scheduleUpgradeAfterTimeValue != null && scheduleUpgradeAfterTimeValue instanceof NullNode == false) { Calendar scheduleUpgradeAfterTimeInstance; scheduleUpgradeAfterTimeInstance = DatatypeConverter .parseDateTime(scheduleUpgradeAfterTimeValue.getTextValue()); result.setScheduleUpgradeAfterTime(scheduleUpgradeAfterTimeInstance); } } } 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(); } } }
From source file:com.heliumv.api.customer.CustomerApi.java
private boolean setupParamValidityDate(KundenpreislisteParams params, String filterValidityDate) { if (StringHelper.isEmpty(filterValidityDate)) return true; try {//from w ww . j a va 2 s .c o m Calendar c = DatatypeConverter.parseDateTime(filterValidityDate); params.setGueltigkeitsDatum(new Date(c.getTimeInMillis())); return true; } catch (IllegalArgumentException e) { System.out.println("illegalargument" + e.getMessage()); } respondBadRequest("filter_validitydate", filterValidityDate); return false; }
From source file:com.microsoft.azure.management.sql.DatabaseActivationOperationsImpl.java
/** * Start an Azure SQL Data Warehouse database pause operation.To determine * the status of the operation call GetDatabaseActivationOperationStatus. * * @param resourceGroupName Required. The name of the Resource Group to * which the Azure SQL Server belongs./*from w w w. java 2s . c o m*/ * @param serverName Required. The name of the Azure SQL Server on which the * data warehouse database is hosted. * @param databaseName Required. The name of the Azure SQL Data Warehouse * database to pause. * @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 Response for long running Azure Sql Database operations. */ @Override public DatabaseCreateOrUpdateResponse beginPause(String resourceGroupName, String serverName, String databaseName) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (serverName == null) { throw new NullPointerException("serverName"); } if (databaseName == null) { throw new NullPointerException("databaseName"); } // 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("resourceGroupName", resourceGroupName); tracingParameters.put("serverName", serverName); tracingParameters.put("databaseName", databaseName); CloudTracing.enter(invocationId, this, "beginPauseAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Sql"; url = url + "/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases/"; url = url + URLEncoder.encode(databaseName, "UTF-8"); url = url + "/pause"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-04-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } 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/json; charset=utf-8"); // 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_OK && statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseCreateOrUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseCreateOrUpdateResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { ErrorResponse errorInstance = new ErrorResponse(); result.setError(errorInstance); JsonNode codeValue = responseDoc.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); errorInstance.setCode(codeInstance); } JsonNode messageValue = responseDoc.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); errorInstance.setMessage(messageInstance); } JsonNode targetValue = responseDoc.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); errorInstance.setTarget(targetInstance); } Database databaseInstance = new Database(); result.setDatabase(databaseInstance); JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { DatabaseProperties propertiesInstance = new DatabaseProperties(); databaseInstance.setProperties(propertiesInstance); JsonNode collationValue = propertiesValue.get("collation"); if (collationValue != null && collationValue instanceof NullNode == false) { String collationInstance; collationInstance = collationValue.getTextValue(); propertiesInstance.setCollation(collationInstance); } JsonNode creationDateValue = propertiesValue.get("creationDate"); if (creationDateValue != null && creationDateValue instanceof NullNode == false) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateValue.getTextValue()); propertiesInstance.setCreationDate(creationDateInstance); } JsonNode currentServiceObjectiveIdValue = propertiesValue.get("currentServiceObjectiveId"); if (currentServiceObjectiveIdValue != null && currentServiceObjectiveIdValue instanceof NullNode == false) { String currentServiceObjectiveIdInstance; currentServiceObjectiveIdInstance = currentServiceObjectiveIdValue.getTextValue(); propertiesInstance.setCurrentServiceObjectiveId(currentServiceObjectiveIdInstance); } JsonNode databaseIdValue = propertiesValue.get("databaseId"); if (databaseIdValue != null && databaseIdValue instanceof NullNode == false) { String databaseIdInstance; databaseIdInstance = databaseIdValue.getTextValue(); propertiesInstance.setDatabaseId(databaseIdInstance); } JsonNode earliestRestoreDateValue = propertiesValue.get("earliestRestoreDate"); if (earliestRestoreDateValue != null && earliestRestoreDateValue instanceof NullNode == false) { Calendar earliestRestoreDateInstance; earliestRestoreDateInstance = DatatypeConverter .parseDateTime(earliestRestoreDateValue.getTextValue()); propertiesInstance.setEarliestRestoreDate(earliestRestoreDateInstance); } JsonNode editionValue = propertiesValue.get("edition"); if (editionValue != null && editionValue instanceof NullNode == false) { String editionInstance; editionInstance = editionValue.getTextValue(); propertiesInstance.setEdition(editionInstance); } JsonNode maxSizeBytesValue = propertiesValue.get("maxSizeBytes"); if (maxSizeBytesValue != null && maxSizeBytesValue instanceof NullNode == false) { long maxSizeBytesInstance; maxSizeBytesInstance = maxSizeBytesValue.getLongValue(); propertiesInstance.setMaxSizeBytes(maxSizeBytesInstance); } JsonNode requestedServiceObjectiveIdValue = propertiesValue .get("requestedServiceObjectiveId"); if (requestedServiceObjectiveIdValue != null && requestedServiceObjectiveIdValue instanceof NullNode == false) { String requestedServiceObjectiveIdInstance; requestedServiceObjectiveIdInstance = requestedServiceObjectiveIdValue.getTextValue(); propertiesInstance.setRequestedServiceObjectiveId(requestedServiceObjectiveIdInstance); } JsonNode requestedServiceObjectiveNameValue = propertiesValue .get("requestedServiceObjectiveName"); if (requestedServiceObjectiveNameValue != null && requestedServiceObjectiveNameValue instanceof NullNode == false) { String requestedServiceObjectiveNameInstance; requestedServiceObjectiveNameInstance = requestedServiceObjectiveNameValue .getTextValue(); propertiesInstance .setRequestedServiceObjectiveName(requestedServiceObjectiveNameInstance); } JsonNode serviceLevelObjectiveValue = propertiesValue.get("serviceLevelObjective"); if (serviceLevelObjectiveValue != null && serviceLevelObjectiveValue instanceof NullNode == false) { String serviceLevelObjectiveInstance; serviceLevelObjectiveInstance = serviceLevelObjectiveValue.getTextValue(); propertiesInstance.setServiceObjective(serviceLevelObjectiveInstance); } JsonNode statusValue = propertiesValue.get("status"); if (statusValue != null && statusValue instanceof NullNode == false) { String statusInstance; statusInstance = statusValue.getTextValue(); propertiesInstance.setStatus(statusInstance); } JsonNode elasticPoolNameValue = propertiesValue.get("elasticPoolName"); if (elasticPoolNameValue != null && elasticPoolNameValue instanceof NullNode == false) { String elasticPoolNameInstance; elasticPoolNameInstance = elasticPoolNameValue.getTextValue(); propertiesInstance.setElasticPoolName(elasticPoolNameInstance); } JsonNode serviceTierAdvisorsArray = propertiesValue.get("serviceTierAdvisors"); if (serviceTierAdvisorsArray != null && serviceTierAdvisorsArray instanceof NullNode == false) { for (JsonNode serviceTierAdvisorsValue : ((ArrayNode) serviceTierAdvisorsArray)) { ServiceTierAdvisor serviceTierAdvisorInstance = new ServiceTierAdvisor(); propertiesInstance.getServiceTierAdvisors().add(serviceTierAdvisorInstance); JsonNode propertiesValue2 = serviceTierAdvisorsValue.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { ServiceTierAdvisorProperties propertiesInstance2 = new ServiceTierAdvisorProperties(); serviceTierAdvisorInstance.setProperties(propertiesInstance2); JsonNode observationPeriodStartValue = propertiesValue2 .get("observationPeriodStart"); if (observationPeriodStartValue != null && observationPeriodStartValue instanceof NullNode == false) { Calendar observationPeriodStartInstance; observationPeriodStartInstance = DatatypeConverter .parseDateTime(observationPeriodStartValue.getTextValue()); propertiesInstance2 .setObservationPeriodStart(observationPeriodStartInstance); } JsonNode observationPeriodEndValue = propertiesValue2 .get("observationPeriodEnd"); if (observationPeriodEndValue != null && observationPeriodEndValue instanceof NullNode == false) { Calendar observationPeriodEndInstance; observationPeriodEndInstance = DatatypeConverter .parseDateTime(observationPeriodEndValue.getTextValue()); propertiesInstance2.setObservationPeriodEnd(observationPeriodEndInstance); } JsonNode activeTimeRatioValue = propertiesValue2.get("activeTimeRatio"); if (activeTimeRatioValue != null && activeTimeRatioValue instanceof NullNode == false) { double activeTimeRatioInstance; activeTimeRatioInstance = activeTimeRatioValue.getDoubleValue(); propertiesInstance2.setActiveTimeRatio(activeTimeRatioInstance); } JsonNode minDtuValue = propertiesValue2.get("minDtu"); if (minDtuValue != null && minDtuValue instanceof NullNode == false) { double minDtuInstance; minDtuInstance = minDtuValue.getDoubleValue(); propertiesInstance2.setMinDtu(minDtuInstance); } JsonNode avgDtuValue = propertiesValue2.get("avgDtu"); if (avgDtuValue != null && avgDtuValue instanceof NullNode == false) { double avgDtuInstance; avgDtuInstance = avgDtuValue.getDoubleValue(); propertiesInstance2.setAvgDtu(avgDtuInstance); } JsonNode maxDtuValue = propertiesValue2.get("maxDtu"); if (maxDtuValue != null && maxDtuValue instanceof NullNode == false) { double maxDtuInstance; maxDtuInstance = maxDtuValue.getDoubleValue(); propertiesInstance2.setMaxDtu(maxDtuInstance); } JsonNode maxSizeInGBValue = propertiesValue2.get("maxSizeInGB"); if (maxSizeInGBValue != null && maxSizeInGBValue instanceof NullNode == false) { double maxSizeInGBInstance; maxSizeInGBInstance = maxSizeInGBValue.getDoubleValue(); propertiesInstance2.setMaxSizeInGB(maxSizeInGBInstance); } JsonNode serviceLevelObjectiveUsageMetricsArray = propertiesValue2 .get("serviceLevelObjectiveUsageMetrics"); if (serviceLevelObjectiveUsageMetricsArray != null && serviceLevelObjectiveUsageMetricsArray instanceof NullNode == false) { for (JsonNode serviceLevelObjectiveUsageMetricsValue : ((ArrayNode) serviceLevelObjectiveUsageMetricsArray)) { SloUsageMetric sloUsageMetricInstance = new SloUsageMetric(); propertiesInstance2.getServiceLevelObjectiveUsageMetrics() .add(sloUsageMetricInstance); JsonNode serviceLevelObjectiveValue2 = serviceLevelObjectiveUsageMetricsValue .get("serviceLevelObjective"); if (serviceLevelObjectiveValue2 != null && serviceLevelObjectiveValue2 instanceof NullNode == false) { String serviceLevelObjectiveInstance2; serviceLevelObjectiveInstance2 = serviceLevelObjectiveValue2 .getTextValue(); sloUsageMetricInstance .setServiceLevelObjective(serviceLevelObjectiveInstance2); } JsonNode serviceLevelObjectiveIdValue = serviceLevelObjectiveUsageMetricsValue .get("serviceLevelObjectiveId"); if (serviceLevelObjectiveIdValue != null && serviceLevelObjectiveIdValue instanceof NullNode == false) { String serviceLevelObjectiveIdInstance; serviceLevelObjectiveIdInstance = serviceLevelObjectiveIdValue .getTextValue(); sloUsageMetricInstance.setServiceLevelObjectiveId( serviceLevelObjectiveIdInstance); } JsonNode inRangeTimeRatioValue = serviceLevelObjectiveUsageMetricsValue .get("inRangeTimeRatio"); if (inRangeTimeRatioValue != null && inRangeTimeRatioValue instanceof NullNode == false) { double inRangeTimeRatioInstance; inRangeTimeRatioInstance = inRangeTimeRatioValue.getDoubleValue(); sloUsageMetricInstance .setInRangeTimeRatio(inRangeTimeRatioInstance); } JsonNode idValue = serviceLevelObjectiveUsageMetricsValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); sloUsageMetricInstance.setId(idInstance); } JsonNode nameValue = serviceLevelObjectiveUsageMetricsValue.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); sloUsageMetricInstance.setName(nameInstance); } JsonNode typeValue = serviceLevelObjectiveUsageMetricsValue.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); sloUsageMetricInstance.setType(typeInstance); } JsonNode locationValue = serviceLevelObjectiveUsageMetricsValue .get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); sloUsageMetricInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) serviceLevelObjectiveUsageMetricsValue .get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement .getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); sloUsageMetricInstance.getTags().put(tagsKey, tagsValue); } } } } JsonNode currentServiceLevelObjectiveValue = propertiesValue2 .get("currentServiceLevelObjective"); if (currentServiceLevelObjectiveValue != null && currentServiceLevelObjectiveValue instanceof NullNode == false) { String currentServiceLevelObjectiveInstance; currentServiceLevelObjectiveInstance = currentServiceLevelObjectiveValue .getTextValue(); propertiesInstance2.setCurrentServiceLevelObjective( currentServiceLevelObjectiveInstance); } JsonNode currentServiceLevelObjectiveIdValue = propertiesValue2 .get("currentServiceLevelObjectiveId"); if (currentServiceLevelObjectiveIdValue != null && currentServiceLevelObjectiveIdValue instanceof NullNode == false) { String currentServiceLevelObjectiveIdInstance; currentServiceLevelObjectiveIdInstance = currentServiceLevelObjectiveIdValue .getTextValue(); propertiesInstance2.setCurrentServiceLevelObjectiveId( currentServiceLevelObjectiveIdInstance); } JsonNode usageBasedRecommendationServiceLevelObjectiveValue = propertiesValue2 .get("usageBasedRecommendationServiceLevelObjective"); if (usageBasedRecommendationServiceLevelObjectiveValue != null && usageBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) { String usageBasedRecommendationServiceLevelObjectiveInstance; usageBasedRecommendationServiceLevelObjectiveInstance = usageBasedRecommendationServiceLevelObjectiveValue .getTextValue(); propertiesInstance2.setUsageBasedRecommendationServiceLevelObjective( usageBasedRecommendationServiceLevelObjectiveInstance); } JsonNode usageBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2 .get("usageBasedRecommendationServiceLevelObjectiveId"); if (usageBasedRecommendationServiceLevelObjectiveIdValue != null && usageBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) { String usageBasedRecommendationServiceLevelObjectiveIdInstance; usageBasedRecommendationServiceLevelObjectiveIdInstance = usageBasedRecommendationServiceLevelObjectiveIdValue .getTextValue(); propertiesInstance2.setUsageBasedRecommendationServiceLevelObjectiveId( usageBasedRecommendationServiceLevelObjectiveIdInstance); } JsonNode databaseSizeBasedRecommendationServiceLevelObjectiveValue = propertiesValue2 .get("databaseSizeBasedRecommendationServiceLevelObjective"); if (databaseSizeBasedRecommendationServiceLevelObjectiveValue != null && databaseSizeBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) { String databaseSizeBasedRecommendationServiceLevelObjectiveInstance; databaseSizeBasedRecommendationServiceLevelObjectiveInstance = databaseSizeBasedRecommendationServiceLevelObjectiveValue .getTextValue(); propertiesInstance2.setDatabaseSizeBasedRecommendationServiceLevelObjective( databaseSizeBasedRecommendationServiceLevelObjectiveInstance); } JsonNode databaseSizeBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2 .get("databaseSizeBasedRecommendationServiceLevelObjectiveId"); if (databaseSizeBasedRecommendationServiceLevelObjectiveIdValue != null && databaseSizeBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) { String databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance; databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance = databaseSizeBasedRecommendationServiceLevelObjectiveIdValue .getTextValue(); propertiesInstance2 .setDatabaseSizeBasedRecommendationServiceLevelObjectiveId( databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance); } JsonNode disasterPlanBasedRecommendationServiceLevelObjectiveValue = propertiesValue2 .get("disasterPlanBasedRecommendationServiceLevelObjective"); if (disasterPlanBasedRecommendationServiceLevelObjectiveValue != null && disasterPlanBasedRecommendationServiceLevelObjectiveValue instanceof NullNode == false) { String disasterPlanBasedRecommendationServiceLevelObjectiveInstance; disasterPlanBasedRecommendationServiceLevelObjectiveInstance = disasterPlanBasedRecommendationServiceLevelObjectiveValue .getTextValue(); propertiesInstance2.setDisasterPlanBasedRecommendationServiceLevelObjective( disasterPlanBasedRecommendationServiceLevelObjectiveInstance); } JsonNode disasterPlanBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2 .get("disasterPlanBasedRecommendationServiceLevelObjectiveId"); if (disasterPlanBasedRecommendationServiceLevelObjectiveIdValue != null && disasterPlanBasedRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) { String disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance; disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance = disasterPlanBasedRecommendationServiceLevelObjectiveIdValue .getTextValue(); propertiesInstance2 .setDisasterPlanBasedRecommendationServiceLevelObjectiveId( disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance); } JsonNode overallRecommendationServiceLevelObjectiveValue = propertiesValue2 .get("overallRecommendationServiceLevelObjective"); if (overallRecommendationServiceLevelObjectiveValue != null && overallRecommendationServiceLevelObjectiveValue instanceof NullNode == false) { String overallRecommendationServiceLevelObjectiveInstance; overallRecommendationServiceLevelObjectiveInstance = overallRecommendationServiceLevelObjectiveValue .getTextValue(); propertiesInstance2.setOverallRecommendationServiceLevelObjective( overallRecommendationServiceLevelObjectiveInstance); } JsonNode overallRecommendationServiceLevelObjectiveIdValue = propertiesValue2 .get("overallRecommendationServiceLevelObjectiveId"); if (overallRecommendationServiceLevelObjectiveIdValue != null && overallRecommendationServiceLevelObjectiveIdValue instanceof NullNode == false) { String overallRecommendationServiceLevelObjectiveIdInstance; overallRecommendationServiceLevelObjectiveIdInstance = overallRecommendationServiceLevelObjectiveIdValue .getTextValue(); propertiesInstance2.setOverallRecommendationServiceLevelObjectiveId( overallRecommendationServiceLevelObjectiveIdInstance); } JsonNode confidenceValue = propertiesValue2.get("confidence"); if (confidenceValue != null && confidenceValue instanceof NullNode == false) { double confidenceInstance; confidenceInstance = confidenceValue.getDoubleValue(); propertiesInstance2.setConfidence(confidenceInstance); } } JsonNode idValue2 = serviceTierAdvisorsValue.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); serviceTierAdvisorInstance.setId(idInstance2); } JsonNode nameValue2 = serviceTierAdvisorsValue.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); serviceTierAdvisorInstance.setName(nameInstance2); } JsonNode typeValue2 = serviceTierAdvisorsValue.get("type"); if (typeValue2 != null && typeValue2 instanceof NullNode == false) { String typeInstance2; typeInstance2 = typeValue2.getTextValue(); serviceTierAdvisorInstance.setType(typeInstance2); } JsonNode locationValue2 = serviceTierAdvisorsValue.get("location"); if (locationValue2 != null && locationValue2 instanceof NullNode == false) { String locationInstance2; locationInstance2 = locationValue2.getTextValue(); serviceTierAdvisorInstance.setLocation(locationInstance2); } JsonNode tagsSequenceElement2 = ((JsonNode) serviceTierAdvisorsValue.get("tags")); if (tagsSequenceElement2 != null && tagsSequenceElement2 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr2 = tagsSequenceElement2.getFields(); while (itr2.hasNext()) { Map.Entry<String, JsonNode> property2 = itr2.next(); String tagsKey2 = property2.getKey(); String tagsValue2 = property2.getValue().getTextValue(); serviceTierAdvisorInstance.getTags().put(tagsKey2, tagsValue2); } } } } JsonNode upgradeHintValue = propertiesValue.get("upgradeHint"); if (upgradeHintValue != null && upgradeHintValue instanceof NullNode == false) { UpgradeHint upgradeHintInstance = new UpgradeHint(); propertiesInstance.setUpgradeHint(upgradeHintInstance); JsonNode targetServiceLevelObjectiveValue = upgradeHintValue .get("targetServiceLevelObjective"); if (targetServiceLevelObjectiveValue != null && targetServiceLevelObjectiveValue instanceof NullNode == false) { String targetServiceLevelObjectiveInstance; targetServiceLevelObjectiveInstance = targetServiceLevelObjectiveValue .getTextValue(); upgradeHintInstance .setTargetServiceLevelObjective(targetServiceLevelObjectiveInstance); } JsonNode targetServiceLevelObjectiveIdValue = upgradeHintValue .get("targetServiceLevelObjectiveId"); if (targetServiceLevelObjectiveIdValue != null && targetServiceLevelObjectiveIdValue instanceof NullNode == false) { String targetServiceLevelObjectiveIdInstance; targetServiceLevelObjectiveIdInstance = targetServiceLevelObjectiveIdValue .getTextValue(); upgradeHintInstance .setTargetServiceLevelObjectiveId(targetServiceLevelObjectiveIdInstance); } JsonNode idValue3 = upgradeHintValue.get("id"); if (idValue3 != null && idValue3 instanceof NullNode == false) { String idInstance3; idInstance3 = idValue3.getTextValue(); upgradeHintInstance.setId(idInstance3); } JsonNode nameValue3 = upgradeHintValue.get("name"); if (nameValue3 != null && nameValue3 instanceof NullNode == false) { String nameInstance3; nameInstance3 = nameValue3.getTextValue(); upgradeHintInstance.setName(nameInstance3); } JsonNode typeValue3 = upgradeHintValue.get("type"); if (typeValue3 != null && typeValue3 instanceof NullNode == false) { String typeInstance3; typeInstance3 = typeValue3.getTextValue(); upgradeHintInstance.setType(typeInstance3); } JsonNode locationValue3 = upgradeHintValue.get("location"); if (locationValue3 != null && locationValue3 instanceof NullNode == false) { String locationInstance3; locationInstance3 = locationValue3.getTextValue(); upgradeHintInstance.setLocation(locationInstance3); } JsonNode tagsSequenceElement3 = ((JsonNode) upgradeHintValue.get("tags")); if (tagsSequenceElement3 != null && tagsSequenceElement3 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr3 = tagsSequenceElement3.getFields(); while (itr3.hasNext()) { Map.Entry<String, JsonNode> property3 = itr3.next(); String tagsKey3 = property3.getKey(); String tagsValue3 = property3.getValue().getTextValue(); upgradeHintInstance.getTags().put(tagsKey3, tagsValue3); } } } JsonNode schemasArray = propertiesValue.get("schemas"); if (schemasArray != null && schemasArray instanceof NullNode == false) { for (JsonNode schemasValue : ((ArrayNode) schemasArray)) { Schema schemaInstance = new Schema(); propertiesInstance.getSchemas().add(schemaInstance); JsonNode propertiesValue3 = schemasValue.get("properties"); if (propertiesValue3 != null && propertiesValue3 instanceof NullNode == false) { SchemaProperties propertiesInstance3 = new SchemaProperties(); schemaInstance.setProperties(propertiesInstance3); JsonNode tablesArray = propertiesValue3.get("tables"); if (tablesArray != null && tablesArray instanceof NullNode == false) { for (JsonNode tablesValue : ((ArrayNode) tablesArray)) { Table tableInstance = new Table(); propertiesInstance3.getTables().add(tableInstance); JsonNode propertiesValue4 = tablesValue.get("properties"); if (propertiesValue4 != null && propertiesValue4 instanceof NullNode == false) { TableProperties propertiesInstance4 = new TableProperties(); tableInstance.setProperties(propertiesInstance4); JsonNode tableTypeValue = propertiesValue4.get("tableType"); if (tableTypeValue != null && tableTypeValue instanceof NullNode == false) { String tableTypeInstance; tableTypeInstance = tableTypeValue.getTextValue(); propertiesInstance4.setTableType(tableTypeInstance); } JsonNode columnsArray = propertiesValue4.get("columns"); if (columnsArray != null && columnsArray instanceof NullNode == false) { for (JsonNode columnsValue : ((ArrayNode) columnsArray)) { Column columnInstance = new Column(); propertiesInstance4.getColumns().add(columnInstance); JsonNode propertiesValue5 = columnsValue.get("properties"); if (propertiesValue5 != null && propertiesValue5 instanceof NullNode == false) { ColumnProperties propertiesInstance5 = new ColumnProperties(); columnInstance.setProperties(propertiesInstance5); JsonNode columnTypeValue = propertiesValue5 .get("columnType"); if (columnTypeValue != null && columnTypeValue instanceof NullNode == false) { String columnTypeInstance; columnTypeInstance = columnTypeValue.getTextValue(); propertiesInstance5 .setColumnType(columnTypeInstance); } } JsonNode idValue4 = columnsValue.get("id"); if (idValue4 != null && idValue4 instanceof NullNode == false) { String idInstance4; idInstance4 = idValue4.getTextValue(); columnInstance.setId(idInstance4); } JsonNode nameValue4 = columnsValue.get("name"); if (nameValue4 != null && nameValue4 instanceof NullNode == false) { String nameInstance4; nameInstance4 = nameValue4.getTextValue(); columnInstance.setName(nameInstance4); } JsonNode typeValue4 = columnsValue.get("type"); if (typeValue4 != null && typeValue4 instanceof NullNode == false) { String typeInstance4; typeInstance4 = typeValue4.getTextValue(); columnInstance.setType(typeInstance4); } JsonNode locationValue4 = columnsValue.get("location"); if (locationValue4 != null && locationValue4 instanceof NullNode == false) { String locationInstance4; locationInstance4 = locationValue4.getTextValue(); columnInstance.setLocation(locationInstance4); } JsonNode tagsSequenceElement4 = ((JsonNode) columnsValue .get("tags")); if (tagsSequenceElement4 != null && tagsSequenceElement4 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr4 = tagsSequenceElement4 .getFields(); while (itr4.hasNext()) { Map.Entry<String, JsonNode> property4 = itr4.next(); String tagsKey4 = property4.getKey(); String tagsValue4 = property4.getValue() .getTextValue(); columnInstance.getTags().put(tagsKey4, tagsValue4); } } } } JsonNode recommendedIndexesArray = propertiesValue4 .get("recommendedIndexes"); if (recommendedIndexesArray != null && recommendedIndexesArray instanceof NullNode == false) { for (JsonNode recommendedIndexesValue : ((ArrayNode) recommendedIndexesArray)) { RecommendedIndex recommendedIndexInstance = new RecommendedIndex(); propertiesInstance4.getRecommendedIndexes() .add(recommendedIndexInstance); JsonNode propertiesValue6 = recommendedIndexesValue .get("properties"); if (propertiesValue6 != null && propertiesValue6 instanceof NullNode == false) { RecommendedIndexProperties propertiesInstance6 = new RecommendedIndexProperties(); recommendedIndexInstance .setProperties(propertiesInstance6); JsonNode actionValue = propertiesValue6.get("action"); if (actionValue != null && actionValue instanceof NullNode == false) { String actionInstance; actionInstance = actionValue.getTextValue(); propertiesInstance6.setAction(actionInstance); } JsonNode stateValue = propertiesValue6.get("state"); if (stateValue != null && stateValue instanceof NullNode == false) { String stateInstance; stateInstance = stateValue.getTextValue(); propertiesInstance6.setState(stateInstance); } JsonNode createdValue = propertiesValue6.get("created"); if (createdValue != null && createdValue instanceof NullNode == false) { Calendar createdInstance; createdInstance = DatatypeConverter .parseDateTime(createdValue.getTextValue()); propertiesInstance6.setCreated(createdInstance); } JsonNode lastModifiedValue = propertiesValue6 .get("lastModified"); if (lastModifiedValue != null && lastModifiedValue instanceof NullNode == false) { Calendar lastModifiedInstance; lastModifiedInstance = DatatypeConverter .parseDateTime( lastModifiedValue.getTextValue()); propertiesInstance6 .setLastModified(lastModifiedInstance); } JsonNode indexTypeValue = propertiesValue6 .get("indexType"); if (indexTypeValue != null && indexTypeValue instanceof NullNode == false) { String indexTypeInstance; indexTypeInstance = indexTypeValue.getTextValue(); propertiesInstance6.setIndexType(indexTypeInstance); } JsonNode schemaValue = propertiesValue6.get("schema"); if (schemaValue != null && schemaValue instanceof NullNode == false) { String schemaInstance2; schemaInstance2 = schemaValue.getTextValue(); propertiesInstance6.setSchema(schemaInstance2); } JsonNode tableValue = propertiesValue6.get("table"); if (tableValue != null && tableValue instanceof NullNode == false) { String tableInstance2; tableInstance2 = tableValue.getTextValue(); propertiesInstance6.setTable(tableInstance2); } JsonNode columnsArray2 = propertiesValue6 .get("columns"); if (columnsArray2 != null && columnsArray2 instanceof NullNode == false) { for (JsonNode columnsValue2 : ((ArrayNode) columnsArray2)) { propertiesInstance6.getColumns() .add(columnsValue2.getTextValue()); } } JsonNode includedColumnsArray = propertiesValue6 .get("includedColumns"); if (includedColumnsArray != null && includedColumnsArray instanceof NullNode == false) { for (JsonNode includedColumnsValue : ((ArrayNode) includedColumnsArray)) { propertiesInstance6.getIncludedColumns().add( includedColumnsValue.getTextValue()); } } JsonNode indexScriptValue = propertiesValue6 .get("indexScript"); if (indexScriptValue != null && indexScriptValue instanceof NullNode == false) { String indexScriptInstance; indexScriptInstance = indexScriptValue .getTextValue(); propertiesInstance6 .setIndexScript(indexScriptInstance); } JsonNode estimatedImpactArray = propertiesValue6 .get("estimatedImpact"); if (estimatedImpactArray != null && estimatedImpactArray instanceof NullNode == false) { for (JsonNode estimatedImpactValue : ((ArrayNode) estimatedImpactArray)) { OperationImpact operationImpactInstance = new OperationImpact(); propertiesInstance6.getEstimatedImpact() .add(operationImpactInstance); JsonNode nameValue5 = estimatedImpactValue .get("name"); if (nameValue5 != null && nameValue5 instanceof NullNode == false) { String nameInstance5; nameInstance5 = nameValue5.getTextValue(); operationImpactInstance .setName(nameInstance5); } JsonNode unitValue = estimatedImpactValue .get("unit"); if (unitValue != null && unitValue instanceof NullNode == false) { String unitInstance; unitInstance = unitValue.getTextValue(); operationImpactInstance .setUnit(unitInstance); } JsonNode changeValueAbsoluteValue = estimatedImpactValue .get("changeValueAbsolute"); if (changeValueAbsoluteValue != null && changeValueAbsoluteValue instanceof NullNode == false) { double changeValueAbsoluteInstance; changeValueAbsoluteInstance = changeValueAbsoluteValue .getDoubleValue(); operationImpactInstance .setChangeValueAbsolute( changeValueAbsoluteInstance); } JsonNode changeValueRelativeValue = estimatedImpactValue .get("changeValueRelative"); if (changeValueRelativeValue != null && changeValueRelativeValue instanceof NullNode == false) { double changeValueRelativeInstance; changeValueRelativeInstance = changeValueRelativeValue .getDoubleValue(); operationImpactInstance .setChangeValueRelative( changeValueRelativeInstance); } } } JsonNode reportedImpactArray = propertiesValue6 .get("reportedImpact"); if (reportedImpactArray != null && reportedImpactArray instanceof NullNode == false) { for (JsonNode reportedImpactValue : ((ArrayNode) reportedImpactArray)) { OperationImpact operationImpactInstance2 = new OperationImpact(); propertiesInstance6.getReportedImpact() .add(operationImpactInstance2); JsonNode nameValue6 = reportedImpactValue .get("name"); if (nameValue6 != null && nameValue6 instanceof NullNode == false) { String nameInstance6; nameInstance6 = nameValue6.getTextValue(); operationImpactInstance2 .setName(nameInstance6); } JsonNode unitValue2 = reportedImpactValue .get("unit"); if (unitValue2 != null && unitValue2 instanceof NullNode == false) { String unitInstance2; unitInstance2 = unitValue2.getTextValue(); operationImpactInstance2 .setUnit(unitInstance2); } JsonNode changeValueAbsoluteValue2 = reportedImpactValue .get("changeValueAbsolute"); if (changeValueAbsoluteValue2 != null && changeValueAbsoluteValue2 instanceof NullNode == false) { double changeValueAbsoluteInstance2; changeValueAbsoluteInstance2 = changeValueAbsoluteValue2 .getDoubleValue(); operationImpactInstance2 .setChangeValueAbsolute( changeValueAbsoluteInstance2); } JsonNode changeValueRelativeValue2 = reportedImpactValue .get("changeValueRelative"); if (changeValueRelativeValue2 != null && changeValueRelativeValue2 instanceof NullNode == false) { double changeValueRelativeInstance2; changeValueRelativeInstance2 = changeValueRelativeValue2 .getDoubleValue(); operationImpactInstance2 .setChangeValueRelative( changeValueRelativeInstance2); } } } } JsonNode idValue5 = recommendedIndexesValue.get("id"); if (idValue5 != null && idValue5 instanceof NullNode == false) { String idInstance5; idInstance5 = idValue5.getTextValue(); recommendedIndexInstance.setId(idInstance5); } JsonNode nameValue7 = recommendedIndexesValue.get("name"); if (nameValue7 != null && nameValue7 instanceof NullNode == false) { String nameInstance7; nameInstance7 = nameValue7.getTextValue(); recommendedIndexInstance.setName(nameInstance7); } JsonNode typeValue5 = recommendedIndexesValue.get("type"); if (typeValue5 != null && typeValue5 instanceof NullNode == false) { String typeInstance5; typeInstance5 = typeValue5.getTextValue(); recommendedIndexInstance.setType(typeInstance5); } JsonNode locationValue5 = recommendedIndexesValue .get("location"); if (locationValue5 != null && locationValue5 instanceof NullNode == false) { String locationInstance5; locationInstance5 = locationValue5.getTextValue(); recommendedIndexInstance.setLocation(locationInstance5); } JsonNode tagsSequenceElement5 = ((JsonNode) recommendedIndexesValue .get("tags")); if (tagsSequenceElement5 != null && tagsSequenceElement5 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr5 = tagsSequenceElement5 .getFields(); while (itr5.hasNext()) { Map.Entry<String, JsonNode> property5 = itr5.next(); String tagsKey5 = property5.getKey(); String tagsValue5 = property5.getValue() .getTextValue(); recommendedIndexInstance.getTags().put(tagsKey5, tagsValue5); } } } } } JsonNode idValue6 = tablesValue.get("id"); if (idValue6 != null && idValue6 instanceof NullNode == false) { String idInstance6; idInstance6 = idValue6.getTextValue(); tableInstance.setId(idInstance6); } JsonNode nameValue8 = tablesValue.get("name"); if (nameValue8 != null && nameValue8 instanceof NullNode == false) { String nameInstance8; nameInstance8 = nameValue8.getTextValue(); tableInstance.setName(nameInstance8); } JsonNode typeValue6 = tablesValue.get("type"); if (typeValue6 != null && typeValue6 instanceof NullNode == false) { String typeInstance6; typeInstance6 = typeValue6.getTextValue(); tableInstance.setType(typeInstance6); } JsonNode locationValue6 = tablesValue.get("location"); if (locationValue6 != null && locationValue6 instanceof NullNode == false) { String locationInstance6; locationInstance6 = locationValue6.getTextValue(); tableInstance.setLocation(locationInstance6); } JsonNode tagsSequenceElement6 = ((JsonNode) tablesValue.get("tags")); if (tagsSequenceElement6 != null && tagsSequenceElement6 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr6 = tagsSequenceElement6 .getFields(); while (itr6.hasNext()) { Map.Entry<String, JsonNode> property6 = itr6.next(); String tagsKey6 = property6.getKey(); String tagsValue6 = property6.getValue().getTextValue(); tableInstance.getTags().put(tagsKey6, tagsValue6); } } } } } JsonNode idValue7 = schemasValue.get("id"); if (idValue7 != null && idValue7 instanceof NullNode == false) { String idInstance7; idInstance7 = idValue7.getTextValue(); schemaInstance.setId(idInstance7); } JsonNode nameValue9 = schemasValue.get("name"); if (nameValue9 != null && nameValue9 instanceof NullNode == false) { String nameInstance9; nameInstance9 = nameValue9.getTextValue(); schemaInstance.setName(nameInstance9); } JsonNode typeValue7 = schemasValue.get("type"); if (typeValue7 != null && typeValue7 instanceof NullNode == false) { String typeInstance7; typeInstance7 = typeValue7.getTextValue(); schemaInstance.setType(typeInstance7); } JsonNode locationValue7 = schemasValue.get("location"); if (locationValue7 != null && locationValue7 instanceof NullNode == false) { String locationInstance7; locationInstance7 = locationValue7.getTextValue(); schemaInstance.setLocation(locationInstance7); } JsonNode tagsSequenceElement7 = ((JsonNode) schemasValue.get("tags")); if (tagsSequenceElement7 != null && tagsSequenceElement7 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr7 = tagsSequenceElement7.getFields(); while (itr7.hasNext()) { Map.Entry<String, JsonNode> property7 = itr7.next(); String tagsKey7 = property7.getKey(); String tagsValue7 = property7.getValue().getTextValue(); schemaInstance.getTags().put(tagsKey7, tagsValue7); } } } } JsonNode defaultSecondaryLocationValue = propertiesValue.get("defaultSecondaryLocation"); if (defaultSecondaryLocationValue != null && defaultSecondaryLocationValue instanceof NullNode == false) { String defaultSecondaryLocationInstance; defaultSecondaryLocationInstance = defaultSecondaryLocationValue.getTextValue(); propertiesInstance.setDefaultSecondaryLocation(defaultSecondaryLocationInstance); } } JsonNode idValue8 = responseDoc.get("id"); if (idValue8 != null && idValue8 instanceof NullNode == false) { String idInstance8; idInstance8 = idValue8.getTextValue(); databaseInstance.setId(idInstance8); } JsonNode nameValue10 = responseDoc.get("name"); if (nameValue10 != null && nameValue10 instanceof NullNode == false) { String nameInstance10; nameInstance10 = nameValue10.getTextValue(); databaseInstance.setName(nameInstance10); } JsonNode typeValue8 = responseDoc.get("type"); if (typeValue8 != null && typeValue8 instanceof NullNode == false) { String typeInstance8; typeInstance8 = typeValue8.getTextValue(); databaseInstance.setType(typeInstance8); } JsonNode locationValue8 = responseDoc.get("location"); if (locationValue8 != null && locationValue8 instanceof NullNode == false) { String locationInstance8; locationInstance8 = locationValue8.getTextValue(); databaseInstance.setLocation(locationInstance8); } JsonNode tagsSequenceElement8 = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement8 != null && tagsSequenceElement8 instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr8 = tagsSequenceElement8.getFields(); while (itr8.hasNext()) { Map.Entry<String, JsonNode> property8 = itr8.next(); String tagsKey8 = property8.getKey(); String tagsValue8 = property8.getValue().getTextValue(); databaseInstance.getTags().put(tagsKey8, tagsValue8); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("Location").length > 0) { result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (statusCode == HttpStatus.SC_OK) { result.setStatus(OperationStatus.Succeeded); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.azure.management.compute.ComputeManagementClientImpl.java
/** * The Get Delete Operation Status operation returns the status of the * specified operation. After calling an asynchronous operation, you can * call GetDeleteOperationStatus to determine whether the operation has * succeeded, failed, or is still in progress. * * @param operationStatusLink Required. Location value returned by the Begin * operation./*w w w.ja v a2 s . com*/ * @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 compute long running operation response. */ @Override public DeleteOperationResponse getDeleteOperationStatus(String operationStatusLink) throws IOException, ServiceException { // Validate if (operationStatusLink == null) { throw new NullPointerException("operationStatusLink"); } // 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("operationStatusLink", operationStatusLink); CloudTracing.enter(invocationId, this, "getDeleteOperationStatusAsync", tracingParameters); } // Construct URL String url = ""; url = url + operationStatusLink; url = url.replace(" ", "%20"); // Create HTTP transport objects HttpGet httpRequest = new HttpGet(url); // Set Headers // Send Request HttpResponse httpResponse = null; try { if (shouldTrace) { 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 && statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DeleteOperationResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DeleteOperationResponse(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { JsonNode operationIdValue = responseDoc.get("operationId"); if (operationIdValue != null && operationIdValue instanceof NullNode == false) { String operationIdInstance; operationIdInstance = operationIdValue.getTextValue(); result.setTrackingOperationId(operationIdInstance); } JsonNode statusValue = responseDoc.get("status"); if (statusValue != null && statusValue instanceof NullNode == false) { OperationStatus statusInstance; statusInstance = Enum.valueOf(OperationStatus.class, statusValue.getTextValue()); result.setStatus(statusInstance); } JsonNode startTimeValue = responseDoc.get("startTime"); if (startTimeValue != null && startTimeValue instanceof NullNode == false) { Calendar startTimeInstance; startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue()); result.setStartTime(startTimeInstance); } JsonNode endTimeValue = responseDoc.get("endTime"); if (endTimeValue != null && endTimeValue instanceof NullNode == false) { Calendar endTimeInstance; endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue()); result.setEndTime(endTimeInstance); } JsonNode errorValue = responseDoc.get("error"); if (errorValue != null && errorValue instanceof NullNode == false) { ApiError errorInstance = new ApiError(); result.setError(errorInstance); JsonNode detailsArray = errorValue.get("details"); if (detailsArray != null && detailsArray instanceof NullNode == false) { for (JsonNode detailsValue : ((ArrayNode) detailsArray)) { ApiErrorBase apiErrorBaseInstance = new ApiErrorBase(); errorInstance.getDetails().add(apiErrorBaseInstance); JsonNode codeValue = detailsValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); apiErrorBaseInstance.setCode(codeInstance); } JsonNode targetValue = detailsValue.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); apiErrorBaseInstance.setTarget(targetInstance); } JsonNode messageValue = detailsValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); apiErrorBaseInstance.setMessage(messageInstance); } } } JsonNode innererrorValue = errorValue.get("innererror"); if (innererrorValue != null && innererrorValue instanceof NullNode == false) { InnerError innererrorInstance = new InnerError(); errorInstance.setInnerError(innererrorInstance); JsonNode exceptiontypeValue = innererrorValue.get("exceptiontype"); if (exceptiontypeValue != null && exceptiontypeValue instanceof NullNode == false) { String exceptiontypeInstance; exceptiontypeInstance = exceptiontypeValue.getTextValue(); innererrorInstance.setExceptionType(exceptiontypeInstance); } JsonNode errordetailValue = innererrorValue.get("errordetail"); if (errordetailValue != null && errordetailValue instanceof NullNode == false) { String errordetailInstance; errordetailInstance = errordetailValue.getTextValue(); innererrorInstance.setErrorDetail(errordetailInstance); } } JsonNode codeValue2 = errorValue.get("code"); if (codeValue2 != null && codeValue2 instanceof NullNode == false) { String codeInstance2; codeInstance2 = codeValue2.getTextValue(); errorInstance.setCode(codeInstance2); } JsonNode targetValue2 = errorValue.get("target"); if (targetValue2 != null && targetValue2 instanceof NullNode == false) { String targetInstance2; targetInstance2 = targetValue2.getTextValue(); errorInstance.setTarget(targetInstance2); } JsonNode messageValue2 = errorValue.get("message"); if (messageValue2 != null && messageValue2 instanceof NullNode == false) { String messageInstance2; messageInstance2 = messageValue2.getTextValue(); errorInstance.setMessage(messageInstance2); } } } } 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(); } } }
From source file:com.microsoft.windowsazure.management.sql.DatabaseOperationsImpl.java
/** * Creates a database in an Azure SQL Database Server. * * @param serverName Required. The name of the Azure SQL Database Server * where the database will be created.// w ww. j a v a 2s. c om * @param parameters Required. The parameters for the create database * 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 Represents the response to a create database request from the * service. */ @Override public DatabaseCreateResponse create(String serverName, DatabaseCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getName() == null) { throw new NullPointerException("parameters.Name"); } // 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("serverName", serverName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createAsync", 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/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/databases"; 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", "2012-03-01"); // Serialize Request String requestContent = null; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document requestDoc = documentBuilder.newDocument(); Element serviceResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceResource"); requestDoc.appendChild(serviceResourceElement); Element nameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Name"); nameElement.appendChild(requestDoc.createTextNode(parameters.getName())); serviceResourceElement.appendChild(nameElement); if (parameters.getEdition() != null) { Element editionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Edition"); editionElement.appendChild(requestDoc.createTextNode(parameters.getEdition())); serviceResourceElement.appendChild(editionElement); } if (parameters.getMaximumDatabaseSizeInGB() != null) { Element maxSizeGBElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); maxSizeGBElement.appendChild( requestDoc.createTextNode(Integer.toString(parameters.getMaximumDatabaseSizeInGB()))); serviceResourceElement.appendChild(maxSizeGBElement); } if (parameters.getCollationName() != null) { Element collationNameElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "CollationName"); collationNameElement.appendChild(requestDoc.createTextNode(parameters.getCollationName())); serviceResourceElement.appendChild(collationNameElement); } if (parameters.getMaximumDatabaseSizeInBytes() != null) { Element maxSizeBytesElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); maxSizeBytesElement.appendChild( requestDoc.createTextNode(Long.toString(parameters.getMaximumDatabaseSizeInBytes()))); serviceResourceElement.appendChild(maxSizeBytesElement); } if (parameters.getServiceObjectiveId() != null) { Element serviceObjectiveIdElement = requestDoc .createElementNS("http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); serviceObjectiveIdElement.appendChild(requestDoc.createTextNode(parameters.getServiceObjectiveId())); serviceResourceElement.appendChild(serviceObjectiveIdElement); } 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_CREATED) { ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result DatabaseCreateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_CREATED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new DatabaseCreateResponse(); DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance(); documentBuilderFactory2.setNamespaceAware(true); DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder(); Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent)); Element serviceResourceElement2 = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResource"); if (serviceResourceElement2 != null) { Database serviceResourceInstance = new Database(); result.setDatabase(serviceResourceInstance); Element idElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Id"); if (idElement != null) { int idInstance; idInstance = DatatypeConverter.parseInt(idElement.getTextContent()); serviceResourceInstance.setId(idInstance); } Element editionElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement2 != null) { String editionInstance; editionInstance = editionElement2.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element maxSizeGBElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "MaxSizeGB"); if (maxSizeGBElement2 != null) { int maxSizeGBInstance; maxSizeGBInstance = DatatypeConverter.parseInt(maxSizeGBElement2.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInGB(maxSizeGBInstance); } Element maxSizeBytesElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "MaxSizeBytes"); if (maxSizeBytesElement2 != null) { long maxSizeBytesInstance; maxSizeBytesInstance = DatatypeConverter.parseLong(maxSizeBytesElement2.getTextContent()); serviceResourceInstance.setMaximumDatabaseSizeInBytes(maxSizeBytesInstance); } Element collationNameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "CollationName"); if (collationNameElement2 != null) { String collationNameInstance; collationNameInstance = collationNameElement2.getTextContent(); serviceResourceInstance.setCollationName(collationNameInstance); } Element creationDateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "CreationDate"); if (creationDateElement != null) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateElement.getTextContent()); serviceResourceInstance.setCreationDate(creationDateInstance); } Element isFederationRootElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsFederationRoot"); if (isFederationRootElement != null) { boolean isFederationRootInstance; isFederationRootInstance = DatatypeConverter .parseBoolean(isFederationRootElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsFederationRoot(isFederationRootInstance); } Element isSystemObjectElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "IsSystemObject"); if (isSystemObjectElement != null) { boolean isSystemObjectInstance; isSystemObjectInstance = DatatypeConverter .parseBoolean(isSystemObjectElement.getTextContent().toLowerCase()); serviceResourceInstance.setIsSystemObject(isSystemObjectInstance); } Element sizeMBElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "SizeMB"); if (sizeMBElement != null) { String sizeMBInstance; sizeMBInstance = sizeMBElement.getTextContent(); serviceResourceInstance.setSizeMB(sizeMBInstance); } Element serviceObjectiveAssignmentErrorCodeElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorCode"); if (serviceObjectiveAssignmentErrorCodeElement != null) { String serviceObjectiveAssignmentErrorCodeInstance; serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorCode( serviceObjectiveAssignmentErrorCodeInstance); } Element serviceObjectiveAssignmentErrorDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentErrorDescription"); if (serviceObjectiveAssignmentErrorDescriptionElement != null) { String serviceObjectiveAssignmentErrorDescriptionInstance; serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentErrorDescription( serviceObjectiveAssignmentErrorDescriptionInstance); } Element serviceObjectiveAssignmentStateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentState"); if (serviceObjectiveAssignmentStateElement != null) { String serviceObjectiveAssignmentStateInstance; serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement .getTextContent(); serviceResourceInstance .setServiceObjectiveAssignmentState(serviceObjectiveAssignmentStateInstance); } Element serviceObjectiveAssignmentStateDescriptionElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentStateDescription"); if (serviceObjectiveAssignmentStateDescriptionElement != null) { String serviceObjectiveAssignmentStateDescriptionInstance; serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentStateDescription( serviceObjectiveAssignmentStateDescriptionInstance); } Element serviceObjectiveAssignmentSuccessDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveAssignmentSuccessDate"); if (serviceObjectiveAssignmentSuccessDateElement != null) { String serviceObjectiveAssignmentSuccessDateInstance; serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement .getTextContent(); serviceResourceInstance.setServiceObjectiveAssignmentSuccessDate( serviceObjectiveAssignmentSuccessDateInstance); } Element serviceObjectiveIdElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "ServiceObjectiveId"); if (serviceObjectiveIdElement2 != null) { String serviceObjectiveIdInstance; serviceObjectiveIdInstance = serviceObjectiveIdElement2.getTextContent(); serviceResourceInstance.setServiceObjectiveId(serviceObjectiveIdInstance); } Element assignedServiceObjectiveIdElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "AssignedServiceObjectiveId"); if (assignedServiceObjectiveIdElement != null) { String assignedServiceObjectiveIdInstance; assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement.getTextContent(); serviceResourceInstance.setAssignedServiceObjectiveId(assignedServiceObjectiveIdInstance); } Element recoveryPeriodStartDateElement = XmlUtility.getElementByTagNameNS( serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "RecoveryPeriodStartDate"); if (recoveryPeriodStartDateElement != null && recoveryPeriodStartDateElement.getTextContent() != null && !recoveryPeriodStartDateElement.getTextContent().isEmpty()) { Calendar recoveryPeriodStartDateInstance; recoveryPeriodStartDateInstance = DatatypeConverter .parseDateTime(recoveryPeriodStartDateElement.getTextContent()); serviceResourceInstance.setRecoveryPeriodStartDate(recoveryPeriodStartDateInstance); } Element nameElement2 = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement2 != null) { String nameInstance; nameInstance = nameElement2.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourceElement2, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } 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(); } } }
From source file:com.microsoft.windowsazure.management.sql.RecoverableDatabaseOperationsImpl.java
/** * Returns a collection of databases that can be recovered from a specified * server./*from ww w .jav a 2 s .co m*/ * * @param serverName Required. The name of the Azure SQL Database Server on * which the databases were hosted. * @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 Contains the response to the List Recoverable Databases request. */ @Override public RecoverableDatabaseListResponse list(String serverName) throws IOException, ServiceException, ParserConfigurationException, SAXException { // Validate if (serverName == null) { throw new NullPointerException("serverName"); } // 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("serverName", serverName); CloudTracing.enter(invocationId, this, "listAsync", 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/sqlservers/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/recoverabledatabases"; ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("contentview=generic"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } 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 HttpGet httpRequest = new HttpGet(url); // Set Headers httpRequest.setHeader("x-ms-version", "2012-03-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_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result RecoverableDatabaseListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new RecoverableDatabaseListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ServiceResources"); if (serviceResourcesSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .size(); i1 = i1 + 1) { org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(serviceResourcesSequenceElement, "http://schemas.microsoft.com/windowsazure", "ServiceResource") .get(i1)); RecoverableDatabase serviceResourceInstance = new RecoverableDatabase(); result.getDatabases().add(serviceResourceInstance); Element entityIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "EntityId"); if (entityIdElement != null) { String entityIdInstance; entityIdInstance = entityIdElement.getTextContent(); serviceResourceInstance.setEntityId(entityIdInstance); } Element serverNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "ServerName"); if (serverNameElement != null) { String serverNameInstance; serverNameInstance = serverNameElement.getTextContent(); serviceResourceInstance.setServerName(serverNameInstance); } Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Edition"); if (editionElement != null) { String editionInstance; editionInstance = editionElement.getTextContent(); serviceResourceInstance.setEdition(editionInstance); } Element lastAvailableBackupDateElement = XmlUtility.getElementByTagNameNS( serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "LastAvailableBackupDate"); if (lastAvailableBackupDateElement != null) { Calendar lastAvailableBackupDateInstance; lastAvailableBackupDateInstance = DatatypeConverter .parseDateTime(lastAvailableBackupDateElement.getTextContent()); serviceResourceInstance.setLastAvailableBackupDate(lastAvailableBackupDateInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); serviceResourceInstance.setName(nameInstance); } Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "Type"); if (typeElement != null) { String typeInstance; typeInstance = typeElement.getTextContent(); serviceResourceInstance.setType(typeInstance); } Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement, "http://schemas.microsoft.com/windowsazure", "State"); if (stateElement != null) { String stateInstance; stateInstance = stateElement.getTextContent(); serviceResourceInstance.setState(stateInstance); } } } } 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(); } } }
From source file:com.microsoft.azure.management.sql.ElasticPoolOperationsImpl.java
/** * Begins creating a new Azure SQL Database Elastic Pool or updating an * existing Azure SQL Database Elastic Pool. To determine the status of the * operation call GetElasticPoolOperationStatus. * * @param resourceGroupName Required. The name of the Resource Group to * which the Azure SQL Database Server belongs. * @param serverName Required. The name of the Azure SQL Database Server on * which the database is hosted./* w w w . j av a2s . c om*/ * @param elasticPoolName Required. The name of the Azure SQL Database * Elastic Pool to be operated on (Updated or created). * @param parameters Required. The required parameters for createing or * updating an Elastic Pool. * @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 Response for long running Azure Sql Database Elastic Pool * operation. */ @Override public ElasticPoolCreateOrUpdateResponse beginCreateOrUpdate(String resourceGroupName, String serverName, String elasticPoolName, ElasticPoolCreateOrUpdateParameters parameters) throws IOException, ServiceException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (serverName == null) { throw new NullPointerException("serverName"); } if (elasticPoolName == null) { throw new NullPointerException("elasticPoolName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } if (parameters.getProperties() == null) { throw new NullPointerException("parameters.Properties"); } // 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("resourceGroupName", resourceGroupName); tracingParameters.put("serverName", serverName); tracingParameters.put("elasticPoolName", elasticPoolName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "beginCreateOrUpdateAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Sql"; url = url + "/servers/"; url = url + URLEncoder.encode(serverName, "UTF-8"); url = url + "/elasticPools/"; url = url + URLEncoder.encode(elasticPoolName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2014-04-01"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } 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/json; charset=utf-8"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode elasticPoolCreateOrUpdateParametersValue = objectMapper.createObjectNode(); requestDoc = elasticPoolCreateOrUpdateParametersValue; ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) elasticPoolCreateOrUpdateParametersValue).put("properties", propertiesValue); if (parameters.getProperties().getEdition() != null) { ((ObjectNode) propertiesValue).put("edition", parameters.getProperties().getEdition()); } if (parameters.getProperties().getDtu() != null) { ((ObjectNode) propertiesValue).put("dtu", Integer.toString(parameters.getProperties().getDtu())); } if (parameters.getProperties().getStorageMB() != null) { ((ObjectNode) propertiesValue).put("storageMB", Integer.toString(parameters.getProperties().getStorageMB())); } if (parameters.getProperties().getDatabaseDtuMin() != null) { ((ObjectNode) propertiesValue).put("databaseDtuMin", Integer.toString(parameters.getProperties().getDatabaseDtuMin())); } if (parameters.getProperties().getDatabaseDtuMax() != null) { ((ObjectNode) propertiesValue).put("databaseDtuMax", Integer.toString(parameters.getProperties().getDatabaseDtuMax())); } ((ObjectNode) elasticPoolCreateOrUpdateParametersValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) elasticPoolCreateOrUpdateParametersValue).put("tags", tagsDictionary); } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json; charset=utf-8"); // 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_OK && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_ACCEPTED) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ElasticPoolCreateOrUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED || statusCode == HttpStatus.SC_ACCEPTED) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ElasticPoolCreateOrUpdateResponse(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { ErrorResponse errorInstance = new ErrorResponse(); result.setError(errorInstance); JsonNode codeValue = responseDoc.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); errorInstance.setCode(codeInstance); } JsonNode messageValue = responseDoc.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); errorInstance.setMessage(messageInstance); } JsonNode targetValue = responseDoc.get("target"); if (targetValue != null && targetValue instanceof NullNode == false) { String targetInstance; targetInstance = targetValue.getTextValue(); errorInstance.setTarget(targetInstance); } ElasticPool elasticPoolInstance = new ElasticPool(); result.setElasticPool(elasticPoolInstance); JsonNode propertiesValue2 = responseDoc.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { ElasticPoolProperties propertiesInstance = new ElasticPoolProperties(); elasticPoolInstance.setProperties(propertiesInstance); JsonNode creationDateValue = propertiesValue2.get("creationDate"); if (creationDateValue != null && creationDateValue instanceof NullNode == false) { Calendar creationDateInstance; creationDateInstance = DatatypeConverter .parseDateTime(creationDateValue.getTextValue()); propertiesInstance.setCreationDate(creationDateInstance); } JsonNode stateValue = propertiesValue2.get("state"); if (stateValue != null && stateValue instanceof NullNode == false) { String stateInstance; stateInstance = stateValue.getTextValue(); propertiesInstance.setState(stateInstance); } JsonNode editionValue = propertiesValue2.get("edition"); if (editionValue != null && editionValue instanceof NullNode == false) { String editionInstance; editionInstance = editionValue.getTextValue(); propertiesInstance.setEdition(editionInstance); } JsonNode dtuValue = propertiesValue2.get("dtu"); if (dtuValue != null && dtuValue instanceof NullNode == false) { int dtuInstance; dtuInstance = dtuValue.getIntValue(); propertiesInstance.setDtu(dtuInstance); } JsonNode databaseDtuMaxValue = propertiesValue2.get("databaseDtuMax"); if (databaseDtuMaxValue != null && databaseDtuMaxValue instanceof NullNode == false) { int databaseDtuMaxInstance; databaseDtuMaxInstance = databaseDtuMaxValue.getIntValue(); propertiesInstance.setDatabaseDtuMax(databaseDtuMaxInstance); } JsonNode databaseDtuMinValue = propertiesValue2.get("databaseDtuMin"); if (databaseDtuMinValue != null && databaseDtuMinValue instanceof NullNode == false) { int databaseDtuMinInstance; databaseDtuMinInstance = databaseDtuMinValue.getIntValue(); propertiesInstance.setDatabaseDtuMin(databaseDtuMinInstance); } JsonNode storageMBValue = propertiesValue2.get("storageMB"); if (storageMBValue != null && storageMBValue instanceof NullNode == false) { int storageMBInstance; storageMBInstance = storageMBValue.getIntValue(); propertiesInstance.setStorageMB(storageMBInstance); } } JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); elasticPoolInstance.setId(idInstance); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); elasticPoolInstance.setName(nameInstance); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); elasticPoolInstance.setType(typeInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); elasticPoolInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); elasticPoolInstance.getTags().put(tagsKey2, tagsValue2); } } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("Location").length > 0) { result.setOperationStatusLink(httpResponse.getFirstHeader("Location").getValue()); } if (httpResponse.getHeaders("Retry-After").length > 0) { result.setRetryAfter( DatatypeConverter.parseInt(httpResponse.getFirstHeader("Retry-After").getValue())); } if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (statusCode == HttpStatus.SC_CREATED) { result.setStatus(OperationStatus.Succeeded); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:com.microsoft.windowsazure.management.compute.VirtualMachineExtensionOperationsImpl.java
/** * The List Resource Extensions operation lists the resource extensions that * are available to add to a Virtual Machine. In Azure, a process can run * as a resource extension of a Virtual Machine. For example, Remote * Desktop Access or the Azure Diagnostics Agent can run as resource * extensions to the Virtual Machine. (see * http://msdn.microsoft.com/en-us/library/windowsazure/dn495441.aspx for * more information)/*from ww w . j a v a 2 s. c om*/ * * @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. * @throws URISyntaxException Thrown if there was an error parsing a URI in * the response. * @return The List Resource Extensions operation response. */ @Override public VirtualMachineExtensionListResponse list() throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException { // Validate // Tracing boolean shouldTrace = CloudTracing.getIsEnabled(); String invocationId = null; if (shouldTrace) { invocationId = Long.toString(CloudTracing.getNextInvocationId()); HashMap<String, Object> tracingParameters = new HashMap<String, Object>(); CloudTracing.enter(invocationId, this, "listAsync", 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/resourceextensions"; 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 HttpGet httpRequest = new HttpGet(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_OK) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result VirtualMachineExtensionListResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new VirtualMachineExtensionListResponse(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent)); Element resourceExtensionsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "ResourceExtensions"); if (resourceExtensionsSequenceElement != null) { for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(resourceExtensionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ResourceExtension") .size(); i1 = i1 + 1) { org.w3c.dom.Element resourceExtensionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility .getElementsByTagNameNS(resourceExtensionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "ResourceExtension") .get(i1)); VirtualMachineExtensionListResponse.ResourceExtension resourceExtensionInstance = new VirtualMachineExtensionListResponse.ResourceExtension(); result.getResourceExtensions().add(resourceExtensionInstance); Element publisherElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Publisher"); if (publisherElement != null) { String publisherInstance; publisherInstance = publisherElement.getTextContent(); resourceExtensionInstance.setPublisher(publisherInstance); } Element nameElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Name"); if (nameElement != null) { String nameInstance; nameInstance = nameElement.getTextContent(); resourceExtensionInstance.setName(nameInstance); } Element versionElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Version"); if (versionElement != null) { String versionInstance; versionInstance = versionElement.getTextContent(); resourceExtensionInstance.setVersion(versionInstance); } Element labelElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Label"); if (labelElement != null) { String labelInstance; labelInstance = labelElement.getTextContent(); resourceExtensionInstance.setLabel(labelInstance); } Element descriptionElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Description"); if (descriptionElement != null) { String descriptionInstance; descriptionInstance = descriptionElement.getTextContent(); resourceExtensionInstance.setDescription(descriptionInstance); } Element publicConfigurationSchemaElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PublicConfigurationSchema"); if (publicConfigurationSchemaElement != null) { String publicConfigurationSchemaInstance; publicConfigurationSchemaInstance = publicConfigurationSchemaElement .getTextContent() != null ? new String( Base64.decode(publicConfigurationSchemaElement.getTextContent())) : null; resourceExtensionInstance .setPublicConfigurationSchema(publicConfigurationSchemaInstance); } Element privateConfigurationSchemaElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PrivateConfigurationSchema"); if (privateConfigurationSchemaElement != null) { String privateConfigurationSchemaInstance; privateConfigurationSchemaInstance = privateConfigurationSchemaElement .getTextContent() != null ? new String( Base64.decode(privateConfigurationSchemaElement.getTextContent())) : null; resourceExtensionInstance .setPrivateConfigurationSchema(privateConfigurationSchemaInstance); } Element sampleConfigElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "SampleConfig"); if (sampleConfigElement != null) { String sampleConfigInstance; sampleConfigInstance = sampleConfigElement.getTextContent() != null ? new String(Base64.decode(sampleConfigElement.getTextContent())) : null; resourceExtensionInstance.setSampleConfig(sampleConfigInstance); } Element replicationCompletedElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "ReplicationCompleted"); if (replicationCompletedElement != null && replicationCompletedElement.getTextContent() != null && !replicationCompletedElement.getTextContent().isEmpty()) { boolean replicationCompletedInstance; replicationCompletedInstance = DatatypeConverter .parseBoolean(replicationCompletedElement.getTextContent().toLowerCase()); resourceExtensionInstance.setReplicationCompleted(replicationCompletedInstance); } Element eulaElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Eula"); if (eulaElement != null) { URI eulaInstance; eulaInstance = new URI(eulaElement.getTextContent()); resourceExtensionInstance.setEula(eulaInstance); } Element privacyUriElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PrivacyUri"); if (privacyUriElement != null) { URI privacyUriInstance; privacyUriInstance = new URI(privacyUriElement.getTextContent()); resourceExtensionInstance.setPrivacyUri(privacyUriInstance); } Element homepageUriElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "HomepageUri"); if (homepageUriElement != null) { URI homepageUriInstance; homepageUriInstance = new URI(homepageUriElement.getTextContent()); resourceExtensionInstance.setHomepageUri(homepageUriInstance); } Element isJsonExtensionElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "IsJsonExtension"); if (isJsonExtensionElement != null && isJsonExtensionElement.getTextContent() != null && !isJsonExtensionElement.getTextContent().isEmpty()) { boolean isJsonExtensionInstance; isJsonExtensionInstance = DatatypeConverter .parseBoolean(isJsonExtensionElement.getTextContent().toLowerCase()); resourceExtensionInstance.setIsJsonExtension(isJsonExtensionInstance); } Element isInternalExtensionElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "IsInternalExtension"); if (isInternalExtensionElement != null && isInternalExtensionElement.getTextContent() != null && !isInternalExtensionElement.getTextContent().isEmpty()) { boolean isInternalExtensionInstance; isInternalExtensionInstance = DatatypeConverter .parseBoolean(isInternalExtensionElement.getTextContent().toLowerCase()); resourceExtensionInstance.setIsInternalExtension(isInternalExtensionInstance); } Element disallowMajorVersionUpgradeElement = XmlUtility.getElementByTagNameNS( resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "DisallowMajorVersionUpgrade"); if (disallowMajorVersionUpgradeElement != null && disallowMajorVersionUpgradeElement.getTextContent() != null && !disallowMajorVersionUpgradeElement.getTextContent().isEmpty()) { boolean disallowMajorVersionUpgradeInstance; disallowMajorVersionUpgradeInstance = DatatypeConverter.parseBoolean( disallowMajorVersionUpgradeElement.getTextContent().toLowerCase()); resourceExtensionInstance .setDisallowMajorVersionUpgrade(disallowMajorVersionUpgradeInstance); } Element supportedOSElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "SupportedOS"); if (supportedOSElement != null) { String supportedOSInstance; supportedOSInstance = supportedOSElement.getTextContent(); resourceExtensionInstance.setSupportedOS(supportedOSInstance); } Element companyNameElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "CompanyName"); if (companyNameElement != null) { String companyNameInstance; companyNameInstance = companyNameElement.getTextContent(); resourceExtensionInstance.setCompanyName(companyNameInstance); } Element publishedDateElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "PublishedDate"); if (publishedDateElement != null && publishedDateElement.getTextContent() != null && !publishedDateElement.getTextContent().isEmpty()) { Calendar publishedDateInstance; publishedDateInstance = DatatypeConverter .parseDateTime(publishedDateElement.getTextContent()); resourceExtensionInstance.setPublishedDate(publishedDateInstance); } Element regionsElement = XmlUtility.getElementByTagNameNS(resourceExtensionsElement, "http://schemas.microsoft.com/windowsazure", "Regions"); if (regionsElement != null) { String regionsInstance; regionsInstance = regionsElement.getTextContent(); resourceExtensionInstance.setRegions(regionsInstance); } } } } 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(); } } }
From source file:com.microsoft.azure.management.compute.AvailabilitySetOperationsImpl.java
/** * The operation to create or update the availability set. * * @param resourceGroupName Required. The name of the resource group. * @param parameters Required. Parameters supplied to the Create * Availability Set operation.// www .jav a 2 s .c om * @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. * @return The Create Availability Set operation response. */ @Override public AvailabilitySetCreateOrUpdateResponse createOrUpdate(String resourceGroupName, AvailabilitySet parameters) throws IOException, ServiceException, InterruptedException, ExecutionException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getLocation() == null) { throw new NullPointerException("parameters.Location"); } // 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("resourceGroupName", resourceGroupName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "createOrUpdateAsync", tracingParameters); } // Construct URL String url = ""; url = url + "/subscriptions/"; if (this.getClient().getCredentials().getSubscriptionId() != null) { url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8"); } url = url + "/resourceGroups/"; url = url + URLEncoder.encode(resourceGroupName, "UTF-8"); url = url + "/providers/"; url = url + "Microsoft.Compute"; url = url + "/availabilitySets/"; if (parameters.getName() != null) { url = url + URLEncoder.encode(parameters.getName(), "UTF-8"); } ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-06-15"); if (queryParameters.size() > 0) { url = url + "?" + CollectionStringBuilder.join(queryParameters, "&"); } 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/json"); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode availabilitySetJsonValue = objectMapper.createObjectNode(); requestDoc = availabilitySetJsonValue; ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) availabilitySetJsonValue).put("properties", propertiesValue); if (parameters.getPlatformUpdateDomainCount() != null) { ((ObjectNode) propertiesValue).put("platformUpdateDomainCount", parameters.getPlatformUpdateDomainCount()); } if (parameters.getPlatformFaultDomainCount() != null) { ((ObjectNode) propertiesValue).put("platformFaultDomainCount", parameters.getPlatformFaultDomainCount()); } if (parameters.getVirtualMachinesReferences() != null) { if (parameters.getVirtualMachinesReferences() instanceof LazyCollection == false || ((LazyCollection) parameters.getVirtualMachinesReferences()).isInitialized()) { ArrayNode virtualMachinesArray = objectMapper.createArrayNode(); for (VirtualMachineReference virtualMachinesItem : parameters.getVirtualMachinesReferences()) { ObjectNode virtualMachineReferenceValue = objectMapper.createObjectNode(); virtualMachinesArray.add(virtualMachineReferenceValue); if (virtualMachinesItem.getReferenceUri() != null) { ((ObjectNode) virtualMachineReferenceValue).put("id", virtualMachinesItem.getReferenceUri()); } } ((ObjectNode) propertiesValue).put("virtualMachines", virtualMachinesArray); } } if (parameters.getStatuses() != null) { if (parameters.getStatuses() instanceof LazyCollection == false || ((LazyCollection) parameters.getStatuses()).isInitialized()) { ArrayNode statusesArray = objectMapper.createArrayNode(); for (InstanceViewStatus statusesItem : parameters.getStatuses()) { ObjectNode instanceViewStatusValue = objectMapper.createObjectNode(); statusesArray.add(instanceViewStatusValue); if (statusesItem.getCode() != null) { ((ObjectNode) instanceViewStatusValue).put("code", statusesItem.getCode()); } if (statusesItem.getLevel() != null) { ((ObjectNode) instanceViewStatusValue).put("level", statusesItem.getLevel()); } if (statusesItem.getDisplayStatus() != null) { ((ObjectNode) instanceViewStatusValue).put("displayStatus", statusesItem.getDisplayStatus()); } if (statusesItem.getMessage() != null) { ((ObjectNode) instanceViewStatusValue).put("message", statusesItem.getMessage()); } if (statusesItem.getTime() != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); ((ObjectNode) instanceViewStatusValue).put("time", simpleDateFormat.format(statusesItem.getTime().getTime())); } } ((ObjectNode) propertiesValue).put("statuses", statusesArray); } } if (parameters.getId() != null) { ((ObjectNode) availabilitySetJsonValue).put("id", parameters.getId()); } if (parameters.getName() != null) { ((ObjectNode) availabilitySetJsonValue).put("name", parameters.getName()); } if (parameters.getType() != null) { ((ObjectNode) availabilitySetJsonValue).put("type", parameters.getType()); } ((ObjectNode) availabilitySetJsonValue).put("location", parameters.getLocation()); if (parameters.getTags() != null) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) availabilitySetJsonValue).put("tags", tagsDictionary); } StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, requestDoc); requestContent = stringWriter.toString(); StringEntity entity = new StringEntity(requestContent); httpRequest.setEntity(entity); httpRequest.setHeader("Content-Type", "application/json"); // 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_OK) { ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result AvailabilitySetCreateOrUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new AvailabilitySetCreateOrUpdateResponse(); JsonNode responseDoc = null; String responseDocContent = IOUtils.toString(responseContent); if (responseDocContent == null == false && responseDocContent.length() > 0) { responseDoc = objectMapper.readTree(responseDocContent); } if (responseDoc != null && responseDoc instanceof NullNode == false) { AvailabilitySet availabilitySetInstance = new AvailabilitySet(); result.setAvailabilitySet(availabilitySetInstance); JsonNode propertiesValue2 = responseDoc.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { JsonNode platformUpdateDomainCountValue = propertiesValue2.get("platformUpdateDomainCount"); if (platformUpdateDomainCountValue != null && platformUpdateDomainCountValue instanceof NullNode == false) { int platformUpdateDomainCountInstance; platformUpdateDomainCountInstance = platformUpdateDomainCountValue.getIntValue(); availabilitySetInstance.setPlatformUpdateDomainCount(platformUpdateDomainCountInstance); } JsonNode platformFaultDomainCountValue = propertiesValue2.get("platformFaultDomainCount"); if (platformFaultDomainCountValue != null && platformFaultDomainCountValue instanceof NullNode == false) { int platformFaultDomainCountInstance; platformFaultDomainCountInstance = platformFaultDomainCountValue.getIntValue(); availabilitySetInstance.setPlatformFaultDomainCount(platformFaultDomainCountInstance); } JsonNode virtualMachinesArray2 = propertiesValue2.get("virtualMachines"); if (virtualMachinesArray2 != null && virtualMachinesArray2 instanceof NullNode == false) { for (JsonNode virtualMachinesValue : ((ArrayNode) virtualMachinesArray2)) { VirtualMachineReference virtualMachineReferenceInstance = new VirtualMachineReference(); availabilitySetInstance.getVirtualMachinesReferences() .add(virtualMachineReferenceInstance); JsonNode idValue = virtualMachinesValue.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); virtualMachineReferenceInstance.setReferenceUri(idInstance); } } } JsonNode statusesArray2 = propertiesValue2.get("statuses"); if (statusesArray2 != null && statusesArray2 instanceof NullNode == false) { for (JsonNode statusesValue : ((ArrayNode) statusesArray2)) { InstanceViewStatus instanceViewStatusInstance = new InstanceViewStatus(); availabilitySetInstance.getStatuses().add(instanceViewStatusInstance); JsonNode codeValue = statusesValue.get("code"); if (codeValue != null && codeValue instanceof NullNode == false) { String codeInstance; codeInstance = codeValue.getTextValue(); instanceViewStatusInstance.setCode(codeInstance); } JsonNode levelValue = statusesValue.get("level"); if (levelValue != null && levelValue instanceof NullNode == false) { String levelInstance; levelInstance = levelValue.getTextValue(); instanceViewStatusInstance.setLevel(levelInstance); } JsonNode displayStatusValue = statusesValue.get("displayStatus"); if (displayStatusValue != null && displayStatusValue instanceof NullNode == false) { String displayStatusInstance; displayStatusInstance = displayStatusValue.getTextValue(); instanceViewStatusInstance.setDisplayStatus(displayStatusInstance); } JsonNode messageValue = statusesValue.get("message"); if (messageValue != null && messageValue instanceof NullNode == false) { String messageInstance; messageInstance = messageValue.getTextValue(); instanceViewStatusInstance.setMessage(messageInstance); } JsonNode timeValue = statusesValue.get("time"); if (timeValue != null && timeValue instanceof NullNode == false) { Calendar timeInstance; timeInstance = DatatypeConverter.parseDateTime(timeValue.getTextValue()); instanceViewStatusInstance.setTime(timeInstance); } } } } JsonNode idValue2 = responseDoc.get("id"); if (idValue2 != null && idValue2 instanceof NullNode == false) { String idInstance2; idInstance2 = idValue2.getTextValue(); availabilitySetInstance.setId(idInstance2); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); availabilitySetInstance.setName(nameInstance); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); availabilitySetInstance.setType(typeInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); availabilitySetInstance.setLocation(locationInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); availabilitySetInstance.getTags().put(tagsKey2, tagsValue2); } } } } 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(); } } }