/// <summary> /// Converts a JobStep model to an AzureSqlElasticJobStepModel /// </summary> /// <param name="resourceGroupName">The resource group name</param> /// <param name="serverName">The server name</param> /// <param name="agentName">The agent name</param> /// <param name="jobName">The job name</param> /// <param name="stepName">The job step name</param> /// <param name="resp">The JobStep model</param> /// <returns>An AzureSqlElasticJobStepModel</returns> private static AzureSqlElasticJobStepModel CreateJobStepModelFromResponse( string resourceGroupName, string serverName, string agentName, string jobName, string stepName, JobStep resp) { AzureSqlElasticJobStepModel jobStep = new AzureSqlElasticJobStepModel { ResourceGroupName = resourceGroupName, ServerName = serverName, AgentName = agentName, JobName = jobName, StepName = stepName, TargetGroupName = new ResourceIdentifier(resp.TargetGroup).ResourceName, CredentialName = new ResourceIdentifier(resp.Credential).ResourceName, CommandText = resp.Action.Value, InitialRetryIntervalSeconds = resp.ExecutionOptions.InitialRetryIntervalSeconds, MaximumRetryIntervalSeconds = resp.ExecutionOptions.MaximumRetryIntervalSeconds, RetryAttempts = resp.ExecutionOptions.RetryAttempts, RetryIntervalBackoffMultiplier = resp.ExecutionOptions.RetryIntervalBackoffMultiplier, TimeoutSeconds = resp.ExecutionOptions.TimeoutSeconds, Output = CreateJobStepOutputModel(resp), ResourceId = resp.Id, StepId = resp.StepId, Type = resp.Type, }; return(jobStep); }
/// <summary> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the job step doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <AzureSqlElasticJobStepModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticJobStepModel> model) { string targetGroupId = CreateTargetGroupId(this.ResourceGroupName, this.ServerName, this.AgentName, this.TargetGroupName); string credentialId = CreateCredentialId(this.ResourceGroupName, this.ServerName, this.AgentName, this.CredentialName); AzureSqlElasticJobStepModel updatedModel = new AzureSqlElasticJobStepModel { ResourceGroupName = this.ResourceGroupName, ServerName = this.ServerName, AgentName = this.AgentName, JobName = this.JobName, StepName = this.Name, TargetGroupName = targetGroupId, CredentialName = credentialId, InitialRetryIntervalSeconds = this.InitialRetryIntervalSeconds, MaximumRetryIntervalSeconds = this.MaximumRetryIntervalSeconds, RetryAttempts = this.RetryAttempts, RetryIntervalBackoffMultiplier = this.RetryIntervalBackoffMultiplier, TimeoutSeconds = this.TimeoutSeconds, CommandText = this.CommandText, StepId = this.StepId }; if (this.OutputDatabaseObject != null) { updatedModel.Output = new AzureSqlElasticJobStepOutputModel { SubscriptionId = this.OutputDatabaseObject != null?Guid.Parse(new ResourceIdentifier(this.OutputDatabaseObject.ResourceId).Subscription) : (Guid?)null, ResourceGroupName = this.OutputDatabaseObject != null ? this.OutputDatabaseObject.ResourceGroupName : null, ServerName = this.OutputDatabaseObject != null ? this.OutputDatabaseObject.ServerName : null, DatabaseName = this.OutputDatabaseObject != null ? this.OutputDatabaseObject.DatabaseName : null, Credential = this.OutputCredentialName != null?CreateCredentialId(this.ResourceGroupName, this.ServerName, this.AgentName, this.OutputCredentialName) : null, SchemaName = this.OutputSchemaName != null ? this.OutputSchemaName : null, TableName = this.OutputTableName != null ? this.OutputTableName : null }; } if (this.OutputDatabaseResourceId != null) { var databaseIdentifier = new ResourceIdentifier(this.OutputDatabaseResourceId); updatedModel.Output = new AzureSqlElasticJobStepOutputModel { SubscriptionId = Guid.Parse(databaseIdentifier.Subscription), ResourceGroupName = databaseIdentifier.ResourceGroupName, ServerName = databaseIdentifier.ParentResource.Split('/')[1], DatabaseName = databaseIdentifier.ResourceName, Credential = this.OutputCredentialName != null?CreateCredentialId(this.ResourceGroupName, this.ServerName, this.AgentName, this.OutputCredentialName) : null, SchemaName = this.OutputSchemaName != null ? this.OutputSchemaName : null, TableName = this.OutputTableName != null ? this.OutputTableName : null }; } return(new List <AzureSqlElasticJobStepModel> { updatedModel }); }
/// <summary> /// Upserts a job step /// </summary> /// <param name="model">The AzureSqlElasticJobStep model</param> /// <returns>The upserted job step</returns> public AzureSqlElasticJobStepModel UpsertJobStep(AzureSqlElasticJobStepModel model) { var param = new JobStep { TargetGroup = model.TargetGroupName, Credential = model.CredentialName, Action = new JobStepAction { Value = model.CommandText }, ExecutionOptions = new JobStepExecutionOptions { TimeoutSeconds = model.TimeoutSeconds, RetryIntervalBackoffMultiplier = model.RetryIntervalBackoffMultiplier, RetryAttempts = model.RetryAttempts, MaximumRetryIntervalSeconds = model.MaximumRetryIntervalSeconds, InitialRetryIntervalSeconds = model.InitialRetryIntervalSeconds }, Output = model.Output != null ? new JobStepOutput { Credential = model.Output.Credential, DatabaseName = model.Output.DatabaseName, ResourceGroupName = model.Output.ResourceGroupName, SchemaName = model.Output.SchemaName, ServerName = model.Output.ServerName, SubscriptionId = model.Output.SubscriptionId, TableName = model.Output.TableName, Type = model.Output.Type } : null, StepId = model.StepId, }; var resp = Communicator.CreateOrUpdateJobStep(model.ResourceGroupName, model.ServerName, model.AgentName, model.JobName, model.StepName, param); return(CreateJobStepModelFromResponse(model.ResourceGroupName, model.ServerName, model.AgentName, model.JobName, model.StepName, resp)); }