public async Task <Response <GalleryApplicationVersion> > GetAsync(string resourceGroupName, string galleryName, string galleryApplicationName, string galleryApplicationVersionName, ReplicationStatusTypes?expand = null, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (galleryName == null)
            {
                throw new ArgumentNullException(nameof(galleryName));
            }
            if (galleryApplicationName == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationName));
            }
            if (galleryApplicationVersionName == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationVersionName));
            }

            using var message = CreateGetRequest(resourceGroupName, galleryName, galleryApplicationName, galleryApplicationVersionName, expand);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                GalleryApplicationVersion value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                value = GalleryApplicationVersion.DeserializeGalleryApplicationVersion(document.RootElement);
                return(Response.FromValue(value, message.Response));
            }
Esempio n. 2
0
        private void ValidateGalleryApplicationVersion(GalleryApplicationVersion applicationVersionIn, GalleryApplicationVersion applicationVersionOut)
        {
            Assert.False(string.IsNullOrEmpty(applicationVersionOut.ProvisioningState));

            if (applicationVersionIn.Tags != null)
            {
                foreach (KeyValuePair <string, string> kvp in applicationVersionIn.Tags)
                {
                    Assert.Equal(kvp.Value, applicationVersionOut.Tags[kvp.Key]);
                }
            }

            Assert.Equal(applicationVersionIn.Location.ToLower(), applicationVersionOut.Location.ToLower());
            Assert.False(string.IsNullOrEmpty(applicationVersionOut.PublishingProfile.Source.MediaLink),
                         "applicationVersionOut.PublishingProfile.Source.MediaLink is null or empty.");
            Assert.NotNull(applicationVersionOut.PublishingProfile.EndOfLifeDate);
            Assert.NotNull(applicationVersionOut.PublishingProfile.PublishedDate);
            Assert.NotNull(applicationVersionOut.Id);
            Assert.Equal(applicationVersionIn.PublishingProfile.Settings.PackageFileName, applicationVersionOut.PublishingProfile.Settings.PackageFileName);
            Assert.Equal(applicationVersionIn.PublishingProfile.Settings.ConfigFileName, applicationVersionOut.PublishingProfile.Settings.ConfigFileName);
            IDictionary <string, string> advancedSettingsIn  = applicationVersionIn.PublishingProfile.AdvancedSettings;
            IDictionary <string, string> advancedSettingsOut = applicationVersionOut.PublishingProfile.AdvancedSettings;

            Assert.Equal(advancedSettingsIn.Count, advancedSettingsOut.Count);
            foreach (KeyValuePair <string, string> kvp in advancedSettingsIn)
            {
                Assert.True(advancedSettingsOut.ContainsKey(kvp.Key));
                Assert.Equal(kvp.Value, advancedSettingsOut[kvp.Key]);
            }
        }
        private void ValidateGalleryApplicationVersion(GalleryApplicationVersion applicationVersionIn, GalleryApplicationVersion applicationVersionOut)
        {
            Assert.False(string.IsNullOrEmpty("properties.provisioningState"));

            if (applicationVersionIn.Tags != null)
            {
                foreach (KeyValuePair <string, string> kvp in applicationVersionIn.Tags)
                {
                    Assert.AreEqual(kvp.Value, applicationVersionOut.Tags[kvp.Key]);
                }
            }

            Assert.AreEqual(applicationVersionIn.Location.ToLower(), applicationVersionOut.Location.ToLower());
            Assert.False(string.IsNullOrEmpty(applicationVersionOut.PublishingProfile.Source.MediaLink),
                         "applicationVersionOut.PublishingProfile.Source.MediaLink is null or empty.");
            Assert.NotNull(applicationVersionOut.PublishingProfile.EndOfLifeDate);
            Assert.NotNull(applicationVersionOut.PublishingProfile.PublishedDate);
            Assert.NotNull(applicationVersionOut.Id);
        }
        public async Task GalleryApplicationVersion_CRUD_Tests()
        {
            string location = DefaultLocation;

            EnsureClientsInitialized(DefaultLocation);
            string rgName                 = Recording.GenerateAssetName(ResourceGroupPrefix);
            string applicationName        = Recording.GenerateAssetName("psTestSourceApplication");
            string galleryName            = Recording.GenerateAssetName(GalleryNamePrefix);
            string galleryApplicationName = Recording.GenerateAssetName(GalleryApplicationNamePrefix);
            string applicationMediaLink   = await CreateApplicationMediaLink(rgName, "test.txt");

            Assert.False(string.IsNullOrEmpty(applicationMediaLink));
            Trace.TraceInformation(string.Format("Created the source application media link: {0}", applicationMediaLink));

            Gallery gallery = GetTestInputGallery();

            gallery.Location = location;
            await WaitForCompletionAsync(await GalleriesOperations.StartCreateOrUpdateAsync(rgName, galleryName, gallery));

            Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName,
                                                 rgName));
            GalleryApplication inputGalleryApplication = GetTestInputGalleryApplication();

            await WaitForCompletionAsync(await GalleryApplicationsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryApplicationName, inputGalleryApplication));

            Trace.TraceInformation(string.Format("Created the gallery application: {0} in gallery: {1}", galleryApplicationName,
                                                 galleryName));

            string galleryApplicationVersionName = "1.0.0";
            GalleryApplicationVersion inputApplicationVersion = GetTestInputGalleryApplicationVersion(applicationMediaLink);

            await WaitForCompletionAsync(await GalleryApplicationVersionsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryApplicationName,
                                                                                                             galleryApplicationVersionName, inputApplicationVersion));

            Trace.TraceInformation(string.Format("Created the gallery application version: {0} in gallery application: {1}",
                                                 galleryApplicationVersionName, galleryApplicationName));

            GalleryApplicationVersion applicationVersionFromGet = await GalleryApplicationVersionsOperations.GetAsync(rgName,
                                                                                                                      galleryName, galleryApplicationName, galleryApplicationVersionName);

            Assert.NotNull(applicationVersionFromGet);
            ValidateGalleryApplicationVersion(inputApplicationVersion, applicationVersionFromGet);
            //applicationVersionFromGet = await GalleryApplicationVersionsClient.Get(rgName, galleryName, galleryApplicationName,
            //    galleryApplicationVersionName, ReplicationStatusTypes.ReplicationStatus);
            applicationVersionFromGet = await GalleryApplicationVersionsOperations.GetAsync(rgName, galleryName, galleryApplicationName,
                                                                                            galleryApplicationVersionName);

            Assert.AreEqual(StorageAccountType.StandardLRS, applicationVersionFromGet.PublishingProfile.StorageAccountType);
            Assert.AreEqual(StorageAccountType.StandardLRS,
                            applicationVersionFromGet.PublishingProfile.TargetRegions.First().StorageAccountType);
            Assert.NotNull(applicationVersionFromGet.ReplicationStatus);
            Assert.NotNull(applicationVersionFromGet.ReplicationStatus.Summary);

            inputApplicationVersion.PublishingProfile.EndOfLifeDate = Recording.UtcNow.AddDays(100);
            await WaitForCompletionAsync(await GalleryApplicationVersionsOperations.StartCreateOrUpdateAsync(rgName, galleryName, galleryApplicationName,
                                                                                                             galleryApplicationVersionName, inputApplicationVersion));

            Trace.TraceInformation(string.Format("Updated the gallery application version: {0} in gallery application: {1}",
                                                 galleryApplicationVersionName, galleryApplicationName));
            applicationVersionFromGet = await GalleryApplicationVersionsOperations.GetAsync(rgName, galleryName,
                                                                                            galleryApplicationName, galleryApplicationVersionName);

            Assert.NotNull(applicationVersionFromGet);
            ValidateGalleryApplicationVersion(inputApplicationVersion, applicationVersionFromGet);

            await WaitForCompletionAsync(await GalleryApplicationVersionsOperations.StartDeleteAsync(rgName, galleryName, galleryApplicationName, galleryApplicationVersionName));

            Trace.TraceInformation(string.Format("Deleted the gallery application version: {0} in gallery application: {1}",
                                                 galleryApplicationVersionName, galleryApplicationName));

            await WaitForCompletionAsync(await GalleryApplicationsOperations.StartDeleteAsync(rgName, galleryName, galleryApplicationName));

            Trace.TraceInformation("Deleted the gallery application.");
            await WaitForCompletionAsync(await GalleriesOperations.StartDeleteAsync(rgName, galleryName));

            Trace.TraceInformation("Deleted the gallery.");
        }
