/// <summary> /// Updates an existing agent /// </summary> /// <param name="model">The existing agent entity</param> /// <returns>The updated agent entity</returns> public AzureSqlElasticJobAgentModel UpdateAgent(AzureSqlElasticJobAgentModel model) { var param = new JobAgentUpdate { Tags = model.Tags }; var resp = Communicator.UpdateAgent(model.ResourceGroupName, model.ServerName, model.AgentName, param); return(CreateAgentModelFromResponse(model.ResourceGroupName, model.ServerName, resp)); }
/// <summary> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the server doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <AzureSqlElasticJobAgentModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticJobAgentModel> model) { string location = ModelAdapter.GetServerLocationAndThrowIfAgentNotSupportedByServer(this.ResourceGroupName, this.ServerName); AzureSqlElasticJobAgentModel newEntity = new AzureSqlElasticJobAgentModel { Location = location, ResourceGroupName = this.ResourceGroupName, ServerName = this.ServerName, AgentName = this.Name, DatabaseName = this.DatabaseName, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true) }; return(new List <AzureSqlElasticJobAgentModel> { newEntity }); }
/// <summary> /// Convert JobAgent model to AzureSqlDatabaseAgentModel /// </summary> /// <param name="resourceGroupName">The resource group the server is in</param> /// <param name="serverName">The server the agent is in</param> /// <param name="resp">The management client server response to convert</param> /// <returns>The converted agent model</returns> private static AzureSqlElasticJobAgentModel CreateAgentModelFromResponse(string resourceGroupName, string serverName, JobAgent resp) { string databaseName = new ResourceIdentifier(resp.DatabaseId).ResourceName; int? workerCount = resp.Sku.Capacity; AzureSqlElasticJobAgentModel agent = new AzureSqlElasticJobAgentModel { ResourceGroupName = resourceGroupName, ServerName = serverName, AgentName = resp.Name, Location = resp.Location, DatabaseName = databaseName, WorkerCount = workerCount, ResourceId = resp.Id, Tags = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false), DatabaseId = resp.DatabaseId, State = resp.State, Type = resp.Type }; return(agent); }
/// <summary> /// Creates or updates an agent /// </summary> /// <param name="model"></param> /// <returns>The upserted Azure SQL Database Agent</returns> public AzureSqlElasticJobAgentModel UpsertAgent(AzureSqlElasticJobAgentModel model) { // Construct database id string databaseId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/servers/{2}/databases/{3}", AzureSqlElasticJobCommunicator.Subscription.Id, model.ResourceGroupName, model.ServerName, model.DatabaseName); // Set agent params var param = new JobAgent { Location = model.Location, Tags = model.Tags, DatabaseId = databaseId }; // Send response var resp = Communicator.CreateOrUpdateAgent(model.ResourceGroupName, model.ServerName, model.AgentName, param); // Return formatted response return(CreateAgentModelFromResponse(model.ResourceGroupName, model.ServerName, resp)); }