public GNode(RemoteEndPoint managerEP, OwnEndPoint ownEP, SecurityCredentials credentials, string remoteObjectPrefix) { _OwnEP = ownEP; _Credentials = credentials; _ManagerEP = managerEP; _RemoteObjPrefix = remoteObjectPrefix; Init(); }
/// <summary> /// Creates a new instance of the GConnection class /// </summary> /// <param name="managerEP">manager end point</param> /// <param name="ownEP">own end point</param> /// <param name="credentials"></param> public GNode(RemoteEndPoint managerEP, OwnEndPoint ownEP, SecurityCredentials credentials) : this(managerEP, ownEP, credentials, DefaultRemoteObjectPrefix) { }
public void Connect() { logger.Info("Connecting...."); if (ExecConnectEvent!=null){ ExecConnectEvent("Connecting....",0); } Executors = new GExecutor[GetNumberOfExecutors()]; for (int executorIndex = 0; executorIndex < Executors.Length; executorIndex++) { RemoteEndPoint rep = new RemoteEndPoint( Config.ManagerHost, Config.ManagerPort, RemotingMechanism.TcpBinary ); logger.Debug("Created remote-end-point"); if (ExecConnectEvent!=null) { ExecConnectEvent("Created remote-end-point",20); } // TODO: kind of hack-ish way of determining the port for higher thread numbers OwnEndPoint oep = new OwnEndPoint( Config.OwnPort + executorIndex, RemotingMechanism.TcpBinary ); logger.Debug("Created own-end-point"); if (ExecConnectEvent!=null) { ExecConnectEvent("Created own-end-point",40); } string executorId = Config.GetIdAtLocation(executorIndex); // the executorId is used in the remoting URI so it MUST be initialized here if (executorId == String.Empty) { executorId = Guid.NewGuid().ToString(); } // connect to manager Executors[executorIndex] = new GExecutor(rep, oep, executorId, Config.Dedicated, new SecurityCredentials(Config.Username, Config.Password), AppDomain.CurrentDomain.BaseDirectory); if (ExecConnectEvent!=null) { ExecConnectEvent("Updating executor configuration.",80); } Config.ConnectVerified = true; Config.SetIdAtLocation(executorIndex, Executors[executorIndex].Id); Config.Dedicated = Executors[executorIndex].Dedicated; if (ExecConnectEvent!=null) { ExecConnectEvent("Saved configuration.",60); } if (ExecConnectEvent!=null) { ExecConnectEvent("Connected successfully.",100); } Executors[executorIndex].GotDisconnected += new GotDisconnectedEventHandler(GExecutor_GotDisconnected); Executors[executorIndex].NonDedicatedExecutingStatusChanged += new NonDedicatedExecutingStatusChangedEventHandler(GExecutor_NonDedicatedExecutingStatusChanged); } Config.Slz(); Config.ConnectVerified = true; logger.Info("Connected successfully."); }
//----------------------------------------------------------------------------------------------- // constructors //----------------------------------------------------------------------------------------------- /// <summary> /// Creates an instance of the GExecutor with the given end points /// (one for itself, and one for the manager), credentials and other options. /// </summary> /// <param name="managerEP">Manager end point</param> /// <param name="ownEP">Own end point</param> /// <param name="id">executor id</param> /// <param name="dedicated">Specifies whether the executor is dedicated</param> /// <param name="sc">Security credentials</param> /// <param name="baseDir">Working directory for the executor</param> public GExecutor(RemoteEndPoint managerEP, OwnEndPoint ownEP, string id, bool dedicated, SecurityCredentials sc, string baseDir) : base(managerEP, ownEP, sc, id) { //eduGRID Addition iBot = new AIMLBot.iBOT(); //Edn of eduGRID Addition _BaseDir = baseDir; if (_BaseDir == "" || _BaseDir==null) { _BaseDir = AppDomain.CurrentDomain.BaseDirectory; } string datDir = Path.Combine(_BaseDir,"dat"); logger.Debug("datadir="+datDir); if (!Directory.Exists(datDir)) { logger.Debug("Couldnot find datadir. Creating it..."+datDir); Directory.CreateDirectory(datDir); } _Dedicated = dedicated; _Id = id; if (_Id == "") { logger.Info("Registering new executor"); _Id = Manager.Executor_RegisterNewExecutor(Credentials, null, Info); logger.Info("Successfully Registered new executor:"+_Id); } else { // update the executor data if it exists in the database or create a new one if it is not found _Id = Manager.Executor_RegisterNewExecutor(Credentials, _Id, Info); logger.Debug("Id is "+_Id); } //handle exception since we want to connect to the manager //even if it doesnt succeed the first time. //that is, we need to handle InvalidExecutor and ConnectBack Exceptions. try { try { ConnectToManager(); } catch (InvalidExecutorException) { logger.Info("Invalid executor! Registering new executor again..."); _Id = Manager.Executor_RegisterNewExecutor(Credentials, null, Info); logger.Info("New ExecutorID = " + _Id); ConnectToManager(); } } catch (ConnectBackException) { logger.Warn("Couldn't connect as dedicated executor. Reverting to non-dedicated executor. ConnectBackException"); _Dedicated = false; ConnectToManager(); } //for non-dedicated mode, the heart-beat thread will be started if (_Dedicated) { logger.Debug("Dedicated mode: starting heart-beat thread"); StartHeartBeatThread(); } }
/// <summary> /// Starts the Manager /// </summary> public void Start() { if (Started || _Starting) return; _Starting = true; try { if (Config==null) { ReadConfig(false); logger.Debug("Config is null. Getting config from file..."); } OwnEndPoint ownEP = new OwnEndPoint( Config.OwnPort, RemotingMechanism.TcpBinary ); logger.Debug("Configuring remoting"); try { if (ManagerStartEvent!=null) ManagerStartEvent("Configuring remoting",10); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } RemotingConfiguration.Configure(AppDomain.CurrentDomain.BaseDirectory+RemotingConfigFile); //TODO: for hierarchical grids // RemoteEndPoint managerEP = null; // if (Config.Intermediate) // { // managerEP = new RemoteEndPoint( // Config.ManagerHost, // Config.ManagerPort, // RemotingMechanism.TcpBinary // ); // } logger.Debug("Registering tcp channel on port: "+ownEP.Port); try { _Chnl = new TcpChannel(ownEP.Port); ChannelServices.RegisterChannel(_Chnl); } catch (Exception ex) { logger.Error("Error registering channel...",ex); } try { if (ManagerStartEvent!=null) ManagerStartEvent("Registered tcp channel on port: "+ownEP.Port,30); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } //since this is a single call thing, thread safety isnt an issue logger.Debug("Registering well known service type"); RemotingConfiguration.RegisterWellKnownServiceType( typeof(GManager), "Alchemi_Node", WellKnownObjectMode.SingleCall); // TODO: hierarchical grids ignored until after v1.0.0 /* _Dedicated = dedicated; _Id = id; if (Manager != null) { if (_Id == "") { Log("Registering new executor ..."); _Id = Manager.Executor_RegisterNewExecutor(null, new ExecutorInfo); Log("New ExecutorID = " + _Id); } try { try { ConnectToManager(); } catch (InvalidExecutorException) { Log("Invalid executor! Registering new executor ..."); _Id = Manager.Executor_RegisterNewExecutor(null, new ExecutorInfo); Log("New ExecutorID = " + _Id); ConnectToManager(); } } catch (ConnectBackException) { Log("Couldn't connect as dedicated executor. Reverting to non-dedicated executor."); _Dedicated = false; ConnectToManager(); } } */ string datDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"dat"); logger.Debug("datadir="+datDir); if (!Directory.Exists(datDir)) { Directory.CreateDirectory(datDir); logger.Debug("Data directory not found. Creating a new one:"+datDir); } try { if (ManagerStartEvent!=null) ManagerStartEvent("Initialising a new scheduler",50); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } logger.Debug("Initialising a new scheduler"); IScheduler scheduler = new DefaultScheduler(); scheduler.Executors = _Executors; scheduler.Applications = _Applications; logger.Debug("Configuring internal shared class..."); ManagerStorageFactory.CreateManagerStorage(Config); try { if (!ManagerStorageFactory.ManagerStorage().VerifyConnection()) { throw new Exception("Error connecting to manager storage. Please check manager log file for details."); } } catch (Exception ex) { throw new Exception("Error connecting to manager storage.", ex); } InternalShared common = InternalShared.GetInstance(datDir,scheduler); logger.Debug("Initialising scheduler - done"); logger.Debug("Starting scheduler thread"); try { if (ManagerStartEvent!=null) ManagerStartEvent("Starting scheduler thread",60); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } _stopScheduler = false; _DedicatedSchedulerThread = new Thread(new ThreadStart(ScheduleDedicated)); _DedicatedSchedulerThread.Start(); try { if (ManagerStartEvent!=null) ManagerStartEvent("Starting watchdog thread",70); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } logger.Info("Starting watchdog thread"); _stopWatchDog = false; _WatchDogThread = new Thread(new ThreadStart(Watchdog)); _WatchDogThread.Start(); try { if (ManagerStartEvent!=null) ManagerStartEvent("Updating configuration",80); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } //start a seperate thread to init-known executors, since this may take a while. _InitExecutorsThread = new Thread(new ThreadStart(InitExecutors)); _InitExecutorsThread.Start(); Config.Slz(); try { if (ManagerStartEvent!=null) ManagerStartEvent("Started Manager",100); } catch (Exception ex) { logger.Debug("Error in ManagerStartStatus event-handler: "+ex.ToString()); } Started = true; _Starting = false; } catch (Exception e) { Stop(); logger.Error("Error Starting Manager Container",e); throw e; } }