示例#1
0
        public String GetPathStats(PathInfo pathInfo)
        {
            InspectNetwork();

            IServiceAddress rootLeader = pathInfo.RootLeader;

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(rootLeader);

            // Check it's root,
            if (!machineP.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + rootLeader + "' is not a root");
            }

            // Perform the command,
            Message message = new Message("getPathStats", pathInfo.PathName, pathInfo.VersionNumber);

            Message m = Command(rootLeader, ServiceType.Root, message.AsStream());

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the stats string for this path
            return((String)m.Arguments[0].Value);
        }
示例#2
0
        public void StartService(IServiceAddress machine, ServiceType serviceType)
        {
            if (serviceType == ServiceType.Admin)
            {
                throw new ArgumentException("Invalid service type.", "serviceType");
            }

            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine_p = CheckMachineInNetwork(machine);

            if (serviceType == ServiceType.Manager)
            {
                MachineProfile current_manager = ManagerServer;
                if (current_manager != null)
                {
                    throw new NetworkAdminException("Manager already assigned on machine " + current_manager);
                }
            }

            if ((machine_p.ServiceType & serviceType) != 0)
            {
                throw new NetworkAdminException("Role '" + serviceType + "' already assigned on machine " + machine);
            }

            ChangeRole(machine_p, "init", serviceType.ToString().ToLower());
        }
示例#3
0
        public void DeregisterManager(IServiceAddress root)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(root);

            MachineProfile[] currentManagers = GetManagerServers();

            if (currentManagers.Length == 0)
            {
                throw new NetworkAdminException("No manager server found");
            }

            // Check it is a manager server,
            if (!machineP.IsManager)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not assigned as a manager");
            }

            Message message = new Message("deregisterManagerServer", root);

            // Register the root server with all the managers currently on the network,
            for (int i = 0; i < currentManagers.Length; ++i)
            {
                Message m = Command(currentManagers[i].ServiceAddress, ServiceType.Manager, message.AsStream());
                if (m.HasError)
                {
                    throw new NetworkAdminException(m.ErrorMessage);
                }
            }
        }
示例#4
0
        public String GetPathStats(IServiceAddress root, string pathName)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine_p = CheckMachineInNetwork(root);

            // Check it's root,
            if (!machine_p.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not a root");
            }

            // Perform the command,
            RequestMessage request = new RequestMessage("getPathStats");

            request.Arguments.Add(pathName);

            Message m = Command(root, ServiceType.Root, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the stats string for this path
            return(m.Arguments[0].ToString());
        }
示例#5
0
        public DataAddress[] GetHistoricalPathRoots(IServiceAddress root, String pathName, DateTime timestamp, int maxCount)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(root);

            // Check it's root,
            if (!machineP.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not a root");
            }

            // Perform the command,
            Message message = new Message("getPathHistorical", pathName, DateTimeUtil.GetMillis(timestamp), DateTimeUtil.GetMillis(timestamp));

            Message m = Command(root, ServiceType.Root, message.AsStream());

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the data address array,
            return((DataAddress[])m.Arguments[0].Value);
        }
示例#6
0
        public void PublishPath(IServiceAddress root, string pathName, DataAddress address)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine = CheckMachineInNetwork(root);

            // Check it's root,
            if (!machine.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not a root");
            }

            // Perform the command,
            RequestMessage request = new RequestMessage("publishPath");

            request.Arguments.Add(pathName);
            request.Arguments.Add(address);

            Message m = Command(root, ServiceType.Root, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }
        }
