Example #1
0
        private void RemoveApplicationInstance_(ApplicationInstance instance_)
        {
            ApplicationInstance clone = instance_.Clone();

            Database.GetInstance().RoutingMesh.Remove(instance_);
            clone.CreatedTime = DateTime.Now;
            clone.State       = "Stopped";
            Database.GetInstance().RoutingMeshHistory.Add(clone);
        }
Example #2
0
        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;
            }
        }