示例#1
0
        /// <summary>
        /// Creates policy given the provider data
        /// </summary>
        /// <returns>Created policy object as returned by the service</returns>
        public ProtectionPolicyResource CreatePolicy()
        {
            string vaultName         = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            string policyName        = (string)ProviderData[PolicyParams.PolicyName];

            CmdletModel.WorkloadType workloadType =
                (CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType];
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;

            ValidateAzureSqlWorkloadType(workloadType);

            // validate RetentionPolicy
            ValidateAzureSqlRetentionPolicy(retentionPolicy);
            Logger.Instance.WriteDebug("Validation of Retention policy is successful");

            // construct Hydra policy request
            ProtectionPolicyResource protectionPolicyResource = new ProtectionPolicyResource()
            {
                Properties = new AzureSqlProtectionPolicy()
                {
                    RetentionPolicy = PolicyHelpers.GetServiceClientSimpleRetentionPolicy(
                        (CmdletModel.SimpleRetentionPolicy)retentionPolicy)
                }
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
                       policyName,
                       protectionPolicyResource,
                       vaultName: vaultName,
                       resourceGroupName: resourceGroupName).Body);
        }
示例#2
0
        public void TestRandomProbability()
        {
            var random  = new Random(1337);
            var epsilon = 0.4;
            var eGreedy = new EGreedy(epsilon, random);
            var qValue  = new QValue(new double[]
            {
                121, 231, 425, 676, 812, 1012, 1231, 1301, 1412, 1541, 1701, 2015
            });
            var bestAction = PolicyHelpers.SelectMax(qValue, random);

            int numBestSelected = 0;
            int numTests        = 3000;

            for (int i = 0; i < numTests; i++)
            {
                int action = eGreedy.Select(qValue);

                if (action == bestAction)
                {
                    numBestSelected++;
                }
            }

            Assert.AreEqual((1 - epsilon) + epsilon * (1.0 / qValue.Count), numBestSelected / (double)numTests, 0.05);
        }
示例#3
0
        /// <summary>
        /// Updates the learning algorithm
        /// </summary>
        /// <param name="currentState">The current state</param>
        /// <param name="newState">The new state</param>
        /// <param name="action">The action that was executed</param>
        /// <param name="reward">The reward that was received</param>
        public void Update(TState currentState, TState newState, int action, double reward)
        {
            double oldValue = this.qValueTable[currentState][action];

            var    newQValue = this.qValueTable[newState];
            double maxQNew   = newQValue[PolicyHelpers.SelectMax(newQValue, this.random)];
            double newValue  = oldValue + this.alpha * (reward + this.gamma * maxQNew - oldValue);

            this.qValueTable[currentState, action] = newValue;
        }
        /// <summary>
        /// Creates policy given the provider data
        /// </summary>
        /// <returns>Created policy object as returned by the service</returns>
        public ProtectionPolicyResponse CreatePolicy()
        {
            string policyName = (string)ProviderData[PolicyParams.PolicyName];

            Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType workloadType =
                (Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData[PolicyParams.WorkloadType];
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;
            SchedulePolicyBase schedulePolicy =
                ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ?
                (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] :
                null;

            // do validations
            ValidateAzureVMWorkloadType(workloadType);
            ValidateAzureVMSchedulePolicy(schedulePolicy);
            Logger.Instance.WriteDebug("Validation of Schedule policy is successful");

            // validate RetentionPolicy
            ValidateAzureVMRetentionPolicy(retentionPolicy);
            Logger.Instance.WriteDebug("Validation of Retention policy is successful");

            // update the retention times from backupSchedule to retentionPolicy after converting to UTC
            CopyScheduleTimeToRetentionTimes((CmdletModel.LongTermRetentionPolicy)retentionPolicy,
                                             (CmdletModel.SimpleSchedulePolicy)schedulePolicy);
            Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

            // Now validate both RetentionPolicy and SchedulePolicy together
            PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
                (CmdletModel.LongTermRetentionPolicy)retentionPolicy,
                (CmdletModel.SimpleSchedulePolicy)schedulePolicy);
            Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

            // construct Service Client policy request
            ProtectionPolicyRequest serviceClientRequest = new ProtectionPolicyRequest()
            {
                Item = new ProtectionPolicyResource()
                {
                    Properties = new AzureIaaSVMProtectionPolicy()
                    {
                        RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy(
                            (CmdletModel.LongTermRetentionPolicy)retentionPolicy),
                        SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy(
                            (CmdletModel.SimpleSchedulePolicy)schedulePolicy)
                    }
                }
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
                       policyName,
                       serviceClientRequest));
        }