示例#7
0
        public PathProfile[] GetPathsFromRoot(IServiceAddress root)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine_p = CheckMachineInNetwork(root);

            RequestMessage request = new RequestMessage("pathReport");
            Message        m       = Command(root, ServiceType.Root, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            string[] paths = (string[])m.Arguments[0].Value;
            string[] funs  = (string[])m.Arguments[1].Value;

            PathProfile[] list = new PathProfile[paths.Length];
            for (int i = 0; i < paths.Length; ++i)
            {
                list[i] = new PathProfile(root, paths[i], funs[i]);
            }

            return(list);
        }
        public void RemoveBlockAssociation(long block_id, long server_guid)
        {
            InspectNetwork();

            // Get the current manager server,
            MachineProfile man = ManagerServer;

            if (man == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            IServiceAddress manager_server = man.Address;

            RequestMessage request = new RequestMessage("removeBlockServerMapping");

            request.Arguments.Add(block_id);
            request.Arguments.Add(server_guid);

            Message m = Command(manager_server, ServiceType.Manager, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }
        }
示例#9
0
        public void ProcessSendBlock(long block_id, IServiceAddress source_block_server, IServiceAddress dest_block_server, long dest_server_sguid)
        {
            InspectNetwork();

            // Get the current manager server,
            MachineProfile man = ManagerServer;

            if (man == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            IServiceAddress manager_server = man.Address;

            RequestMessage request = new RequestMessage("sendBlockTo");

            request.Arguments.Add(block_id);
            request.Arguments.Add(dest_block_server);
            request.Arguments.Add(dest_server_sguid);
            request.Arguments.Add(manager_server);

            Message m = Command(source_block_server, ServiceType.Block, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }
        }
示例#10
0
        public DataAddress[] GetHistoricalPathRoots(IServiceAddress root, string pathName, DateTime time, int maxCount)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine = CheckMachineInNetwork(root);

            // Check it's root,
            if (!machine.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not a root");
            }

            // Perform the command,
            RequestMessage request = new RequestMessage("getPathHistorical");

            request.Arguments.Add(pathName);
            request.Arguments.Add(time.ToBinary());
            request.Arguments.Add(time.ToBinary());

            ResponseMessage m = (ResponseMessage)Command(root, ServiceType.Root, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the data address array,
            return((DataAddress[])m.ReturnValue);
        }
示例#11
0
        public long GetBlockGuid(IServiceAddress block)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine_p = CheckMachineInNetwork(block);

            // Check it's a block server,
            if (!machine_p.IsBlock)
            {
                throw new NetworkAdminException("Machine '" + block + "' is not a block role");
            }

            RequestMessage request = new RequestMessage("serverGUID");

            request.Arguments.Add(block);

            Message m = Command(block, ServiceType.Block, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the GUID
            return((long)m.Arguments[0].Value);
        }
示例#12
0
        private void ChangeRole(MachineProfile machine, string status, ServiceType roleType)
        {
            Message message = new Message(status);

            message.Arguments.Add((byte)roleType);

            Message m = Command(machine.ServiceAddress, ServiceType.Admin, message.AsStream());

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }
            // Success,

            // Update the network profile,
            if (roleType == ServiceType.Manager && status.Equals("start"))
            {
                machine.Roles |= MachineRoles.Manager;
            }
            else if (roleType == ServiceType.Root && status.Equals("start"))
            {
                machine.Roles |= MachineRoles.Root;
            }
            else if (roleType == ServiceType.Block && status.Equals("start"))
            {
                machine.Roles |= MachineRoles.Block;
            }
        }
示例#13
0
        public IServiceAddress GetRoot(string pathName)
        {
            InspectNetwork();

            // Get the current manager server,
            MachineProfile man = ManagerServer;

            if (man == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            IServiceAddress manager_server = man.Address;

            RequestMessage request = new RequestMessage("getRootFor");

            request.Arguments.Add(pathName);

            Message m = Command(manager_server, ServiceType.Manager, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the service address for the root server,
            return((IServiceAddress)m.Arguments[0].Value);
        }
示例#14
0
        private void RegisterService(IServiceAddress address, ServiceType serviceType)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine_p      = CheckMachineInNetwork(address);
            MachineProfile currentManager = ManagerServer;

            if (currentManager == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            if ((machine_p.ServiceType & serviceType) == 0)
            {
                throw new NetworkAdminException("Machine '" + address + "' is not assigned as a " + serviceType.ToString().ToLower() +
                                                " role");
            }

            string         messageName = serviceType == ServiceType.Block ? "registerBlockServer" : "registerRootServer";
            RequestMessage request     = new RequestMessage(messageName);

            request.Arguments.Add(address);

            Message m = Command(currentManager.Address, ServiceType.Manager, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage, m.ErrorStackTrace);
            }
        }
示例#15
0
        public long[] GetBlockMappingRange(long p1, long p2)
        {
            InspectNetwork();

            // Get the current manager server,
            MachineProfile man = ManagerServer;

            if (man == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            IServiceAddress manager_server = man.Address;

            RequestMessage request = new RequestMessage("getBlockMappingRange");

            request.Arguments.Add(p1);
            request.Arguments.Add(p2);

            Message m = Command(manager_server, ServiceType.Manager, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the service address for the root server,
            return((long[])m.Arguments[0].Value);
        }
示例#16
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);
        }
示例#17
0
        public void StartBlock()
        {
            StartManager();

            MachineProfile machine = NetworkProfile.GetMachineProfile(LocalAddress);

            Assert.IsNotNull(machine);
            Assert.IsFalse(machine.IsBlock);
            NetworkProfile.StartService(LocalAddress, ServiceType.Block);
            NetworkProfile.RegisterBlock(LocalAddress);
        }
示例#18
0
        public void RegisterService(IServiceAddress address, ServiceType serviceType)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(address);

            MachineProfile[] currentManagers = GetManagerServers();

            if (currentManagers.Length == 0)
            {
                throw new NetworkAdminException("No manager server found");
            }

            // Check it is a root server,
            if (!machineP.IsInRole(serviceType))
            {
                throw new NetworkAdminException("Machine '" + address + "' is assigned as a " + serviceType);
            }

            string command = null;

            if (serviceType == ServiceType.Manager)
            {
                RegisterManager(address);
            }
            else if (serviceType == ServiceType.Root)
            {
                command = "registerRootServer";
            }
            else if (serviceType == ServiceType.Block)
            {
                command = "registerBlockServer";
            }
            else
            {
                throw new ArgumentException();
            }

            Message message = new Message(command, address);

            // Register the root server with all the managers currently on the network,
            for (int i = 0; i < currentManagers.Length; ++i)
            {
                Message m = Command(currentManagers[i].ServiceAddress, ServiceType.Manager, message.AsStream());
                if (m.HasError)
                {
                    throw new NetworkAdminException(m.ErrorMessage);
                }
            }
        }
示例#19
0
        private void ChangeRole(MachineProfile machine, string status, string roleType)
        {
            RequestMessage request = new RequestMessage(status);
            request.Arguments.Add(roleType);
            Message m = Command(machine.Address, ServiceType.Admin, request);
            if (m.HasError)
                throw new NetworkAdminException(m.ErrorMessage);

            // Update the network profile,
            if (status.Equals("init")) {
                ServiceType type = (ServiceType)Enum.Parse(typeof(ServiceType), roleType, true);
                machine.ServiceType |= type;
            }
        }
示例#20
0
        public void StartAndStopRoot()
        {
            StartRoot();

            MachineProfile machine = NetworkProfile.GetMachineProfile(LocalAddress);

            Assert.IsNotNull(machine);
            Assert.IsTrue(machine.IsRoot);

            NetworkProfile.StopService(LocalAddress, ServiceType.Root);
            NetworkProfile.Refresh();

            machine = NetworkProfile.GetMachineProfile(LocalAddress);
            Assert.IsNotNull(machine);
            Assert.IsFalse(machine.IsRoot);
        }
示例#21
0
        public void StartManager()
        {
            MachineProfile machine = NetworkProfile.GetMachineProfile(LocalAddress);

            Assert.IsNotNull(machine);
            Assert.IsEmpty(NetworkProfile.GetManagerServers());
            Assert.IsFalse(machine.IsManager);
            NetworkProfile.StartService(LocalAddress, ServiceType.Manager);
            NetworkProfile.RegisterManager(LocalAddress);

            NetworkProfile.Refresh();

            machine = NetworkProfile.GetMachineProfile(LocalAddress);
            Assert.IsNotNull(machine);
            Assert.IsNotNull(NetworkProfile.GetManagerServers());
            Assert.IsTrue(machine.IsManager);
        }
示例#22
0
        public void StartService(IServiceAddress machine, ServiceType serviceType)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(machine);

            if (!machineP.IsInRole(serviceType))
            {
                // No current manager, so go ahead and assign,
                ChangeRole(machineP, "start", serviceType);
            }
            else
            {
                throw new NetworkAdminException("Manager already assigned on machine " + machine);
            }
        }
