public async Task <Response> CreateOrUpdateAsync(string resourceGroupName, string galleryName, string galleryApplicationName, GalleryApplication galleryApplication, 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 (galleryApplication == null) { throw new ArgumentNullException(nameof(galleryApplication)); } using var message = CreateCreateOrUpdateRequest(resourceGroupName, galleryName, galleryApplicationName, galleryApplication); 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); } }
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); string galleryApplicationVersionName = "1.0.0"; 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)); 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)); ComputeManagementTestUtilities.WaitSeconds(300); 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); } } }
public string GetApplicationPackagePath(GalleryApplication app) { // string appPackagePath = null; // if (app != null) { InstallerFile installerFile = null; // Acquire root installer item #region Atom Feed Version 0.2 if (app.InstallerItems.Count > 0) { InstallerItem installerItem_0 = app.InstallerItems[0]; if (installerItem_0 == null) { Log.WriteWarning(WEB_PI_APP_PACK_ROOT_INSTALLER_ITEM_MISSING, app.Title); return(appPackagePath); } // Ensure web app package can be reached installerFile = installerItem_0.InstallerFile; } #endregion #region Atom Feed Version 2.0.1.0 else if (app.Installers.Count > 0) { Installer installerItem_0 = app.Installers[0]; if (installerItem_0 == null) { Log.WriteWarning(WEB_PI_APP_PACK_ROOT_INSTALLER_ITEM_MISSING, app.Title); return(appPackagePath); } // Ensure web app package can be reached installerFile = installerItem_0.InstallerFile; } #endregion if (installerFile == null || String.IsNullOrEmpty(installerFile.InstallerUrl)) { Log.WriteWarning(WEB_PI_APP_PACK_DISPLAY_URL_MISSING, app.Title); return(appPackagePath); } // Log.WriteInfo("Web App Download URL: {0}", installerFile.InstallerUrl); // Trying to match the original file name HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(installerFile.InstallerUrl); { // Regex regex = new Regex("filename=\"(?<packageName>.{0,})\""); string packageName = null; // webReq.UserAgent = String.Format(WEB_PI_USER_AGENT_HEADER, Environment.OSVersion.VersionString); // using (HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse()) { string httpHeader = webResp.Headers["Content-Disposition"]; // if (!String.IsNullOrEmpty(httpHeader)) { string fileName = Array.Find <string>(httpHeader.Split(';'), x => x.Trim().StartsWith("filename=")); // Match match = regex.Match(fileName); // Match has been acquired if (match != null && match.Success) { packageName = match.Groups["packageName"].Value; } } } // Download URL points to the download package directly if (String.IsNullOrEmpty(packageName)) { packageName = Path.GetFileName(installerFile.InstallerUrl); } // if (HttpContext.Current != null) { appPackagePath = HttpContext.Current.Server.MapPath(String.Format("~/App_Cache/{0}", packageName)); } else { string assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); appPackagePath = Path.Combine(assemblyPath, String.Format(@"App_Cache\{0}", packageName)); } } } // return(appPackagePath); }
internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string galleryName, string galleryApplicationName, GalleryApplication galleryApplication) { 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.AppendQuery("api-version", "2019-12-01", true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(galleryApplication); request.Content = content; return(message); }
public virtual GalleryApplicationsCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string galleryName, string galleryApplicationName, GalleryApplication galleryApplication, 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 (galleryApplication == null) { throw new ArgumentNullException(nameof(galleryApplication)); } using var scope = _clientDiagnostics.CreateScope("GalleryApplicationsClient.StartCreateOrUpdate"); scope.Start(); try { var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, galleryName, galleryApplicationName, galleryApplication, cancellationToken); return(new GalleryApplicationsCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, galleryName, galleryApplicationName, galleryApplication).Request, originalResponse)); } catch (Exception e) { scope.Failed(e); throw; } }
private void InstallApplication() { if (!Page.IsValid) { return; // server-side validation } // collect parameters List <DeploymentParameter> parameters = GetParameters(); // install application ResultObject res = ES.Services.WebApplicationGallery.Install(PanelSecurity.PackageId, PanelRequest.ApplicationID, ddlWebSite.SelectedItem.Text, directoryName.Text.Trim(), parameters.ToArray()); // show message box with results messageBox.ShowMessage(res, "WEB_APPLICATION_GALLERY_INSTALLED", "WebAppGallery"); // toggle controls if there are no errors if (res.ErrorCodes.Count == 0) { secAppSettings.Visible = false; btnCancel.Visible = false; btnInstall.Visible = false; btnOK.Visible = true; urlPanel.Visible = true; try { GalleryApplicationResult appResult = ES.Services.WebApplicationGallery.GetGalleryApplicationDetails(PanelSecurity.PackageId, PanelRequest.ApplicationID); // GalleryApplication application = appResult.Value; // if (application != null) { // change "Launch" link hlApplication.Text = String.Format(GetLocalizedString("LaunchApplication.Text"), application.Title); // set "main" application URL hlApplication.NavigateUrl = GetAppLaunchUrl(application, ddlWebSite.SelectedItem.Text); // set "temp" application URL if required DomainInfo[] domains = ES.Services.WebServers.GetWebSitePointers(Int32.Parse(ddlWebSite.SelectedValue)); foreach (DomainInfo domain in domains) { if (domain.IsInstantAlias) { // show temp URL tempUrlPanel.Visible = true; // set URL text tempUrl.Text = String.Format(GetLocalizedString("LaunchApplicationTemp.Text"), GetAppLaunchUrl(application, domain.DomainName)); break; } } } } catch (Exception ex) { ShowErrorMessage("GET_GALLERY_APPLIACTION_DETAILS", ex); } } }
/// <summary> /// Create or update a gallery Application Definition. /// </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 is to be created. /// </param> /// <param name='galleryApplicationName'> /// The name of the gallery Application Definition to be created or updated. /// The allowed characters are alphabets and numbers with dots, dashes, and /// periods allowed in the middle. The maximum length is 80 characters. /// </param> /// <param name='galleryApplication'> /// Parameters supplied to the create or update gallery Application operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <GalleryApplication> CreateOrUpdateAsync(this IGalleryApplicationsOperations operations, string resourceGroupName, string galleryName, string galleryApplicationName, GalleryApplication galleryApplication, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, galleryName, galleryApplicationName, galleryApplication, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Create or update a gallery Application Definition. /// </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 is to be created. /// </param> /// <param name='galleryApplicationName'> /// The name of the gallery Application Definition to be created or updated. /// The allowed characters are alphabets and numbers with dots, dashes, and /// periods allowed in the middle. The maximum length is 80 characters. /// </param> /// <param name='galleryApplication'> /// Parameters supplied to the create or update gallery Application operation. /// </param> public static GalleryApplication CreateOrUpdate(this IGalleryApplicationsOperations operations, string resourceGroupName, string galleryName, string galleryApplicationName, GalleryApplication galleryApplication) { return(operations.CreateOrUpdateAsync(resourceGroupName, galleryName, galleryApplicationName, galleryApplication).GetAwaiter().GetResult()); }
public static GalleryApplicationResult GetGalleryApplicationDetails(int packageId, string applicationId) { GalleryApplicationResult result; // try { TaskManager.StartTask(TASK_MANAGER_SOURCE, GET_GALLERY_APP_DETAILS_TASK); // check if WAG is installed WebServer webServer = GetAssociatedWebServer(packageId); if (!webServer.IsMsDeployInstalled()) { return(Error <GalleryApplicationResult>(GalleryErrors.MsDeployIsNotInstalled)); } // get application details result = webServer.GetGalleryApplication(applicationId); if (!result.IsSuccess) { return(Error <GalleryApplicationResult>(result, GalleryErrors.GetApplicationError)); } // check application requirements PackageContext context = PackageController.GetPackageContext(packageId); GalleryApplication app = result.Value; // ASP.NET 2.0 if ((app.WellKnownDependencies & GalleryApplicationWellKnownDependency.AspNet20) == GalleryApplicationWellKnownDependency.AspNet20 && context.Quotas.ContainsKey(Quotas.WEB_ASPNET20) && context.Quotas[Quotas.WEB_ASPNET20].QuotaAllocatedValue < 1) { result.ErrorCodes.Add(GalleryErrors.AspNet20Required); } // ASP.NET 4.0 else if ((app.WellKnownDependencies & GalleryApplicationWellKnownDependency.AspNet40) == GalleryApplicationWellKnownDependency.AspNet40 && context.Quotas.ContainsKey(Quotas.WEB_ASPNET40) && context.Quotas[Quotas.WEB_ASPNET40].QuotaAllocatedValue < 1) { result.ErrorCodes.Add(GalleryErrors.AspNet40Required); } // PHP else if ((app.WellKnownDependencies & GalleryApplicationWellKnownDependency.PHP) == GalleryApplicationWellKnownDependency.PHP && context.Quotas.ContainsKey(Quotas.WEB_PHP4) && context.Quotas[Quotas.WEB_PHP4].QuotaAllocatedValue < 1 && context.Quotas.ContainsKey(Quotas.WEB_PHP5) && context.Quotas[Quotas.WEB_PHP5].QuotaAllocatedValue < 1) { result.ErrorCodes.Add(GalleryErrors.PhpRequired); } // any database GalleryApplicationWellKnownDependency anyDatabaseFlag = GalleryApplicationWellKnownDependency.SQL | GalleryApplicationWellKnownDependency.MySQL; if ((app.WellKnownDependencies & anyDatabaseFlag) == anyDatabaseFlag && !(context.Groups.ContainsKey(ResourceGroups.MsSql2000) || context.Groups.ContainsKey(ResourceGroups.MsSql2005) || context.Groups.ContainsKey(ResourceGroups.MsSql2008) || context.Groups.ContainsKey(ResourceGroups.MySql4) || context.Groups.ContainsKey(ResourceGroups.MySql5))) { result.ErrorCodes.Add(GalleryErrors.DatabaseRequired); } // SQL Server else if ((app.WellKnownDependencies & GalleryApplicationWellKnownDependency.SQL) == GalleryApplicationWellKnownDependency.SQL && !(context.Groups.ContainsKey(ResourceGroups.MsSql2000) || context.Groups.ContainsKey(ResourceGroups.MsSql2005) || context.Groups.ContainsKey(ResourceGroups.MsSql2008))) { result.ErrorCodes.Add(GalleryErrors.SQLRequired); } // MySQL else if ((app.WellKnownDependencies & GalleryApplicationWellKnownDependency.MySQL) == GalleryApplicationWellKnownDependency.MySQL && !(context.Groups.ContainsKey(ResourceGroups.MySql4) || context.Groups.ContainsKey(ResourceGroups.MySql5))) { result.ErrorCodes.Add(GalleryErrors.MySQLRequired); } if (result.ErrorCodes.Count > 0) { GalleryApplicationResult warning = Warning <GalleryApplicationResult>(result, GalleryErrors.PackageDoesNotMeetRequirements); warning.Value = app; return(warning); } } catch (Exception ex) { TaskManager.WriteError(ex); return(Error <GalleryApplicationResult>(GalleryErrors.GeneralError, ex.Message)); } finally { TaskManager.CompleteTask(); } // return(result); }