/**
*
* Copyright (c) Microsoft and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.
package com.microsoft.windowsazure.scheduler;
import com.microsoft.windowsazure.core.OperationResponse;
import com.microsoft.windowsazure.core.ServiceOperations;
import com.microsoft.windowsazure.core.TimeSpan8601Converter;
import com.microsoft.windowsazure.core.pipeline.apache.CustomHttpDelete;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.scheduler.models.Job;
import com.microsoft.windowsazure.scheduler.models.JobAction;
import com.microsoft.windowsazure.scheduler.models.JobActionType;
import com.microsoft.windowsazure.scheduler.models.JobCollectionJobsUpdateStateParameters;
import com.microsoft.windowsazure.scheduler.models.JobCollectionJobsUpdateStateResponse;
import com.microsoft.windowsazure.scheduler.models.JobCreateOrUpdateParameters;
import com.microsoft.windowsazure.scheduler.models.JobCreateOrUpdateResponse;
import com.microsoft.windowsazure.scheduler.models.JobCreateParameters;
import com.microsoft.windowsazure.scheduler.models.JobCreateResponse;
import com.microsoft.windowsazure.scheduler.models.JobErrorAction;
import com.microsoft.windowsazure.scheduler.models.JobGetHistoryParameters;
import com.microsoft.windowsazure.scheduler.models.JobGetHistoryResponse;
import com.microsoft.windowsazure.scheduler.models.JobGetHistoryWithFilterParameters;
import com.microsoft.windowsazure.scheduler.models.JobGetResponse;
import com.microsoft.windowsazure.scheduler.models.JobHistoryActionName;
import com.microsoft.windowsazure.scheduler.models.JobHistoryStatus;
import com.microsoft.windowsazure.scheduler.models.JobHttpRequest;
import com.microsoft.windowsazure.scheduler.models.JobListParameters;
import com.microsoft.windowsazure.scheduler.models.JobListResponse;
import com.microsoft.windowsazure.scheduler.models.JobListWithFilterParameters;
import com.microsoft.windowsazure.scheduler.models.JobQueueMessage;
import com.microsoft.windowsazure.scheduler.models.JobRecurrence;
import com.microsoft.windowsazure.scheduler.models.JobRecurrenceFrequency;
import com.microsoft.windowsazure.scheduler.models.JobRecurrenceSchedule;
import com.microsoft.windowsazure.scheduler.models.JobScheduleDay;
import com.microsoft.windowsazure.scheduler.models.JobScheduleMonthlyOccurrence;
import com.microsoft.windowsazure.scheduler.models.JobState;
import com.microsoft.windowsazure.scheduler.models.JobStatus;
import com.microsoft.windowsazure.scheduler.models.JobUpdateStateParameters;
import com.microsoft.windowsazure.scheduler.models.JobUpdateStateResponse;
import com.microsoft.windowsazure.scheduler.models.RetryPolicy;
import com.microsoft.windowsazure.scheduler.models.RetryType;
import com.microsoft.windowsazure.tracing.CloudTracing;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import javax.xml.bind.DatatypeConverter;
import javax.xml.datatype.Duration;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ArrayNode;
import org.codehaus.jackson.node.ObjectNode;
public class JobOperationsImpl implements ServiceOperations<SchedulerClientImpl>, JobOperations {
/**
* Initializes a new instance of the JobOperationsImpl class.
*
* @param client Reference to the service client.
*/
JobOperationsImpl(SchedulerClientImpl client) {
this.client = client;
}
private SchedulerClientImpl client;
/**
* Gets a reference to the
* microsoft.windowsazure.scheduler.SchedulerClientImpl.
* @return The Client value.
*/
public SchedulerClientImpl getClient() {
return this.client;
}
/**
* Creates a new Job, allowing the service to generate a job id. Use
* CreateOrUpdate if a user-chosen job id is required.
*
* @param parameters Required. Parameters specifying the job definition for
* a Create Job operation.
* @return The Create Job operation response.
*/
@Override
public Future<JobCreateResponse> createAsync(final JobCreateParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobCreateResponse>() {
@Override
public JobCreateResponse call() throws Exception {
return create(parameters);
}
});
}
/**
* Creates a new Job, allowing the service to generate a job id. Use
* CreateOrUpdate if a user-chosen job id is required.
*
* @param parameters Required. Parameters specifying the job definition for
* a Create Job operation.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Create Job operation response.
*/
@Override
public JobCreateResponse create(JobCreateParameters parameters) throws IOException, ServiceException, URISyntaxException {
// Validate
if (parameters == null) {
throw new NullPointerException("parameters");
}
if (parameters.getAction() == null) {
throw new NullPointerException("parameters.Action");
}
if (parameters.getAction().getErrorAction() != null) {
if (parameters.getAction().getErrorAction().getQueueMessage() != null) {
if (parameters.getAction().getErrorAction().getQueueMessage().getMessage() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.Message");
}
if (parameters.getAction().getErrorAction().getQueueMessage().getQueueName() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.QueueName");
}
if (parameters.getAction().getErrorAction().getQueueMessage().getSasToken() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.SasToken");
}
if (parameters.getAction().getErrorAction().getQueueMessage().getStorageAccountName() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.StorageAccountName");
}
}
if (parameters.getAction().getErrorAction().getRequest() != null) {
if (parameters.getAction().getErrorAction().getRequest().getMethod() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.Request.Method");
}
if (parameters.getAction().getErrorAction().getRequest().getUri() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.Request.Uri");
}
}
}
if (parameters.getAction().getQueueMessage() != null) {
if (parameters.getAction().getQueueMessage().getMessage() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.Message");
}
if (parameters.getAction().getQueueMessage().getQueueName() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.QueueName");
}
if (parameters.getAction().getQueueMessage().getSasToken() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.SasToken");
}
if (parameters.getAction().getQueueMessage().getStorageAccountName() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.StorageAccountName");
}
}
if (parameters.getAction().getRequest() != null) {
if (parameters.getAction().getRequest().getMethod() == null) {
throw new NullPointerException("parameters.Action.Request.Method");
}
if (parameters.getAction().getRequest().getUri() == null) {
throw new NullPointerException("parameters.Action.Request.Uri");
}
}
// 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("parameters", parameters);
CloudTracing.enter(invocationId, this, "createAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs" + "?";
url = url + "api-version=" + "2014-04-01";
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");
httpRequest.setHeader("x-ms-version", "2013-03-01");
// Serialize Request
String requestContent = null;
JsonNode requestDoc = null;
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode jobCreateParametersValue = objectMapper.createObjectNode();
requestDoc = jobCreateParametersValue;
if (parameters.getStartTime() != null) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
((ObjectNode) jobCreateParametersValue).put("startTime", simpleDateFormat.format(parameters.getStartTime().getTime()));
}
ObjectNode actionValue = objectMapper.createObjectNode();
((ObjectNode) jobCreateParametersValue).put("action", actionValue);
((ObjectNode) actionValue).put("type", SchedulerClientImpl.jobActionTypeToString(parameters.getAction().getType()));
if (parameters.getAction().getRetryPolicy() != null) {
ObjectNode retryPolicyValue = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("retryPolicy", retryPolicyValue);
((ObjectNode) retryPolicyValue).put("retryType", SchedulerClientImpl.retryTypeToString(parameters.getAction().getRetryPolicy().getRetryType()));
if (parameters.getAction().getRetryPolicy().getRetryInterval() != null) {
((ObjectNode) retryPolicyValue).put("retryInterval", TimeSpan8601Converter.format(parameters.getAction().getRetryPolicy().getRetryInterval()));
}
if (parameters.getAction().getRetryPolicy().getRetryCount() != null) {
((ObjectNode) retryPolicyValue).put("retryCount", parameters.getAction().getRetryPolicy().getRetryCount());
}
}
if (parameters.getAction().getErrorAction() != null) {
ObjectNode errorActionValue = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("errorAction", errorActionValue);
((ObjectNode) errorActionValue).put("type", SchedulerClientImpl.jobActionTypeToString(parameters.getAction().getErrorAction().getType()));
if (parameters.getAction().getErrorAction().getRequest() != null) {
ObjectNode requestValue = objectMapper.createObjectNode();
((ObjectNode) errorActionValue).put("request", requestValue);
((ObjectNode) requestValue).put("uri", parameters.getAction().getErrorAction().getRequest().getUri().toString());
((ObjectNode) requestValue).put("method", parameters.getAction().getErrorAction().getRequest().getMethod());
ObjectNode headersDictionary = objectMapper.createObjectNode();
if (parameters.getAction().getErrorAction().getRequest().getHeaders() != null) {
for (Map.Entry<String, String> entry : parameters.getAction().getErrorAction().getRequest().getHeaders().entrySet()) {
String headersKey = entry.getKey();
String headersValue = entry.getValue();
((ObjectNode) headersDictionary).put(headersKey, headersValue);
}
}
((ObjectNode) requestValue).put("headers", headersDictionary);
if (parameters.getAction().getErrorAction().getRequest().getBody() != null) {
((ObjectNode) requestValue).put("body", parameters.getAction().getErrorAction().getRequest().getBody());
}
}
if (parameters.getAction().getErrorAction().getQueueMessage() != null) {
ObjectNode queueMessageValue = objectMapper.createObjectNode();
((ObjectNode) errorActionValue).put("queueMessage", queueMessageValue);
((ObjectNode) queueMessageValue).put("storageAccount", parameters.getAction().getErrorAction().getQueueMessage().getStorageAccountName());
((ObjectNode) queueMessageValue).put("queueName", parameters.getAction().getErrorAction().getQueueMessage().getQueueName());
((ObjectNode) queueMessageValue).put("sasToken", parameters.getAction().getErrorAction().getQueueMessage().getSasToken());
((ObjectNode) queueMessageValue).put("message", parameters.getAction().getErrorAction().getQueueMessage().getMessage());
}
}
if (parameters.getAction().getRequest() != null) {
ObjectNode requestValue2 = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("request", requestValue2);
((ObjectNode) requestValue2).put("uri", parameters.getAction().getRequest().getUri().toString());
((ObjectNode) requestValue2).put("method", parameters.getAction().getRequest().getMethod());
ObjectNode headersDictionary2 = objectMapper.createObjectNode();
if (parameters.getAction().getRequest().getHeaders() != null) {
for (Map.Entry<String, String> entry2 : parameters.getAction().getRequest().getHeaders().entrySet()) {
String headersKey2 = entry2.getKey();
String headersValue2 = entry2.getValue();
((ObjectNode) headersDictionary2).put(headersKey2, headersValue2);
}
}
((ObjectNode) requestValue2).put("headers", headersDictionary2);
if (parameters.getAction().getRequest().getBody() != null) {
((ObjectNode) requestValue2).put("body", parameters.getAction().getRequest().getBody());
}
}
if (parameters.getAction().getQueueMessage() != null) {
ObjectNode queueMessageValue2 = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("queueMessage", queueMessageValue2);
((ObjectNode) queueMessageValue2).put("storageAccount", parameters.getAction().getQueueMessage().getStorageAccountName());
((ObjectNode) queueMessageValue2).put("queueName", parameters.getAction().getQueueMessage().getQueueName());
((ObjectNode) queueMessageValue2).put("sasToken", parameters.getAction().getQueueMessage().getSasToken());
((ObjectNode) queueMessageValue2).put("message", parameters.getAction().getQueueMessage().getMessage());
}
if (parameters.getRecurrence() != null) {
ObjectNode recurrenceValue = objectMapper.createObjectNode();
((ObjectNode) jobCreateParametersValue).put("recurrence", recurrenceValue);
((ObjectNode) recurrenceValue).put("frequency", SchedulerClientImpl.jobRecurrenceFrequencyToString(parameters.getRecurrence().getFrequency()));
if (parameters.getRecurrence().getInterval() != null) {
((ObjectNode) recurrenceValue).put("interval", parameters.getRecurrence().getInterval());
}
if (parameters.getRecurrence().getCount() != null) {
((ObjectNode) recurrenceValue).put("count", parameters.getRecurrence().getCount());
}
if (parameters.getRecurrence().getEndTime() != null) {
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
((ObjectNode) recurrenceValue).put("endTime", simpleDateFormat2.format(parameters.getRecurrence().getEndTime().getTime()));
}
if (parameters.getRecurrence().getSchedule() != null) {
ObjectNode scheduleValue = objectMapper.createObjectNode();
((ObjectNode) recurrenceValue).put("schedule", scheduleValue);
if (parameters.getRecurrence().getSchedule().getMinutes() != null) {
ArrayNode minutesArray = objectMapper.createArrayNode();
for (int minutesItem : parameters.getRecurrence().getSchedule().getMinutes()) {
minutesArray.add(minutesItem);
}
((ObjectNode) scheduleValue).put("minutes", minutesArray);
}
if (parameters.getRecurrence().getSchedule().getHours() != null) {
ArrayNode hoursArray = objectMapper.createArrayNode();
for (int hoursItem : parameters.getRecurrence().getSchedule().getHours()) {
hoursArray.add(hoursItem);
}
((ObjectNode) scheduleValue).put("hours", hoursArray);
}
if (parameters.getRecurrence().getSchedule().getDays() != null) {
ArrayNode weekDaysArray = objectMapper.createArrayNode();
for (JobScheduleDay weekDaysItem : parameters.getRecurrence().getSchedule().getDays()) {
weekDaysArray.add(SchedulerClientImpl.jobScheduleDayToString(weekDaysItem));
}
((ObjectNode) scheduleValue).put("weekDays", weekDaysArray);
}
if (parameters.getRecurrence().getSchedule().getMonths() != null) {
ArrayNode monthsArray = objectMapper.createArrayNode();
for (int monthsItem : parameters.getRecurrence().getSchedule().getMonths()) {
monthsArray.add(monthsItem);
}
((ObjectNode) scheduleValue).put("months", monthsArray);
}
if (parameters.getRecurrence().getSchedule().getMonthDays() != null) {
ArrayNode monthDaysArray = objectMapper.createArrayNode();
for (int monthDaysItem : parameters.getRecurrence().getSchedule().getMonthDays()) {
monthDaysArray.add(monthDaysItem);
}
((ObjectNode) scheduleValue).put("monthDays", monthDaysArray);
}
if (parameters.getRecurrence().getSchedule().getMonthlyOccurrences() != null) {
ArrayNode monthlyOccurrencesArray = objectMapper.createArrayNode();
for (JobScheduleMonthlyOccurrence monthlyOccurrencesItem : parameters.getRecurrence().getSchedule().getMonthlyOccurrences()) {
ObjectNode jobScheduleMonthlyOccurrenceValue = objectMapper.createObjectNode();
monthlyOccurrencesArray.add(jobScheduleMonthlyOccurrenceValue);
((ObjectNode) jobScheduleMonthlyOccurrenceValue).put("day", SchedulerClientImpl.jobScheduleDayToString(monthlyOccurrencesItem.getDay()));
if (monthlyOccurrencesItem.getOccurrence() != null) {
((ObjectNode) jobScheduleMonthlyOccurrenceValue).put("occurrence", monthlyOccurrencesItem.getOccurrence());
}
}
((ObjectNode) scheduleValue).put("monthlyOccurrences", monthlyOccurrencesArray);
}
}
}
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_CREATED) {
ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobCreateResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobCreateResponse();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
Job jobInstance = new Job();
result.setJob(jobInstance);
JsonNode idValue = responseDoc.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = responseDoc.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue2 = responseDoc.get("action");
if (actionValue2 != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue2.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue2 = actionValue2.get("retryPolicy");
if (retryPolicyValue2 != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue2.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue2.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue2.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue2 = actionValue2.get("errorAction");
if (errorActionValue2 != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue2.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue3 = errorActionValue2.get("request");
if (requestValue3 != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue3.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue3.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue3.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey3 = property.getKey();
String headersValue3 = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey3, headersValue3);
}
}
JsonNode bodyValue = requestValue3.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue3 = errorActionValue2.get("queueMessage");
if (queueMessageValue3 != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue3.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue3.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue3.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue3.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue4 = actionValue2.get("request");
if (requestValue4 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue4.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue4.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue4.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey4 = property2.getKey();
String headersValue4 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey4, headersValue4);
}
}
JsonNode bodyValue2 = requestValue4.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue4 = actionValue2.get("queueMessage");
if (queueMessageValue4 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue4.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue4.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue4.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue4.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue2 = responseDoc.get("recurrence");
if (recurrenceValue2 != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue2.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue2.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue2.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue2.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue2 = recurrenceValue2.get("schedule");
if (scheduleValue2 != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray2 = scheduleValue2.get("minutes");
if (minutesArray2 != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray2)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray2 = scheduleValue2.get("hours");
if (hoursArray2 != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray2)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray2 = scheduleValue2.get("weekDays");
if (weekDaysArray2 != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray2)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray2 = scheduleValue2.get("months");
if (monthsArray2 != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray2)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray2 = scheduleValue2.get("monthDays");
if (monthDaysArray2 != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray2)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray2 = scheduleValue2.get("monthlyOccurrences");
if (monthlyOccurrencesArray2 != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray2)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = responseDoc.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = responseDoc.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
/**
* Creates a new Job with a user-provided job id, or updates an existing
* job, replacing its definition with that specified.
*
* @param jobId Required. Id of the job to create or update.
* @param parameters Required. Parameters specifying the job definition for
* a CreateOrUpdate Job operation.
* @return The CreateOrUpdate Job operation response.
*/
@Override
public Future<JobCreateOrUpdateResponse> createOrUpdateAsync(final String jobId, final JobCreateOrUpdateParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobCreateOrUpdateResponse>() {
@Override
public JobCreateOrUpdateResponse call() throws Exception {
return createOrUpdate(jobId, parameters);
}
});
}
/**
* Creates a new Job with a user-provided job id, or updates an existing
* job, replacing its definition with that specified.
*
* @param jobId Required. Id of the job to create or update.
* @param parameters Required. Parameters specifying the job definition for
* a CreateOrUpdate Job operation.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The CreateOrUpdate Job operation response.
*/
@Override
public JobCreateOrUpdateResponse createOrUpdate(String jobId, JobCreateOrUpdateParameters parameters) throws IOException, ServiceException, URISyntaxException {
// Validate
if (jobId == null) {
throw new NullPointerException("jobId");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
if (parameters.getAction() == null) {
throw new NullPointerException("parameters.Action");
}
if (parameters.getAction().getErrorAction() != null) {
if (parameters.getAction().getErrorAction().getQueueMessage() != null) {
if (parameters.getAction().getErrorAction().getQueueMessage().getMessage() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.Message");
}
if (parameters.getAction().getErrorAction().getQueueMessage().getQueueName() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.QueueName");
}
if (parameters.getAction().getErrorAction().getQueueMessage().getSasToken() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.SasToken");
}
if (parameters.getAction().getErrorAction().getQueueMessage().getStorageAccountName() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.QueueMessage.StorageAccountName");
}
}
if (parameters.getAction().getErrorAction().getRequest() != null) {
if (parameters.getAction().getErrorAction().getRequest().getMethod() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.Request.Method");
}
if (parameters.getAction().getErrorAction().getRequest().getUri() == null) {
throw new NullPointerException("parameters.Action.ErrorAction.Request.Uri");
}
}
}
if (parameters.getAction().getQueueMessage() != null) {
if (parameters.getAction().getQueueMessage().getMessage() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.Message");
}
if (parameters.getAction().getQueueMessage().getQueueName() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.QueueName");
}
if (parameters.getAction().getQueueMessage().getSasToken() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.SasToken");
}
if (parameters.getAction().getQueueMessage().getStorageAccountName() == null) {
throw new NullPointerException("parameters.Action.QueueMessage.StorageAccountName");
}
}
if (parameters.getAction().getRequest() != null) {
if (parameters.getAction().getRequest().getMethod() == null) {
throw new NullPointerException("parameters.Action.Request.Method");
}
if (parameters.getAction().getRequest().getUri() == null) {
throw new NullPointerException("parameters.Action.Request.Uri");
}
}
// 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("jobId", jobId);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "createOrUpdateAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs/" + jobId.trim() + "?";
url = url + "api-version=" + "2014-04-01";
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");
httpRequest.setHeader("x-ms-version", "2013-03-01");
// Serialize Request
String requestContent = null;
JsonNode requestDoc = null;
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode jobCreateOrUpdateParametersValue = objectMapper.createObjectNode();
requestDoc = jobCreateOrUpdateParametersValue;
if (parameters.getStartTime() != null) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
((ObjectNode) jobCreateOrUpdateParametersValue).put("startTime", simpleDateFormat.format(parameters.getStartTime().getTime()));
}
ObjectNode actionValue = objectMapper.createObjectNode();
((ObjectNode) jobCreateOrUpdateParametersValue).put("action", actionValue);
((ObjectNode) actionValue).put("type", SchedulerClientImpl.jobActionTypeToString(parameters.getAction().getType()));
if (parameters.getAction().getRetryPolicy() != null) {
ObjectNode retryPolicyValue = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("retryPolicy", retryPolicyValue);
((ObjectNode) retryPolicyValue).put("retryType", SchedulerClientImpl.retryTypeToString(parameters.getAction().getRetryPolicy().getRetryType()));
if (parameters.getAction().getRetryPolicy().getRetryInterval() != null) {
((ObjectNode) retryPolicyValue).put("retryInterval", TimeSpan8601Converter.format(parameters.getAction().getRetryPolicy().getRetryInterval()));
}
if (parameters.getAction().getRetryPolicy().getRetryCount() != null) {
((ObjectNode) retryPolicyValue).put("retryCount", parameters.getAction().getRetryPolicy().getRetryCount());
}
}
if (parameters.getAction().getErrorAction() != null) {
ObjectNode errorActionValue = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("errorAction", errorActionValue);
((ObjectNode) errorActionValue).put("type", SchedulerClientImpl.jobActionTypeToString(parameters.getAction().getErrorAction().getType()));
if (parameters.getAction().getErrorAction().getRequest() != null) {
ObjectNode requestValue = objectMapper.createObjectNode();
((ObjectNode) errorActionValue).put("request", requestValue);
((ObjectNode) requestValue).put("uri", parameters.getAction().getErrorAction().getRequest().getUri().toString());
((ObjectNode) requestValue).put("method", parameters.getAction().getErrorAction().getRequest().getMethod());
ObjectNode headersDictionary = objectMapper.createObjectNode();
if (parameters.getAction().getErrorAction().getRequest().getHeaders() != null) {
for (Map.Entry<String, String> entry : parameters.getAction().getErrorAction().getRequest().getHeaders().entrySet()) {
String headersKey = entry.getKey();
String headersValue = entry.getValue();
((ObjectNode) headersDictionary).put(headersKey, headersValue);
}
}
((ObjectNode) requestValue).put("headers", headersDictionary);
if (parameters.getAction().getErrorAction().getRequest().getBody() != null) {
((ObjectNode) requestValue).put("body", parameters.getAction().getErrorAction().getRequest().getBody());
}
}
if (parameters.getAction().getErrorAction().getQueueMessage() != null) {
ObjectNode queueMessageValue = objectMapper.createObjectNode();
((ObjectNode) errorActionValue).put("queueMessage", queueMessageValue);
((ObjectNode) queueMessageValue).put("storageAccount", parameters.getAction().getErrorAction().getQueueMessage().getStorageAccountName());
((ObjectNode) queueMessageValue).put("queueName", parameters.getAction().getErrorAction().getQueueMessage().getQueueName());
((ObjectNode) queueMessageValue).put("sasToken", parameters.getAction().getErrorAction().getQueueMessage().getSasToken());
((ObjectNode) queueMessageValue).put("message", parameters.getAction().getErrorAction().getQueueMessage().getMessage());
}
}
if (parameters.getAction().getRequest() != null) {
ObjectNode requestValue2 = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("request", requestValue2);
((ObjectNode) requestValue2).put("uri", parameters.getAction().getRequest().getUri().toString());
((ObjectNode) requestValue2).put("method", parameters.getAction().getRequest().getMethod());
ObjectNode headersDictionary2 = objectMapper.createObjectNode();
if (parameters.getAction().getRequest().getHeaders() != null) {
for (Map.Entry<String, String> entry2 : parameters.getAction().getRequest().getHeaders().entrySet()) {
String headersKey2 = entry2.getKey();
String headersValue2 = entry2.getValue();
((ObjectNode) headersDictionary2).put(headersKey2, headersValue2);
}
}
((ObjectNode) requestValue2).put("headers", headersDictionary2);
if (parameters.getAction().getRequest().getBody() != null) {
((ObjectNode) requestValue2).put("body", parameters.getAction().getRequest().getBody());
}
}
if (parameters.getAction().getQueueMessage() != null) {
ObjectNode queueMessageValue2 = objectMapper.createObjectNode();
((ObjectNode) actionValue).put("queueMessage", queueMessageValue2);
((ObjectNode) queueMessageValue2).put("storageAccount", parameters.getAction().getQueueMessage().getStorageAccountName());
((ObjectNode) queueMessageValue2).put("queueName", parameters.getAction().getQueueMessage().getQueueName());
((ObjectNode) queueMessageValue2).put("sasToken", parameters.getAction().getQueueMessage().getSasToken());
((ObjectNode) queueMessageValue2).put("message", parameters.getAction().getQueueMessage().getMessage());
}
if (parameters.getRecurrence() != null) {
ObjectNode recurrenceValue = objectMapper.createObjectNode();
((ObjectNode) jobCreateOrUpdateParametersValue).put("recurrence", recurrenceValue);
((ObjectNode) recurrenceValue).put("frequency", SchedulerClientImpl.jobRecurrenceFrequencyToString(parameters.getRecurrence().getFrequency()));
if (parameters.getRecurrence().getInterval() != null) {
((ObjectNode) recurrenceValue).put("interval", parameters.getRecurrence().getInterval());
}
if (parameters.getRecurrence().getCount() != null) {
((ObjectNode) recurrenceValue).put("count", parameters.getRecurrence().getCount());
}
if (parameters.getRecurrence().getEndTime() != null) {
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
simpleDateFormat2.setTimeZone(TimeZone.getTimeZone("UTC"));
((ObjectNode) recurrenceValue).put("endTime", simpleDateFormat2.format(parameters.getRecurrence().getEndTime().getTime()));
}
if (parameters.getRecurrence().getSchedule() != null) {
ObjectNode scheduleValue = objectMapper.createObjectNode();
((ObjectNode) recurrenceValue).put("schedule", scheduleValue);
if (parameters.getRecurrence().getSchedule().getMinutes() != null) {
ArrayNode minutesArray = objectMapper.createArrayNode();
for (int minutesItem : parameters.getRecurrence().getSchedule().getMinutes()) {
minutesArray.add(minutesItem);
}
((ObjectNode) scheduleValue).put("minutes", minutesArray);
}
if (parameters.getRecurrence().getSchedule().getHours() != null) {
ArrayNode hoursArray = objectMapper.createArrayNode();
for (int hoursItem : parameters.getRecurrence().getSchedule().getHours()) {
hoursArray.add(hoursItem);
}
((ObjectNode) scheduleValue).put("hours", hoursArray);
}
if (parameters.getRecurrence().getSchedule().getDays() != null) {
ArrayNode weekDaysArray = objectMapper.createArrayNode();
for (JobScheduleDay weekDaysItem : parameters.getRecurrence().getSchedule().getDays()) {
weekDaysArray.add(SchedulerClientImpl.jobScheduleDayToString(weekDaysItem));
}
((ObjectNode) scheduleValue).put("weekDays", weekDaysArray);
}
if (parameters.getRecurrence().getSchedule().getMonths() != null) {
ArrayNode monthsArray = objectMapper.createArrayNode();
for (int monthsItem : parameters.getRecurrence().getSchedule().getMonths()) {
monthsArray.add(monthsItem);
}
((ObjectNode) scheduleValue).put("months", monthsArray);
}
if (parameters.getRecurrence().getSchedule().getMonthDays() != null) {
ArrayNode monthDaysArray = objectMapper.createArrayNode();
for (int monthDaysItem : parameters.getRecurrence().getSchedule().getMonthDays()) {
monthDaysArray.add(monthDaysItem);
}
((ObjectNode) scheduleValue).put("monthDays", monthDaysArray);
}
if (parameters.getRecurrence().getSchedule().getMonthlyOccurrences() != null) {
ArrayNode monthlyOccurrencesArray = objectMapper.createArrayNode();
for (JobScheduleMonthlyOccurrence monthlyOccurrencesItem : parameters.getRecurrence().getSchedule().getMonthlyOccurrences()) {
ObjectNode jobScheduleMonthlyOccurrenceValue = objectMapper.createObjectNode();
monthlyOccurrencesArray.add(jobScheduleMonthlyOccurrenceValue);
((ObjectNode) jobScheduleMonthlyOccurrenceValue).put("day", SchedulerClientImpl.jobScheduleDayToString(monthlyOccurrencesItem.getDay()));
if (monthlyOccurrencesItem.getOccurrence() != null) {
((ObjectNode) jobScheduleMonthlyOccurrenceValue).put("occurrence", monthlyOccurrencesItem.getOccurrence());
}
}
((ObjectNode) scheduleValue).put("monthlyOccurrences", monthlyOccurrencesArray);
}
}
}
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 && statusCode != HttpStatus.SC_CREATED) {
ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobCreateOrUpdateResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobCreateOrUpdateResponse();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
Job jobInstance = new Job();
result.setJob(jobInstance);
JsonNode idValue = responseDoc.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = responseDoc.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue2 = responseDoc.get("action");
if (actionValue2 != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue2.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue2 = actionValue2.get("retryPolicy");
if (retryPolicyValue2 != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue2.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue2.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue2.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue2 = actionValue2.get("errorAction");
if (errorActionValue2 != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue2.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue3 = errorActionValue2.get("request");
if (requestValue3 != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue3.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue3.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue3.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey3 = property.getKey();
String headersValue3 = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey3, headersValue3);
}
}
JsonNode bodyValue = requestValue3.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue3 = errorActionValue2.get("queueMessage");
if (queueMessageValue3 != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue3.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue3.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue3.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue3.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue4 = actionValue2.get("request");
if (requestValue4 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue4.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue4.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue4.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey4 = property2.getKey();
String headersValue4 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey4, headersValue4);
}
}
JsonNode bodyValue2 = requestValue4.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue4 = actionValue2.get("queueMessage");
if (queueMessageValue4 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue4.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue4.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue4.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue4.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue2 = responseDoc.get("recurrence");
if (recurrenceValue2 != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue2.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue2.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue2.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue2.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue2 = recurrenceValue2.get("schedule");
if (scheduleValue2 != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray2 = scheduleValue2.get("minutes");
if (minutesArray2 != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray2)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray2 = scheduleValue2.get("hours");
if (hoursArray2 != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray2)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray2 = scheduleValue2.get("weekDays");
if (weekDaysArray2 != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray2)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray2 = scheduleValue2.get("months");
if (monthsArray2 != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray2)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray2 = scheduleValue2.get("monthDays");
if (monthDaysArray2 != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray2)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray2 = scheduleValue2.get("monthlyOccurrences");
if (monthlyOccurrencesArray2 != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray2)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = responseDoc.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = responseDoc.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
/**
* Deletes a job.
*
* @param jobId Required. Id of the job to delete.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<OperationResponse> deleteAsync(final String jobId) {
return this.getClient().getExecutorService().submit(new Callable<OperationResponse>() {
@Override
public OperationResponse call() throws Exception {
return delete(jobId);
}
});
}
/**
* Deletes a job.
*
* @param jobId Required. Id of the job to delete.
* @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 A standard service response including an HTTP status code and
* request ID.
*/
@Override
public OperationResponse delete(String jobId) throws IOException, ServiceException {
// Validate
if (jobId == null) {
throw new NullPointerException("jobId");
}
// 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("jobId", jobId);
CloudTracing.enter(invocationId, this, "deleteAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs/" + jobId.trim() + "?";
url = url + "api-version=" + "2014-04-01";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
url = url.replace(" ", "%20");
// Create HTTP transport objects
CustomHttpDelete httpRequest = new CustomHttpDelete(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2013-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
OperationResponse result = null;
result = new OperationResponse();
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();
}
}
}
/**
* Get the definition and status of a job.
*
* @param jobId Required. Id of the job to get.
* @return The Get Job operation response.
*/
@Override
public Future<JobGetResponse> getAsync(final String jobId) {
return this.getClient().getExecutorService().submit(new Callable<JobGetResponse>() {
@Override
public JobGetResponse call() throws Exception {
return get(jobId);
}
});
}
/**
* Get the definition and status of a job.
*
* @param jobId Required. Id of the job to get.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Get Job operation response.
*/
@Override
public JobGetResponse get(String jobId) throws IOException, ServiceException, URISyntaxException {
// Validate
if (jobId == null) {
throw new NullPointerException("jobId");
}
// 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("jobId", jobId);
CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs/" + jobId.trim() + "?";
url = url + "api-version=" + "2014-04-01";
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", "2013-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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobGetResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobGetResponse();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
Job jobInstance = new Job();
result.setJob(jobInstance);
JsonNode idValue = responseDoc.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = responseDoc.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue = responseDoc.get("action");
if (actionValue != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue = actionValue.get("retryPolicy");
if (retryPolicyValue != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue = actionValue.get("errorAction");
if (errorActionValue != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue = errorActionValue.get("request");
if (requestValue != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey = property.getKey();
String headersValue = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey, headersValue);
}
}
JsonNode bodyValue = requestValue.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue = errorActionValue.get("queueMessage");
if (queueMessageValue != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue2 = actionValue.get("request");
if (requestValue2 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue2.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue2.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue2.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey2 = property2.getKey();
String headersValue2 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey2, headersValue2);
}
}
JsonNode bodyValue2 = requestValue2.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue2 = actionValue.get("queueMessage");
if (queueMessageValue2 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue2.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue2.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue2.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue2.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue = responseDoc.get("recurrence");
if (recurrenceValue != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue = recurrenceValue.get("schedule");
if (scheduleValue != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray = scheduleValue.get("minutes");
if (minutesArray != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray = scheduleValue.get("hours");
if (hoursArray != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray = scheduleValue.get("weekDays");
if (weekDaysArray != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray = scheduleValue.get("months");
if (monthsArray != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray = scheduleValue.get("monthDays");
if (monthDaysArray != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray = scheduleValue.get("monthlyOccurrences");
if (monthlyOccurrencesArray != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = responseDoc.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = responseDoc.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
/**
* Get the execution history of a Job.
*
* @param jobId Required. Id of the job to get the history of.
* @param parameters Required. Parameters supplied to the Get Job History
* operation.
* @return The Get Job History operation response.
*/
@Override
public Future<JobGetHistoryResponse> getHistoryAsync(final String jobId, final JobGetHistoryParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobGetHistoryResponse>() {
@Override
public JobGetHistoryResponse call() throws Exception {
return getHistory(jobId, parameters);
}
});
}
/**
* Get the execution history of a Job.
*
* @param jobId Required. Id of the job to get the history of.
* @param parameters Required. Parameters supplied to the Get Job History
* operation.
* @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 Get Job History operation response.
*/
@Override
public JobGetHistoryResponse getHistory(String jobId, JobGetHistoryParameters parameters) throws IOException, ServiceException {
// Validate
if (jobId == null) {
throw new NullPointerException("jobId");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("jobId", jobId);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "getHistoryAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs/" + jobId.trim() + "/history" + "?";
url = url + "api-version=" + "2014-04-01";
url = url + "&" + "$skip=" + URLEncoder.encode(Integer.toString(parameters.getSkip()), "UTF-8");
url = url + "&" + "$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8");
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
url = url.replace(" ", "%20");
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2013-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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobGetHistoryResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobGetHistoryResponse();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
JsonNode jobHistoryArray = responseDoc;
if (jobHistoryArray != null) {
for (JsonNode jobHistoryValue : ((ArrayNode) jobHistoryArray)) {
JobGetHistoryResponse.JobHistoryEntry jobHistoryEntryInstance = new JobGetHistoryResponse.JobHistoryEntry();
result.getJobHistory().add(jobHistoryEntryInstance);
JsonNode jobIdValue = jobHistoryValue.get("jobId");
if (jobIdValue != null) {
String jobIdInstance;
jobIdInstance = jobIdValue.getTextValue();
jobHistoryEntryInstance.setId(jobIdInstance);
}
JsonNode timestampValue = jobHistoryValue.get("timestamp");
if (timestampValue != null) {
Calendar timestampInstance;
timestampInstance = DatatypeConverter.parseDateTime(timestampValue.getTextValue());
jobHistoryEntryInstance.setTimestamp(timestampInstance);
}
JsonNode startTimeValue = jobHistoryValue.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobHistoryEntryInstance.setStartTime(startTimeInstance);
}
JsonNode endTimeValue = jobHistoryValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
jobHistoryEntryInstance.setEndTime(endTimeInstance);
}
JsonNode stateValue = jobHistoryValue.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobHistoryEntryInstance.setState(stateInstance);
}
JsonNode messageValue = jobHistoryValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
jobHistoryEntryInstance.setMessage(messageInstance);
}
JsonNode statusValue = jobHistoryValue.get("status");
if (statusValue != null) {
JobHistoryStatus statusInstance;
statusInstance = SchedulerClientImpl.parseJobHistoryStatus(statusValue.getTextValue());
jobHistoryEntryInstance.setStatus(statusInstance);
}
JsonNode actionNameValue = jobHistoryValue.get("actionName");
if (actionNameValue != null) {
JobHistoryActionName actionNameInstance;
actionNameInstance = SchedulerClientImpl.parseJobHistoryActionName(actionNameValue.getTextValue());
jobHistoryEntryInstance.setActionName(actionNameInstance);
}
JsonNode repeatCountValue = jobHistoryValue.get("repeatCount");
if (repeatCountValue != null) {
int repeatCountInstance;
repeatCountInstance = repeatCountValue.getIntValue();
jobHistoryEntryInstance.setRepeatCount(repeatCountInstance);
}
JsonNode retryCountValue = jobHistoryValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
jobHistoryEntryInstance.setRetryCount(retryCountInstance);
}
}
}
}
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();
}
}
}
/**
* Get the execution history of a Job with a filter on the job Status.
*
* @param jobId Required. Id of the job to get the history of.
* @param parameters Required. Parameters supplied to the Get Job History
* With Filter operation.
* @return The Get Job History operation response.
*/
@Override
public Future<JobGetHistoryResponse> getHistoryWithFilterAsync(final String jobId, final JobGetHistoryWithFilterParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobGetHistoryResponse>() {
@Override
public JobGetHistoryResponse call() throws Exception {
return getHistoryWithFilter(jobId, parameters);
}
});
}
/**
* Get the execution history of a Job with a filter on the job Status.
*
* @param jobId Required. Id of the job to get the history of.
* @param parameters Required. Parameters supplied to the Get Job History
* With Filter operation.
* @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 Get Job History operation response.
*/
@Override
public JobGetHistoryResponse getHistoryWithFilter(String jobId, JobGetHistoryWithFilterParameters parameters) throws IOException, ServiceException {
// Validate
if (jobId == null) {
throw new NullPointerException("jobId");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("jobId", jobId);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "getHistoryWithFilterAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs/" + jobId.trim() + "/history" + "?";
url = url + "api-version=" + "2014-04-01";
url = url + "&" + "$filter=status eq " + URLEncoder.encode(SchedulerClientImpl.jobHistoryStatusToString(parameters.getStatus()), "UTF-8");
url = url + "&" + "$skip=" + URLEncoder.encode(Integer.toString(parameters.getSkip()), "UTF-8");
url = url + "&" + "$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8");
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
url = url.replace(" ", "%20");
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2013-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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobGetHistoryResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobGetHistoryResponse();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
JsonNode jobHistoryArray = responseDoc;
if (jobHistoryArray != null) {
for (JsonNode jobHistoryValue : ((ArrayNode) jobHistoryArray)) {
JobGetHistoryResponse.JobHistoryEntry jobHistoryEntryInstance = new JobGetHistoryResponse.JobHistoryEntry();
result.getJobHistory().add(jobHistoryEntryInstance);
JsonNode jobIdValue = jobHistoryValue.get("jobId");
if (jobIdValue != null) {
String jobIdInstance;
jobIdInstance = jobIdValue.getTextValue();
jobHistoryEntryInstance.setId(jobIdInstance);
}
JsonNode timestampValue = jobHistoryValue.get("timestamp");
if (timestampValue != null) {
Calendar timestampInstance;
timestampInstance = DatatypeConverter.parseDateTime(timestampValue.getTextValue());
jobHistoryEntryInstance.setTimestamp(timestampInstance);
}
JsonNode startTimeValue = jobHistoryValue.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobHistoryEntryInstance.setStartTime(startTimeInstance);
}
JsonNode endTimeValue = jobHistoryValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
jobHistoryEntryInstance.setEndTime(endTimeInstance);
}
JsonNode stateValue = jobHistoryValue.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobHistoryEntryInstance.setState(stateInstance);
}
JsonNode messageValue = jobHistoryValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
jobHistoryEntryInstance.setMessage(messageInstance);
}
JsonNode statusValue = jobHistoryValue.get("status");
if (statusValue != null) {
JobHistoryStatus statusInstance;
statusInstance = SchedulerClientImpl.parseJobHistoryStatus(statusValue.getTextValue());
jobHistoryEntryInstance.setStatus(statusInstance);
}
JsonNode actionNameValue = jobHistoryValue.get("actionName");
if (actionNameValue != null) {
JobHistoryActionName actionNameInstance;
actionNameInstance = SchedulerClientImpl.parseJobHistoryActionName(actionNameValue.getTextValue());
jobHistoryEntryInstance.setActionName(actionNameInstance);
}
JsonNode repeatCountValue = jobHistoryValue.get("repeatCount");
if (repeatCountValue != null) {
int repeatCountInstance;
repeatCountInstance = repeatCountValue.getIntValue();
jobHistoryEntryInstance.setRepeatCount(repeatCountInstance);
}
JsonNode retryCountValue = jobHistoryValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
jobHistoryEntryInstance.setRetryCount(retryCountInstance);
}
}
}
}
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();
}
}
}
/**
* Get the list of all jobs in a job collection.
*
* @param parameters Required. Parameters supplied to the List Jobs
* operation.
* @return The List Jobs operation response.
*/
@Override
public Future<JobListResponse> listAsync(final JobListParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobListResponse>() {
@Override
public JobListResponse call() throws Exception {
return list(parameters);
}
});
}
/**
* Get the list of all jobs in a job collection.
*
* @param parameters Required. Parameters supplied to the List Jobs
* operation.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Jobs operation response.
*/
@Override
public JobListResponse list(JobListParameters parameters) throws IOException, ServiceException, URISyntaxException {
// Validate
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs" + "?";
url = url + "api-version=" + "2014-04-01";
if (parameters.getSkip() != null) {
url = url + "&" + "$skip=" + URLEncoder.encode(Integer.toString(parameters.getSkip()), "UTF-8");
}
if (parameters.getTop() != null) {
url = url + "&" + "$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8");
}
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
url = url.replace(" ", "%20");
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2013-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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobListResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobListResponse();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
JsonNode jobsArray = responseDoc;
if (jobsArray != null) {
for (JsonNode jobsValue : ((ArrayNode) jobsArray)) {
Job jobInstance = new Job();
result.getJobs().add(jobInstance);
JsonNode idValue = jobsValue.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = jobsValue.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue = jobsValue.get("action");
if (actionValue != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue = actionValue.get("retryPolicy");
if (retryPolicyValue != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue = actionValue.get("errorAction");
if (errorActionValue != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue = errorActionValue.get("request");
if (requestValue != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey = property.getKey();
String headersValue = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey, headersValue);
}
}
JsonNode bodyValue = requestValue.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue = errorActionValue.get("queueMessage");
if (queueMessageValue != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue2 = actionValue.get("request");
if (requestValue2 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue2.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue2.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue2.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey2 = property2.getKey();
String headersValue2 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey2, headersValue2);
}
}
JsonNode bodyValue2 = requestValue2.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue2 = actionValue.get("queueMessage");
if (queueMessageValue2 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue2.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue2.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue2.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue2.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue = jobsValue.get("recurrence");
if (recurrenceValue != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue = recurrenceValue.get("schedule");
if (scheduleValue != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray = scheduleValue.get("minutes");
if (minutesArray != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray = scheduleValue.get("hours");
if (hoursArray != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray = scheduleValue.get("weekDays");
if (weekDaysArray != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray = scheduleValue.get("months");
if (monthsArray != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray = scheduleValue.get("monthDays");
if (monthDaysArray != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray = scheduleValue.get("monthlyOccurrences");
if (monthlyOccurrencesArray != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = jobsValue.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = jobsValue.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
/**
* Get the list of jobs in a job collection matching a filter on job state.
*
* @param parameters Required. Parameters supplied to the List Jobs with
* filter operation.
* @return The List Jobs operation response.
*/
@Override
public Future<JobListResponse> listWithFilterAsync(final JobListWithFilterParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobListResponse>() {
@Override
public JobListResponse call() throws Exception {
return listWithFilter(parameters);
}
});
}
/**
* Get the list of jobs in a job collection matching a filter on job state.
*
* @param parameters Required. Parameters supplied to the List Jobs with
* filter operation.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Jobs operation response.
*/
@Override
public JobListResponse listWithFilter(JobListWithFilterParameters parameters) throws IOException, ServiceException, URISyntaxException {
// Validate
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "listWithFilterAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs" + "?";
url = url + "api-version=" + "2014-04-01";
url = url + "&" + "$filter=state eq " + URLEncoder.encode(SchedulerClientImpl.jobStateToString(parameters.getState()), "UTF-8");
if (parameters.getSkip() != null) {
url = url + "&" + "$skip=" + URLEncoder.encode(Integer.toString(parameters.getSkip()), "UTF-8");
}
if (parameters.getTop() != null) {
url = url + "&" + "$top=" + URLEncoder.encode(Integer.toString(parameters.getTop()), "UTF-8");
}
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
url = url.replace(" ", "%20");
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2013-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.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
JobListResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobListResponse();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
JsonNode jobsArray = responseDoc;
if (jobsArray != null) {
for (JsonNode jobsValue : ((ArrayNode) jobsArray)) {
Job jobInstance = new Job();
result.getJobs().add(jobInstance);
JsonNode idValue = jobsValue.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = jobsValue.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue = jobsValue.get("action");
if (actionValue != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue = actionValue.get("retryPolicy");
if (retryPolicyValue != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue = actionValue.get("errorAction");
if (errorActionValue != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue = errorActionValue.get("request");
if (requestValue != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey = property.getKey();
String headersValue = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey, headersValue);
}
}
JsonNode bodyValue = requestValue.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue = errorActionValue.get("queueMessage");
if (queueMessageValue != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue2 = actionValue.get("request");
if (requestValue2 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue2.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue2.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue2.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey2 = property2.getKey();
String headersValue2 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey2, headersValue2);
}
}
JsonNode bodyValue2 = requestValue2.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue2 = actionValue.get("queueMessage");
if (queueMessageValue2 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue2.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue2.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue2.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue2.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue = jobsValue.get("recurrence");
if (recurrenceValue != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue = recurrenceValue.get("schedule");
if (scheduleValue != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray = scheduleValue.get("minutes");
if (minutesArray != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray = scheduleValue.get("hours");
if (hoursArray != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray = scheduleValue.get("weekDays");
if (weekDaysArray != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray = scheduleValue.get("months");
if (monthsArray != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray = scheduleValue.get("monthDays");
if (monthDaysArray != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray = scheduleValue.get("monthlyOccurrences");
if (monthlyOccurrencesArray != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = jobsValue.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = jobsValue.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
/**
* Update the state of all jobs in a job collections.
*
* @param parameters Required. Parameters supplied to the Update Jobs State
* operation.
* @return The Update Jobs State operation response.
*/
@Override
public Future<JobCollectionJobsUpdateStateResponse> updateJobCollectionStateAsync(final JobCollectionJobsUpdateStateParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobCollectionJobsUpdateStateResponse>() {
@Override
public JobCollectionJobsUpdateStateResponse call() throws Exception {
return updateJobCollectionState(parameters);
}
});
}
/**
* Update the state of all jobs in a job collections.
*
* @param parameters Required. Parameters supplied to the Update Jobs State
* operation.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Update Jobs State operation response.
*/
@Override
public JobCollectionJobsUpdateStateResponse updateJobCollectionState(JobCollectionJobsUpdateStateParameters parameters) throws IOException, ServiceException, URISyntaxException {
// Validate
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "updateJobCollectionStateAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs";
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
HttpPatch httpRequest = new HttpPatch(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/json");
httpRequest.setHeader("x-ms-version", "2013-03-01");
// Serialize Request
String requestContent = null;
JsonNode requestDoc = null;
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode jobCollectionJobsUpdateStateParametersValue = objectMapper.createObjectNode();
requestDoc = jobCollectionJobsUpdateStateParametersValue;
if (parameters.isStateIsIncluded()) {
((ObjectNode) jobCollectionJobsUpdateStateParametersValue).put("state", SchedulerClientImpl.jobStateToString(parameters.getState()));
}
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
JobCollectionJobsUpdateStateResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobCollectionJobsUpdateStateResponse();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
JsonNode jobsArray = responseDoc;
if (jobsArray != null) {
for (JsonNode jobsValue : ((ArrayNode) jobsArray)) {
Job jobInstance = new Job();
result.getJobs().add(jobInstance);
JsonNode idValue = jobsValue.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = jobsValue.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue = jobsValue.get("action");
if (actionValue != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue = actionValue.get("retryPolicy");
if (retryPolicyValue != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue = actionValue.get("errorAction");
if (errorActionValue != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue = errorActionValue.get("request");
if (requestValue != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey = property.getKey();
String headersValue = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey, headersValue);
}
}
JsonNode bodyValue = requestValue.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue = errorActionValue.get("queueMessage");
if (queueMessageValue != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue2 = actionValue.get("request");
if (requestValue2 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue2.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue2.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue2.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey2 = property2.getKey();
String headersValue2 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey2, headersValue2);
}
}
JsonNode bodyValue2 = requestValue2.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue2 = actionValue.get("queueMessage");
if (queueMessageValue2 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue2.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue2.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue2.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue2.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue = jobsValue.get("recurrence");
if (recurrenceValue != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue = recurrenceValue.get("schedule");
if (scheduleValue != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray = scheduleValue.get("minutes");
if (minutesArray != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray = scheduleValue.get("hours");
if (hoursArray != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray = scheduleValue.get("weekDays");
if (weekDaysArray != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray = scheduleValue.get("months");
if (monthsArray != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray = scheduleValue.get("monthDays");
if (monthDaysArray != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray = scheduleValue.get("monthlyOccurrences");
if (monthlyOccurrencesArray != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = jobsValue.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = jobsValue.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
/**
* Update the state of a job.
*
* @param jobId Required. Id of the job to update.
* @param parameters Required. Parameters supplied to the Update Job State
* operation.
* @return The Update Job State operation response.
*/
@Override
public Future<JobUpdateStateResponse> updateStateAsync(final String jobId, final JobUpdateStateParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<JobUpdateStateResponse>() {
@Override
public JobUpdateStateResponse call() throws Exception {
return updateState(jobId, parameters);
}
});
}
/**
* Update the state of a job.
*
* @param jobId Required. Id of the job to update.
* @param parameters Required. Parameters supplied to the Update Job State
* operation.
* @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 URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The Update Job State operation response.
*/
@Override
public JobUpdateStateResponse updateState(String jobId, JobUpdateStateParameters parameters) throws IOException, ServiceException, URISyntaxException {
// Validate
if (jobId == null) {
throw new NullPointerException("jobId");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("jobId", jobId);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "updateStateAsync", tracingParameters);
}
// Construct URL
String url = (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/cloudservices/" + this.getClient().getCloudServiceName().trim() + "/resources/" + "scheduler" + "/~/" + "JobCollections" + "/" + this.getClient().getJobCollectionName().trim() + "/jobs/" + jobId.trim() + "?";
url = url + "api-version=" + "2014-04-01";
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
HttpPatch httpRequest = new HttpPatch(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/json");
httpRequest.setHeader("x-ms-version", "2013-03-01");
// Serialize Request
String requestContent = null;
JsonNode requestDoc = null;
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode jobUpdateStateParametersValue = objectMapper.createObjectNode();
requestDoc = jobUpdateStateParametersValue;
((ObjectNode) jobUpdateStateParametersValue).put("state", SchedulerClientImpl.jobStateToString(parameters.getState()));
if (parameters.getUpdateStateReason() != null) {
((ObjectNode) jobUpdateStateParametersValue).put("stateDetails", parameters.getUpdateStateReason());
}
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
JobUpdateStateResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new JobUpdateStateResponse();
JsonNode responseDoc = null;
if (responseContent == null == false) {
responseDoc = objectMapper.readTree(responseContent);
}
if (responseDoc != null) {
Job jobInstance = new Job();
result.setJob(jobInstance);
JsonNode idValue = responseDoc.get("id");
if (idValue != null) {
String idInstance;
idInstance = idValue.getTextValue();
jobInstance.setId(idInstance);
}
JsonNode startTimeValue = responseDoc.get("startTime");
if (startTimeValue != null) {
Calendar startTimeInstance;
startTimeInstance = DatatypeConverter.parseDateTime(startTimeValue.getTextValue());
jobInstance.setStartTime(startTimeInstance);
}
JsonNode actionValue = responseDoc.get("action");
if (actionValue != null) {
JobAction actionInstance = new JobAction();
jobInstance.setAction(actionInstance);
JsonNode typeValue = actionValue.get("type");
if (typeValue != null) {
JobActionType typeInstance;
typeInstance = SchedulerClientImpl.parseJobActionType(typeValue.getTextValue());
actionInstance.setType(typeInstance);
}
JsonNode retryPolicyValue = actionValue.get("retryPolicy");
if (retryPolicyValue != null) {
RetryPolicy retryPolicyInstance = new RetryPolicy();
actionInstance.setRetryPolicy(retryPolicyInstance);
JsonNode retryTypeValue = retryPolicyValue.get("retryType");
if (retryTypeValue != null) {
RetryType retryTypeInstance;
retryTypeInstance = SchedulerClientImpl.parseRetryType(retryTypeValue.getTextValue());
retryPolicyInstance.setRetryType(retryTypeInstance);
}
JsonNode retryIntervalValue = retryPolicyValue.get("retryInterval");
if (retryIntervalValue != null) {
Duration retryIntervalInstance;
retryIntervalInstance = TimeSpan8601Converter.parse(retryIntervalValue.getTextValue());
retryPolicyInstance.setRetryInterval(retryIntervalInstance);
}
JsonNode retryCountValue = retryPolicyValue.get("retryCount");
if (retryCountValue != null) {
int retryCountInstance;
retryCountInstance = retryCountValue.getIntValue();
retryPolicyInstance.setRetryCount(retryCountInstance);
}
}
JsonNode errorActionValue = actionValue.get("errorAction");
if (errorActionValue != null) {
JobErrorAction errorActionInstance = new JobErrorAction();
actionInstance.setErrorAction(errorActionInstance);
JsonNode typeValue2 = errorActionValue.get("type");
if (typeValue2 != null) {
JobActionType typeInstance2;
typeInstance2 = SchedulerClientImpl.parseJobActionType(typeValue2.getTextValue());
errorActionInstance.setType(typeInstance2);
}
JsonNode requestValue = errorActionValue.get("request");
if (requestValue != null) {
JobHttpRequest requestInstance = new JobHttpRequest();
errorActionInstance.setRequest(requestInstance);
JsonNode uriValue = requestValue.get("uri");
if (uriValue != null) {
URI uriInstance;
uriInstance = new URI(uriValue.getTextValue());
requestInstance.setUri(uriInstance);
}
JsonNode methodValue = requestValue.get("method");
if (methodValue != null) {
String methodInstance;
methodInstance = methodValue.getTextValue();
requestInstance.setMethod(methodInstance);
}
JsonNode headersSequenceElement = ((JsonNode) requestValue.get("headers"));
if (headersSequenceElement != null) {
Iterator<Map.Entry<String, JsonNode>> itr = headersSequenceElement.getFields();
while (itr.hasNext()) {
Map.Entry<String, JsonNode> property = itr.next();
String headersKey = property.getKey();
String headersValue = property.getValue().getTextValue();
requestInstance.getHeaders().put(headersKey, headersValue);
}
}
JsonNode bodyValue = requestValue.get("body");
if (bodyValue != null) {
String bodyInstance;
bodyInstance = bodyValue.getTextValue();
requestInstance.setBody(bodyInstance);
}
}
JsonNode queueMessageValue = errorActionValue.get("queueMessage");
if (queueMessageValue != null) {
JobQueueMessage queueMessageInstance = new JobQueueMessage();
errorActionInstance.setQueueMessage(queueMessageInstance);
JsonNode storageAccountValue = queueMessageValue.get("storageAccount");
if (storageAccountValue != null) {
String storageAccountInstance;
storageAccountInstance = storageAccountValue.getTextValue();
queueMessageInstance.setStorageAccountName(storageAccountInstance);
}
JsonNode queueNameValue = queueMessageValue.get("queueName");
if (queueNameValue != null) {
String queueNameInstance;
queueNameInstance = queueNameValue.getTextValue();
queueMessageInstance.setQueueName(queueNameInstance);
}
JsonNode sasTokenValue = queueMessageValue.get("sasToken");
if (sasTokenValue != null) {
String sasTokenInstance;
sasTokenInstance = sasTokenValue.getTextValue();
queueMessageInstance.setSasToken(sasTokenInstance);
}
JsonNode messageValue = queueMessageValue.get("message");
if (messageValue != null) {
String messageInstance;
messageInstance = messageValue.getTextValue();
queueMessageInstance.setMessage(messageInstance);
}
}
}
JsonNode requestValue2 = actionValue.get("request");
if (requestValue2 != null) {
JobHttpRequest requestInstance2 = new JobHttpRequest();
actionInstance.setRequest(requestInstance2);
JsonNode uriValue2 = requestValue2.get("uri");
if (uriValue2 != null) {
URI uriInstance2;
uriInstance2 = new URI(uriValue2.getTextValue());
requestInstance2.setUri(uriInstance2);
}
JsonNode methodValue2 = requestValue2.get("method");
if (methodValue2 != null) {
String methodInstance2;
methodInstance2 = methodValue2.getTextValue();
requestInstance2.setMethod(methodInstance2);
}
JsonNode headersSequenceElement2 = ((JsonNode) requestValue2.get("headers"));
if (headersSequenceElement2 != null) {
Iterator<Map.Entry<String, JsonNode>> itr2 = headersSequenceElement2.getFields();
while (itr2.hasNext()) {
Map.Entry<String, JsonNode> property2 = itr2.next();
String headersKey2 = property2.getKey();
String headersValue2 = property2.getValue().getTextValue();
requestInstance2.getHeaders().put(headersKey2, headersValue2);
}
}
JsonNode bodyValue2 = requestValue2.get("body");
if (bodyValue2 != null) {
String bodyInstance2;
bodyInstance2 = bodyValue2.getTextValue();
requestInstance2.setBody(bodyInstance2);
}
}
JsonNode queueMessageValue2 = actionValue.get("queueMessage");
if (queueMessageValue2 != null) {
JobQueueMessage queueMessageInstance2 = new JobQueueMessage();
actionInstance.setQueueMessage(queueMessageInstance2);
JsonNode storageAccountValue2 = queueMessageValue2.get("storageAccount");
if (storageAccountValue2 != null) {
String storageAccountInstance2;
storageAccountInstance2 = storageAccountValue2.getTextValue();
queueMessageInstance2.setStorageAccountName(storageAccountInstance2);
}
JsonNode queueNameValue2 = queueMessageValue2.get("queueName");
if (queueNameValue2 != null) {
String queueNameInstance2;
queueNameInstance2 = queueNameValue2.getTextValue();
queueMessageInstance2.setQueueName(queueNameInstance2);
}
JsonNode sasTokenValue2 = queueMessageValue2.get("sasToken");
if (sasTokenValue2 != null) {
String sasTokenInstance2;
sasTokenInstance2 = sasTokenValue2.getTextValue();
queueMessageInstance2.setSasToken(sasTokenInstance2);
}
JsonNode messageValue2 = queueMessageValue2.get("message");
if (messageValue2 != null) {
String messageInstance2;
messageInstance2 = messageValue2.getTextValue();
queueMessageInstance2.setMessage(messageInstance2);
}
}
}
JsonNode recurrenceValue = responseDoc.get("recurrence");
if (recurrenceValue != null) {
JobRecurrence recurrenceInstance = new JobRecurrence();
jobInstance.setRecurrence(recurrenceInstance);
JsonNode frequencyValue = recurrenceValue.get("frequency");
if (frequencyValue != null) {
JobRecurrenceFrequency frequencyInstance;
frequencyInstance = SchedulerClientImpl.parseJobRecurrenceFrequency(frequencyValue.getTextValue());
recurrenceInstance.setFrequency(frequencyInstance);
}
JsonNode intervalValue = recurrenceValue.get("interval");
if (intervalValue != null) {
int intervalInstance;
intervalInstance = intervalValue.getIntValue();
recurrenceInstance.setInterval(intervalInstance);
}
JsonNode countValue = recurrenceValue.get("count");
if (countValue != null) {
int countInstance;
countInstance = countValue.getIntValue();
recurrenceInstance.setCount(countInstance);
}
JsonNode endTimeValue = recurrenceValue.get("endTime");
if (endTimeValue != null) {
Calendar endTimeInstance;
endTimeInstance = DatatypeConverter.parseDateTime(endTimeValue.getTextValue());
recurrenceInstance.setEndTime(endTimeInstance);
}
JsonNode scheduleValue = recurrenceValue.get("schedule");
if (scheduleValue != null) {
JobRecurrenceSchedule scheduleInstance = new JobRecurrenceSchedule();
recurrenceInstance.setSchedule(scheduleInstance);
JsonNode minutesArray = scheduleValue.get("minutes");
if (minutesArray != null) {
for (JsonNode minutesValue : ((ArrayNode) minutesArray)) {
scheduleInstance.getMinutes().add(minutesValue.getIntValue());
}
}
JsonNode hoursArray = scheduleValue.get("hours");
if (hoursArray != null) {
for (JsonNode hoursValue : ((ArrayNode) hoursArray)) {
scheduleInstance.getHours().add(hoursValue.getIntValue());
}
}
JsonNode weekDaysArray = scheduleValue.get("weekDays");
if (weekDaysArray != null) {
for (JsonNode weekDaysValue : ((ArrayNode) weekDaysArray)) {
scheduleInstance.getDays().add(SchedulerClientImpl.parseJobScheduleDay(weekDaysValue.getTextValue()));
}
}
JsonNode monthsArray = scheduleValue.get("months");
if (monthsArray != null) {
for (JsonNode monthsValue : ((ArrayNode) monthsArray)) {
scheduleInstance.getMonths().add(monthsValue.getIntValue());
}
}
JsonNode monthDaysArray = scheduleValue.get("monthDays");
if (monthDaysArray != null) {
for (JsonNode monthDaysValue : ((ArrayNode) monthDaysArray)) {
scheduleInstance.getMonthDays().add(monthDaysValue.getIntValue());
}
}
JsonNode monthlyOccurrencesArray = scheduleValue.get("monthlyOccurrences");
if (monthlyOccurrencesArray != null) {
for (JsonNode monthlyOccurrencesValue : ((ArrayNode) monthlyOccurrencesArray)) {
JobScheduleMonthlyOccurrence jobScheduleMonthlyOccurrenceInstance = new JobScheduleMonthlyOccurrence();
scheduleInstance.getMonthlyOccurrences().add(jobScheduleMonthlyOccurrenceInstance);
JsonNode dayValue = monthlyOccurrencesValue.get("day");
if (dayValue != null) {
JobScheduleDay dayInstance;
dayInstance = SchedulerClientImpl.parseJobScheduleDay(dayValue.getTextValue());
jobScheduleMonthlyOccurrenceInstance.setDay(dayInstance);
}
JsonNode occurrenceValue = monthlyOccurrencesValue.get("occurrence");
if (occurrenceValue != null) {
int occurrenceInstance;
occurrenceInstance = occurrenceValue.getIntValue();
jobScheduleMonthlyOccurrenceInstance.setOccurrence(occurrenceInstance);
}
}
}
}
}
JsonNode statusValue = responseDoc.get("status");
if (statusValue != null) {
JobStatus statusInstance = new JobStatus();
jobInstance.setStatus(statusInstance);
JsonNode lastExecutionTimeValue = statusValue.get("lastExecutionTime");
if (lastExecutionTimeValue != null) {
Calendar lastExecutionTimeInstance;
lastExecutionTimeInstance = DatatypeConverter.parseDateTime(lastExecutionTimeValue.getTextValue());
statusInstance.setLastExecutionTime(lastExecutionTimeInstance);
}
JsonNode nextExecutionTimeValue = statusValue.get("nextExecutionTime");
if (nextExecutionTimeValue != null) {
Calendar nextExecutionTimeInstance;
nextExecutionTimeInstance = DatatypeConverter.parseDateTime(nextExecutionTimeValue.getTextValue());
statusInstance.setNextExecutionTime(nextExecutionTimeInstance);
}
JsonNode executionCountValue = statusValue.get("executionCount");
if (executionCountValue != null) {
int executionCountInstance;
executionCountInstance = executionCountValue.getIntValue();
statusInstance.setExecutionCount(executionCountInstance);
}
JsonNode failureCountValue = statusValue.get("failureCount");
if (failureCountValue != null) {
int failureCountInstance;
failureCountInstance = failureCountValue.getIntValue();
statusInstance.setFailureCount(failureCountInstance);
}
JsonNode faultedCountValue = statusValue.get("faultedCount");
if (faultedCountValue != null) {
int faultedCountInstance;
faultedCountInstance = faultedCountValue.getIntValue();
statusInstance.setFaultedCount(faultedCountInstance);
}
}
JsonNode stateValue = responseDoc.get("state");
if (stateValue != null) {
JobState stateInstance;
stateInstance = SchedulerClientImpl.parseJobState(stateValue.getTextValue());
jobInstance.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();
}
}
}
}