コード例 #1
0
        /// <summary>
        /// Initializes a cluster manager and starts the acquisition for all nodes.
        /// </summary>
        /// <param name="url">The url of the head-node.</param>
        /// <param name="username">The username to login.</param>
        /// <param name="password">The password to login.</param>
        /// <param name="platform">The platform of the cluster.</param>
        /// <param name="id">An ID for the cluster, to be able to have multiple clusters of one platform.</param>
        public void Initialize(object cred)
        {
            try
            {
                var credentials = (ClusterCredential)cred;

                timerJobs   = new List <TimerJobBase>();
                clusterType = (Platform)credentials.Platform;
                ID          = credentials.ID;

                if (!OUManager.Instance.Exists(clusterType.ToString() + ID))
                {
                    OUManager.Instance.CreateOU(clusterType.ToString() + ID, null, DateTime.Now);
                }
                using (var datacontext = DataContextFactory.CreateReadOnlyDataContext())
                {
                    var OU = (from p in datacontext.OrganizationalUnit
                              where p.FQDN.Equals(clusterType.ToString() + ID)
                              select p).First();
                    this.OUID = OU.ID;
                }

                switch (clusterType)
                {
                case Platform.Bright:
                    clusterConnection = new BrightClusterConnection();
                    clusterConnection.Init(credentials.HeadNodeUrl, credentials.Username, credentials.Password);
                    clusterNodes = clusterConnection.GetNodes();

                    if (PluginManager.Instance.BrightPlugins != null)
                    {
                        clusterPlugins = PluginManager.Instance.BrightPlugins.ToList();
                        this.AddNodes(clusterNodes);
                    }
                    break;

                case Platform.HPC:
                    clusterConnection = new HpcClusterConnection();
                    clusterConnection.Init(credentials.HeadNodeUrl, credentials.Username, credentials.Password);
                    clusterNodes = clusterConnection.GetNodes();
                    if (PluginManager.Instance.HPCPlugins != null)
                    {
                        clusterPlugins = PluginManager.Instance.HPCPlugins.ToList();
                        this.AddNodes(clusterNodes);
                    }
                    break;

                default:
                    // logging unsupported platform
                    var messageEx = new StringBuilder();
                    messageEx.Append("ClusterManager_AddNodes: ");
                    messageEx.Append("The platform " + clusterType.ToString());
                    messageEx.Append(" is not supported.");
                    MISD.Core.Logger.Instance.WriteEntry(messageEx.ToString(), LogType.Exception);
                    break;
                }

                // Register this cluster at the metacluster manager
                MetaClusterManager.Instance.AddCluster(this);
            }
            catch (Exception e)
            {
                Logger.Instance.WriteEntry("ClusterManager_Initialize: Problem initilizing cluster, " + e.ToString(), LogType.Exception);
            }
        }
コード例 #2
0
        /// <summary>
        /// Refreshes the nodes, deletes old nodes and adds new nodes with the corresponding timer jobs.
        /// </summary>
        public void RefreshNodes()
        {
            #region Initialize Lists

            List <WorkstationInfo> currentNodes       = clusterConnection.GetNodes();
            List <WorkstationInfo> oldNodes           = new List <WorkstationInfo>(clusterNodes);
            List <WorkstationInfo> doubleNodesCurrent = new List <WorkstationInfo>();
            List <WorkstationInfo> doubleNodesOld     = new List <WorkstationInfo>();

            #endregion

            #region Find diff

            foreach (WorkstationInfo current in currentNodes)
            {
                foreach (WorkstationInfo old in oldNodes)
                {
                    if (current.MacAddress == old.MacAddress)
                    {
                        doubleNodesCurrent.Add(current);
                        doubleNodesOld.Add(old);
                    }
                }
            }

            foreach (WorkstationInfo current in doubleNodesCurrent)
            {
                currentNodes.Remove(current);
            }
            foreach (WorkstationInfo current in doubleNodesOld)
            {
                oldNodes.Remove(current);
            }

            #endregion

            #region Add new timerjobs and delete old timerjobs

            List <WorkstationInfo> newNodes = new List <WorkstationInfo>();
            foreach (WorkstationInfo current in currentNodes)
            {
                newNodes.Add(current);
            }

            if (newNodes.Count > 0)
            {
                AddNodes(newNodes);
            }

            // old approach
            //List<TimerJobBase> toBeDeleted = new List<TimerJobBase>();
            //foreach (WorkstationInfo old in oldNodes)
            //{
            //    var timerjob = (from node in timerJobs
            //                    where node.ID.Contains(old.MacAddress + ".")
            //                    select node).First();
            //    toBeDeleted.Add(timerjob);
            //}

            // old approach
            //foreach (TimerJobBase current in toBeDeleted)
            //{
            //    timerJobs.Remove(current);
            //    current.Stop();
            //    current.Dispose();
            //}

            // new approach
            foreach (WorkstationInfo old in oldNodes)
            {
                ClusterJobScheduler.Instance.RemoveAllJobsForNode(old);
            }

            #endregion

            StartJobs();
        }