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); } } }
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 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); } }