示例#5
0
 /// <summary>
 /// Returns the action to execute in the given state
 /// </summary>
 /// <param name="state">The state</param>
 public int SelectAction(TState state)
 {
     if (!this.FollowPolicy)
     {
         return(this.selectionPolicy.Select(this.qValueTable[state]));
     }
     else
     {
         return(PolicyHelpers.SelectMax(this.qValueTable[state], this.random));
     }
 }
示例#6
0
文件: Sarsa.cs 项目: play3577/SharpRL
 /// <summary>
 /// Returns the action to execute in the given state
 /// </summary>
 /// <param name="state">The state</param>
 public int SelectAction(TState state)
 {
     if (!this.FollowPolicy)
     {
         if (this.possibleState == null || !this.possibleState.Equals(state))
         {
             return(this.selectionPolicy.Select(this.qValueTable[state]));
         }
         else
         {
             return(this.possibleAction);
         }
     }
     else
     {
         return(PolicyHelpers.SelectMax(this.qValueTable[state], this.random));
     }
 }
示例#7
0
        /// <summary>
        /// Modifies policy using the provider data
        /// </summary>
        /// <returns>Modified policy object as returned by the service</returns>
        public RestAzureNS.AzureOperationResponse <ProtectionPolicyResource> ModifyPolicy()
        {
            string vaultName                    = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName            = (string)ProviderData[VaultParams.ResourceGroupName];
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;

            PolicyBase policy =
                ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ?
                (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] :
                null;

            // RetentionPolicy
            if (retentionPolicy == null)
            {
                throw new ArgumentException(Resources.RetentionPolicyEmptyInAzureSql);
            }
            else
            {
                ValidateAzureSqlRetentionPolicy(retentionPolicy);
                ((AzureSqlPolicy)policy).RetentionPolicy = retentionPolicy;
                Logger.Instance.WriteDebug("Validation of Retention policy is successful");
            }

            CmdletModel.SimpleRetentionPolicy sqlRetentionPolicy =
                (CmdletModel.SimpleRetentionPolicy)((AzureSqlPolicy)policy).RetentionPolicy;
            ProtectionPolicyResource protectionPolicyResource = new ProtectionPolicyResource()
            {
                Properties = new AzureSqlProtectionPolicy()
                {
                    RetentionPolicy =
                        PolicyHelpers.GetServiceClientSimpleRetentionPolicy(sqlRetentionPolicy)
                }
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
                       policy.Name,
                       protectionPolicyResource,
                       vaultName: vaultName,
                       resourceGroupName: resourceGroupName));
        }
