Skip to content

Adit branch #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ internal static class AzureBackupCmdletHelpMessage
public const string ContainerId = "The container ID.";
public const string ContainerRegistrationStatus = "The container registration status.";
public const string ContainerType = "The container type.";

public const string JobFilterJobIdHelpMessage = "The job ID to filter jobs";
public const string JobFilterJobHelpMessage = "The job for filtering";
public const string JobFilterStartTimeHelpMessage = "The start time of query range";
public const string JobFilterEndTimeHelpMessage = "The end time of query range";
public const string JobFilterOperationHelpMessage = "The operation for filtering jos";
public const string JobFilterStatusHelpMessage = "The status for filtering jobs";
public const string JobFitlerVaultHelpMessage = "The vault of which jobs have to be filtered";
public const string JobFilterTypeHelpMessage = "The type of workload whose jobs have to be filtered";

public const string JobDetailsFilterJobIdHelpMessage = "The job ID to get details";
public const string JobDetailsFilterVaultHelpMessage = "The vault of which job details should be fetched";
public const string JobDetailsFilterJobHelpMessage = "The job whose full details should be fetched";

public const string StopJobFilterJobIdHelpMessage = "The job ID to stop job";
public const string StopJobFilterVaultHelpMessage = "The vault of which a job has to be stopped";
public const string StopJobFilterJobHelpMessage = "The job which should be stopped";

public const string WaitJobFilterJobIdHelpMessage = "The job ID to stop job";
public const string WaitJobFilterVaultHelpMessage = "The vault of which a job has to be stopped";
public const string WaitJobFilterJobHelpMessage = "The job which should be stopped";
public const string WaitJobFilterTimeoutHelpMessage = "Maximum number of seconds for which cmdlet should wait before job(s) complete running.";

public const string ContainerResourceGroupName = "The container resource group name.";
public const string ProtectionStatus = "Protection Status of the azure backup item.";
public const string AzureBackUpItem = "Azure BackUp Item.";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using System.Collections.Generic;
using System.Xml;
using System.Linq;
using Mgmt = Microsoft.Azure.Management.BackupServices.Models;


namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
public enum JobStatus
{
Invalid = 0,

InProgress,

Completed,

Failed,

CompletedWithWarnings,

Cancelled,

Cancelling
}

public enum JobOperationType
{
Invalid = 0,

Register,

ConfigureBackup,

Backup,

Restore,

UnProtect,

DeleteBackupData,

Unregister
}

public static class AzureBackupJobHelper
{
public static bool IsValidStatus(string inputStatus)
{
JobStatus status;
if(!Enum.TryParse<JobStatus>(inputStatus, out status) || status == JobStatus.Invalid)
{
return false;
}
return true;
}

public static bool IsValidOperationType(string inputOperationType)
{
JobOperationType operationType;
if(!Enum.TryParse<JobOperationType>(inputOperationType, out operationType) || operationType == JobOperationType.Invalid)
{
return false;
}
return true;
}

public static bool IsJobRunning(string status)
{
return ((status.CompareTo("InProgress") == 0) || (status.CompareTo("Cancelling") == 0));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,137 @@
using System.Management.Automation;
using System.Collections.Generic;
using System.Xml;
using System.Linq;
using System.Web;
using Microsoft.Azure.Management.BackupServices;
using Mgmt = Microsoft.Azure.Management.BackupServices.Models;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
/// <summary>
/// Get list of containers
/// Get list of jobs pertaining to the filters specified. Gets list of all jobs created in the last 24 hours if no filters are specified.
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureBackupJob"), OutputType(typeof(string))]
public class GetAzureBackupJob : AzureBackupCmdletBase
[Cmdlet(VerbsCommon.Get, "AzureBackupJob"), OutputType(typeof(List<Mgmt.Job>), typeof(Mgmt.Job))]
public class GetAzureBackupJob : AzureBackupVaultCmdletBase
{
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterJobIdHelpMessage)]
[ValidateNotNullOrEmpty]
public string JobId { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterJobHelpMessage)]
[ValidateNotNull]
public AzureBackupJob Job { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterStartTimeHelpMessage)]
[ValidateNotNull]
public DateTime? StartTime { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterEndTimeHelpMessage)]
[ValidateNotNull]
public DateTime? EndTime { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterStatusHelpMessage)]
[ValidateSet("Cancelled", "Cancelling", "Completed", "CompletedWithWarnings", "Failed", "InProgress")]
public string Status { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterTypeHelpMessage)]
[ValidateSet("VM")]
public string Type { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterOperationHelpMessage)]
[ValidateSet("Backup", "ConfigureBackup", "DeleteBackupData", "Register", "Restore", "UnProtect", "Unregister")]
public string Operation { get; set; }

