public ResponseMessage(string name, RequestMessage request) : base(name) { if (request != null) request.OnResponseMessageCreated(this); this.request = request; }
public ResponseMessage(RequestMessage request, ResponseMessage baseResponse) : this(baseResponse != null ? baseResponse.Name : null, request) { if (baseResponse == null) throw new ArgumentNullException("baseResponse"); foreach(KeyValuePair<string, object> attribute in baseResponse.attributes) attributes.Add(attribute.Key, attribute.Value); foreach(MessageArgument argument in baseResponse.arguments) arguments.Add(argument); }
public void AddPath(IServiceAddress root, string pathName, string pathType) { InspectNetwork(); // Check machine is in the schema, MachineProfile machineProfile = CheckMachineInNetwork(root); if (!machineProfile.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"); // Check with the root server that the class instantiates, Message outputStream = new RequestMessage("checkPathType"); outputStream.Arguments.Add(pathType); Message m = Command(root, ServiceType.Root, outputStream); if (m.HasError) throw new NetworkAdminException("Type '" + pathType + "' doesn't instantiate on the root"); IServiceAddress managerServer = man.Address; // Create a new empty database, NetworkClient client = new NetworkClient(managerServer, connector); client.Connect(); DataAddress dataAddress = client.CreateEmptyDatabase(); client.Disconnect(); // Perform the command, outputStream = new MessageStream(MessageType.Request); RequestMessage request = new RequestMessage("addPath"); request.Arguments.Add(pathName); request.Arguments.Add(pathType); request.Arguments.Add(dataAddress); ((MessageStream)outputStream).AddMessage(request); request = new RequestMessage("initPath"); request.Arguments.Add(pathName); ((MessageStream)outputStream).AddMessage(request); Message message = Command(root, ServiceType.Root, outputStream); if (message.HasError) throw new NetworkAdminException(message.ErrorMessage); // Tell the manager server about this path, outputStream = new RequestMessage("addPathRootMapping"); outputStream.Arguments.Add(pathName); outputStream.Arguments.Add(root); message = Command(managerServer, ServiceType.Manager, outputStream); if (message.HasError) throw new NetworkAdminException(message.ErrorMessage); }
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; } }
public bool IsValidNode(IServiceAddress machine) { // Request a report from the administration role on the machine, IMessageProcessor mp = connector.Connect(machine, ServiceType.Admin); RequestMessage request = new RequestMessage("report"); Message response = mp.Process(request); if (response.HasError) // Not a valid node, // Should we break this error down to smaller questions. Such as, is the // password incorrect, etc? return false; return true; }
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; }
public void Test1() { RequestMessage request = new RequestMessage("testMethod1"); request.Arguments.Add("string1"); request.Arguments.Add(34L); request.Arguments.Add(new TcpServiceAddress("127.0.0.1", 3500)); Stream stream = Serialize(request); Message message = Deserialize(stream, MessageType.Request); Assert.IsNotNull(message); Assert.AreEqual(MessageType.Request, message.MessageType); Assert.AreEqual("string1", message.Arguments[0].Value); Assert.AreEqual(34L, message.Arguments[1].Value); Assert.AreEqual(new TcpServiceAddress("127.0.0.1", 3500), message.Arguments[2].Value); }
public AnalyticsRecord[] GetAnalyticsStats(IServiceAddress server) { RequestMessage request = new RequestMessage("reportStats"); Message m = Command(server, ServiceType.Admin, request); if (m.HasError) throw new NetworkAdminException(m.ErrorMessage); long[] stats = (long[])m.Arguments[0].Value; int sz = stats.Length; List<AnalyticsRecord> records = new List<AnalyticsRecord>(sz / 4); for (int i = 0; i < sz; i += 4) { records.Add(new AnalyticsRecord(stats[i], stats[i + 1], stats[i + 2], stats[i + 3])); } return records.ToArray(); }
protected override Message Deserialize(TextReader reader, MessageType messageType) { XmlTextReader xmlReader = new XmlTextReader(reader); Message message = null; while (xmlReader.Read()) { XmlNodeType nodeType = xmlReader.NodeType; //TODO: should we take the 'encoding' attribute? if (nodeType == XmlNodeType.XmlDeclaration) continue; if (nodeType == XmlNodeType.Comment || nodeType == XmlNodeType.Whitespace) continue; if (nodeType == XmlNodeType.Element) { string elementName = xmlReader.LocalName; if (message == null) { if (messageType == MessageType.Request) message = new RequestMessage(elementName); else message = new ResponseMessage(elementName); continue; } MessageArgument argument = ReadArgument(xmlReader); message.Arguments.Add(argument); } else if (nodeType == XmlNodeType.Attribute) { if (message == null) throw new FormatException("Attribute '" + xmlReader.LocalName + "' found at the wrong moment."); message.Attributes.Add(xmlReader.LocalName, xmlReader.Value); } else if (nodeType == XmlNodeType.EndElement) { break; } } if (message == null) throw new FormatException("Invalid format."); return message; }
public void AddBlockAssociation(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("addBlockServerMapping"); 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); }
public long GetBlockMappingCount() { 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("getBlockMappingCount"); 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; }
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; }
public void ArraySerialize() { RequestMessage request = new RequestMessage("testArray"); request.Arguments.Add(new int[] { 45, 87, 90, 112 }); string s = Serialize(request); StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"jsonrpc\":\"1.0\","); sb.Append("\"method\":\"testArray\","); sb.Append("\"params\":["); sb.Append("[45,87,90,112]"); sb.Append("]"); sb.Append("}"); Console.Out.WriteLine("Generated:"); Console.Out.WriteLine(s); Assert.AreEqual(sb.ToString(), s); }
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); }
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; }
private void RegisterBlockServer(IServiceAddress serviceAddress) { // Open a connection with the block service, IMessageProcessor processor = connector.Connect(serviceAddress, ServiceType.Block); // Lock the block service with this manager RequestMessage request = new RequestMessage("bindWithManager"); request.Arguments.Add(address); Message response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); // Get the block set report from the service, request = new RequestMessage("blockSetReport"); response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); long serverGuid = response.Arguments[0].ToInt64(); long[] blockIdList = (long[])response.Arguments[1].Value; // Create a transaction lock (blockDbWriteLock) { ITransaction transaction = blockDatabase.CreateTransaction(); try { // Get the map, BlockServerTable blockServerTable = new BlockServerTable(transaction.GetFile(BlockServerKey, FileAccess.ReadWrite)); int actualAdded = 0; // Read until the end int sz = blockIdList.Length; // Put each block item into the database, for (int i = 0; i < sz; ++i) { long block_id = blockIdList[i]; bool added = blockServerTable.Add(block_id, serverGuid); if (added) { // TODO: Check if a service is adding polluted blocks into the // network via checksum, ++actualAdded; } } if (actualAdded > 0) { // Commit and check point the update, blockDatabase.Publish(transaction); blockDatabase.CheckPoint(); } } finally { blockDatabase.Dispose(transaction); } } BlockServerInfo blockServer = new BlockServerInfo(serverGuid, serviceAddress, ServiceStatus.Up); // Add it to the map lock (blockServersMap) { blockServersMap[serverGuid] = blockServer; blockServers.Add(blockServer); PersistBlockServers(blockServers); } // Update the address space end variable, UpdateAddressSpaceEnd(); }
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; }
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); }
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; }
private void UnregisterRootServer(IServiceAddress serviceAddress) { // Open a connection with the block service, IMessageProcessor processor = connector.Connect(serviceAddress, ServiceType.Root); // Unlock the block service from this manager RequestMessage request = new RequestMessage("unbindWithManager"); request.Arguments.Add(address); Message response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); // Remove it from the map and persist lock (rootServers) { // Find the service to remove, for (int i = rootServers.Count - 1; i >= 0; i--) { if (rootServers[i].Address.Equals(serviceAddress)) rootServers.RemoveAt(i); } PersistRootServers(rootServers); } }
private Message Deserialize(XmlReader xmlReader, MessageType messageType) { Message message = null; while (xmlReader.Read()) { XmlNodeType nodeType = xmlReader.NodeType; if (nodeType == XmlNodeType.DocumentType || nodeType == XmlNodeType.Document || nodeType == XmlNodeType.Comment || nodeType == XmlNodeType.XmlDeclaration) continue; if (nodeType == XmlNodeType.Element) { string elementName = xmlReader.LocalName; if (message == null) { if (elementName == "methodCall") { if (!xmlReader.Read()) throw new FormatException(); if (xmlReader.NodeType != XmlNodeType.Element) throw new FormatException("Invalid node type found."); if (xmlReader.LocalName != "methodName") throw new FormatException("Unexpected element name."); if (!xmlReader.Read()) throw new FormatException("Method name not found."); if (xmlReader.NodeType != XmlNodeType.Text) throw new FormatException("Invalid content in method name element."); message = new RequestMessage(xmlReader.Value); } else if (elementName == "methodResponse") { message = new ResponseMessage(); } else if (elementName == "messageStream") { message = new MessageStream(messageType); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.EndElement) { if (xmlReader.LocalName == "message") continue; if (xmlReader.LocalName == "messageStream") break; } ((MessageStream)message).AddMessage(Deserialize(xmlReader, messageType)); } } else { throw new FormatException("Invalid root element name."); } } else if (xmlReader.LocalName == "fault") { if (messageType != MessageType.Response) throw new FormatException("Fault element found in a request message."); object value = ReadValue(xmlReader); if (!(value is MessageError)) throw new FormatException(); } else if (xmlReader.LocalName == "params") { ReadParams(message, xmlReader); } else { throw new FormatException("Invalid element name."); } } else if (nodeType == XmlNodeType.EndElement) { string elementName = xmlReader.LocalName; if (elementName == "methodCall" || elementName == "methodResponse") break; continue; } else { throw new FormatException("Invalid node type."); } } if (message == null) throw new FormatException("Invalid format"); if (message.MessageType != messageType) throw new FormatException("The returned message is not expected."); return message; }
private void UnregisterAllRootServers() { // Create a list of servers to be deregistered, List<RootServerInfo> to_remove; lock (rootServers) { to_remove = new List<RootServerInfo>(rootServers.Count); to_remove.AddRange(rootServers); } foreach (RootServerInfo s in to_remove) { // Open a connection with the root service, IMessageProcessor processor = connector.Connect(s.Address, ServiceType.Root); // Unlock the root service from this manager RequestMessage request = new RequestMessage("unbindWithManager"); request.Arguments.Add(address); Message response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); } // Remove the entries from the map and persist lock (rootServers) { // Remove the entries that match, foreach (RootServerInfo item in to_remove) { rootServers.Remove(item); } PersistRootServers(rootServers); } }
private void UnregisterBlockServer(IServiceAddress serviceAddress) { // Open a connection with the block service, IMessageProcessor processor = connector.Connect(serviceAddress, ServiceType.Block); // Unlock the block service from this manager RequestMessage request = new RequestMessage("unbindWithManager"); request.Arguments.Add(address); Message inputStream = processor.Process(request); if (inputStream.HasError) throw new ApplicationException(inputStream.ErrorMessage); // Remove it from the map and persist lock (blockServersMap) { // Find the service to remove, List<BlockServerInfo> to_remove = new List<BlockServerInfo>(); foreach (BlockServerInfo server in blockServers) { if (server.Address.Equals(serviceAddress)) to_remove.Add(server); } // Remove the entries that match, foreach (BlockServerInfo item in to_remove) { blockServersMap.Remove(item.Guid); blockServers.Remove(item); } PersistBlockServers(blockServers); } // Check that we aren't allocating against servers no longer in // the list. If so, fix the error. CheckAndFixAllocationServers(); }
private void UnregisterAllBlockServers() { // Create a list of servers to be deregistered, List<BlockServerInfo> to_remove; lock (blockServersMap) { to_remove = new List<BlockServerInfo>(blockServers.Count); to_remove.AddRange(blockServers); } foreach (BlockServerInfo s in to_remove) { // Open a connection with the block service, IMessageProcessor processor = connector.Connect(s.Address, ServiceType.Block); // Unlock the block service from this manager RequestMessage request = new RequestMessage("unbindWithManager"); request.Arguments.Add(address); Message response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); } // Remove the entries from the map and persist lock (blockServersMap) { // Remove the entries that match, foreach (BlockServerInfo item in to_remove) { blockServersMap.Remove(item.Guid); blockServers.Remove(item); } PersistBlockServers(blockServers); } // Check that we aren't allocating against servers no longer in // the list. If so, fix the error. CheckAndFixAllocationServers(); }
public DataAddress Commit(IServiceAddress root_server, String path_name, DataAddress proposal) { IMessageProcessor processor = connector.Connect(root_server, ServiceType.Root); RequestMessage request = new RequestMessage("commit"); request.Arguments.Add(path_name); request.Arguments.Add(proposal); Message response = processor.Process(request); if (response.HasError) { MessageError et = response.Error; // If it's a commit fault exception, wrap it locally. if (et.Source.Equals("Deveel.Data.Net.CommitFaultException")) throw new CommitFaultException(et.Message); throw new Exception(et.Message); } // Return the DataAddress of the result transaction, return (DataAddress) response.Arguments[0].Value; }
private IDictionary<long, IList<BlockServerElement>> GetServersForBlock(IList<long> blockIds) { // The result map, Dictionary<long, IList<BlockServerElement>> resultMap = new Dictionary<long, IList<BlockServerElement>>(); List<long> noneCached = new List<long>(blockIds.Count); foreach (long blockId in blockIds) { IList<BlockServerElement> v = networkCache.GetServers(blockId); // If it's cached (and the cache is current), if (v != null) { resultMap.Add(blockId, v); } // If not cached, add to the list of none cached entries, else { noneCached.Add(blockId); } } // If there are no 'none_cached' blocks, if (noneCached.Count == 0) // Return the result, return resultMap; // Otherwise, we query the manager server for current records on the given // blocks. IMessageProcessor manager = connector.Connect(managerAddress, ServiceType.Manager); MessageStream message_out = new MessageStream(MessageType.Request); foreach (long block_id in noneCached) { RequestMessage request = new RequestMessage("getServerListForBlock"); request.Arguments.Add(block_id); message_out.AddMessage(request); } MessageStream message_in = (MessageStream) manager.Process(message_out); int n = 0; foreach (ResponseMessage m in message_in) { if (m.HasError) throw new Exception(m.ErrorMessage, m.Error.AsException()); int sz = m.Arguments[0].ToInt32(); List<BlockServerElement> srvs = new List<BlockServerElement>(sz); IServiceAddress[] addresses = (IServiceAddress[]) m.Arguments[1].Value; int[] status = (int[]) m.Arguments[2].Value; for (int i = 0; i < sz; ++i) { srvs.Add(new BlockServerElement(addresses[i], (ServiceStatus) status[i])); } // Shuffle the list CollectionsUtil.Shuffle(srvs); // Move the server closest to this node to the start of the list, int closest = 0; int cur_close_factor = Int32.MaxValue; for (int i = 0; i < sz; ++i) { BlockServerElement elem = srvs[i]; int closeness_factor = GetProximity(elem.Address); if (closeness_factor < cur_close_factor) { cur_close_factor = closeness_factor; closest = i; } } // Swap if necessary, if (closest > 0) { CollectionsUtil.Swap(srvs, 0, closest); } // Put it in the result map, long block_id = noneCached[n]; resultMap.Add(block_id, srvs); // Add it to the cache, // NOTE: TTL hard-coded to 15 minute networkCache.SetServers(block_id, srvs, 15*60*1000); ++n; } // Return the list return resultMap; }
private void PollServer(BlockServerInfo server) { bool pollOk = true; // Send the poll command to the service, IMessageProcessor p = connector.Connect(server.Address, ServiceType.Block); RequestMessage request = new RequestMessage("poll"); request.Arguments.Add("manager heartbeat"); Message response = p.Process(request); // Any error with the poll means no status change, if (response.HasError) { pollOk = false; } // If the poll is ok, set the status of the service to UP and remove from // the monitor list, if (pollOk) { // The service status is set to 'Up' if either the current state // is 'DownClientReport' or 'DownHeartbeat' // Lock over servers map for safe alteration of the ref. lock (blockServersMap) { if (server.Status == ServiceStatus.DownClientReport || server.Status == ServiceStatus.DownHeartbeat) { server.Status = ServiceStatus.Up; } } // Remove the service from the monitored_servers list. lock (heartbeatLock) { monitoredServers.Remove(server); } } else { // Make sure the service status is set to 'DownHeartbeat' if the poll // failed, // Lock over servers map for safe alteration of the ref. lock (blockServersMap) { if (server.Status == ServiceStatus.Up || server.Status == ServiceStatus.DownClientReport) { server.Status = ServiceStatus.DownHeartbeat; } } } }
private void ReportBlockServerFailure(IServiceAddress address) { logger.Warning("Reporting failure for " + address + " to manager service."); // Failure throttling, lock (failures) { DateTime current_time = DateTime.Now; DateTime last_address_fail_time; if (failures.TryGetValue(address, out last_address_fail_time) && last_address_fail_time.AddMilliseconds(30 * 1000) > current_time) { // We don't respond to failure notifications on the same address if a // failure notice arrived within a minute of the last one accepted. return; } failures.Add(address, current_time); } IMessageProcessor manager = connector.Connect(managerAddress, ServiceType.Manager); RequestMessage requestMessage = new RequestMessage("notifyBlockServerFailure"); requestMessage.Arguments.Add(address); // Process the failure report message on the manager server, Message responseMessage = manager.Process(requestMessage); if (responseMessage.HasError) logger.Error("Error found while processing 'notifyBlockServerFailure': " + responseMessage.ErrorMessage); }
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; } }
private void RegisterRootServer(IServiceAddress serviceAddress) { // Open a connection with the root service, IMessageProcessor processor = connector.Connect(serviceAddress, ServiceType.Root); // Lock the root service with this manager RequestMessage request = new RequestMessage("bindWithManager"); request.Arguments.Add(address); Message response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); // Get the database path report from the service, request = new RequestMessage("pathReport"); response = processor.Process(request); if (response.HasError) throw new ApplicationException(response.ErrorMessage); string[] pathsNames = (string[])response.Arguments[0].Value; // Create a transaction lock (blockDbWriteLock) { ITransaction transaction = blockDatabase.CreateTransaction(); try { // Get the map, PathRootTable pathRootTable = new PathRootTable(transaction.GetFile(PathRootKey, FileAccess.ReadWrite)); // Read until the end int sz = pathsNames.Length; // Put each block item into the database, for (int i = 0; i < sz; ++i) { // Put the mapping of path_root to the root service that manages it. pathRootTable.Set(pathsNames[i], serviceAddress); } // Commit and check point the update, blockDatabase.Publish(transaction); blockDatabase.CheckPoint(); } finally { blockDatabase.Dispose(transaction); } } // Add it to the map lock (rootServers) { rootServers.Add(new RootServerInfo(serviceAddress, ServiceStatus.Up)); PersistRootServers(rootServers); } }