示例#8
0
        /// <summary>
        /// Modifies policy using the provider data
        /// </summary>
        /// <returns>Modified policy object as returned by the service</returns>
        public ProtectionPolicyResponse ModifyPolicy()
        {
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;

            PolicyBase policy =
                ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ?
                (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] :
                null;

            // RetentionPolicy
            if (retentionPolicy == null)
            {
                throw new ArgumentException(Resources.RetentionPolicyEmptyInAzureSql);
            }
            else
            {
                ValidateAzureSqlRetentionPolicy(retentionPolicy);
                ((AzureSqlPolicy)policy).RetentionPolicy = retentionPolicy;
                Logger.Instance.WriteDebug("Validation of Retention policy is successful");
            }

            CmdletModel.SimpleRetentionPolicy sqlRetentionPolicy =
                (CmdletModel.SimpleRetentionPolicy)((AzureSqlPolicy)policy).RetentionPolicy;
            ProtectionPolicyRequest hydraRequest = new ProtectionPolicyRequest()
            {
                Item = new ProtectionPolicyResource()
                {
                    Properties = new AzureSqlProtectionPolicy()
                    {
                        RetentionPolicy =
                            PolicyHelpers.GetServiceClientSimpleRetentionPolicy(sqlRetentionPolicy)
                    }
                }
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(policy.Name,
                                                                       hydraRequest));
        }
