Пример #1
0
        private bool ScaleDown(int applicationId, string tenantName, int scale)
        {
            Log.Info(this, "Scaling down application: " + applicationId);
            LbGetApplicationInstancesRequest request_ = new LbGetApplicationInstancesRequest(Settings.Credentials);
            request_.NodeId = -1;
            request_.ApplicationId = applicationId;
            LbGetApplicationInstancesResponse response_ = EndPoints.GetLbApplicationGridService().GetApplicationInstances(request_);
            List<ApplicationInstance> list = response_.ApplicationInstances.OrderBy(x => x.Id).ToList();

            if ((list != null) && (list.Count >= scale))
            {
                // Stop idling application instances
                List<ApplicationInstance> idlingInstances = list.FindAll(x => x.RequestCount == 0);
                // Keep one instance alive
                if (idlingInstances.Count == list.Count)
                    idlingInstances.Remove(idlingInstances.Last());

                if (idlingInstances.Count > 0)
                {
                    foreach (ApplicationInstance instance in idlingInstances)
                    {
                        ApStopApplicationInstanceRequest request = new ApStopApplicationInstanceRequest(Settings.Credentials);
                        request.NodeId = instance.NodeId;
                        request.ApplicationId = instance.ApplicationId;
                        request.InstanceId = instance.Id;
                        GetApDashboardService().StopApplicationInstance(request);
                    }
                    return true;
                }
            }
            return false;
        }
Пример #2
0
        public ApStopApplicationInstanceResponse StopApplicationInstance(ApStopApplicationInstanceRequest request)
        {
            Log.Info(this, "StopApplicationInstance()");

            try
            {
                Authenticate(request);
                ApStopApplicationInstanceResponse response = new ApStopApplicationInstanceResponse();
                Node node = Database.GetInstance().Nodes.Where(x => x.Id == request.NodeId).FirstOrDefault();
                if (node != null)
                {
                    // Stop application instance in the node
                    NcStopApplicationRequest ncRequest = new NcStopApplicationRequest(Credentials);
                    ncRequest.ApplicationId = request.ApplicationId;
                    ncRequest.InstanceId = request.InstanceId;
                    EndPoints.GetNcApplicationGridService(node).StopApplicationInstance(ncRequest);

                    // Update routing mesh in the load balancer
                    LbRemoveApplicationInstanceRequest request_ = new LbRemoveApplicationInstanceRequest(Credentials);
                    request_.NodeId = request.NodeId;
                    request_.ApplicationId = request.ApplicationId;
                    request_.InstanceId = request.InstanceId;
                    EndPoints.GetLbApplicationGridService().RemoveApplicationInstances(request_);
                }
                else
                {
                    throw new MonoscapeException("Node not found");
                }
                return response;
            }
            catch (Exception e)
            {
                Log.Error(this, e);
                throw e;
            }
        }
Пример #3
0
 //
 // GET: /applicationgrid/stopapplicationinstance
 public ActionResult StopApplicationInstance(int nodeId, int applicationId, int instanceId)
 {
     try
     {
         ApStopApplicationInstanceRequest request = new ApStopApplicationInstanceRequest(Credentials);
         request.NodeId = nodeId;
         request.ApplicationId = applicationId;
         request.InstanceId = instanceId;
         EndPoints.ApDashboardService.StopApplicationInstance(request);
         return RedirectToAction("ApplicationInstances");
     }
     catch (Exception e)
     {
         return ShowError(e);
     }
 }