示例#1
0
        private List <MachineProfile> InspectNetwork()
        {
            // If cached,
            if (machineProfiles != null)
            {
                return(machineProfiles);
            }

            // The sorted list of all servers in the schema,
            IEnumerable <IServiceAddress> slist = SortedServers;

            // The list of machine profiles,
            List <MachineProfile> machines = new List <MachineProfile>();

            // For each machine in the network,
            foreach (IServiceAddress server in slist)
            {
                MachineProfile machineProfile = new MachineProfile(server);

                // Request a report from the administration role on the machine,
                IMessageProcessor     mp       = Connector.Connect(server, ServiceType.Admin);
                Message               message  = new Message("report");
                IEnumerable <Message> response = mp.Process(message.AsStream());
                Message               lastM    = null;

                foreach (Message m in response)
                {
                    lastM = m;
                }

                if (lastM.HasError)
                {
                    machineProfile.ErrorMessage = lastM.ErrorMessage;
                }
                else
                {
                    // Get the message replies,
                    MachineRoles roles = (MachineRoles)(byte)lastM.Arguments[0].Value;

                    long usedMem   = (long)lastM.Arguments[1].Value;
                    long totalMem  = (long)lastM.Arguments[2].Value;
                    long usedDisk  = (long)lastM.Arguments[3].Value;
                    long totalDisk = (long)lastM.Arguments[4].Value;

                    // Populate the lists,
                    machineProfile.Roles = roles;

                    machineProfile.MemoryUsed  = usedMem;
                    machineProfile.MemoryTotal = totalMem;
                    machineProfile.DiskUsed    = usedDisk;
                    machineProfile.DiskTotal   = totalDisk;
                }

                // Add the machine profile to the list
                machines.Add(machineProfile);
            }

            machineProfiles = machines;
            return(machineProfiles);
        }
示例#2
0
            public IEnumerable <Message> Process(IEnumerable <Message> request)
            {
                // The message output,
                MessageStream response = new MessageStream();

                // For each message in the message input,
                foreach (Message m in request)
                {
                    try {
                        string command = m.Name;
                        // Report on the services running,
                        if (command.Equals("report"))
                        {
                            lock (service.serverManagerLock) {
                                long tm = System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64;
                                long fm = 0 /* TODO: GetFreeMemory()*/;
                                long td = 0 /* TODO: GetTotalSpace(service.basePath) */;
                                long fd = 0 /* TODO: GetUsableSpace(service.basePath)*/;

                                MachineRoles roles   = MachineRoles.None;
                                Message      message = new Message();
                                if (service.block != null)
                                {
                                    roles |= MachineRoles.Block;
                                }
                                if (service.manager != null)
                                {
                                    roles |= MachineRoles.Manager;
                                }
                                if (service.root != null)
                                {
                                    roles |= MachineRoles.Root;
                                }

                                message.Arguments.Add((byte)roles);
                                message.Arguments.Add(tm - fm);
                                message.Arguments.Add(tm);
                                message.Arguments.Add(td - fd);
                                message.Arguments.Add(td);
                                response.AddMessage(message);
                            }
                        }
                        else if (command.Equals("reportStats"))
                        {
                            // Analytics stats; we convert the stats to a long[] array and
                            // send it as a reply.
                            long[] stats = GetStats();
                            response.AddMessage(new Message(new object[] { stats }));
                        }
                        else
                        {
                            // Starts a service,
                            if (command.Equals("start"))
                            {
                                ServiceType serviceType = (ServiceType)(byte)m.Arguments[0].Value;
                                service.StartService(serviceType);
                            }
                            // Stops a service,
                            else if (command.Equals("stop"))
                            {
                                ServiceType serviceType = (ServiceType)(byte)m.Arguments[0].Value;
                                service.StopService(serviceType);
                            }
                            else
                            {
                                throw new ApplicationException("Unknown command: " + command);
                            }

                            // Add reply message,
                            response.AddMessage(new Message(1L));
                        }
                    } catch (OutOfMemoryException e) {
                        service.Logger.Error("Out-Of-Memory", e);
                        // This will end the connection
                        throw;
                    } catch (Exception e) {
                        service.Logger.Error("Exception during process", e);
                        response.AddMessage(new Message(new MessageError(e)));
                    }
                }
                return(response);
            }