Example #1
0
 public GNode(RemoteEndPoint managerEP, OwnEndPoint ownEP, SecurityCredentials credentials, string remoteObjectPrefix)
 {
     _OwnEP           = ownEP;
     _Credentials     = credentials;
     _ManagerEP       = managerEP;
     _RemoteObjPrefix = remoteObjectPrefix;
     Init();
 }
Example #2
0
        public static GNode GetRemoteRef(RemoteEndPoint remoteEP, string remoteObjectPrefix)
        {
            switch (remoteEP.RemotingMechanism)
            {
            case RemotingMechanism.TcpBinary:
                string uri = "tcp://" + remoteEP.Host + ":" + remoteEP.Port + "/" + remoteObjectPrefix;
                return((GNode)Activator.GetObject(typeof(GNode), uri));

            default:
                return(null);
            }
        }
Example #3
0
        //-----------------------------------------------------------------------------------------------
        // public methods
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Initialised the remoted "node"
        /// </summary>
        protected void Init()
        {
            if (_Initted)
            {
                return;
            }

            if (_Connection != null)
            {
                _Credentials = new SecurityCredentials(_Connection.Username, _Connection.Password);
                _ManagerEP   = new RemoteEndPoint(_Connection.Host, _Connection.Port, RemotingMechanism.TcpBinary);
            }
            GetManagerRef();
            RemoteSelf();
            _Initted = true;
        }
Example #4
0
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the reference to a remote manager
        /// </summary>
        /// <param name="remoteEP">end point of the remote manager</param>
        /// <returns>Manager reference</returns>
        public static IManager GetRemoteManagerRef(RemoteEndPoint remoteEP)
        {
            IManager manager;

            try
            {
                manager = (IManager)GetRemoteRef(remoteEP);
                manager.PingManager();
            }
            catch (Exception e)
            {
                throw new RemotingException("Could not connect to Manager.", e);
            }

            return(manager);
        }
Example #5
0
 /// <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)
 {
 }
Example #6
0
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Connect to an executor which is in non-dedicated mode.
        /// This is called by a non-dedicated executor using its reference to this manager.
        /// </summary>
        /// <param name="sc">security credentials to verify if the executor has permission to perform this operation 
        /// (i.e connect non-dedicated, which is associated with the ExecuteThread permission)</param>
        /// <param name="executorId">executor id</param>
        public void Executor_ConnectNonDedicatedExecutor(SecurityCredentials sc, string executorId, RemoteEndPoint executorEP)
        {
            logger.Debug("Executor called: ConnectNonDedicated");
            AuthenticateUser(sc);
            EnsurePermission(sc, Permission.ExecuteThread);

            _Executors[executorId].ConnectNonDedicated(executorEP);

            logger.Debug("Connected to executor non-dedicated: "+executorId);
            _Executors[executorId].HeartbeatUpdate(new HeartbeatInfo(0, 0, 0));
        }
Example #7
0
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Connect to an executor which is in dedicated mode.
        /// This method is called by the remote executor using its reference to this manager.
        /// </summary>
        /// <param name="sc">security credentials to verify if the executor has permission to perform this operation 
        /// (i.e connect dedicated, which is associated with the ExecuteThread permission)</param>
        /// <param name="executorId">executor id</param>
        /// <param name="executorEP">end point of the executor</param>
        public void Executor_ConnectDedicatedExecutor(SecurityCredentials sc, string executorId, RemoteEndPoint executorEP)
        {
            logger.Debug("Executor called: ConnectDedicated: Authenticate,EnsurePermission,Connect,Set DedicatedScheduler");
            AuthenticateUser(sc);
            EnsurePermission(sc, Permission.ExecuteThread);

            try
            {
                _Executors[executorId].ConnectDedicated(executorEP);
                InternalShared.Instance.DedicatedSchedulerActive.Set();
            }
            catch (ExecutorCommException ece)
            {
                logger.Error("Couldnt connect back to the supplied executor",ece);
                throw new ConnectBackException("Couldn't connect back to the supplied Executor", ece);
            }
        }
Example #8
0
        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.");
        }
Example #9
0
 //-----------------------------------------------------------------------------------------------
 /// <summary>
 /// Gets the reference to the remote node
 /// </summary>
 /// <param name="remoteEP">end point of the remote node</param>
 /// <returns>Node reference</returns>
 public static GNode GetRemoteRef(RemoteEndPoint remoteEP)
 {
     return GetRemoteRef(remoteEP, DefaultRemoteObjectPrefix);
 }
Example #10
0
        /// <summary>
        /// Verify if the executor exists in the database and the remote endpoint host matches the database setting
        /// </summary>
        /// <param name="ep"></param>
        /// <returns></returns>
        private bool VerifyExists(RemoteEndPoint ep)
        {
            bool exists = false;

            try
            {
                logger.Debug("Checking if executor :"+_Id+" exists in db");

                ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

                bool remoteEndPointNullOrHostIsSameAsExecutor;
                remoteEndPointNullOrHostIsSameAsExecutor =
                    ep == null || (ep != null && executorStorage.HostName == ep.Host);

                if (executorStorage != null && remoteEndPointNullOrHostIsSameAsExecutor)
                {
                    exists = true;
                }

                logger.Debug("Executor :" + _Id + " exists in db=" + exists);
            }
            catch (Exception ex)
            {
                logger.Error("Executor :"+_Id+ " invalid id? ",ex);
                throw new InvalidExecutorException("The supplied Executor ID is invalid.", ex);
            }

            return exists;
        }
