/// <summary> /// Create a test job of the runbook. (see /// http://aka.ms/azureautomationsdk/testjoboperations for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Automation.ITestJobOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group /// </param> /// <param name='automationAccount'> /// Required. The automation account name. /// </param> /// <param name='parameters'> /// Required. The parameters supplied to the create test job operation. /// </param> /// <returns> /// The response model for the create test job operation. /// </returns> public static TestJobCreateResponse Create(this ITestJobOperations operations, string resourceGroupName, string automationAccount, TestJobCreateParameters parameters) { return Task.Factory.StartNew((object s) => { return ((ITestJobOperations)s).CreateAsync(resourceGroupName, automationAccount, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
private async Task<TestJobCreateResponse> createTestJob() { RunbookDraft draft = await AutomationRunbookManager.GetRunbookDraft(runbookName, iseClient.automationManagementClient, iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name); if (draft.InEdit == false) throw new Exception("This runbook has no draft to test because it is in a 'Published' state."); HybridRunbookWorkerGroupsListResponse hybridGroupResponse = await iseClient.automationManagementClient.HybridRunbookWorkerGroups.ListAsync( iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name, new CancellationToken()); TestJobCreateParameters jobCreationParams = new TestJobCreateParameters(); jobCreationParams.RunbookName = runbookName; if (draft.Parameters.Count > 0 || hybridGroupResponse.HybridRunbookWorkerGroups.Count > 0) { /* User needs to specify some things */ var existingParams = await GetLastTestJobParams(); RunbookParamDialog paramDialog = new RunbookParamDialog(draft.Parameters, existingParams, hybridGroupResponse.HybridRunbookWorkerGroups); if (paramDialog.ShowDialog() == true) { if (draft.Parameters.Count > 0) jobCreationParams.Parameters = paramDialog.paramValues; if (!String.IsNullOrEmpty(paramDialog.runOnSelection) && !paramDialog.runOnSelection.Equals("Azure")) jobCreationParams.RunOn = paramDialog.runOnSelection; } else { return null; } } /* start the test job */ CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TIMEOUT_MS); TestJobCreateResponse jobResponse = await iseClient.automationManagementClient.TestJobs.CreateAsync( iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name, jobCreationParams, cts.Token); if (jobResponse == null || jobResponse.StatusCode != System.Net.HttpStatusCode.Created) throw new Exception("The test job could not be created: received HTTP status code " + jobResponse.StatusCode); return jobResponse; }
public Guid? TestRunbook(RunbookModelProxy runbookProxy, List<NameValuePair> parameters) { var jobGuid = Guid.NewGuid(); var runbook = _client.Runbooks.Get(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, runbookProxy.RunbookName); if (runbook.StatusCode == System.Net.HttpStatusCode.NotFound) return null; var jobParameters = new TestJobCreateParameters(); jobParameters.RunbookName = runbookProxy.RunbookName; foreach (var param in parameters) jobParameters.Parameters.Add(param.Name, param.Value); var response = _client.TestJobs.Create(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, jobParameters); if ((int)response.StatusCode > 299) { _output.AppendLine("Unable to start the job, please verify your connectivity and parameters and try again."); return null; } _testJobCache.Add(jobGuid, response.TestJob); runbookProxy.IsTestRun = true; return jobGuid; }
private async Task<TestJobCreateResponse> createTestJob() { RunbookDraft draft = await AutomationRunbookManager.GetRunbookDraft(runbookName, iseClient.automationManagementClient, iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name); if (draft.InEdit == false) throw new Exception("This runbook has no draft to test because it is in a 'Published' state."); TestJobCreateParameters jobCreationParams = new TestJobCreateParameters(); jobCreationParams.RunbookName = runbookName; if (draft.Parameters.Count > 0) { /* User needs to specify values for them */ var existingParams = await GetTestJobParams(); RunbookParamDialog paramDialog = new RunbookParamDialog(draft.Parameters,existingParams); if (paramDialog.ShowDialog() == true) jobCreationParams.Parameters = paramDialog.paramValues; else return null; } /* start the test job */ TestJobCreateResponse jobResponse = await iseClient.automationManagementClient.TestJobs.CreateAsync( iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name, jobCreationParams, new System.Threading.CancellationToken()); if (jobResponse == null || jobResponse.StatusCode != System.Net.HttpStatusCode.Created) throw new Exception("The test job could not be created: received HTTP status code " + jobResponse.StatusCode); return jobResponse; }
/// <summary> /// Create a test job of the runbook. (see /// http://aka.ms/azureautomationsdk/testjoboperations for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Automation.ITestJobOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group /// </param> /// <param name='automationAccount'> /// Required. The automation account name. /// </param> /// <param name='parameters'> /// Required. The parameters supplied to the create test job operation. /// </param> /// <returns> /// The response model for the create test job operation. /// </returns> public static Task<TestJobCreateResponse> CreateAsync(this ITestJobOperations operations, string resourceGroupName, string automationAccount, TestJobCreateParameters parameters) { return operations.CreateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None); }