Esempio n. 5
0
        public void GalleryApplicationVersion_CRUD_Tests()
        {
            string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                string location = ComputeManagementTestUtilities.DefaultLocation;
                Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", location);
                EnsureClientsInitialized(context);
                string rgName                 = ComputeManagementTestUtilities.GenerateName(ResourceGroupPrefix);
                string applicationName        = ComputeManagementTestUtilities.GenerateName("psTestSourceApplication");
                string galleryName            = ComputeManagementTestUtilities.GenerateName(GalleryNamePrefix);
                string galleryApplicationName = ComputeManagementTestUtilities.GenerateName(GalleryApplicationNamePrefix);

                try
                {
                    string applicationMediaLink = CreateApplicationMediaLink(rgName, "test.txt");

                    Assert.False(string.IsNullOrEmpty(applicationMediaLink));
                    Trace.TraceInformation(string.Format("Created the source application media link: {0}", applicationMediaLink));

                    Gallery gallery = GetTestInputGallery();
                    gallery.Location = location;
                    m_CrpClient.Galleries.CreateOrUpdate(rgName, galleryName, gallery);
                    Trace.TraceInformation(string.Format("Created the gallery: {0} in resource group: {1}", galleryName,
                                                         rgName));
                    GalleryApplication inputGalleryApplication = GetTestInputGalleryApplication();
                    m_CrpClient.GalleryApplications.CreateOrUpdate(rgName, galleryName, galleryApplicationName, inputGalleryApplication);
                    Trace.TraceInformation(string.Format("Created the gallery application: {0} in gallery: {1}", galleryApplicationName,
                                                         galleryName));

                    string galleryApplicationVersionName = "1.0.0";
                    GalleryApplicationVersion inputApplicationVersion = GetTestInputGalleryApplicationVersion(applicationMediaLink);
                    m_CrpClient.GalleryApplicationVersions.CreateOrUpdate(rgName, galleryName, galleryApplicationName,
                                                                          galleryApplicationVersionName, inputApplicationVersion);
                    Trace.TraceInformation(string.Format("Created the gallery application version: {0} in gallery application: {1}",
                                                         galleryApplicationVersionName, galleryApplicationName));

                    GalleryApplicationVersion applicationVersionFromGet = m_CrpClient.GalleryApplicationVersions.Get(rgName,
                                                                                                                     galleryName, galleryApplicationName, galleryApplicationVersionName);
                    Assert.NotNull(applicationVersionFromGet);
                    ValidateGalleryApplicationVersion(inputApplicationVersion, applicationVersionFromGet);
                    applicationVersionFromGet = m_CrpClient.GalleryApplicationVersions.Get(rgName, galleryName, galleryApplicationName,
                                                                                           galleryApplicationVersionName, ReplicationStatusTypes.ReplicationStatus);
                    Assert.Equal(StorageAccountType.StandardLRS, applicationVersionFromGet.PublishingProfile.StorageAccountType);
                    Assert.Equal(StorageAccountType.StandardLRS,
                                 applicationVersionFromGet.PublishingProfile.TargetRegions.First().StorageAccountType);
                    Assert.NotNull(applicationVersionFromGet.ReplicationStatus);
                    Assert.NotNull(applicationVersionFromGet.ReplicationStatus.Summary);

                    inputApplicationVersion.PublishingProfile.EndOfLifeDate = DateTime.Now.AddDays(100).Date;
                    m_CrpClient.GalleryApplicationVersions.CreateOrUpdate(rgName, galleryName, galleryApplicationName,
                                                                          galleryApplicationVersionName, inputApplicationVersion);
                    Trace.TraceInformation(string.Format("Updated the gallery application version: {0} in gallery application: {1}",
                                                         galleryApplicationVersionName, galleryApplicationName));
                    applicationVersionFromGet = m_CrpClient.GalleryApplicationVersions.Get(rgName, galleryName,
                                                                                           galleryApplicationName, galleryApplicationVersionName);
                    Assert.NotNull(applicationVersionFromGet);
                    ValidateGalleryApplicationVersion(inputApplicationVersion, applicationVersionFromGet);

                    m_CrpClient.GalleryApplicationVersions.Delete(rgName, galleryName, galleryApplicationName, galleryApplicationVersionName);
                    Trace.TraceInformation(string.Format("Deleted the gallery application version: {0} in gallery application: {1}",
                                                         galleryApplicationVersionName, galleryApplicationName));

                    m_CrpClient.GalleryApplications.Delete(rgName, galleryName, galleryApplicationName);
                    Trace.TraceInformation("Deleted the gallery application.");
                    m_CrpClient.Galleries.Delete(rgName, galleryName);
                    Trace.TraceInformation("Deleted the gallery.");
                }
                finally
                {
                    Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
                }
            }
        }
 /// <summary>
 /// Create or update a gallery Application Version.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='galleryName'>
 /// The name of the Shared Application Gallery in which the Application
 /// Definition resides.
 /// </param>
 /// <param name='galleryApplicationName'>
 /// The name of the gallery Application Definition in which the Application
 /// Version is to be created.
 /// </param>
 /// <param name='galleryApplicationVersionName'>
 /// The name of the gallery Application Version to be created. Needs to follow
 /// semantic version name pattern: The allowed characters are digit and period.
 /// Digits must be within the range of a 32-bit integer. Format:
 /// &lt;MajorVersion&gt;.&lt;MinorVersion&gt;.&lt;Patch&gt;
 /// </param>
 /// <param name='galleryApplicationVersion'>
 /// Parameters supplied to the create or update gallery Application Version
 /// operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <GalleryApplicationVersion> CreateOrUpdateAsync(this IGalleryApplicationVersionsOperations operations, string resourceGroupName, string galleryName, string galleryApplicationName, string galleryApplicationVersionName, GalleryApplicationVersion galleryApplicationVersion, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Create or update a gallery Application Version.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='galleryName'>
 /// The name of the Shared Application Gallery in which the Application
 /// Definition resides.
 /// </param>
 /// <param name='galleryApplicationName'>
 /// The name of the gallery Application Definition in which the Application
 /// Version is to be created.
 /// </param>
 /// <param name='galleryApplicationVersionName'>
 /// The name of the gallery Application Version to be created. Needs to follow
 /// semantic version name pattern: The allowed characters are digit and period.
 /// Digits must be within the range of a 32-bit integer. Format:
 /// &lt;MajorVersion&gt;.&lt;MinorVersion&gt;.&lt;Patch&gt;
 /// </param>
 /// <param name='galleryApplicationVersion'>
 /// Parameters supplied to the create or update gallery Application Version
 /// operation.
 /// </param>
 public static GalleryApplicationVersion CreateOrUpdate(this IGalleryApplicationVersionsOperations operations, string resourceGroupName, string galleryName, string galleryApplicationName, string galleryApplicationVersionName, GalleryApplicationVersion galleryApplicationVersion)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion).GetAwaiter().GetResult());
 }
        public virtual GalleryApplicationVersionsCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string galleryName, string galleryApplicationName, string galleryApplicationVersionName, GalleryApplicationVersion galleryApplicationVersion, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (galleryName == null)
            {
                throw new ArgumentNullException(nameof(galleryName));
            }
            if (galleryApplicationName == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationName));
            }
            if (galleryApplicationVersionName == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationVersionName));
            }
            if (galleryApplicationVersion == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationVersion));
            }

            using var scope = _clientDiagnostics.CreateScope("GalleryApplicationVersionsClient.StartCreateOrUpdate");
            scope.Start();
            try
            {
                var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion, cancellationToken);
                return(new GalleryApplicationVersionsCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion).Request, originalResponse));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Esempio n. 9