示例#9
0
        public void TestRandomProbability()
        {
            var random  = new Random(1337);
            var tau     = 200;
            var softmax = new Softmax(tau, random);
            var qValue  = new QValue(new double[]
            {
                121, 231, 425, 676
            });
            var bestAction = PolicyHelpers.SelectMax(qValue, random);

            var numSelected = new TestInstance[qValue.Count];

            for (int i = 0; i < qValue.Count; i++)
            {
                numSelected[i] = new TestInstance()
                {
                    Action = i
                };
            }

            int numTests = 3000;

            for (int i = 0; i < numTests; i++)
            {
                int action = softmax.Select(qValue);
                numSelected[action].Count++;
            }

            numSelected = numSelected.OrderBy(x => x.Count).ToArray();

            Assert.AreEqual(0, numSelected[0].Action);
            Assert.AreEqual(1, numSelected[1].Action);
            Assert.AreEqual(2, numSelected[2].Action);
            Assert.AreEqual(3, numSelected[3].Action);
        }
        private WindowsUpdateRingState RingStateFromJson(ILogger logger, JObject input)
        {
            string ringString;

            if (!JsonHelpers.TryGetString(input, TCJsonRing, out ringString))
            {
                ReportError(logger, "Missing " + TCJsonRing);
                return(null);
            }

            string settingsPriorityString;

            if (!JsonHelpers.TryGetString(input, TCJsonSettingsPriority, out settingsPriorityString))
            {
                ReportError(logger, "Missing " + TCJsonSettingsPriority);
                return(null);
            }

            WindowsUpdateRingState state = new WindowsUpdateRingState();

            state.ring             = WindowsUpdateRingState.RingFromJsonString(ringString);
            state.settingsPriority = PolicyHelpers.SettingsPriorityFromString(settingsPriorityString);
            return(state);
        }
        /// <summary>
        /// Modifies policy using the provider data
        /// </summary>
        /// <returns>Modified policy object as returned by the service</returns>
        public ProtectionPolicyResponse ModifyPolicy()
        {
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;
            SchedulePolicyBase schedulePolicy =
                ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ?
                (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] :
                null;

            PolicyBase policy =
                ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ?
                (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] :
                null;

            // do validations
            ValidateAzureVMProtectionPolicy(policy);
            Logger.Instance.WriteDebug("Validation of Protection Policy is successful");

            // RetentionPolicy and SchedulePolicy both should not be empty
            if (retentionPolicy == null && schedulePolicy == null)
            {
                throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty);
            }

            // validate RetentionPolicy and SchedulePolicy
            if (schedulePolicy != null)
            {
                ValidateAzureVMSchedulePolicy(schedulePolicy);
                ((AzureVmPolicy)policy).SchedulePolicy = schedulePolicy;
                Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
            }
            if (retentionPolicy != null)
            {
                ValidateAzureVMRetentionPolicy(retentionPolicy);
                ((AzureVmPolicy)policy).RetentionPolicy = retentionPolicy;
                Logger.Instance.WriteDebug("Validation of Retention policy is successful");
            }

            // copy the backupSchedule time to retentionPolicy after converting to UTC
            CopyScheduleTimeToRetentionTimes(
                (CmdletModel.LongTermRetentionPolicy)((AzureVmPolicy)policy).RetentionPolicy,
                (CmdletModel.SimpleSchedulePolicy)((AzureVmPolicy)policy).SchedulePolicy);
            Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

            // Now validate both RetentionPolicy and SchedulePolicy matches or not
            PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
                (CmdletModel.LongTermRetentionPolicy)((AzureVmPolicy)policy).RetentionPolicy,
                (CmdletModel.SimpleSchedulePolicy)((AzureVmPolicy)policy).SchedulePolicy);
            Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

            // construct Service Client policy request
            ProtectionPolicyRequest serviceClientRequest = new ProtectionPolicyRequest()
            {
                Item = new ProtectionPolicyResource()
                {
                    Properties = new AzureIaaSVMProtectionPolicy()
                    {
                        RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy(
                            (CmdletModel.LongTermRetentionPolicy)((AzureVmPolicy)policy).RetentionPolicy),
                        SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy(
                            (CmdletModel.SimpleSchedulePolicy)((AzureVmPolicy)policy).SchedulePolicy)
                    }
                }
            };

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(policy.Name,
                                                                       serviceClientRequest));
        }
        private RestAzureNS.AzureOperationResponse <ProtectionPolicyResource> CreateorModifyPolicy()
        {
            string vaultName         = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            string policyName        = ProviderData.ContainsKey(PolicyParams.PolicyName) ?
                                       (string)ProviderData[PolicyParams.PolicyName] : null;
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;
            SchedulePolicyBase schedulePolicy =
                ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ?
                (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] :
                null;
            PolicyBase policy =
                ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ?
                (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] :
                null;
            bool fixForInconsistentItems = ProviderData.ContainsKey(PolicyParams.FixForInconsistentItems) ?
                                           (bool)ProviderData[PolicyParams.FixForInconsistentItems] : false;
            ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource();

            if (policy != null)
            {
                // do validations
                ValidateAzureWorkloadProtectionPolicy(policy);
                Logger.Instance.WriteDebug("Validation of Protection Policy is successful");

                // RetentionPolicy and SchedulePolicy both should not be empty
                if (retentionPolicy == null && schedulePolicy == null)
                {
                    if (fixForInconsistentItems == false)
                    {
                        throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty);
                    }
                    AzureVmWorkloadProtectionPolicy azureVmWorkloadModifyPolicy = new AzureVmWorkloadProtectionPolicy();
                    azureVmWorkloadModifyPolicy.Settings = new Settings("UTC",
                                                                        ((AzureVmWorkloadPolicy)policy).IsCompression,
                                                                        ((AzureVmWorkloadPolicy)policy).IsCompression);
                    azureVmWorkloadModifyPolicy.WorkLoadType         = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString());
                    azureVmWorkloadModifyPolicy.SubProtectionPolicy  = new List <SubProtectionPolicy>();
                    azureVmWorkloadModifyPolicy.SubProtectionPolicy  = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy);
                    azureVmWorkloadModifyPolicy.MakePolicyConsistent = true;
                    serviceClientRequest.Properties = azureVmWorkloadModifyPolicy;
                }
                else
                {
                    // validate RetentionPolicy and SchedulePolicy
                    if (schedulePolicy != null)
                    {
                        AzureWorkloadProviderHelper.ValidateSQLSchedulePolicy(schedulePolicy);
                        AzureWorkloadProviderHelper.GetUpdatedSchedulePolicy(policy, (SQLSchedulePolicy)schedulePolicy);
                        Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
                    }
                    if (retentionPolicy != null)
                    {
                        AzureWorkloadProviderHelper.ValidateSQLRetentionPolicy(retentionPolicy);
                        AzureWorkloadProviderHelper.GetUpdatedRetentionPolicy(policy, (SQLRetentionPolicy)retentionPolicy);
                        Logger.Instance.WriteDebug("Validation of Retention policy is successful");
                    }

                    // copy the backupSchedule time to retentionPolicy after converting to UTC
                    AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes(
                        (CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
                        (CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
                    Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

                    // Now validate both RetentionPolicy and SchedulePolicy matches or not
                    PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
                        (CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy,
                        (CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy);
                    Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

                    // construct Service Client policy request
                    AzureVmWorkloadProtectionPolicy azureVmWorkloadProtectionPolicy = new AzureVmWorkloadProtectionPolicy();
                    azureVmWorkloadProtectionPolicy.Settings = new Settings("UTC",
                                                                            ((AzureVmWorkloadPolicy)policy).IsCompression,
                                                                            ((AzureVmWorkloadPolicy)policy).IsCompression);
                    azureVmWorkloadProtectionPolicy.WorkLoadType        = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString());
                    azureVmWorkloadProtectionPolicy.SubProtectionPolicy = new List <SubProtectionPolicy>();
                    azureVmWorkloadProtectionPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy);
                    serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy;
                }
            }
            else
            {
                CmdletModel.WorkloadType workloadType =
                    (CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType];

                // do validations
                ValidateAzureWorkloadWorkloadType(workloadType);
                AzureWorkloadProviderHelper.ValidateSQLSchedulePolicy(schedulePolicy);
                Logger.Instance.WriteDebug("Validation of Schedule policy is successful");

                // validate RetentionPolicy
                AzureWorkloadProviderHelper.ValidateSQLRetentionPolicy(retentionPolicy);
                Logger.Instance.WriteDebug("Validation of Retention policy is successful");

                // update the retention times from backupSchedule to retentionPolicy after converting to UTC
                AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes(((SQLRetentionPolicy)retentionPolicy).FullBackupRetentionPolicy,
                                                                             ((SQLSchedulePolicy)schedulePolicy).FullBackupSchedulePolicy);
                Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

                // Now validate both RetentionPolicy and SchedulePolicy together
                PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
                    (SQLRetentionPolicy)retentionPolicy,
                    (SQLSchedulePolicy)schedulePolicy);
                Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

                // construct Service Client policy request
                AzureVmWorkloadProtectionPolicy azureVmWorkloadProtectionPolicy = new AzureVmWorkloadProtectionPolicy();
                azureVmWorkloadProtectionPolicy.Settings = new Settings("UTC",
                                                                        ((SQLSchedulePolicy)schedulePolicy).IsCompression,
                                                                        ((SQLSchedulePolicy)schedulePolicy).IsCompression);
                azureVmWorkloadProtectionPolicy.WorkLoadType        = ConversionUtils.GetServiceClientWorkloadType(workloadType.ToString());
                azureVmWorkloadProtectionPolicy.SubProtectionPolicy = new List <SubProtectionPolicy>();
                azureVmWorkloadProtectionPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy(
                    (SQLRetentionPolicy)retentionPolicy,
                    (SQLSchedulePolicy)schedulePolicy);
                serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy;
            }

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
                       policyName = policyName ?? policy.Name,
                       serviceClientRequest,
                       vaultName: vaultName,
                       resourceGroupName: resourceGroupName));
        }