示例#23
0
        public void StopService(IServiceAddress machine, ServiceType serviceType)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(machine);

            if (machineP.IsInRole(serviceType))
            {
                // The current manager matches, so we can stop
                ChangeRole(machineP, "stop", serviceType);
            }
            else
            {
                throw new NetworkAdminException("Manager not assigned to machine " + machine);
            }
        }
示例#24
0
        public void StopService(IServiceAddress machine, ServiceType serviceType)
        {
            if (serviceType == ServiceType.Admin)
            {
                throw new ArgumentException("Invalid service type.", "serviceType");
            }

            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machine_p = CheckMachineInNetwork(machine);

            if ((machine_p.ServiceType & serviceType) == 0)
            {
                throw new NetworkAdminException("Manager not assigned to machine " + machine);
            }

            ChangeRole(machine_p, "dispose", serviceType.ToString().ToLower());
        }
示例#25
0
        private void ChangeRole(MachineProfile machine, string status, string roleType)
        {
            RequestMessage request = new RequestMessage(status);

            request.Arguments.Add(roleType);
            Message m = Command(machine.Address, ServiceType.Admin, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Update the network profile,
            if (status.Equals("init"))
            {
                ServiceType type = (ServiceType)Enum.Parse(typeof(ServiceType), roleType, true);
                machine.ServiceType |= type;
            }
        }
示例#26
0
        public void RemovePath(IServiceAddress root, string path_name)
        {
            InspectNetwork();

            MachineProfile machine_p = CheckMachineInNetwork(root);

            if (!machine_p.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not a root");
            }

            // Get the current manager server,
            MachineProfile man = ManagerServer;

            if (man == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            IServiceAddress manager_server = man.Address;

            // Perform the command,
            RequestMessage request = new RequestMessage("removePath");

            request.Arguments.Add(path_name);

            Message m = Command(root, ServiceType.Root, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Tell the manager server to remove this path association,
            request = new RequestMessage("removePathRootMapping");
            request.Arguments.Add(path_name);

            m = Command(manager_server, ServiceType.Manager, request);
            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }
        }
示例#27
0
        private CommandResultCode RemovePath(NetworkContext context, string pathName, string rootAddress)
        {
            IServiceAddress address;

            // If machine is null, we need to find the machine the path is on,
            if (rootAddress == null)
            {
                PathInfo pathInfo = context.Network.GetPathInfo(pathName);
                if (pathInfo == null)
                {
                    Out.WriteLine("The path '" + pathName + "' was not found.");
                    return(CommandResultCode.ExecutionFailed);
                }
                address = pathInfo.RootLeader;
            }
            else
            {
                address = ServiceAddresses.ParseString(rootAddress);
            }

            Out.WriteLine("Removing path " + pathName + " from root " + address);
            Out.Flush();

            MachineProfile p = context.Network.GetMachineProfile(address);

            if (p == null)
            {
                Out.WriteLine("Error: Machine was not found in the network schema.");
                return(CommandResultCode.ExecutionFailed);
            }
            if (!p.IsRoot)
            {
                Out.WriteLine("Error: Given machine is not a root.");
                return(CommandResultCode.ExecutionFailed);
            }

            // Remove the path,
            context.Network.RemovePathFromNetwork(pathName, address);
            Out.WriteLine("done.");
            return(CommandResultCode.Success);
        }
示例#28
0
        public long[] GetBlockList(IServiceAddress block)
        {
            InspectNetwork();

            MachineProfile machine_p = CheckMachineInNetwork(block);

            if (!machine_p.IsBlock)
            {
                throw new NetworkAdminException("Machine '" + block + "' is not a block role");
            }

            RequestMessage request = new RequestMessage("blockSetReport");
            Message        m       = Command(block, ServiceType.Block, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the block list,
            return((long[])m.Arguments[1].Value);
        }
示例#29
0
        public void SetPathRoot(IServiceAddress root, String pathName, DataAddress address)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(root);

            // Check it's root,
            if (!machineP.IsRoot)
            {
                throw new NetworkAdminException("Machine '" + root + "' is not a root");
            }

            // Perform the command,
            Message message = new Message("publishPath", pathName, address);

            Message m = Command(root, ServiceType.Root, message.AsStream());

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }
        }
示例#30
0
        public IDictionary <IServiceAddress, String> GetBlocksStatus()
        {
            InspectNetwork();

            // Get the current manager server,
            MachineProfile man = ManagerServer;

            if (man == null)
            {
                throw new NetworkAdminException("No manager server found");
            }

            IServiceAddress manager_server = man.Address;

            RequestMessage request = new RequestMessage("getRegisteredServerList");

            Message m = Command(manager_server, ServiceType.Manager, request);

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // The list of block servers registered with the manager,
            IServiceAddress[] regservers        = (IServiceAddress[])m.Arguments[0].Value;
            String[]          regservers_status = (String[])m.Arguments[1].Value;

            Dictionary <IServiceAddress, string> map = new Dictionary <IServiceAddress, string>();

            for (int i = 0; i < regservers.Length; ++i)
            {
                map.Add(regservers[i], regservers_status[i]);
            }

            // Return the map,
            return(map);
        }
示例#31
0
        public long[] GetBlockList(IServiceAddress block)
        {
            InspectNetwork();

            // Check machine is in the schema,
            MachineProfile machineP = CheckMachineInNetwork(block);

            // Check it's a block server,
            if (!machineP.IsBlock)
            {
                throw new NetworkAdminException("Machine '" + block + "' is not a block role");
            }

            Message message = new Message("blockSetReport");
            Message m       = Command(block, ServiceType.Block, message.AsStream());

            if (m.HasError)
            {
                throw new NetworkAdminException(m.ErrorMessage);
            }

            // Return the block list,
            return((long[])m.Arguments[1].Value);
        }
示例#32
0
        private void InspectNetwork()
        {
            // If cached,
            if (machine_profiles == null) {
                // The sorted list of all servers in the schema,
                IServiceAddress[] slist = ServiceAddresses;

                List<MachineProfile> machines = new List<MachineProfile>();

                foreach (IServiceAddress server in slist) {
                    MachineProfile machine_profile = new MachineProfile(server);

                    // Request a report from the administration role on the machine,
                    IMessageProcessor mp = connector.Connect(server, ServiceType.Admin);
                    RequestMessage request = new RequestMessage("report");
                    Message response = mp.Process(request);

                    if (response.HasError) {
                        machine_profile.ErrorState = response.ErrorMessage;
                    } else {
                        // Get the message replies,
                        string b = response.Arguments[0].ToString();
                        bool is_block = !b.Equals("block=no");
                        String m = response.Arguments[1].ToString();
                        bool is_manager = !m.Equals("manager=no");
                        string r = response.Arguments[2].ToString();
                        bool is_root = !r.Equals("root=no");

                        long used_mem = response.Arguments[3].ToInt64();
                        long total_mem = response.Arguments[4].ToInt64();
                        long used_disk = response.Arguments[5].ToInt64();
                        long total_disk = response.Arguments[6].ToInt64();

                        ServiceType type = new ServiceType();
                        if (is_block)
                            type |= ServiceType.Block;
                        if (is_manager)
                            type |= ServiceType.Manager;
                        if (is_root)
                            type |= ServiceType.Root;

                        // Populate the lists,
                        machine_profile.ServiceType = type;

                        machine_profile.MemoryUsed = used_mem;
                        machine_profile.MemoryTotal = total_mem;
                        machine_profile.StorageUsed = used_disk;
                        machine_profile.StorageTotal = total_disk;
                    }

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

                machine_profiles = machines;
            }
        }
示例#33
0
        private void ChangeRole(MachineProfile machine, string status, ServiceType roleType)
        {
            Message message = new Message(status);
            message.Arguments.Add((byte)roleType);

            Message m = Command(machine.ServiceAddress, ServiceType.Admin, message.AsStream());
            if (m.HasError) {
                throw new NetworkAdminException(m.ErrorMessage);
            }
            // Success,

            // Update the network profile,
            if (roleType == ServiceType.Manager && status.Equals("start")) {
                machine.Roles |= MachineRoles.Manager;
            } else if (roleType == ServiceType.Root && status.Equals("start")) {
                machine.Roles |= MachineRoles.Root;
            } else if (roleType == ServiceType.Block && status.Equals("start")) {
                machine.Roles |= MachineRoles.Block;
            }
        }
示例#34
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;
        }