Exemplo n.º 1
0
        /// <summary>
        /// Helper function to convert ps backup job model from service response.
        /// </summary>
        public static CmdletModel.JobBase GetPSJobCrr(CrrModel.JobResource serviceClientJob)
        {
            CmdletModel.JobBase response = null;

            // ServiceClient doesn't initialize Properties if the type of job is not known to current version of ServiceClient.
            if (serviceClientJob.Properties == null)
            {
                Logger.Instance.WriteWarning(Resources.UnsupportedJobWarning);
            }
            else if (serviceClientJob.Properties.GetType() == typeof(CrrModel.AzureIaaSVMJob))
            {
                response = GetPSAzureVmJobCrr(serviceClientJob);
            }
            else if (serviceClientJob.Properties.GetType() == typeof(CrrModel.AzureStorageJob))
            {
                response = GetPSAzureFileShareJobCrr(serviceClientJob);
            }
            else if (serviceClientJob.Properties.GetType() == typeof(CrrModel.AzureWorkloadJob))
            {
                response = GetPSAzureWorkloadJobCrr(serviceClientJob);
            }
            else if (serviceClientJob.Properties.GetType() == typeof(CrrModel.MabJob))
            {
                response = GetPSMabJobCrr(serviceClientJob);
            }

            /*else if (serviceClientJob.Properties.GetType() == typeof(VaultJob))
             * {
             *  response = GetPSAzureVaultJob(serviceClientJob); // add Crr if needed
             * }*/

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Helper function to convert ps azure vm backup policy job from service response.
        /// </summary>
        private static CmdletModel.AzureJob GetPSAzureBaseJobCrr(CrrModel.JobResource serviceClientJob)
        {
            CrrModel.Job         baseJob  = serviceClientJob.Properties;
            CmdletModel.AzureJob response = new CmdletModel.AzureJob();

            response.JobId                = GetLastIdFromFullId(serviceClientJob.Id);
            response.StartTime            = GetJobStartTime(baseJob.StartTime);
            response.EndTime              = baseJob.EndTime;
            response.Status               = baseJob.Status;
            response.WorkloadName         = baseJob.EntityFriendlyName;
            response.ActivityId           = baseJob.ActivityId;
            response.BackupManagementType = CmdletModel.ConversionUtils.GetPsBackupManagementType(baseJob.BackupManagementType);
            response.Operation            = baseJob.Operation;

            return(response);
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                if (ParameterSetName == JobFilterSet)
                {
                    JobId = Job.JobId;
                }

                WriteDebug("Fetching job with ID: " + JobId);

                if (UseSecondaryRegion.IsPresent)
                {
                    CrrModel.CrrJobRequest jobRequest = new CrrModel.CrrJobRequest();
                    jobRequest.JobName    = JobId;
                    jobRequest.ResourceId = VaultId;

                    // check this GetVault for rainy day scenario
                    ARSVault vault         = ServiceClientAdapter.GetVault(resourceGroupName, vaultName);
                    string secondaryRegion = BackupUtils.regionMap[vault.Location];

                    CrrModel.JobResource jobDetailsCrr = ServiceClientAdapter.GetCRRJobDetails(secondaryRegion, jobRequest);
                    WriteObject(JobConversions.GetPSJobCrr(jobDetailsCrr));
                }
                else
                {
                    JobResource jobDetails = ServiceClientAdapter.GetJob(
                        JobId,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName);

                    WriteObject(JobConversions.GetPSJob(jobDetails));
                }
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Helper function to convert ps azure vm backup policy job from service response.
        /// </summary>
        private static CmdletModel.AzureVmJob GetPSAzureVmJobCrr(CrrModel.JobResource serviceClientJob)
        {
            CmdletModel.AzureVmJob response;

            CrrModel.AzureIaaSVMJob vmJob = serviceClientJob.Properties as CrrModel.AzureIaaSVMJob;

            if (vmJob.ExtendedInfo != null)
            {
                response = new CmdletModel.AzureVmJobDetails();
            }
            else
            {
                response = new CmdletModel.AzureVmJob();
            }

            response.JobId                = GetLastIdFromFullId(serviceClientJob.Id);
            response.StartTime            = GetJobStartTime(vmJob.StartTime);
            response.EndTime              = vmJob.EndTime;
            response.Duration             = GetJobDuration(vmJob.Duration);
            response.Status               = vmJob.Status;
            response.VmVersion            = vmJob.VirtualMachineVersion;
            response.WorkloadName         = vmJob.EntityFriendlyName;
            response.ActivityId           = vmJob.ActivityId;
            response.BackupManagementType =
                CmdletModel.ConversionUtils.GetPsBackupManagementType(vmJob.BackupManagementType);
            response.Operation = vmJob.Operation;

            if (vmJob.ErrorDetails != null)
            {
                response.ErrorDetails = new List <CmdletModel.AzureJobErrorInfo>();
                foreach (var vmError in vmJob.ErrorDetails)
                {
                    response.ErrorDetails.Add(GetPSAzureVmErrorInfoCrr(vmError));
                }
            }

            // fill extended info if present
            if (vmJob.ExtendedInfo != null)
            {
                CmdletModel.AzureVmJobDetails detailedResponse =
                    response as CmdletModel.AzureVmJobDetails;

                detailedResponse.DynamicErrorMessage = vmJob.ExtendedInfo.DynamicErrorMessage;
                if (vmJob.ExtendedInfo.PropertyBag != null)
                {
                    detailedResponse.Properties = new Dictionary <string, string>();
                    foreach (var key in vmJob.ExtendedInfo.PropertyBag.Keys)
                    {
                        detailedResponse.Properties.Add(key, vmJob.ExtendedInfo.PropertyBag[key]);
                    }
                }

                if (vmJob.ExtendedInfo.TasksList != null)
                {
                    detailedResponse.SubTasks = new List <CmdletModel.AzureVmJobSubTask>();
                    foreach (var vmJobTask in vmJob.ExtendedInfo.TasksList)
                    {
                        detailedResponse.SubTasks.Add(new CmdletModel.AzureVmJobSubTask()
                        {
                            Name   = vmJobTask.TaskId,
                            Status = vmJobTask.Status
                        });
                    }
                }
            }

            return(response);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the powershell MabJob object from service response.
        /// </summary>
        private static CmdletModel.JobBase GetPSMabJobCrr(CrrModel.JobResource serviceClientJob)
        {
            CmdletModel.MabJob response;

            CrrModel.MabJob mabJob = serviceClientJob.Properties as CrrModel.MabJob;

            if (mabJob.ExtendedInfo != null)
            {
                response = new CmdletModel.MabJobDetails();
            }
            else
            {
                response = new CmdletModel.MabJob();
            }

            // Transfer values from service job object to powershell job object.
            response.JobId                = GetLastIdFromFullId(serviceClientJob.Id);
            response.StartTime            = GetJobStartTime(mabJob.StartTime);
            response.EndTime              = mabJob.EndTime;
            response.Duration             = GetJobDuration(mabJob.Duration);
            response.Status               = mabJob.Status;
            response.WorkloadName         = mabJob.EntityFriendlyName;
            response.ActivityId           = mabJob.ActivityId;
            response.BackupManagementType =
                CmdletModel.ConversionUtils.GetPsBackupManagementType(mabJob.BackupManagementType);
            response.Operation = mabJob.Operation;

            if (mabJob.ErrorDetails != null)
            {
                response.ErrorDetails = new List <CmdletModel.AzureJobErrorInfo>();
                foreach (var mabError in mabJob.ErrorDetails)
                {
                    response.ErrorDetails.Add(GetPSMabErrorInfoCrr(mabError));
                }
            }

            // fill extended info if present
            if (mabJob.ExtendedInfo != null)
            {
                CmdletModel.MabJobDetails detailedResponse = response as CmdletModel.MabJobDetails;

                detailedResponse.DynamicErrorMessage = mabJob.ExtendedInfo.DynamicErrorMessage;
                if (mabJob.ExtendedInfo.PropertyBag != null)
                {
                    detailedResponse.Properties = new Dictionary <string, string>();
                    foreach (var key in mabJob.ExtendedInfo.PropertyBag.Keys)
                    {
                        detailedResponse.Properties.Add(key, mabJob.ExtendedInfo.PropertyBag[key]);
                    }
                }

                if (mabJob.ExtendedInfo.TasksList != null)
                {
                    detailedResponse.SubTasks = new List <CmdletModel.MabJobSubTask>();
                    foreach (var mabJobTask in mabJob.ExtendedInfo.TasksList)
                    {
                        detailedResponse.SubTasks.Add(new CmdletModel.MabJobSubTask()
                        {
                            Name   = mabJobTask.TaskId,
                            Status = mabJobTask.Status
                        });
                    }
                }
            }

            return(response);
        }