/// <summary> /// Helper function to convert ps backup job model from service response. /// </summary> public static CmdletModel.JobBase GetPSJob(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(AzureIaaSVMJob)) { response = GetPSAzureVmJob(serviceClientJob); } else if (serviceClientJob.Properties.GetType() == typeof(AzureStorageJob)) { response = GetPSAzureFileShareJob(serviceClientJob); } else if (serviceClientJob.Properties.GetType() == typeof(AzureWorkloadJob)) { response = GetPSAzureWorkloadJob(serviceClientJob); } else if (serviceClientJob.Properties.GetType() == typeof(MabJob)) { response = GetPSMabJob(serviceClientJob); } else if (serviceClientJob.Properties.GetType() == typeof(VaultJob)) { response = GetPSAzureVaultJob(serviceClientJob); } return(response); }
/// <summary> /// This method cancels the specified job. /// </summary> private static void CancelJob() { string resourceGroupName = "<resource-group-name>"; string jobName = "<job-name>"; string reason = "<reason>"; // Initializes a new instance of the DataBoxManagementClient class. DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (jobResource.IsCancellable != null && (bool)jobResource.IsCancellable) { CancellationReason cancellationReason = new CancellationReason(reason); // Initiate cancel job JobsOperationsExtensions.Cancel( dataBoxManagementClient.Jobs, resourceGroupName, jobName, cancellationReason); } }
/// <summary> /// This method gets shipping label sas uri for the specified job. /// </summary> private static void GetShippingLableUri() { string resourceGroupName = "<resource-group-name>"; string jobName = "<job-name>"; // Initializes a new instance of the DataBoxManagementClient class. DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (jobResource.Status == StageName.Delivered) { // Initiate cancel job ShippingLabelDetails shippingLabelDetails = JobsOperationsExtensions.DownloadShippingLabelUri( dataBoxManagementClient.Jobs, resourceGroupName, jobName); Console.WriteLine("Shipping address sas url: \n{0}", shippingLabelDetails.ShippingLabelSasUri); } else { Console.WriteLine("Shipment address will be available only when the job is in delivered stage."); } }
public void JobExists() { string api = UrlFormatter.AddNameToRoot(EmployeeCreator.JobApi, EmployeeCreator.JobName); JobResource payPolicies = _Client.Get <JobResource>(api).Result; Assert.AreEqual(EmployeeCreator.JobName, payPolicies.Name); Assert.AreNotEqual(0, payPolicies.ID); }
public PSDataBoxJob(JobResource jobResource) { if (jobResource == null) { throw new ArgumentNullException("jobResource"); } this.JobResource = jobResource; this.ResourceGroup = ResourceIdHandler.GetResourceGroupName(jobResource.Id); this.Id = jobResource.Id; }
/// <summary> /// Gets information about the specified job. /// </summary> private static void GetJob() { string resourceGroupName = "<resource-group-name>"; string jobName = "<job-name>"; string expand = "details"; //Initializes a new instance of the DataBoxManagementClient class DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get(dataBoxManagementClient.Jobs, resourceGroupName, jobName, expand); }
/// <summary> /// This method gets the unencrypted secrets related to the job. /// </summary> private static void GetSecrets() { string resourceGroupName = "<resource-group-name>"; string jobName = "<job-name>"; // Initializes a new instance of the DataBoxManagementClient class DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (jobResource.Status != null && (int)jobResource.Status >= (int)StageName.Delivered && (int)jobResource.Status <= (int)StageName.DataCopy) { // Fetches the list of unencrypted secrets UnencryptedSecrets secrets = ListSecretsOperationsExtensions.ListByJobs( dataBoxManagementClient.ListSecrets, resourceGroupName, jobName); PodJobSecrets podSecret = (PodJobSecrets)secrets.JobSecrets; if (podSecret.PodSecrets != null) { Console.WriteLine("Azure Databox device credentails"); foreach (PodSecret accountCredentials in podSecret.PodSecrets) { Console.WriteLine(" Device serial number: {0}", accountCredentials.DeviceSerialNumber); Console.WriteLine(" Device password: {0}", accountCredentials.DevicePassword); foreach (AccountCredentialDetails accountCredentialDetails in accountCredentials.AccountCredentialDetails) { Console.WriteLine(" Account name: {0}", accountCredentialDetails.AccountName); foreach (ShareCredentialDetails shareCredentialDetails in accountCredentialDetails.ShareCredentialDetails) { Console.WriteLine(" Share name: {0}", shareCredentialDetails.ShareName); Console.WriteLine(" User name: {0}", shareCredentialDetails.UserName); Console.WriteLine(" Password: {0}{1}", shareCredentialDetails.Password, Environment.NewLine); } } Console.WriteLine(); } Console.ReadLine(); } } }
/// <summary> /// Helper function to convert ps azure vm backup policy job from service response. /// </summary> private static CmdletModel.VaultJob GetPSAzureVaultJob(JobResource serviceClientJob) { CmdletModel.VaultJob response; VaultJob vaultJob = serviceClientJob.Properties as VaultJob; if (vaultJob.ExtendedInfo != null) { response = new CmdletModel.VaultJobDetails(); } else { response = new CmdletModel.VaultJob(); } response.JobId = GetLastIdFromFullId(serviceClientJob.Id); response.StartTime = GetJobStartTime(vaultJob.StartTime); response.EndTime = vaultJob.EndTime; response.Duration = GetJobDuration(vaultJob.Duration); response.Status = vaultJob.Status; response.WorkloadName = vaultJob.EntityFriendlyName; response.ActivityId = vaultJob.ActivityId; response.BackupManagementType = CmdletModel.ConversionUtils.GetPsBackupManagementType(vaultJob.BackupManagementType); response.Operation = vaultJob.Operation; if (vaultJob.ErrorDetails != null) { response.ErrorDetails = new List <CmdletModel.AzureJobErrorInfo>(); foreach (var vaultError in vaultJob.ErrorDetails) { response.ErrorDetails.Add(GetPSVaultErrorInfo(vaultError)); } } if (vaultJob.ExtendedInfo != null) { CmdletModel.VaultJobDetails detailedResponse = response as CmdletModel.VaultJobDetails; if (vaultJob.ExtendedInfo.PropertyBag != null) { detailedResponse.Properties = new Dictionary <string, string>(); foreach (var key in vaultJob.ExtendedInfo.PropertyBag.Keys) { detailedResponse.Properties.Add(key, vaultJob.ExtendedInfo.PropertyBag[key]); } } } return(response); }
public void DevicePasswordTest() { var resourceGroupName = TestUtilities.GenerateName("SdkRg"); var jobName = TestUtilities.GenerateName("SdkJob"); //var jobName = "SdkJob5929"; ContactDetails contactDetails = GetDefaultContactDetails(); ShippingAddress shippingAddress = GetDefaultShippingAddress(); Sku sku = GetDefaultSku(); var destinationAccountsList = new List <StorageAccountDetails> { new StorageAccountDetails { StorageAccountId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/databoxbvt1/providers/Microsoft.Storage/storageAccounts/databoxbvttestaccount2" } }; destinationAccountsList[0].SharePassword = "******"; JobDetails jobDetails = new DataBoxJobDetails { ContactDetails = contactDetails, ShippingAddress = shippingAddress, DevicePassword = "******" }; jobDetails.DataImportDetails = new List <DataImportDetails>(); jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault())); var jobResource = new JobResource { Sku = sku, Location = TestConstants.DefaultResourceLocation, Details = jobDetails, }; this.RMClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = TestConstants.DefaultResourceLocation }); var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource); var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, job); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, job.Status); }
public void TestDeleteResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.NoContent, "null" )); var response = JobResource.Delete("JSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }
public void TestFetchResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"start_day\": \"start_day\",\"job_sid\": \"JSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"url\": \"https://preview.twilio.com/BulkExports/Exports/Jobs/JSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"friendly_name\": \"friendly_name\",\"end_day\": \"end_day\",\"details\": {},\"resource_type\": \"resource_type\"}" )); var response = JobResource.Fetch("JSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.NotNull(response); }
protected static void ValidateJobWithoutDetails(string jobName, Sku sku, JobResource job, bool cancellableCheck = true) { Assert.NotNull(job); job.Validate(); Assert.NotNull(job.Id); Assert.NotNull(job.Type); Assert.Equal(cancellableCheck, job.IsCancellable); Assert.Equal(cancellableCheck, job.IsShippingAddressEditable); Assert.NotNull(job.Sku); Assert.NotNull(job.StartTime); Assert.Equal(sku.Name, job.Sku.Name); Assert.Equal(TestConstants.DefaultResourceLocation, job.Location); Assert.Equal(jobName, job.Name); Assert.Equal(TestConstants.DefaultType, job.Type); }
public void TestDeleteRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Delete, Twilio.Rest.Domain.Preview, "/BulkExports/Exports/Jobs/JSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "" ); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { JobResource.Delete("JSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
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)); } }); }
/// <summary> /// This method provides list of copy logs uri. /// </summary> private static void GetCopyLogsUri() { string resourceGroupName = "<resource-group-name>"; string jobName = "<job-name>"; // Initializes a new instance of the DataBoxManagementClient class DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (jobResource.Status == StageName.DataCopy || jobResource.Status == StageName.Completed || jobResource.Status == StageName.CompletedWithErrors) { // Fetches the Copy log details GetCopyLogsUriOutput getCopyLogsUriOutput = JobsOperationsExtensions.GetCopyLogsUri( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (getCopyLogsUriOutput.CopyLogDetails != null) { Console.WriteLine("Copy log details"); foreach (AccountCopyLogDetails copyLogitem in getCopyLogsUriOutput.CopyLogDetails) { Console.WriteLine(string.Concat(" Account name: ", copyLogitem.AccountName, Environment.NewLine, " Copy log link: ", copyLogitem.CopyLogLink, Environment.NewLine, Environment.NewLine)); } } } else { Console.WriteLine("Copy logs will be available only when the job is in either data copy or completed status."); } }
/// <summary> /// This method initiates a shipment pickup. /// </summary> private static void BookShipmentPickup() { string resourceGroupName = "<resoruce-group-name>"; string jobName = "<job-name>"; DateTime dtStartTime = new DateTime(); DateTime dtEndTime = new DateTime(); string shipmentLocation = "<shipment-location>"; ShipmentPickUpRequest shipmentPickUpRequest = new ShipmentPickUpRequest(dtStartTime, dtEndTime, shipmentLocation); // Initializes a new instance of the DataBoxManagementClient class DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (jobResource.Status == StageName.Delivered) { // Initiate Book shipment pick up ShipmentPickUpResponse shipmentPickUpResponse = JobsOperationsExtensions.BookShipmentPickUp( dataBoxManagementClient.Jobs, resourceGroupName, jobName, shipmentPickUpRequest); Console.WriteLine("Confirmation number: {0}", shipmentPickUpResponse.ConfirmationNumber); } else { Console.WriteLine("Shipment pickup will be initiated only when the job is in delivered stage."); } }
/// <summary> /// This method deletes the specified job. /// </summary> private static void DeleteJob() { string resourceGroupName = "<resource-group-name>"; string jobName = "<job-name>"; // Initializes a new instance of the DataBoxManagementClient class. DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); // Gets information about the specified job. JobResource jobResource = JobsOperationsExtensions.Get( dataBoxManagementClient.Jobs, resourceGroupName, jobName); if (jobResource.Status == StageName.Cancelled || jobResource.Status == StageName.Completed || jobResource.Status == StageName.CompletedWithErrors) { // Initiate delete job JobsOperationsExtensions.Delete(dataBoxManagementClient.Jobs, resourceGroupName, jobName); } }
public PSDataBoxJob() { JobResource = new JobResource(); }
/// <summary> /// Creates the powershell MabJob object from service response. /// </summary> private static CmdletModel.JobBase GetPSMabJob(JobResource serviceClientJob) { CmdletModel.MabJob response; MabJob mabJob = serviceClientJob.Properties as 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(GetPSMabErrorInfo(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); }
/// <summary> /// Creates a new job with the specified parameters. /// </summary> private static void CreateJob() { AddressType addressType = AddressType.None; string streetAddress1 = "<street-address-1>"; string streetAddress2 = "<street-address-2>"; string streetAddress3 = "<street-address-3>"; string postalCode = "<postal-code>"; string city = "<city>"; string stateOrProvince = "<state-or-province>"; CountryCode countryCode = CountryCode.US; ShippingAddress shippingAddress = new ShippingAddress() { StreetAddress1 = streetAddress1, StreetAddress2 = streetAddress2, StreetAddress3 = streetAddress3, AddressType = addressType, Country = countryCode.ToString(), PostalCode = postalCode, City = city, StateOrProvince = stateOrProvince, }; string emailIds = "<email-ids>"; // Input a semicolon (;) separated string of email ids, eg. "[email protected];[email protected]" string phoneNumber = "<phone-number>"; string contactName = "<contact-name>"; List <string> emailIdList = new List <string>(); emailIdList = emailIds.Split(new char[';'], StringSplitOptions.RemoveEmptyEntries).ToList(); ContactDetails contactDetails = new ContactDetails() { Phone = phoneNumber, EmailList = emailIdList, ContactName = contactName }; string storageAccProviderType = "Microsoft.Storage"; // Input the storage account provider type; Valid types: Microsoft.Storage / Microsoft.ClassicStorage string storageAccResourceGroupName = "<storage-account-resource-group-name>"; string storageAccName = "<storage-account-name>"; AccountType accountType = "<account-type>"; // Choose account type from Storage AccountType list. eg. AccountType.GeneralPurposeStorage List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>(); destinationAccountDetails.Add( new DestinationAccountDetails( string.Concat("/subscriptions/", subscriptionId, "/resourceGroups/", storageAccResourceGroupName, "/providers/", storageAccProviderType, "/storageAccounts/", storageAccName.ToLower()), accountType)); // Note. // For multiple destination storage accounts, follow above steps to add more than one account. // The storage accounts should be in the same Azure DataBox order's subscription and location (region). PodJobDetails jobDetails = new PodJobDetails(contactDetails, shippingAddress); string resourceGroupName = "<resource-group-name>"; string location = "<location>"; string jobName = "<job-or-order-name>"; JobResource newJobResource = new JobResource(location, destinationAccountDetails, jobDetails); newJobResource.DeviceType = DeviceType.Pod; // Initializes a new instance of the DataBoxManagementClient class. DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); dataBoxManagementClient.Location = location; // Validate shipping address AddressValidationOutput addressValidateResult = ServiceOperationsExtensions.ValidateAddressMethod( dataBoxManagementClient.Service, new ValidateAddress( shippingAddress, newJobResource.DeviceType)); // Verify shipping address validation status CheckShippingAddressValidationResult(addressValidateResult); // Creates a new job. if (addressValidateResult.ValidationStatus == AddressValidationStatus.Valid) { JobResource jobResource = JobsOperationsExtensions.Create( dataBoxManagementClient.Jobs, resourceGroupName, jobName, newJobResource); } }
public override void ExecuteCmdlet() { if (DataBoxType == "DataBoxDisk" && ExpectedDataSizeInTeraBytes.Equals(0)) { throw new PSArgumentNullException("ExpectedDataSizeInTeraBytes"); } ShippingAddress shippingAddress = new ShippingAddress() { AddressType = this.AddressType, CompanyName = this.CompanyName, StreetAddress1 = this.StreetAddress1, StreetAddress2 = this.StreetAddress2, StreetAddress3 = this.StreetAddress3, City = this.City, StateOrProvince = this.StateOrProvinceCode, Country = this.CountryCode, PostalCode = this.PostalCode }; ContactDetails contactDetails = new ContactDetails() { Phone = this.PhoneNumber, EmailList = EmailId, ContactName = this.ContactName }; List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>(); foreach (var storageAccount in StorageAccountResourceId) { destinationAccountDetails.Add( new DestinationAccountDetails(storageAccount)); } DataBoxDiskJobDetails diskDetails; DataBoxJobDetails databoxDetails; DataBoxHeavyJobDetails heavyDetails; JobResource newJobResource = new JobResource(); Sku sku = new Sku(); switch (DataBoxType) { case "DataBoxDisk": diskDetails = new DataBoxDiskJobDetails(contactDetails, shippingAddress, destinationAccountDetails, expectedDataSizeInTeraBytes: ExpectedDataSizeInTeraBytes); sku.Name = SkuName.DataBoxDisk; newJobResource = new JobResource(Location, sku, details: diskDetails); break; case "DataBox": databoxDetails = new DataBoxJobDetails(contactDetails, shippingAddress, destinationAccountDetails); sku.Name = SkuName.DataBox; newJobResource = new JobResource(Location, sku, details: databoxDetails); break; case "DataBoxHeavy": heavyDetails = new DataBoxHeavyJobDetails(contactDetails, shippingAddress, destinationAccountDetails); sku.Name = SkuName.DataBoxHeavy; newJobResource = new JobResource(Location, sku, details: heavyDetails); break; default: break; } AddressValidationOutput addressValidationResult = ServiceOperationsExtensions.ValidateAddressMethod( DataBoxManagementClient.Service, Location, shippingAddress, newJobResource.Sku.Name); if (addressValidationResult.ValidationStatus != AddressValidationStatus.Valid) { WriteVerbose(Resource.AddressValidationStatus + addressValidationResult.ValidationStatus + "\n"); //print alternate address if (addressValidationResult.ValidationStatus == AddressValidationStatus.Ambiguous) { WriteVerbose(Resource.SupportAddresses + "\n\n"); foreach (ShippingAddress address in addressValidationResult.AlternateAddresses) { WriteVerbose(Resource.AddressType + address.AddressType + "\n"); if (!(string.IsNullOrEmpty(address.CompanyName))) { WriteVerbose(Resource.CompanyName + address.CompanyName); } if (!(string.IsNullOrEmpty(address.StreetAddress1))) { WriteVerbose(Resource.StreetAddress1 + address.StreetAddress1); } if (!(string.IsNullOrEmpty(address.StreetAddress2))) { WriteVerbose(Resource.StreetAddress2 + address.StreetAddress2); } if (!(string.IsNullOrEmpty(address.StreetAddress3))) { WriteVerbose(Resource.StreetAddress3 + address.StreetAddress3); } if (!(string.IsNullOrEmpty(address.City))) { WriteVerbose(Resource.City + address.City); } if (!(string.IsNullOrEmpty(address.StateOrProvince))) { WriteVerbose(Resource.StateOrProvince + address.StateOrProvince); } if (!(string.IsNullOrEmpty(address.Country))) { WriteVerbose(Resource.Country + address.Country); } if (!(string.IsNullOrEmpty(address.PostalCode))) { WriteVerbose(Resource.PostalCode + address.PostalCode); } if (!(string.IsNullOrEmpty(address.ZipExtendedCode))) { WriteVerbose(Resource.ZipExtendedCode + address.ZipExtendedCode); } WriteVerbose("\n\n"); } throw new PSNotSupportedException(Resource.AmbiguousAddressMessage); } throw new PSNotSupportedException(Resource.InvalidAddressMessage); } if (ShouldProcess(this.Name, string.Format(Resource.CreatingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName))) { JobResource finalJobResource = JobsOperationsExtensions.Create( DataBoxManagementClient.Jobs, ResourceGroupName, Name, newJobResource); WriteObject(new PSDataBoxJob(finalJobResource)); } }
public void DoubleEncryptionTest() { var resourceGroupName = TestUtilities.GenerateName("SdkRg"); var jobName = TestUtilities.GenerateName("SdkJob"); ContactDetails contactDetails = GetDefaultContactDetails(); ShippingAddress shippingAddress = GetDefaultShippingAddress(); Preferences preferences = new Preferences { EncryptionPreferences = new EncryptionPreferences { DoubleEncryption = DoubleEncryption.Enabled } }; Sku sku = GetDefaultSku(); var destinationAccountsList = GetDestinationAccountsList(); JobDetails jobDetails = new DataBoxJobDetails { ContactDetails = contactDetails, ShippingAddress = shippingAddress, Preferences = preferences }; jobDetails.DataImportDetails = new List <DataImportDetails>(); jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault())); var jobResource = new JobResource { Sku = sku, Location = TestConstants.DefaultResourceLocation, Details = jobDetails }; this.RMClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = TestConstants.DefaultResourceLocation }); var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource); ValidateJobWithoutDetails(jobName, sku, job); Assert.Equal(StageName.DeviceOrdered, job.Status); var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, job.Status); Assert.Equal(DoubleEncryption.Enabled, getJob.Details.Preferences.EncryptionPreferences.DoubleEncryption); contactDetails.ContactName = "Update Job"; getJob.Details.ContactDetails = contactDetails; var Details = new UpdateJobDetails { ContactDetails = getJob.Details.ContactDetails, ShippingAddress = getJob.Details.ShippingAddress }; var updateParams = new JobResourceUpdateParameter { Details = Details }; var updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams); ValidateJobWithoutDetails(jobName, sku, updateJob); Assert.Equal(StageName.DeviceOrdered, updateJob.Status); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, getJob.Status); var jobList = this.Client.Jobs.List(); Assert.NotNull(jobList); jobList = this.Client.Jobs.ListByResourceGroup(resourceGroupName); Assert.NotNull(jobList); this.Client.Jobs.Cancel(resourceGroupName, jobName, "CancelTest"); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); Assert.Equal(StageName.Cancelled, getJob.Status); while (!string.IsNullOrWhiteSpace(getJob.Details.ContactDetails.ContactName)) { Wait(TimeSpan.FromMinutes(5)); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); } this.Client.Jobs.Delete(resourceGroupName, jobName); }
public void TestExportJobCRUDOperations() { var resourceGroupName = TestUtilities.GenerateName("SdkRg"); var jobName = TestUtilities.GenerateName("SdkJob"); ContactDetails contactDetails = GetDefaultContactDetails(); ShippingAddress shippingAddress = GetDefaultShippingAddress(); Sku sku = GetDefaultSku(); var sourceAccountsList = GetSourceAccountsList(); JobDetails jobDetails = new DataBoxJobDetails { ContactDetails = contactDetails, ShippingAddress = shippingAddress }; jobDetails.DataExportDetails = new List <DataExportDetails>(); TransferConfiguration transferCofiguration = new TransferConfiguration { TransferConfigurationType = TransferConfigurationType.TransferAll, TransferAllDetails = new TransferConfigurationTransferAllDetails { Include = new TransferAllDetails { DataAccountType = DataAccountType.StorageAccount, TransferAllBlobs = true, TransferAllFiles = true } } }; jobDetails.DataExportDetails.Add(new DataExportDetails(transferCofiguration, sourceAccountsList.FirstOrDefault())); var jobResource = new JobResource { Sku = sku, Location = TestConstants.DefaultResourceLocation, Details = jobDetails, TransferType = TransferType.ExportFromAzure }; this.RMClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = TestConstants.DefaultResourceLocation }); var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource); ValidateJobWithoutDetails(jobName, sku, job); Assert.Equal(StageName.DeviceOrdered, job.Status); var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, job.Status); contactDetails.ContactName = "Update Job"; getJob.Details.ContactDetails = contactDetails; var Details = new UpdateJobDetails { ContactDetails = getJob.Details.ContactDetails, ShippingAddress = getJob.Details.ShippingAddress }; var updateParams = new JobResourceUpdateParameter { Details = Details }; var updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams); ValidateJobWithoutDetails(jobName, sku, updateJob); Assert.Equal(StageName.DeviceOrdered, updateJob.Status); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, getJob.Status); var jobList = this.Client.Jobs.List(); Assert.NotNull(jobList); jobList = this.Client.Jobs.ListByResourceGroup(resourceGroupName); Assert.NotNull(jobList); this.Client.Jobs.Cancel(resourceGroupName, jobName, "CancelTest"); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); Assert.Equal(StageName.Cancelled, getJob.Status); while (!string.IsNullOrWhiteSpace(getJob.Details.ContactDetails.ContactName)) { Wait(TimeSpan.FromMinutes(5)); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); } this.Client.Jobs.Delete(resourceGroupName, jobName); }
public void TestJobCRUDOperations() { var resourceGroupName = TestUtilities.GenerateName("SdkRg"); var jobName = TestUtilities.GenerateName("SdkJob"); ContactDetails contactDetails = GetDefaultContactDetails(); ShippingAddress shippingAddress = GetDefaultShippingAddress(); Sku sku = GetDefaultSku(); JobDetails jobDetails = new DataBoxJobDetails { ContactDetails = contactDetails, ShippingAddress = shippingAddress, DestinationAccountDetails = GetDestinationAccountsList(), }; var jobResource = new JobResource { Sku = sku, Location = TestConstants.DefaultResourceLocation, Details = jobDetails }; this.RMClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = TestConstants.DefaultResourceLocation }); var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource); ValidateJobWithoutDetails(jobName, sku, job); Assert.Equal(StageName.DeviceOrdered, job.Status); var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob); Assert.Equal(StageName.DeviceOrdered, job.Status); contactDetails.ContactName = "Update Job"; getJob.Details.ContactDetails = contactDetails; var Details = new UpdateJobDetails { ContactDetails = getJob.Details.ContactDetails, ShippingAddress = getJob.Details.ShippingAddress }; var updateParams = new JobResourceUpdateParameter { Details = Details }; var updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams); ValidateJobWithoutDetails(jobName, sku, updateJob); Assert.Equal(StageName.DeviceOrdered, updateJob.Status); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob); Assert.Equal(StageName.DeviceOrdered, getJob.Status); var jobList = this.Client.Jobs.List(); Assert.NotNull(jobList); jobList = this.Client.Jobs.ListByResourceGroup(resourceGroupName); Assert.NotNull(jobList); this.Client.Jobs.Cancel(resourceGroupName, jobName, "CancelTest"); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); Assert.Equal(StageName.Cancelled, getJob.Status); while (!string.IsNullOrWhiteSpace(getJob.Details.ContactDetails.ContactName)) { Wait(TimeSpan.FromMinutes(5)); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); } this.Client.Jobs.Delete(resourceGroupName, jobName); }
protected static void ValidateJobDetails(ContactDetails contactDetails, ShippingAddress shippingAddress, JobResource getJob) { Assert.NotNull(getJob.Details); Assert.NotNull(getJob.Details.ContactDetails.NotificationPreference); Assert.Equal(contactDetails.ContactName, getJob.Details.ContactDetails.ContactName); Assert.Equal(contactDetails.Phone, getJob.Details.ContactDetails.Phone); Assert.Equal(contactDetails.PhoneExtension, getJob.Details.ContactDetails.PhoneExtension); Assert.Equal(contactDetails.EmailList, getJob.Details.ContactDetails.EmailList); Assert.Equal(shippingAddress.AddressType, getJob.Details.ShippingAddress.AddressType); Assert.Equal(shippingAddress.City, getJob.Details.ShippingAddress.City); Assert.Equal(shippingAddress.CompanyName, getJob.Details.ShippingAddress.CompanyName); Assert.Equal(shippingAddress.Country, getJob.Details.ShippingAddress.Country); Assert.Equal(shippingAddress.PostalCode, getJob.Details.ShippingAddress.PostalCode); Assert.Equal(shippingAddress.StateOrProvince, getJob.Details.ShippingAddress.StateOrProvince); Assert.Equal(shippingAddress.StreetAddress1, getJob.Details.ShippingAddress.StreetAddress1); Assert.Equal(shippingAddress.StreetAddress2, getJob.Details.ShippingAddress.StreetAddress2); Assert.Equal(shippingAddress.StreetAddress3, getJob.Details.ShippingAddress.StreetAddress3); }
/// <summary> /// Creates a new job with the specified parameters. Existing job cannot be /// updated with this API and should instead be updated with the Update job /// API. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The Resource Group Name /// </param> /// <param name='jobName'> /// The name of the job Resource within the specified resource group. job names /// must be between 3 and 24 characters in length and use any alphanumeric and /// underscore only /// </param> /// <param name='jobResource'> /// Job details from request body. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <JobResource> BeginCreateAsync(this IJobsOperations operations, string resourceGroupName, string jobName, JobResource jobResource, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, jobName, jobResource, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a new job with the specified parameters. Existing job cannot be /// updated with this API and should instead be updated with the Update job /// API. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The Resource Group Name /// </param> /// <param name='jobName'> /// The name of the job Resource within the specified resource group. job names /// must be between 3 and 24 characters in length and use any alphanumeric and /// underscore only /// </param> /// <param name='jobResource'> /// Job details from request body. /// </param> public static JobResource BeginCreate(this IJobsOperations operations, string resourceGroupName, string jobName, JobResource jobResource) { return(operations.BeginCreateAsync(resourceGroupName, jobName, jobResource).GetAwaiter().GetResult()); }
/// <summary> /// Helper function to convert ps azure vm backup policy job from service response. /// </summary> private static CmdletModel.AzureVmJob GetPSAzureVmJob(JobResource serviceClientJob) { CmdletModel.AzureVmJob response; AzureIaaSVMJob vmJob = serviceClientJob.Properties as 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(GetPSAzureVmErrorInfo(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); }
public void CreateJobWithUserAssignedIdentity() { var resourceGroupName = TestUtilities.GenerateName("SdkRg"); var jobName = TestUtilities.GenerateName("SdkJob"); //var jobName = "SdkJob5929"; ContactDetails contactDetails = GetDefaultContactDetails(); ShippingAddress shippingAddress = GetDefaultShippingAddress(); Sku sku = GetDefaultSku(); var destinationAccountsList = new List <StorageAccountDetails> { new StorageAccountDetails { StorageAccountId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/databoxbvt1/providers/Microsoft.Storage/storageAccounts/databoxbvttestaccount2" } }; var uaiId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.ManagedIdentity/userAssignedIdentities/sdkIdentity"; var kekDetails = new KeyEncryptionKey(KekType.CustomerManaged) { KekType = KekType.CustomerManaged, KekUrl = @"https://sdkkeyvault.vault.azure.net/keys/SSDKEY/", KekVaultResourceID = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.KeyVault/vaults/SDKKeyVault", IdentityProperties = new IdentityProperties { Type = "UserAssigned", UserAssigned = new UserAssignedProperties { ResourceId = uaiId } } }; JobDetails jobDetails = new DataBoxJobDetails(contactDetails, default(IList <JobStages>), shippingAddress, default(PackageShippingDetails), default(PackageShippingDetails), default(IList <DataImportDetails>), default(IList <DataExportDetails>), default(Preferences), default(IList <CopyLogDetails>), default(string), default(string), kekDetails); jobDetails.DataImportDetails = new List <DataImportDetails>(); jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault())); var jobResource = new JobResource { Sku = sku, Location = TestConstants.DefaultResourceLocation, Details = jobDetails, }; UserAssignedIdentity uid = new UserAssignedIdentity(); var identity = new ResourceIdentity//ResourceIdentity checked by auto mapper { Type = "UserAssigned", UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { uaiId, uid } }, }; jobResource.Identity = identity; this.RMClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = TestConstants.DefaultResourceLocation }); var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource); ValidateJobWithoutDetails(jobName, sku, job); Assert.Equal(StageName.DeviceOrdered, job.Status); String iden = "UserAssigned"; Assert.Equal(iden, job.Identity.Type); var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, getJob); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, getJob.Status); Assert.True(!string.IsNullOrEmpty(getJob.Identity.UserAssignedIdentities[uaiId].ClientId)); Assert.True(!string.IsNullOrEmpty(getJob.Identity.UserAssignedIdentities[uaiId].PrincipalId)); Assert.Equal(KekType.CustomerManaged, getJob.Details.KeyEncryptionKey.KekType); }
public void UpdateSystemAssignedToUserAssigned() { var resourceGroupName = TestUtilities.GenerateName("SdkRg"); var jobName = TestUtilities.GenerateName("SdkJob"); //var jobName = "SdkJob5929"; ContactDetails contactDetails = GetDefaultContactDetails(); ShippingAddress shippingAddress = GetDefaultShippingAddress(); Sku sku = GetDefaultSku(); var destinationAccountsList = new List <StorageAccountDetails> { new StorageAccountDetails { StorageAccountId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/databoxbvt1/providers/Microsoft.Storage/storageAccounts/databoxbvttestaccount2" } }; JobDetails jobDetails = new DataBoxJobDetails { ContactDetails = contactDetails, ShippingAddress = shippingAddress }; jobDetails.DataImportDetails = new List <DataImportDetails>(); jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault())); var jobResource = new JobResource { Sku = sku, Location = TestConstants.DefaultResourceLocation, Details = jobDetails, }; this.RMClient.ResourceGroups.CreateOrUpdate( resourceGroupName, new ResourceGroup { Location = TestConstants.DefaultResourceLocation }); var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource); ValidateJobWithoutDetails(jobName, sku, job); Assert.Equal(StageName.DeviceOrdered, job.Status); // Set Msi details. string tenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47"; string identityType = "SystemAssigned"; var identity = new ResourceIdentity(identityType, Guid.NewGuid().ToString(), tenantId); var updateParams = new JobResourceUpdateParameter { Identity = identity }; var updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams); ValidateJobWithoutDetails(jobName, sku, updateJob); var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobWithoutDetails(jobName, sku, job); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, updateJob.Status); Assert.Equal(identityType, updateJob.Identity.Type); //Updating to User Assigned var uaiId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.ManagedIdentity/userAssignedIdentities/sdkIdentity"; var keyEncryptionKey = new KeyEncryptionKey(KekType.CustomerManaged) { KekUrl = @"https://sdkkeyvault.vault.azure.net/keys/SSDKEY/", KekVaultResourceID = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.KeyVault/vaults/SDKKeyVault", IdentityProperties = new IdentityProperties { Type = "UserAssigned", UserAssigned = new UserAssignedProperties { ResourceId = uaiId } } }; UserAssignedIdentity uid = new UserAssignedIdentity(); identity = new ResourceIdentity//ResourceIdentity checked by auto mapper { Type = "SystemAssigned,UserAssigned", UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity> { { uaiId, uid } }, }; var details = new UpdateJobDetails { KeyEncryptionKey = keyEncryptionKey }; updateParams = new JobResourceUpdateParameter { Details = details, Identity = identity }; updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams); ValidateJobWithoutDetails(jobName, sku, updateJob); getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details); ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled); Assert.Equal(StageName.DeviceOrdered, getJob.Status); Assert.True(!string.IsNullOrEmpty(getJob.Identity.UserAssignedIdentities[uaiId].ClientId)); Assert.True(!string.IsNullOrEmpty(getJob.Identity.UserAssignedIdentities[uaiId].PrincipalId)); }