0
        public async Task <Response> CreateOrUpdateAsync(string resourceGroupName, string galleryName, string galleryApplicationName, string galleryApplicationVersionName, GalleryApplicationVersion galleryApplicationVersion, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (galleryName == null)
            {
                throw new ArgumentNullException(nameof(galleryName));
            }
            if (galleryApplicationName == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationName));
            }
            if (galleryApplicationVersionName == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationVersionName));
            }
            if (galleryApplicationVersion == null)
            {
                throw new ArgumentNullException(nameof(galleryApplicationVersion));
            }

            using var message = CreateCreateOrUpdateRequest(resourceGroupName, galleryName, galleryApplicationName, galleryApplicationVersionName, galleryApplicationVersion);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            case 201:
            case 202:
                return(message.Response);

            default:
                throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
            }
        }
Esempio n. 10
0
        internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string galleryName, string galleryApplicationName, string galleryApplicationVersionName, GalleryApplicationVersion galleryApplicationVersion)
        {
            var message = _pipeline.CreateMessage();
            var request = message.Request;

            request.Method = RequestMethod.Put;
            var uri = new RawRequestUriBuilder();

            uri.Reset(endpoint);
            uri.AppendPath("/subscriptions/", false);
            uri.AppendPath(subscriptionId, true);
            uri.AppendPath("/resourceGroups/", false);
            uri.AppendPath(resourceGroupName, true);
            uri.AppendPath("/providers/Microsoft.Compute/galleries/", false);
            uri.AppendPath(galleryName, true);
            uri.AppendPath("/applications/", false);
            uri.AppendPath(galleryApplicationName, true);
            uri.AppendPath("/versions/", false);
            uri.AppendPath(galleryApplicationVersionName, true);
            uri.AppendQuery("api-version", "2019-12-01", true);
            request.Uri = uri;
            request.Headers.Add("Content-Type", "application/json");
            var content = new Utf8JsonRequestContent();

            content.JsonWriter.WriteObjectValue(galleryApplicationVersion);
            request.Content = content;
            return(message);
        }