示例#13
0
        private RestAzureNS.AzureOperationResponse <ProtectionPolicyResource> CreateorModifyPolicy()
        {
            string vaultName         = (string)ProviderData[VaultParams.VaultName];
            string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName];
            string policyName        = ProviderData.ContainsKey(PolicyParams.PolicyName) ?
                                       (string)ProviderData[PolicyParams.PolicyName] : null;
            RetentionPolicyBase retentionPolicy =
                ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ?
                (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] :
                null;
            SchedulePolicyBase schedulePolicy =
                ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ?
                (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] :
                null;
            PolicyBase policy =
                ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ?
                (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] :
                null;
            ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource();

            if (policy != null)
            {
                // do validations
                ValidateAzureFileProtectionPolicy(policy);
                Logger.Instance.WriteDebug("Validation of Protection Policy is successful");

                // RetentionPolicy and SchedulePolicy both should not be empty
                if (retentionPolicy == null && schedulePolicy == null)
                {
                    throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty);
                }

                // validate RetentionPolicy and SchedulePolicy
                if (schedulePolicy != null)
                {
                    AzureWorkloadProviderHelper.ValidateSimpleSchedulePolicy(schedulePolicy);
                    ((AzureFileSharePolicy)policy).SchedulePolicy = schedulePolicy;
                    Logger.Instance.WriteDebug("Validation of Schedule policy is successful");
                }
                if (retentionPolicy != null)
                {
                    AzureWorkloadProviderHelper.ValidateLongTermRetentionPolicy(retentionPolicy);
                    ((AzureFileSharePolicy)policy).RetentionPolicy = retentionPolicy;
                    Logger.Instance.WriteDebug("Validation of Retention policy is successful");
                }

                // copy the backupSchedule time to retentionPolicy after converting to UTC
                AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes(
                    (CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy,
                    (CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy);
                Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

                // Now validate both RetentionPolicy and SchedulePolicy matches or not
                PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
                    (CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy,
                    (CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy);
                Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

                // construct Service Client policy request
                AzureFileShareProtectionPolicy azureFileShareProtectionPolicy = new AzureFileShareProtectionPolicy();
                azureFileShareProtectionPolicy.RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy(
                    (CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy);
                azureFileShareProtectionPolicy.SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy(
                    (CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy);
                azureFileShareProtectionPolicy.TimeZone     = DateTimeKind.Utc.ToString().ToUpper();
                azureFileShareProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString());
                serviceClientRequest.Properties             = azureFileShareProtectionPolicy;
            }
            else
            {
                CmdletModel.WorkloadType workloadType =
                    (CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType];

                // do validations
                ValidateAzureFilesWorkloadType(workloadType);
                AzureWorkloadProviderHelper.ValidateSimpleSchedulePolicy(schedulePolicy);
                Logger.Instance.WriteDebug("Validation of Schedule policy is successful");

                // validate RetentionPolicy
                AzureWorkloadProviderHelper.ValidateLongTermRetentionPolicy(retentionPolicy);
                Logger.Instance.WriteDebug("Validation of Retention policy is successful");

                // update the retention times from backupSchedule to retentionPolicy after converting to UTC
                AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes((CmdletModel.LongTermRetentionPolicy)retentionPolicy,
                                                                             (CmdletModel.SimpleSchedulePolicy)schedulePolicy);
                Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful");

                // Now validate both RetentionPolicy and SchedulePolicy together
                PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy(
                    (CmdletModel.LongTermRetentionPolicy)retentionPolicy,
                    (CmdletModel.SimpleSchedulePolicy)schedulePolicy);
                Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful");

                // construct Service Client policy request
                AzureFileShareProtectionPolicy azureFileShareProtectionPolicy = new AzureFileShareProtectionPolicy();
                azureFileShareProtectionPolicy.RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy(
                    (CmdletModel.LongTermRetentionPolicy)retentionPolicy);
                azureFileShareProtectionPolicy.RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy(
                    (CmdletModel.LongTermRetentionPolicy)retentionPolicy);
                azureFileShareProtectionPolicy.SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy(
                    (CmdletModel.SimpleSchedulePolicy)schedulePolicy);
                azureFileShareProtectionPolicy.TimeZone     = DateTimeKind.Utc.ToString().ToUpper();
                azureFileShareProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(workloadType.ToString());
                serviceClientRequest.Properties             = azureFileShareProtectionPolicy;
            }

            return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(
                       policyName = policyName ?? policy.Name,
                       serviceClientRequest,
                       vaultName: vaultName,
                       resourceGroupName: resourceGroupName));
        }