/// <summary> /// Get maximum recurrence in string. /// </summary> /// <param name="jobCollectionQuota">The job collection quota.</param> /// <returns>Maximum recurrence in string.</returns> internal static string GetMaxRecurrenceInString(JobCollectionQuota jobCollectionQuota) { if (jobCollectionQuota != null && jobCollectionQuota.MaxRecurrence != null) { return("Every " + jobCollectionQuota.MaxRecurrence.Interval.ToString() + " " + jobCollectionQuota.MaxRecurrence.Frequency.ToString()); } return(null); }
/// <summary> /// Get maximum recurrence in string. /// </summary> /// <param name="jobCollectionQuota">The job collection quota.</param> /// <returns>Maximum recurrence in string.</returns> internal static string GetMaxRecurrenceInString(JobCollectionQuota jobCollectionQuota) { if (jobCollectionQuota != null && jobCollectionQuota.MaxRecurrence != null) { return "Every " + jobCollectionQuota.MaxRecurrence.Interval.ToString() + " " + jobCollectionQuota.MaxRecurrence.Frequency.ToString(); } return null; }
/// <summary> /// Create job collection. /// </summary> /// <param name="createJobCollectionParams">Job collection properties entered by user via Powershell.</param> /// <returns>Job collection definition.</returns> public PSJobCollectionDefinition CreateJobCollection(PSJobCollectionsParams createJobCollectionParams) { if (string.IsNullOrWhiteSpace(createJobCollectionParams.ResourceGroupName)) { throw new PSArgumentNullException(paramName: "ResourceGroupName"); } if (string.IsNullOrWhiteSpace(createJobCollectionParams.JobCollectionName)) { throw new PSArgumentNullException(paramName: "JobCollectionName"); } if (string.IsNullOrWhiteSpace(createJobCollectionParams.Region)) { throw new PSArgumentNullException(paramName: "Region"); } if (!DoesResourceGroupExists(createJobCollectionParams.ResourceGroupName)) { throw new PSArgumentException(Resources.SchedulerInvalidResourceGroup); } if (!this.AvailableRegions.Contains(createJobCollectionParams.Region)) { throw new PSArgumentException(Resources.SchedulerInvalidLocation); } if (HasJobCollection(createJobCollectionParams.ResourceGroupName, createJobCollectionParams.JobCollectionName)) { throw new PSInvalidOperationException(string.Format(Resources.SchedulerExistingJobCollection, createJobCollectionParams.JobCollectionName, createJobCollectionParams.ResourceGroupName)); } var skuDefinition = createJobCollectionParams.Plan.GetValueOrDefaultEnum <SkuDefinition>(defaultValue: SkuDefinition.Standard); if (skuDefinition == SkuDefinition.Free && HasFreeJobCollection()) { throw new PSInvalidOperationException(Resources.SchedulerNoMoreFreeJobCollection); } var quota = new JobCollectionQuota(); this.PopulateJobCollectionQuota(quota, skuDefinition, createJobCollectionParams, newQuota: true); var jcProperties = new JobCollectionProperties() { Sku = new Sku(skuDefinition), Quota = quota, }; var jobCollectionDefinition = new JobCollectionDefinition() { Location = createJobCollectionParams.Region, Name = createJobCollectionParams.JobCollectionName, Properties = jcProperties, }; var jobCollectionDefinitionResult = this.SchedulerManagementClient.JobCollections.CreateOrUpdate( createJobCollectionParams.ResourceGroupName, createJobCollectionParams.JobCollectionName, jobCollectionDefinition); return(Converter.ConvertJobCollectionDefinitionToPS(jobCollectionDefinitionResult)); }
/// <summary> /// Populate quota object with valid values. /// </summary> /// <param name="quota">Quota object.</param> /// <param name="skuDefinition">Sku definition (Free, Standard, P10Premium, and P20Premium</param> /// <param name="jobCollectionParams">Job collection parameters set via powershell.</param> /// <param name="newQuota">boolean to indicate whether quota object is new or existing.</param> private void PopulateJobCollectionQuota(JobCollectionQuota quota, SkuDefinition skuDefinition, PSJobCollectionsParams jobCollectionParams, bool newQuota = true) { if (quota == null && !newQuota) { throw new ArgumentOutOfRangeException("quota", "Quota is null."); } if (quota == null) { quota = new JobCollectionQuota(); } int existingMaxCountValue = Constants.MaxJobCountQuotaStandard; TimeSpan existingMinRecurrenceValue = Constants.MinRecurrenceQuotaStandard; if (!newQuota) { existingMaxCountValue = quota.MaxJobCount.Value; existingMinRecurrenceValue = SchedulerUtility.ToTimeSpan(quota.MaxRecurrence.Frequency.Value, quota.MaxRecurrence.Interval.Value); } switch (skuDefinition) { case SkuDefinition.Free: quota.MaxJobCount = this.GetMaxJobCount( jobCollectionParams.MaxJobCount, newQuota ? Constants.MaxJobCountQuotaFree : existingMaxCountValue, Resources.JobCollectionMaxJobQuotaTooLargeForFree); quota.MaxRecurrence = this.GetMaxRecurrence( jobCollectionParams.Frequency, jobCollectionParams.Interval, newQuota ? Constants.MinRecurrenceQuotaFree : existingMinRecurrenceValue, Resources.JobCollectionMaxRecurrenceQuotaTooLargeForFree); break; case SkuDefinition.Standard: case SkuDefinition.P10Premium: default: quota.MaxJobCount = this.GetMaxJobCount( jobCollectionParams.MaxJobCount, newQuota ? Constants.MaxJobCountQuotaStandard : existingMaxCountValue, Resources.JobCollectionMaxJobQuotaTooLargeForPaid); quota.MaxRecurrence = this.GetMaxRecurrence( jobCollectionParams.Frequency, jobCollectionParams.Interval, newQuota ? Constants.MinRecurrenceQuotaStandard : existingMinRecurrenceValue, Resources.JobCollectionMaxJobQuotaTooLargeForPaid); break; case SkuDefinition.P20Premium: quota.MaxJobCount = this.GetMaxJobCount( jobCollectionParams.MaxJobCount, newQuota ? Constants.MaxJobCountQuotaP20Premium : existingMaxCountValue, Resources.JobCollectionMaxJobQuotaTooLargeForPaid); quota.MaxRecurrence = this.GetMaxRecurrence( jobCollectionParams.Frequency, jobCollectionParams.Interval, newQuota ? Constants.MinRecurrenceQuotaP20Premium : existingMinRecurrenceValue, Resources.JobCollectionMaxJobQuotaTooLargeForPaid); break; } }
/// <summary> /// Updates job collection. /// </summary> /// <param name="updateJobCollectionParams">Job collection properties to update.</param> /// <returns>Job collection definition.</returns> public PSJobCollectionDefinition UpdateJobCollection(PSJobCollectionsParams updateJobCollectionParams) { if (string.IsNullOrWhiteSpace(updateJobCollectionParams.ResourceGroupName)) { throw new PSArgumentNullException(paramName: "ResourceGroupName"); } if (string.IsNullOrWhiteSpace(updateJobCollectionParams.JobCollectionName)) { throw new PSArgumentNullException(paramName: "JobCollectionName"); } if (!string.IsNullOrWhiteSpace(updateJobCollectionParams.Region) && !this.AvailableRegions.Contains(updateJobCollectionParams.Region)) { throw new PSArgumentException(Resources.SchedulerInvalidLocation); } IList <JobCollectionDefinition> jobCollectionsDefition = this.ListJobCollection( updateJobCollectionParams.ResourceGroupName, updateJobCollectionParams.JobCollectionName); if (jobCollectionsDefition == null) { throw new PSArgumentException( string.Format(Resources.JobCollectionDoesnotExist, updateJobCollectionParams.ResourceGroupName, updateJobCollectionParams.JobCollectionName)); } JobCollectionDefinition jobCollectionDefinition = jobCollectionsDefition[0]; if (jobCollectionDefinition.Properties.Sku.Name != SkuDefinition.Free && !string.IsNullOrWhiteSpace(updateJobCollectionParams.Plan) && updateJobCollectionParams.Plan.Equals(Constants.FreePlan, StringComparison.InvariantCultureIgnoreCase) && this.HasFreeJobCollection()) { throw new PSInvalidOperationException(Resources.SchedulerNoMoreFreeJobCollection); } JobCollectionQuota quota = jobCollectionDefinition.Properties.Quota; SkuDefinition skuDefinition = jobCollectionDefinition.Properties.Sku.Name.Value; bool newQuota = false; if (!string.IsNullOrWhiteSpace(updateJobCollectionParams.Plan)) { skuDefinition = updateJobCollectionParams.Plan.GetValueOrDefaultEnum <SkuDefinition>(defaultValue: SkuDefinition.Standard); newQuota = true; } this.PopulateJobCollectionQuota(quota, skuDefinition, updateJobCollectionParams, newQuota); var jcProperties = new JobCollectionProperties() { Sku = new Sku(skuDefinition), Quota = quota, }; jobCollectionDefinition.Location = updateJobCollectionParams.Region != null ? updateJobCollectionParams.Region : jobCollectionDefinition.Location; jobCollectionDefinition.Properties = jcProperties; var jobCollectionDefinitionResult = this.SchedulerManagementClient.JobCollections.CreateOrUpdate( updateJobCollectionParams.ResourceGroupName, updateJobCollectionParams.JobCollectionName, jobCollectionDefinition); return(Converter.ConvertJobCollectionDefinitionToPS(jobCollectionDefinitionResult)); }
/// <summary> /// Create job collection. /// </summary> /// <param name="createJobCollectionParams">Job collection properties entered by user via Powershell.</param> /// <returns>Job collection definition.</returns> public PSJobCollectionDefinition CreateJobCollection(PSJobCollectionsParams createJobCollectionParams) { if (string.IsNullOrWhiteSpace(createJobCollectionParams.ResourceGroupName)) { throw new PSArgumentNullException(paramName: "ResourceGroupName"); } if (string.IsNullOrWhiteSpace(createJobCollectionParams.JobCollectionName)) { throw new PSArgumentNullException(paramName: "JobCollectionName"); } if (string.IsNullOrWhiteSpace(createJobCollectionParams.Region)) { throw new PSArgumentNullException(paramName: "Region"); } if (!DoesResourceGroupExists(createJobCollectionParams.ResourceGroupName)) { throw new PSArgumentException(Resources.SchedulerInvalidResourceGroup); } if (!this.AvailableRegions.Contains(createJobCollectionParams.Region)) { throw new PSArgumentException(Resources.SchedulerInvalidLocation); } if (HasJobCollection(createJobCollectionParams.ResourceGroupName, createJobCollectionParams.JobCollectionName)) { throw new PSInvalidOperationException(string.Format(Resources.SchedulerExistingJobCollection, createJobCollectionParams.JobCollectionName, createJobCollectionParams.ResourceGroupName)); } var skuDefinition = createJobCollectionParams.Plan.GetValueOrDefaultEnum<SkuDefinition>(defaultValue: SkuDefinition.Standard); if (skuDefinition == SkuDefinition.Free && HasFreeJobCollection()) { throw new PSInvalidOperationException(Resources.SchedulerNoMoreFreeJobCollection); } var quota = new JobCollectionQuota(); this.PopulateJobCollectionQuota(quota, skuDefinition, createJobCollectionParams, newQuota: true); var jcProperties = new JobCollectionProperties() { Sku = new Sku(skuDefinition), Quota = quota, }; var jobCollectionDefinition = new JobCollectionDefinition() { Location = createJobCollectionParams.Region, Name = createJobCollectionParams.JobCollectionName, Properties = jcProperties, }; var jobCollectionDefinitionResult = this.SchedulerManagementClient.JobCollections.CreateOrUpdate( createJobCollectionParams.ResourceGroupName, createJobCollectionParams.JobCollectionName, jobCollectionDefinition); return Converter.ConvertJobCollectionDefinitionToPS(jobCollectionDefinitionResult); }