private bool IsValidPointInTime(long?restoreTimeSecs, long?startTime, long sourceId, Model.ProtectionJob job) { // identifying range from preceeding day System.DateTime startDate = RestApiCommon.ConvertUsecsToDateTime((long)startTime); startDate = startDate.AddDays(-1); long startTimeInUsec = RestApiCommon.ConvertDateTimeToUsecs(startDate); var pointsInTimeRange = new Model.RestorePointsForTimeRangeParam { EndTimeUsecs = RestApiCommon.ConvertDateTimeToUsecs(System.DateTime.Now), Environment = Model.RestorePointsForTimeRangeParam.EnvironmentEnum.KSQL, JobUids = new List <Model.UniversalId>(), ProtectionSourceId = sourceId, StartTimeUsecs = startTimeInUsec }; pointsInTimeRange.JobUids.Add(job.Uid); var pointsForTimeRangeUrl = $"/public/restore/pointsForTimeRange"; var timeRangeResult = Session.ApiClient.Post <Model.RestorePointsForTimeRange>(pointsForTimeRangeUrl, pointsInTimeRange); bool foundPointInTime = false; if (null != timeRangeResult.TimeRanges) { foreach (var item in timeRangeResult.TimeRanges) { var restoreTimeUsecs = restoreTimeSecs * 1000 * 1000; if (item.StartTimeUsecs < restoreTimeUsecs && restoreTimeUsecs < item.EndTimeUsecs) { foundPointInTime = true; break; } } } return(foundPointInTime); }
protected override void ProcessRecord() { if (string.IsNullOrWhiteSpace(Timezone)) { Timezone = TimeZoneInfoExtensions.GetOlsonTimeZone(); } if (!string.IsNullOrWhiteSpace(PolicyName)) { var policy = RestApiCommon.GetPolicyByName(Session.ApiClient, PolicyName); PolicyId = policy.Id; } if (!string.IsNullOrWhiteSpace(StorageDomainName)) { var domain = RestApiCommon.GetStorageDomainByName(Session.ApiClient, StorageDomainName); StorageDomainId = (long)domain.Id; } var newProtectionJob = new Model.ProtectionJob(name: Name, policyId: PolicyId, viewBoxId: StorageDomainId) { Timezone = Timezone, StartTime = new TimeOfDay(ScheduleStartTime.Hour, ScheduleStartTime.Minute) }; if (ParentSourceId.HasValue) { newProtectionJob.ParentSourceId = ParentSourceId; } if (SourceIds != null && SourceIds.Any()) { newProtectionJob.SourceIds = SourceIds.ToList(); } if (ExcludeSourceIds != null && ExcludeSourceIds.Any()) { newProtectionJob.ExcludeSourceIds = ExcludeSourceIds.ToList(); } if (VmTagIds != null && VmTagIds.Any()) { var vmTagIdsList = VmTagIds.ToList(); newProtectionJob.VmTagIds = new List <List <long> >(); foreach (var vmTagIds in vmTagIdsList) { newProtectionJob.VmTagIds.Add(new List <long> { vmTagIds }); } } if (ExcludeVmTagIds != null && ExcludeVmTagIds.Any()) { var excludeVmTagIdsList = ExcludeVmTagIds.ToList(); newProtectionJob.ExcludeVmTagIds = new List <List <long> >(); foreach (var excludeVmTagIds in excludeVmTagIdsList) { newProtectionJob.ExcludeVmTagIds.Add(new List <long> { excludeVmTagIds }); } } if (!string.IsNullOrWhiteSpace(ViewName)) { newProtectionJob.ViewName = ViewName; } newProtectionJob.Environment = Environment != null ? Environment : Model.ProtectionJob.EnvironmentEnum.KView; if (FullSLATimeInMinutes != null) { newProtectionJob.FullProtectionSlaTimeMins = FullSLATimeInMinutes; } if (IncrementalSLATimeInMinutes != null) { newProtectionJob.IncrementalProtectionSlaTimeMins = IncrementalSLATimeInMinutes; } if (SourceSpecialParameters != null && SourceSpecialParameters.Any()) { newProtectionJob.SourceSpecialParameters = SourceSpecialParameters.ToList(); } var preparedUrl = $"/public/protectionJobs"; var result = Session.ApiClient.Post <Model.ProtectionJob>(preparedUrl, newProtectionJob); WriteObject(result); }
/// <summary> /// Process Record /// </summary> protected override void ProcessRecord() { Model.ProtectionJob currentProtectionjob = null; if (!string.IsNullOrWhiteSpace(Name)) { var job = RestApiCommon.GetProtectionJobByName(Session.ApiClient, Name); Id = (long)job.Id; currentProtectionjob = job; } if (JobRunId == null) { var job = RestApiCommon.GetProtectionJobById(Session.ApiClient, Id); JobRunId = (long)job.LastRun.BackupRun.JobRunId; currentProtectionjob = job; } UniversalId copyTaskUid = null; CopyRun copyRun = null; if (StopArchivalJob) { copyRun = currentProtectionjob.LastRun.CopyRun.Find(x => x.Target.Type == SnapshotTargetSettings.TypeEnum.KArchival); if (null == copyRun) { WriteObject("Could not find the archival task."); return; } } if (StopCloudSpinJob) { copyRun = currentProtectionjob.LastRun.CopyRun.Find(x => x.Target.Type == SnapshotTargetSettings.TypeEnum.KCloudDeploy); if (null == copyRun) { WriteObject("Could not find the cloud deploy task."); return; } } if (StopReplicationJob) { copyRun = currentProtectionjob.LastRun.CopyRun.Find(x => x.Target.Type == SnapshotTargetSettings.TypeEnum.KRemote); if (null == copyRun) { WriteObject("Could not find the replication task."); return; } } object body; if (null != copyRun) { copyTaskUid = copyRun.TaskUid; // When the non-local job is being stopped body = new CancelProtectionJobRunParam { // The copy task uid and job id would be used for Archival, Cloud spin and Remote targets CopyTaskUid = copyTaskUid, }; } else { // When the local job is being stopped body = new CancelProtectionJobRunParam { JobRunId = this.JobRunId }; } var url = $"/public/protectionRuns/cancel/{Id.ToString()}"; Session.ApiClient.Post(url, body); WriteObject("Protection Job Run cancelled."); }