public override void ExecuteCmdlet()
{
if (Job != null)
{
this.ResourceGroupName = Job.ResourceGroupName;
this.ResourceName = Job.ResourceName;
}

base.ExecuteCmdlet();

ExecutionBlock(() =>
{
//if (Job != null && JobId != null)
//{
// throw new Exception("Please use either JobID filter or Job filter but not both.");
//}

if (Job != null)
{
JobId = Job.InstanceId;
}

// validations
if (!StartTime.HasValue)
{
WriteDebug("Setting StartTime to min value.");
StartTime = new DateTime();
StartTime = DateTime.MinValue;
}

if (EndTime.HasValue && EndTime.Value <= StartTime.Value)
{
throw new Exception("StartTime should be greater than EndTime.");
}
else
{
if (StartTime != DateTime.MinValue)
{
WriteDebug("End time not set. Setting it to current time.");
EndTime = DateTime.Now;
}
else
{
WriteDebug("Setting EndTime to min value.");
EndTime = new DateTime();
EndTime = DateTime.MinValue;
}
}

StartTime = TimeZoneInfo.ConvertTimeToUtc(StartTime.Value);
EndTime = TimeZoneInfo.ConvertTimeToUtc(EndTime.Value);

// if user hasn't specified any filters, then default filter fetches
// all jobs that were created in last 24 hours.
if (StartTime == DateTime.MinValue && EndTime == DateTime.MinValue &&
Operation == string.Empty && Status == string.Empty &&
Type == string.Empty && JobId == string.Empty)
{
StartTime = DateTime.UtcNow.AddDays(-1);
EndTime = DateTime.UtcNow;
}

WriteDebug("StartTime filter is: " + System.Uri.EscapeDataString(StartTime.Value.ToString("yyyy-MM-dd hh:mm:ss tt")));
WriteDebug("EndTime filter is: " + System.Uri.EscapeDataString(EndTime.Value.ToString("yyyy-MM-dd hh:mm:ss tt")));
WriteDebug("Operation filter is: " + Operation);
WriteDebug("Status filter is: " + Status);
WriteDebug("Type filter is: " + Type);
WriteDebug("JobID filter is: " + JobId);

JobQueryParameter queryParams = new JobQueryParameter()
{
StartTime = StartTime.Value.ToString("yyyy-MM-dd hh:mm:ss tt"),
EndTime = EndTime.Value.ToString("yyyy-MM-dd hh:mm:ss tt"),
Operation = Operation,
Status = Status,
Type = Type,
JobId = JobId
};

Mgmt.JobListResponse jobsList = AzureBackupClient.Job.ListAsync(queryParams, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
List<AzureBackupJob> retrievedJobs = new List<AzureBackupJob>();

foreach (Mgmt.Job serviceJob in jobsList.Jobs)
{
retrievedJobs.Add(new AzureBackupJob(serviceJob, ResourceGroupName, ResourceName, Location));
}

WriteDebug("Successfully retrieved all jobs. Number of jobs retrieved: " + retrievedJobs.Count());
WriteObject(retrievedJobs);
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Management.Automation;
using System.Collections.Generic;
using System.Xml;
using System.Linq;
using Mgmt = Microsoft.Azure.Management.BackupServices.Models;

namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
{
/// <summary>
/// Get full details of a job
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureBackupJobDetails"), OutputType(typeof(Mgmt.JobProperties))]
public class GetAzureBackupJobDetils : AzureBackupVaultCmdletBase
{
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobDetailsFilterJobIdHelpMessage)]
[ValidateNotNullOrEmpty]
public string JobID { get; set; }

[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobDetailsFilterJobHelpMessage)]
[ValidateNotNull]
public AzureBackupJob Job { get; set; }

public override void ExecuteCmdlet()
{
if (Job != null)
{
this.ResourceGroupName = Job.ResourceGroupName;
this.ResourceName = Job.ResourceName;
}

base.ExecuteCmdlet();

ExecutionBlock(() =>
{
//if (Job != null && JobID != null)
//{
// throw new Exception("Please use either JobID filter or Job filter but not both.");
//}

if (Job != null)
{
JobID = Job.InstanceId;
}

WriteDebug("JobID filter is: " + JobID);

Mgmt.JobProperties serviceJobProperties = AzureBackupClient.Job.GetAsync(JobID, GetCustomRequestHeaders(), CmdletCancellationToken).Result.Job;
AzureBackupJobDetails jobDetails = new AzureBackupJobDetails(serviceJobProperties, ResourceGroupName, ResourceName, Location);

WriteDebug("Retrieved JobDetails from service.");
WriteObject(jobDetails);
});
}
}
}
Loading