Exemple #1
0
        public string GetAllClusterDps(int computerId)
        {
            var rnd = new Random();
            var computerServices = new ComputerServices();
            var computer         = computerServices.GetComputer(computerId);

            if (SettingServices.ServerIsNotClustered)
            {
                return("single");
            }

            var clusterServices = new ClusterGroupServices();

            ClusterGroupEntity clusterGroup;

            if (computer != null)
            {
                clusterGroup = new ComputerServices().GetClusterGroup(computer.Id);
            }
            else
            {
                //on demand computer might be null
                //use default cluster group
                clusterGroup = clusterServices.GetDefaultClusterGroup();
            }

            //Something went wrong
            if (clusterGroup == null)
            {
                return("false");
            }

            var clusterDps   = clusterServices.GetClusterDps(clusterGroup.Id);
            var dpList       = clusterDps.Select(clusterDp => clusterDp.DistributionPointId).ToList();
            var randomDpList = new List <int>();

            try
            {
                randomDpList = dpList.OrderBy(x => rnd.Next()).ToList();
            }
            catch (Exception ex)
            {
                log.Error("Could Not Select Random Distribution Point");
                log.Error(ex.Message);
                return("false");
            }

            var result = "";

            foreach (var dpId in randomDpList)
            {
                result += dpId + " ";
            }

            return(result);
        }
        public TftpServerDTO GetComputerTftpServers(string mac)
        {
            var tftpDto = new TftpServerDTO();

            tftpDto.TftpServers = new List <string>();
            if (SettingServices.ServerIsNotClustered)
            {
                tftpDto.TftpServers.Add(
                    StringManipulationServices.PlaceHolderReplace(
                        SettingServices.GetSettingValue(SettingStrings.TftpServerIp)));
            }

            else
            {
                var clusterServices         = new ClusterGroupServices();
                var secondaryServerServices = new SecondaryServerServices();
                List <ClusterGroupServerEntity> clusterServers;
                var computer = new ComputerServices().GetComputerFromMac(mac);
                if (computer == null)
                {
                    var cg = new ClusterGroupServices().GetDefaultClusterGroup();
                    clusterServers = clusterServices.GetActiveClusterServers(cg.Id);
                }
                else
                {
                    var cg = new ComputerServices().GetClusterGroup(computer.Id);
                    clusterServers = clusterServices.GetActiveClusterServers(cg.Id);
                }

                foreach (var tftpServer in clusterServers.Where(x => x.TftpRole == 1))
                {
                    if (tftpServer.ServerId == -1)
                    {
                        tftpDto.TftpServers.Add(
                            StringManipulationServices.PlaceHolderReplace(
                                SettingServices.GetSettingValue(SettingStrings.TftpServerIp)));
                    }
                    else
                    {
                        var serverIdentifier =
                            secondaryServerServices.GetSecondaryServer(tftpServer.ServerId).Name;
                        var tServer =
                            new APICall(new SecondaryServerServices().GetToken(serverIdentifier)).ServiceAccountApi
                            .GetTftpServer();
                        if (tServer != null)
                        {
                            tftpDto.TftpServers.Add(tServer);
                        }
                    }
                }
            }

            return(tftpDto);
        }
Exemple #3
0
        public ClusterGroupEntity GetClusterGroup(int computerId)
        {
            ClusterGroupEntity cg = null;
            var cgServices        = new ClusterGroupServices();
            var computer          = GetComputer(computerId);

            if (computer.ClusterGroupId != -1)
            {
                cg = cgServices.GetClusterGroup(computer.ClusterGroupId);
                return(cg ?? cgServices.GetDefaultClusterGroup());
            }
            if (computer.RoomId != -1)
            {
                var room = new RoomServices().GetRoom(computer.RoomId);
                if (room != null)
                {
                    if (room.ClusterGroupId != -1)
                    {
                        cg =
                            cgServices.GetClusterGroup(room.ClusterGroupId);
                        return(cg ?? cgServices.GetDefaultClusterGroup());
                    }
                }
            }
            if (computer.BuildingId != -1)
            {
                var building = new BuildingServices().GetBuilding(computer.BuildingId);
                if (building != null)
                {
                    if (building.ClusterGroupId != -1)
                    {
                        cg =
                            cgServices.GetClusterGroup(building.ClusterGroupId);
                        return(cg ?? cgServices.GetDefaultClusterGroup());
                    }
                }
            }
            if (computer.SiteId != -1)
            {
                var site = new SiteServices().GetSite(computer.SiteId);
                if (site != null)
                {
                    if (site.ClusterGroupId != -1)
                    {
                        cg =
                            cgServices.GetClusterGroup(site.ClusterGroupId);
                        return(cg ?? cgServices.GetDefaultClusterGroup());
                    }
                }
            }

            return(cgServices.GetDefaultClusterGroup());
        }
Exemple #4
0
        public ClusterGroupEntity GetClusterGroup(int groupId)
        {
            var cgServices = new ClusterGroupServices();
            var group      = GetGroup(groupId);

            if (group.ClusterGroupId != -1)
            {
                var cg = cgServices.GetClusterGroup(@group.ClusterGroupId);
                return(cg ?? cgServices.GetDefaultClusterGroup());
            }

            return(cgServices.GetDefaultClusterGroup());
        }