protected void AddRegisteredRootServer(IServiceAddress address) { lock (rootServers) { // Add to the internal map/list rootServers.Add(new RootServerInfo(address, ServiceStatus.Up)); } }
public void ReportServiceDownClientReport(IServiceAddress address, ServiceType type) { if (log.IsInterestedIn(LogLevel.Information)) log.Info(string.Format("reportServiceDownClientReport {0} {1}", address, type)); ReportServiceDown(address, type, ServiceStatus.DownClientReport); }
public FileSystemRootService(IServiceConnector connector, IServiceAddress address, string path) : base(connector, address) { this.path = path; pathInitializationQueue = new List<string>(64); }
public static INetworkCache GetCacheForManager(IServiceAddress[] managers) { lock (ServiceCacheMap) { INetworkCache picked = null; int pickedCount = 0; for (int i = 0; i < managers.Length; ++i) { INetworkCache g; if (ServiceCacheMap.TryGetValue(managers[i], out g)) { picked = g; ++pickedCount; } } if (picked == null) { picked = CreateDefaultCacheFor(managers); for (int i = 0; i < managers.Length; ++i) { ServiceCacheMap[managers[i]] = picked; } } else if (pickedCount != managers.Length) { for (int i = 0; i < managers.Length; ++i) { ServiceCacheMap[managers[i]] = picked; } } return picked; } }
IMessageProcessor IServiceConnector.Connect(IServiceAddress address, ServiceType type) { if (!connected) { if (!OnConnect(address, type)) { logger.Warning(this, "Unable to connect to '" + address + "' after check."); return null; } try { processor = Connect(address, type); } catch (Exception e) { logger.Error(this, "Error while connecting.", e); throw; } connected = true; if (processor == null) { logger.Error(this, "It was not possible to obtain a valid message processor for the connection."); connected = false; throw new InvalidOperationException("Was not able to connect."); } OnConnected(address, type); logger.Info(this, "Connected to '" + address + "'."); } return processor; }
public static ServiceStatusTracker GetServiceTracker(IServiceAddress[] managers, IServiceConnector connector) { lock (TrackerCacheMap) { ServiceStatusTracker picked = null; int pickedCount = 0; for (int i = 0; i < managers.Length; ++i) { ServiceStatusTracker g; if (TrackerCacheMap.TryGetValue(managers[i], out g)) { picked = g; ++pickedCount; } } if (picked == null) { picked = new ServiceStatusTracker(connector); for (int i = 0; i < managers.Length; ++i) { TrackerCacheMap[managers[i]] = picked; } } else if (pickedCount != managers.Length) { for (int i = 0; i < managers.Length; ++i) { TrackerCacheMap[managers[i]] = picked; } } return picked; } }
internal ServiceStatusEventArgs(IServiceAddress serviceAddress, ServiceType serviceType, ServiceStatus oldStatus, ServiceStatus newStatus) { this.serviceAddress = serviceAddress; this.serviceType = serviceType; this.oldStatus = oldStatus; this.newStatus = newStatus; }
private CommandResultCode StopRole(NetworkContext context, string role, IServiceAddress address) { Out.WriteLine("Stopping role " + role + " on " + address); MachineProfile p = context.Network.GetMachineProfile(address); if (p == null) { Out.WriteLine("Error: Machine was not found in the network schema."); return CommandResultCode.ExecutionFailed; } // Here we have some rules, // 1. The manager can not be relieved until all block and root servers have // been. MachineProfile currentManager = context.Network.ManagerServer; MachineProfile[] currentRoots = context.Network.RootServers; MachineProfile[] currentBlocks = context.Network.BlockServers; if (role.Equals("manager")) { if (currentRoots.Length > 0 || currentBlocks.Length > 0) { Error.WriteLine("Error: Can not relieve manager role when there are existing block and root assignments."); return CommandResultCode.ExecutionFailed; } } // Check that the machine is performing the role, bool isPerforming = false; if (role.Equals("block")) { isPerforming = p.IsBlock; } else if (role.Equals("manager")) { isPerforming = p.IsManager; } else if (role.Equals("root")) { isPerforming = p.IsRoot; } else { Error.WriteLine("Unknown role " + role); return CommandResultCode.SyntaxError; } if (!isPerforming) { Error.WriteLine("Error: The machine is not assigned to the " + role + " role."); return CommandResultCode.ExecutionFailed; } // Perform the assignment, if (role.Equals("block")) { context.Network.DeregisterBlock(address); context.Network.StopService(address, ServiceType.Block); } else if (role.Equals("manager")) { context.Network.StopService(address, ServiceType.Manager); } else if (role.Equals("root")) { context.Network.DeregisterRoot(address); context.Network.StopService(address, ServiceType.Root); } else { Error.WriteLine("Unknown role " + role); return CommandResultCode.SyntaxError; } Out.WriteLine("done."); return CommandResultCode.Success; }
public void AddValueToPath(string path, string tableName, string key, string value) { if (!BasePathWrapper.IsSupported) throw new ApplicationException("Base path is not supported."); MachineProfile[] managers = netProfile.GetManagerServers(); if (managers.Length == 0) throw new ApplicationException(); IServiceAddress[] managerAddresses = new IServiceAddress[managers.Length]; for (int i = 0; i < managers.Length; i++) { managerAddresses[i] = managers[i].ServiceAddress; } NetworkClient client = new NetworkClient(managerAddresses, netProfile.Connector); BasePathWrapper wrapper = new BasePathWrapper(); object session = wrapper.CreateDbSession(client, path); using (IDisposable transaction = wrapper.CreateDbTransaction(session) as IDisposable) { if (!wrapper.TableExists(transaction, tableName)) throw new ApplicationException(); wrapper.Insert(transaction, tableName, key, value); wrapper.Commit(transaction); } }
public FileSystemManagerService(IServiceConnector connector, string basePath, string dbPath, IServiceAddress address) : base(connector, address) { this.basePath = basePath; this.dbPath = dbPath; }
private CommandResultCode StartRole(NetworkContext context, string role, IServiceAddress address) { Out.WriteLine("Starting role " + role + " on " + address); MachineProfile p = context.Network.GetMachineProfile(address); if (p == null) { Error.WriteLine("Error: Machine was not found in the network schema."); return CommandResultCode.ExecutionFailed; } // Here we have some rules, // 1. There must be a manager service assigned before block and roots can be // assigned. // 2. Only one manager server can exist. MachineProfile current_manager = context.Network.ManagerServer; if (!role.Equals("manager") && current_manager == null) { Error.WriteLine("Error: Can not assign block or root role when no manager is available on the network."); return CommandResultCode.ExecutionFailed; } else if (role.Equals("manager") && current_manager != null) { Out.WriteLine("Error: Can not assign manager because manager role already assigned."); return CommandResultCode.ExecutionFailed; } // Check if the machine already performing the role, bool already_doing_it = false; if (role.Equals("block")) { already_doing_it = p.IsBlock; } else if (role.Equals("manager")) { already_doing_it = p.IsManager; } else if (role.Equals("root")) { already_doing_it = p.IsRoot; } else { Error.WriteLine("Unknown role " + role); return CommandResultCode.SyntaxError; } if (already_doing_it) { Error.WriteLine("Error: The machine is already assigned to the " + role + " role."); return CommandResultCode.ExecutionFailed; } // Perform the assignment, if (role.Equals("block")) { context.Network.StartService(address, ServiceType.Block); context.Network.RegisterBlock(address); } else if (role.Equals("manager")) { context.Network.StartService(address, ServiceType.Manager); } else if (role.Equals("root")) { context.Network.StartService(address, ServiceType.Root); context.Network.RegisterRoot(address); } else { Error.WriteLine("Unknown role " + role); return CommandResultCode.SyntaxError; } Out.WriteLine("done."); return CommandResultCode.Success; }
public void Set(String path, IServiceAddress rootAddress) { string rootAddrStr = null; if (rootAddress != null) rootAddrStr = rootAddress.ToString(); dictionary.SetValue(path, rootAddrStr); }
public NetworkClient(IServiceAddress[] managerAddresses, IServiceConnector connector, INetworkCache lnc) { this.connector = connector; this.managerAddresses = managerAddresses; this.localNetworkCache = lnc; // Default values, MaxTransactionNodeCacheHeapSize = 14*1024*1024; }
public static void SetCache(IServiceAddress manager, INetworkCache cache) { if (manager == null) throw new ArgumentNullException("manager"); lock (serviceCacheMap) { serviceCacheMap[manager] = cache; } }
public AdminService(IServiceAddress address, IServiceConnector connector, IServiceFactory serviceFactory) { if (serviceFactory == null) throw new ArgumentNullException("serviceFactory"); this.serviceFactory = serviceFactory; this.address = address; this.connector = connector; analytics = new Analytics(); }
public NetworkClient(IServiceAddress managerAddress, IServiceConnector connector, INetworkCache cache) { if (!(connector.MessageSerializer is IRpcMessageSerializer) || !((IRpcMessageSerializer)connector.MessageSerializer).SupportsMessageStream) throw new ArgumentException("The connector given has an invalid message serializer for this context (must be a IRPC serializer)."); this.connector = connector; this.managerAddress = managerAddress; this.cache = cache; }
protected override void OnStop() { managerAddress = null; if (pathCache != null) { foreach (KeyValuePair<string, PathAccess> path in pathCache) { path.Value.AccessStream.Close(); } } }
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); }
public IService CreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector) { if (serviceType == ServiceType.Manager) return new MemoryManagerService(connector, serviceAddress); if (serviceType == ServiceType.Root) return new MemoryRootService(connector); if (serviceType == ServiceType.Block) return new MemoryBlockService(connector); throw new ArgumentException("An invalid service type was specified."); }
public NetworkTreeSystem(IServiceConnector connector, IServiceAddress[] managerAddresses, INetworkCache networkCache, ServiceStatusTracker serviceTracker) { this.connector = connector; this.managerAddresses = managerAddresses; this.networkCache = networkCache; this.serviceTracker = serviceTracker; failureFloodControl = new Dictionary<IServiceAddress, DateTime>(); failureFloodControlBidc = new Dictionary<IServiceAddress, DateTime>(); }
public ProviderService(IRepositoryProvider repositoryProvider, IUnitOfWork unitOfWork, IServiceAddress serviceAddress, IServiceContact serviceContact, INotifier notifier) : base(notifier) { _repositoryProvider = repositoryProvider; _unitOfWork = unitOfWork; _serviceAddress = serviceAddress; _serviceContact = serviceContact; }
private RetryMessageQueue GetRetryMessageQueue(IServiceAddress serviceAddress) { lock (queueMap) { RetryMessageQueue queue; if (!queueMap.TryGetValue(serviceAddress, out queue)) { queue = new RetryMessageQueue(serviceAddress); queueMap[serviceAddress] = queue; } return queue; } }
public static INetworkCache GetCache(IServiceAddress manager) { lock (serviceCacheMap) { INetworkCache cache; if (!serviceCacheMap.TryGetValue(manager, out cache)) { cache = CreateDefault(); serviceCacheMap[manager] = cache; } return cache; } }
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args) { NetworkContext networkContext = context as NetworkContext; if (networkContext == null) { return(CommandResultCode.ExecutionFailed); } if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } string role = args.Current; IServiceAddress address = null; if (args.MoveNext()) { if (args.Current != "on") { return(CommandResultCode.SyntaxError); } if (!args.MoveNext()) { return(CommandResultCode.SyntaxError); } try { address = ServiceAddresses.ParseString(args.Current); } catch (Exception) { Error.WriteLine("Invalid service address"); return(CommandResultCode.ExecutionFailed); } } else { IServiceAddress[] addresses = networkContext.Network.Configuration.NetworkNodes; if (addresses != null && addresses.Length == 1) { address = addresses[0]; } } if (address == null) { Error.WriteLine("cannot determine the address of the service to stop."); return(CommandResultCode.ExecutionFailed); } return(StopRole(networkContext, role, address)); }
public void Set(String path, IServiceAddress rootAddress) { string rootAddrStr = null; if (rootAddress != null) { rootAddrStr = rootAddress.ToString(); } dictionary.SetValue(path, rootAddrStr); }
public byte[] ToBytes(IServiceAddress address) { TcpServiceAddress tcpAddress = (TcpServiceAddress)address; int length = tcpAddress.IsIPv4 ? 4 : 16; byte[] buffer = new byte[length + 2 + 4]; Util.ByteBuffer.WriteInt2((short)length, buffer, 0); Array.Copy(tcpAddress.Address, 0, buffer, 2, length); Util.ByteBuffer.WriteInt4(tcpAddress.Port, buffer, length + 2); return buffer; }
protected void AddRegisteredBlockServer(long serverGuid, IServiceAddress address) { lock (blockServersMap) { BlockServerInfo blockServer = new BlockServerInfo(serverGuid, address, ServiceStatus.Up); // Add to the internal map/list blockServersMap[serverGuid] = blockServer; blockServers.Add(blockServer); } UpdateAddressSpaceEnd(); }
public ServiceClient(IRepositoryClient repositoruClient, IUnitOfWork unitOfWork, IServiceAddress serviceAddress, IServiceContact serviceContact, INotifier notifier) : base(notifier) { _repositoryClient = repositoruClient; _unitOfWork = unitOfWork; _serviceAddress = serviceAddress; _serviceContact = serviceContact; }
public long[] GetAnalyticsStats(IServiceAddress server) { Message message = new Message("reportStats"); Message m = Command(server, ServiceType.Admin, message.AsStream()); if (m.HasError) { throw new NetworkAdminException(m.ErrorMessage); } return((long[])m.Arguments[0].Value); }
public MachineProfile GetMachineProfile(IServiceAddress address) { InspectNetwork(); foreach (MachineProfile p in machineProfiles) { if (p.ServiceAddress.Equals(address)) { return(p); } } return(null); }
public AdminService(IServiceAddress address, IServiceConnector connector, IServiceFactory serviceFactory) { if (serviceFactory == null) { throw new ArgumentNullException("serviceFactory"); } this.serviceFactory = serviceFactory; this.address = address; this.connector = connector; analytics = new Analytics(); }
public byte[] ToBytes(IServiceAddress address) { HttpServiceAddress httpAddress = (HttpServiceAddress) address; MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); writer.Write(httpAddress.Host); writer.Write(httpAddress.Port); writer.Write(httpAddress.Path); writer.Write(httpAddress.Query); return stream.ToArray(); }
public byte[] ToBytes(IServiceAddress address) { TcpServiceAddress tcpAddress = (TcpServiceAddress)address; int length = tcpAddress.IsIPv4 ? 4 : 16; byte[] buffer = new byte[length + 2 + 4]; Util.ByteBuffer.WriteInt2((short)length, buffer, 0); Array.Copy(tcpAddress.Address, 0, buffer, 2, length); Util.ByteBuffer.WriteInt4(tcpAddress.Port, buffer, length + 2); return(buffer); }
private Message Command(IServiceAddress machine, ServiceType serviceType, MessageStream message) { IMessageProcessor proc = Connector.Connect(machine, serviceType); IEnumerable <Message> msgIn = proc.Process(message); Message lastM = null; foreach (Message m in msgIn) { lastM = m; } return(lastM); }
private static bool ListsEqual(IServiceAddress[] list1, IServiceAddress[] list2) { if (list1 == null && list2 == null) { return(true); } if (list1 == null || list2 == null) { return(false); } // Both non-null int sz = list1.Length; if (sz != list2.Length) { return(false); } for (int i = 0; i < sz; ++i) { IServiceAddress addr = list1[i]; bool found = false; for (int n = 0; n < sz; ++n) { if (list2[n].Equals(addr)) { found = true; break; } } if (!found) { return(false); } } for (int i = 0; i < sz; ++i) { IServiceAddress addr = list2[i]; bool found = false; for (int n = 0; n < sz; ++n) { if (list1[n].Equals(addr)) { found = true; break; } } if (!found) { return(false); } } return(true); }
protected RootService(IServiceConnector connector, IServiceAddress address) { this.connector = connector; this.address = address; lockDb = new Dictionary<string, PathAccess>(128); pathInfoMap = new Dictionary<string, PathInfo>(128); loadPathInfoQueue = new List<PathInfo>(64); serviceTracker = new ServiceStatusTracker(connector); serviceTracker.StatusChange += ServiceTracker_OnStatusChange; }
private RetryMessageQueue GetRetryMessageQueue(IServiceAddress serviceAddress) { lock (queueMap) { RetryMessageQueue queue; if (!queueMap.TryGetValue(serviceAddress, out queue)) { queue = new RetryMessageQueue(serviceAddress); queueMap[serviceAddress] = queue; } return(queue); } }
protected override bool OnConnect(IServiceAddress address, ServiceType serviceType) { connections = new Dictionary<TcpServiceAddress, TcpConnection>(); // This thread kills connections that have timed out. backgroundThread = new Thread(PurgeConnections); backgroundThread.Name = "TCP::PurgeConnections"; backgroundThread.IsBackground = true; backgroundThread.Start(); return true; }
public byte[] ToBytes(IServiceAddress address) { HttpServiceAddress httpAddress = (HttpServiceAddress)address; MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); writer.Write(httpAddress.Host); writer.Write(httpAddress.Port); writer.Write(httpAddress.Path); writer.Write(httpAddress.Query); return(stream.ToArray()); }
public override void Enqueue() { int sz = ServiceAddresses.Count; for (int i = 0; i < sz; ++i) { IServiceAddress service_address = ServiceAddresses[i]; MessageStream message_stream = Messages[i]; ServiceType service_type = Types[i]; communicator.GetRetryMessageQueue(service_address).add(message_stream, service_type); } }
private long SendBlockTo(BlockId blockId, IServiceAddress destAddress, long destServerId, IServiceAddress[] managerServers) { lock (service.processLock) { long processId = service.processIdSeq++; SendBlockInfo info = new SendBlockInfo(processId, blockId, destAddress, destServerId, managerServers); // Schedule the process to happen immediately (or as immediately as // possible). new Timer(SendBlockToTask, info, 0, Timeout.Infinite); return(processId); } }
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); } } }
internal NetworkTreeSystem(IServiceConnector connector, IServiceAddress managerAddress, INetworkCache networkCache) { if (!(connector.MessageSerializer is IRpcMessageSerializer) || !((IRpcMessageSerializer)connector.MessageSerializer).SupportsMessageStream) throw new ArgumentException("The message serializer specified by the connector is not valid (must be IRPC)."); this.connector = connector; this.managerAddress = managerAddress; this.networkCache = networkCache; failures = new Dictionary<IServiceAddress, DateTime>(); pathToRoot = new Dictionary<string, IServiceAddress>(); logger = Logger.Network; }
private MachineProfile CheckMachineInNetwork(IServiceAddress machine) { InspectNetwork(); foreach (MachineProfile m in machineProfiles) { if (m.ServiceAddress.Equals(machine)) { return(m); } } throw new NetworkAdminException("Machine '" + machine + "' is not in the network schema"); }
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()); }
protected PathClientService(IServiceAddress address, IServiceAddress managerAddress, IServiceConnector connector) { this.address = address; this.managerAddress = managerAddress; this.connector = connector; NetworkConfigSource netConfig = new NetworkConfigSource(); netConfig.AddNetworkNode(managerAddress); network = new NetworkProfile(connector); network.Configuration = netConfig; log = Logger.Network; }
internal void RetryMessagesFor(IServiceAddress address) { RetryMessageQueue queue; lock (queueMap) { queueMap.TryGetValue(address, out queue); } if (queue != null) { // Schedule on the timer queue, new Timer(RetryMessageTask, null, 500, Timeout.Infinite); } }
private IServiceAddress[] ParseMachineAddressList(string rootAddress) { String[] machines = rootAddress.Split(','); try { IServiceAddress[] services = new IServiceAddress[machines.Length]; for (int i = 0; i < machines.Length; ++i) { services[i] = ServiceAddresses.ParseString(machines[i].Trim()); } return(services); } catch (FormatException e) { Out.WriteLine("Error parsing machine address: " + e.Message); throw; } }
public void AddNetworkNode(string address) { if (String.IsNullOrEmpty(address)) { throw new ArgumentNullException("address"); } IServiceAddress serviceAddress = ServiceAddresses.ParseString(address); if (serviceAddress == null) { throw new ArgumentException("The address '" + address + "' is not supported."); } AddNetworkNode(serviceAddress); }
public IService CreateService(IServiceAddress serviceAddress, ServiceType serviceType, IServiceConnector connector) { if (serviceType == ServiceType.Manager) { return(new MemoryManagerService(connector, serviceAddress)); } if (serviceType == ServiceType.Root) { return(new MemoryRootService(connector, serviceAddress)); } if (serviceType == ServiceType.Block) { return(new MemoryBlockService(connector)); } throw new ArgumentException("An invalid service type was specified."); }
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); } }
public ServiceStatus GetServiceCurrentStatus(IServiceAddress address, ServiceType type) { // Search and return, // TODO: Should this be a hash lookup instead for speed? lock (monitoredServers) { foreach (TrackedService s in monitoredServers) { if (s.ServiceAddress.Equals(address) && s.ServiceType == type) { return(s.CurrentStatus); } } } // Not found in list, so assume the service is up, return(ServiceStatus.Up); }
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 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); } }
public static IServiceAddress ParseString(string s) { InspectAddressTypes(); foreach (IServiceAddressHandler handler in handlers.Values) { try { IServiceAddress a = handler.FromString(s); if (a != null) { return(a); } } catch (Exception) { } } throw new ArgumentException("The string '" + s + "' is not of a recognized format."); }
public void AddPathToNetwork(string pathName, string pathType, IServiceAddress rootLeader, IServiceAddress[] rootServers) { InspectNetwork(); // Send the add path command to the first available manager server. SendManagerCommand("addPathToNetwork", pathName, pathType, rootLeader, rootServers); // Fetch the path info from the manager cluster, PathInfo pathInfo = (PathInfo)SendManagerFunction("getPathInfoForPath", pathName); // Send command to all the root servers, SendAllRootServers(rootServers, "internalSetPathInfo", pathName, pathInfo.VersionNumber, pathInfo); SendAllRootServers(rootServers, "loadPathInfo", pathInfo); // Initialize the path on the leader, SendRootServer(rootLeader, "initialize", pathInfo.PathName, pathInfo.VersionNumber); }
protected override void OnStart() { try { // Read the manager server address from the properties file, Properties p = new Properties(); // Contains the root properties, string propFile = Path.Combine(path, "00.properties"); if (File.Exists(propFile)) { FileStream fin = new FileStream(propFile, FileMode.Open, FileAccess.Read, FileShare.Read); p.Load(fin); fin.Close(); } // Fetch the manager server property, String v = p.GetProperty("manager_server_address"); if (v != null) { String[] addresses = v.Split(','); int sz = addresses.Length; ManagerServices = new IServiceAddress[sz]; for (int i = 0; i < sz; ++i) { ManagerServices[i] = ServiceAddresses.ParseString(addresses[i]); } } } catch (IOException e) { throw new ApplicationException("IO Error: " + e.Message); } // Adds all the files to the path info queue, string[] rootFiles = Directory.GetFiles(path); foreach (string f in rootFiles) { String fname = Path.GetFileName(f); if (!fname.Contains(".")) { pathInitializationQueue.Add(f); } } base.OnStart(); }
private void SendAllRootServers(IServiceAddress[] roots, string functionName, params object[] args) { Message message = new Message(functionName, args); // Send the command to all the root servers, Message lastError = null; IEnumerable <Message>[] responses = new IEnumerable <Message> [roots.Length]; for (int i = 0; i < roots.Length; ++i) { IServiceAddress rootServer = roots[i]; IMessageProcessor proc = Connector.Connect(rootServer, ServiceType.Root); responses[i] = proc.Process(message.AsStream()); } int successCount = 0; foreach (MessageStream response in responses) { foreach (Message m in response) { if (m.HasError) { if (!IsConnectionFailure(m)) { throw new NetworkAdminException(m.ErrorMessage); } lastError = m; } else { ++successCount; } } } // Any one root failed, if (successCount != roots.Length) { throw new NetworkAdminException(lastError.ErrorMessage); } }
private void OutputPathInfo(NetworkContext context, PathInfo p) { string pathName = p.PathName; Out.Write("+Name: "); Out.Write(pathName); Out.Write(" ("); Out.Write(p.PathType); Out.WriteLine(")"); Out.Write(" Srvs: "); IServiceAddress leader = p.RootLeader; IServiceAddress[] srvs = p.RootServers; foreach (IServiceAddress srv in srvs) { bool il = srv.Equals(leader); if (il) { Out.Write("["); } Out.Write(srv.ToString()); if (il) { Out.Write("*]"); } Out.Write(" "); } Out.WriteLine(); Out.Write(" Status: "); try { String stats = context.Network.GetPathStats(p); if (stats != null) { Out.Write(stats); } } catch (NetworkAdminException e) { Out.Write("Error retrieving stats: " + e.Message); } Out.WriteLine(); Out.WriteLine(); }
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); } }