Пример #1
0
        public LbGetApplicationInstancesResponse GetApplicationInstances(LbGetApplicationInstancesRequest request)
        {
            try
            {
                Log.Debug(this, "GetApplicationInstances()");

                Authenticate(request);
                LbGetApplicationInstancesResponse response = new LbGetApplicationInstancesResponse();
                List<ApplicationInstance> instances = Database.GetInstance().RoutingMesh.FindAll(x => x.ApplicationId == request.ApplicationId);
                if (instances != null)
                {
                    if (request.NodeId == -1)
                        response.ApplicationInstances = instances;
                    else
                        response.ApplicationInstances = instances.FindAll(x => x.NodeId == request.NodeId);
                }
                else
                    response.ApplicationInstances = new List<ApplicationInstance>();
                return response;
            }
            catch (Exception e)
            {
                Log.Error(this, e);
                throw e;
            }
        }
Пример #2
0
 private void UpdateApplications(List<Node> nodes)
 {
     foreach (Node node in nodes)
     {
         try
         {
             NcDescribeApplicationsRequest request = new NcDescribeApplicationsRequest(Settings.Credentials);
             var channel = EndPoints.GetNcApplicationGridService(node);
             NcDescribeApplicationsResponse response = channel.DescribeApplications(request);
             node.Applications = response.Applications;
             foreach(Application application in node.Applications)
             {
                 LbGetApplicationInstancesRequest request1 = new LbGetApplicationInstancesRequest(Settings.Credentials);
                 request1.NodeId = node.Id;
                 request1.ApplicationId = application.Id;
                 LbGetApplicationInstancesResponse response1 = EndPoints.GetLbApplicationGridService().GetApplicationInstances(request1);
                 application.ApplicationInstances = response1.ApplicationInstances;
             }
             Log.Debug(this, "Updated applications of node " + node.ToString());
         }
         catch(Exception e)
         {
             Log.Error(this, "Could not update applications of node " + node.ToString());
             throw e;
         }
     }
 }
Пример #3
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;
        }