Example #11
0
        /// <summary>
        /// Connects to the executor in non-dedicated mode.
        /// </summary>
        public void ConnectNonDedicated(RemoteEndPoint ep)
        {
            logger.Debug("Trying to connect NON-Dedicated to executor: "+_Id);
            if (!VerifyExists(ep))
            {
                logger.Debug("The supplied Executor ID does not exist.");
                throw new InvalidExecutorException("The supplied Executor ID does not exist.", null);
            }

            //here we don't ping back, since we know non-dedicated nodes can't be pinged back.

            ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

            executorStorage.Connected = true;
            executorStorage.Dedicated = false;

            // update state in db
            ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);

            logger.Debug("Connected non-dedicated. Updated db. executor_id="+_Id);
        }
Example #12
0
 public GNode(RemoteEndPoint managerEP, OwnEndPoint ownEP, SecurityCredentials credentials, string remoteObjectPrefix)
 {
     _OwnEP = ownEP;
     _Credentials = credentials;
     _ManagerEP = managerEP;
     _RemoteObjPrefix = remoteObjectPrefix;
     Init();
 }
Example #13
0
 /// <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)
 {
 }
Example #14
0
        //-----------------------------------------------------------------------------------------------
        // public methods
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Initialised the remoted "node"
        /// </summary>
        protected void Init()
        {
            if (_Initted)
            {
                return;
            }

            if (_Connection != null)
            {
                _Credentials = new SecurityCredentials(_Connection.Username, _Connection.Password);
                _ManagerEP = new RemoteEndPoint(_Connection.Host, _Connection.Port, RemotingMechanism.TcpBinary);
            }
            GetManagerRef();
            RemoteSelf();
            _Initted = true;
        }
Example #15
0
 public static GNode GetRemoteRef(RemoteEndPoint remoteEP, string remoteObjectPrefix)
 {
     switch (remoteEP.RemotingMechanism)
     {
         case RemotingMechanism.TcpBinary:
             string uri = "tcp://" + remoteEP.Host + ":" + remoteEP.Port + "/" + remoteObjectPrefix;
             return (GNode) Activator.GetObject(typeof(GNode), uri);
         default:
             return null;
     }
 }
Example #16
0
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Gets the reference to the remote node
        /// </summary>
        /// <param name="remoteEP">end point of the remote node</param>
        /// <returns>Node reference</returns>
        public static GNode GetRemoteRef(RemoteEndPoint remoteEP)
        {
            return(GetRemoteRef(remoteEP, DefaultRemoteObjectPrefix));
        }
Example #17
0
        /// <summary>
        /// Connects to the executor in dedicated mode.
        /// </summary>
        /// <param name="ep">end point of the executor</param>
        public void ConnectDedicated(RemoteEndPoint ep)
        {
            logger.Debug("Trying to connect Dedicated to executor: "+_Id);
            if (!VerifyExists(ep))
            {
                logger.Debug("The supplied Executor ID does not exist.");
                throw new InvalidExecutorException("The supplied Executor ID does not exist.", null);
            }

            bool success = false;
            IExecutor executor;
            try
            {
                executor = (IExecutor) GNode.GetRemoteRef(ep, _Id);
                executor.PingExecutor(); //connect back to executor.
                success = true;
                logger.Debug("Connected dedicated. Executor_id="+_Id);
                ExecutorStorageView executorStorage = ManagerStorageFactory.ManagerStorage().GetExecutor(_Id);

                executorStorage.Connected = success;
                executorStorage.Dedicated = true;
                executorStorage.HostName = ep.Host;
                executorStorage.Port = ep.Port;

                // update state in db (always happens even if cannnot connect back to executor
                ManagerStorageFactory.ManagerStorage().UpdateExecutor(executorStorage);

                logger.Debug("Updated db after ping back to executor. dedicated executor_id="+_Id + ", dedicated = true, connected = "+success);
                // update hashtable
                if (!_DedicatedExecutors.ContainsKey(_Id))
                {
                    _DedicatedExecutors.Add(_Id, executor);
                    logger.Debug("Added to list of dedicated executors: executor_id="+_Id);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error connecting to exec: "+_Id,e);
                throw new ExecutorCommException(_Id, e);
            }
        }
Example #18
0
        //-----------------------------------------------------------------------------------------------
        // 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();
            }
        }
Example #19
0
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the reference to a remote manager
        /// </summary>
        /// <param name="remoteEP">end point of the remote manager</param>
        /// <returns>Manager reference</returns>
        public static IManager GetRemoteManagerRef(RemoteEndPoint remoteEP)
        {
            IManager manager;

            try
            {
                manager = (IManager) GetRemoteRef(remoteEP);
                manager.PingManager();
            }
            catch (Exception e)
            {
                throw new RemotingException("Could not connect to Manager.", e);
            }

            return manager;
        }