/// <summary> /// Sends the changes to the service -> Creates or updates the target if necessary /// </summary> /// <param name="updatedTargets">The list of updated targets</param> /// <returns>The target that was created/updated or null if nothing changed.</returns> protected override IEnumerable <AzureSqlElasticJobTargetModel> PersistChanges(IEnumerable <AzureSqlElasticJobTargetModel> updatedTargets) { // If we don't need to update the target group member's return null. if (!this.NeedsUpdate) { return(null); } // Update list of targets AzureSqlElasticJobTargetGroupModel model = new AzureSqlElasticJobTargetGroupModel { ResourceGroupName = this.ResourceGroupName, ServerName = this.AgentServerName, AgentName = this.AgentName, TargetGroupName = this.TargetGroupName, Targets = updatedTargets.ToList() }; var resp = ModelAdapter.UpsertTargetGroup(model).Targets.ToList(); // Reset target refresh credential back this.Target.RefreshCredentialName = this.RefreshCredentialName; return(new List <AzureSqlElasticJobTargetModel> { this.Target }); }
/// <summary> /// Gets the list of existing targets in the target group. /// </summary> /// <returns>The list of existing targets</returns> protected override IEnumerable <AzureSqlElasticJobTargetModel> GetEntity() { AzureSqlElasticJobTargetGroupModel targetGroup = ModelAdapter.GetTargetGroup(this.ResourceGroupName, this.AgentServerName, this.AgentName, this.TargetGroupName); List <AzureSqlElasticJobTargetModel> existingTargets = targetGroup.Targets.ToList(); return(existingTargets); }
/// <summary> /// Uperts a target group to the control database /// </summary> /// <param name="model">The target group model</param> /// <returns>The upserted target group model</returns> public AzureSqlElasticJobTargetGroupModel UpsertTargetGroup(AzureSqlElasticJobTargetGroupModel model) { var param = new JobTargetGroup { Members = model.Targets.Select((target) => CreateJobTargetModel(target)).ToList() }; var resp = Communicator.CreateOrUpdateTargetGroup(model.ResourceGroupName, model.ServerName, model.AgentName, model.TargetGroupName, param); return(CreateTargetGroupModelFromResponse(model.ResourceGroupName, model.ServerName, model.AgentName, resp)); }
/// <summary> /// Converts a JobTargetGroup model to an AzureSqlElasticJobTargetGroupModel /// </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="resp">The JobTargetGroup model</param> /// <returns></returns> private AzureSqlElasticJobTargetGroupModel CreateTargetGroupModelFromResponse(string resourceGroupName, string serverName, string agentName, JobTargetGroup resp) { AzureSqlElasticJobTargetGroupModel targetGroup = new AzureSqlElasticJobTargetGroupModel { ResourceGroupName = resourceGroupName, ServerName = serverName, AgentName = agentName, TargetGroupName = resp.Name, Targets = resp.Members.Select((target) => CreateAzureSqlElasticJobTargetModel(resourceGroupName, serverName, agentName, resp.Name, target)).ToList(), ResourceId = resp.Id, Type = resp.Type }; return(targetGroup); }
/// <summary> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the target group doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <AzureSqlElasticJobTargetGroupModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticJobTargetGroupModel> model) { AzureSqlElasticJobTargetGroupModel targetGroup = new AzureSqlElasticJobTargetGroupModel { ResourceGroupName = this.ResourceGroupName, ServerName = this.ServerName, AgentName = this.AgentName, TargetGroupName = this.Name, Targets = new List <AzureSqlElasticJobTargetModel> { }, // We create an empty list of targets on creation of new target group }; return(new List <AzureSqlElasticJobTargetGroupModel> { targetGroup }); }