public NcStartApplicationInstancesResponse StartApplicationInstances(NcStartApplicationInstancesRequest request) { Log.Info (this, "StartApplicationInstances()"); try { Application app = Database.Applications.Where (x => x.Id == request.ApplicationId).FirstOrDefault (); if (app != null) { Tenant tenant = null; if (string.IsNullOrEmpty (request.TenantName)) { throw new MonoscapeException ("Tenant name should be specified"); } else { tenant = app.Tenants.Where (x => x.Name.Equals (request.TenantName)).FirstOrDefault (); if (tenant == null) throw new MonoscapeException ("Tenant " + request.TenantName + " not found"); } List<ApplicationInstance> instancesStarted = new List<ApplicationInstance> (); NcStartApplicationInstancesResponse response = new NcStartApplicationInstancesResponse (); for (int i = 0; i < request.NumberOfInstances; i++) { // Extract application to a new folder int port = ExtractApplicationPackage (app, tenant.Name); // Start a web server instance ApplicationInstance instance = StartWebServer (app, tenant, port); if (instance != null) { // Add to database if (app.ApplicationInstances == null) app.ApplicationInstances = new List<ApplicationInstance> (); app.ApplicationInstances.Add (instance); // Track instances started instancesStarted.Add (instance.Clone ()); // Add server url to the response if (response.Urls == null) response.Urls = new List<string> (); response.Urls.Add (instance.Url); } } response.ApplicationInstances = instancesStarted; return response; } else { throw new MonoscapeException ("Application not found"); } } catch (Exception e) { Log.Error (this, e); throw e; } }
public ApStartApplicationResponse StartApplication(ApStartApplicationRequest request) { Log.Info(this, "StartApplication()"); try { Authenticate(request); ApStartApplicationResponse response = new ApStartApplicationResponse(); List<Node> nodes = FindAvailableNodes(); foreach (Node node in nodes) { if (!ApplicationExistsInNode(request.ApplicationId, node)) { // Upload application to node UploadApplicationToNode(request.ApplicationId, node); } NcStartApplicationInstancesRequest ncRequest = new NcStartApplicationInstancesRequest(Credentials); ncRequest.ApplicationId = request.ApplicationId; ncRequest.TenantName = request.TenantName; ncRequest.NumberOfInstances = request.NumberOfInstances; NcStartApplicationInstancesResponse ncResponse = EndPoints.GetNcApplicationGridService(node).StartApplicationInstances(ncRequest); response.Urls = ncResponse.Urls; // Update Routing Mesh in Load Balancer LbAddApplicationInstancesRequest request2 = new LbAddApplicationInstancesRequest(Credentials); request2.AppInstances = ncResponse.ApplicationInstances; EndPoints.GetLbApplicationGridService().AddApplicationInstances(request2); } return response; } catch(Exception e) { Log.Error(this, e); throw e; } }
public NcStartApplicationInstancesResponse StartApplicationInstances(NcStartApplicationInstancesRequest request) { throw new NotImplementedException(); }