public static Tenant GetDefaultTenant() { Tenant tenant = new Tenant(); tenant.Name = "Default"; tenant.UpperScaleLimit = 1; return tenant; }
// // GET: /applicationgrid/addapplicationtenant public ActionResult AddApplicationTenant(int applicationId) { try { Application app = GetApplication(applicationId); if (app != null) { Tenant tenant = new Tenant(); tenant.ApplicationId = app.Id; tenant.UpperScaleLimit = 1; ViewData["ApplicationName"] = app.Name; return View("AddApplicationTenant", tenant); } else { throw new MonoscapeException("Application not found"); } } catch (Exception e) { return ShowError(e); } }
public NcDeployApplicationResponse DeployApplication(NcDeployApplicationRequest request) { Log.Info (this, "DeployApplication()"); try { Application app = Database.Applications.Where (x => x.Id == request.ApplicationId).FirstOrDefault (); if (app != null) { NcDeployApplicationResponse response = new NcDeployApplicationResponse (); if ((app.Tenants != null) && (app.Tenants.Count > 0)) { // Start application instance per tenant foreach (Tenant tenant in app.Tenants) { int port = ExtractApplicationPackage (app, tenant.Name); ApplicationInstance instance = StartWebServer (app, tenant, port); if (instance != null) { response.Deployed = true; response.Url = instance.Url; } } } else { // No tenants found, start default Tenant tenant = new Tenant (); tenant.Name = "Default"; int port = ExtractApplicationPackage (app, tenant.Name); ApplicationInstance instance = StartWebServer (app, tenant, port); if (instance != null) { response.Deployed = true; response.Url = instance.Url; } } return response; } else { throw new MonoscapeException ("Application not found"); } } catch (Exception e) { Log.Error (this, e); throw e; } }
private ApplicationInstance StartWebServer(Application application, Tenant tenant, int port) { try { string xsp = Settings.WindowsXSPWebServerPath; if (MonoscapeUtil.IsRunningOnMono () && (Environment.OSVersion.Platform == PlatformID.Unix)) xsp = Settings.UnixXSPWebServerPath; string arguments = "--port " + port + " --applications /" + tenant.Name.Replace (" ", "").ToLower () + "/" + MonoscapeUtil.PrepareApplicationVirtualFolderName (application.Name) + ":."; string workingDirectory = PrepareApplicationDeployPath (application, tenant.Name, port); var p = new Process () { StartInfo = new ProcessStartInfo(xsp, arguments) { RedirectStandardOutput = false, RedirectStandardError = false, UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = workingDirectory } }; if (p.Start ()) { Database.LastWebServerPort = port; ApplicationInstance instance = new ApplicationInstance (); instance.Id = FindNextInstanceId (application); instance.ProcessId = p.Id; instance.ApplicationId = application.Id; instance.ApplicationName = application.Name; instance.NodeId = Database.Node.Id; instance.IpAddress = Database.Node.IpAddress; instance.Port = port; instance.Tenant = tenant; instance.CreatedTime = DateTime.Now; instance.State = "Started"; instance.Url = "http://" + instance.IpAddress + ":" + instance.Port + "/" + tenant.Name.Replace (" ", "").ToLower () + "/" + MonoscapeUtil.PrepareApplicationVirtualFolderName (application.Name); Database.ChildProcesses.Add (p); Log.Info (typeof(NcApplicationGridService), "Started web server: " + instance.Url); return instance; } else { Database.ChildProcesses.Add (p); Log.Error (typeof(NcApplicationGridService), "Could not start web server for application " + application.Name + " " + application.Version); return null; } } catch (Exception e) { Log.Error (this, "Could not start web server"); throw e; } }
public ActionResult AddApplicationTenant(Tenant tenant) { try { ApAddApplicationTenantsRequest request = new ApAddApplicationTenantsRequest(Credentials); request.ApplicationId = tenant.ApplicationId; List<Tenant> tenants = new List<Tenant>(); tenants.Add(tenant); request.Tenants = tenants; EndPoints.ApDashboardService.AddApplicationTenants(request); return RedirectToAction("ApplicationInfo", new { applicationId = tenant.ApplicationId }); } catch (Exception e) { return ShowError(e); } }