コード例 #1
0
 public ActiveMulticastSessionController()
 {
     _activeMulticastSessionService = new ServiceActiveMulticastSession();
     _auditLogService = new ServiceAuditLog();
     _userId          = Convert.ToInt32(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == "user_id")
                                        .Select(c => c.Value).SingleOrDefault());
 }
コード例 #2
0
ファイル: Multicast.cs プロジェクト: theopenem/Toems
        private int GenerateProcessArguments()
        {
            var multicastArgs = new DtoMulticastArgs();

            multicastArgs.schema      = new ServiceClientPartition(_imageProfile).GetImageSchema();
            multicastArgs.Environment = _imageProfile.Image.Environment;
            multicastArgs.ImageName   = _imageProfile.Image.Name;
            multicastArgs.Port        = _multicastSession.Port.ToString();

            var comServer = new ServiceClientComServer().GetServer(_multicastSession.ComServerId);

            if (_isOnDemand)
            {
                multicastArgs.ExtraArgs = string.IsNullOrEmpty(_imageProfile.SenderArguments)
                    ? comServer.MulticastSenderArguments
                    : _imageProfile.SenderArguments;
                if (!string.IsNullOrEmpty(_clientCount))
                {
                    multicastArgs.clientCount = _clientCount;
                }
            }
            else
            {
                multicastArgs.ExtraArgs = string.IsNullOrEmpty(_imageProfile.SenderArguments)
                    ? comServer.MulticastSenderArguments
                    : _imageProfile.SenderArguments;
                multicastArgs.clientCount = _computers.Count.ToString();
            }

            if (_multicastServerId == null)
            {
                return(0);
            }


            var pid = new MulticastArguments().RunOnComServer(multicastArgs, comServer);


            if (pid == 0)
            {
                return(pid);
            }

            var activeMulticastSessionServices = new ServiceActiveMulticastSession();

            if (_isOnDemand)
            {
                _multicastSession.Pid  = pid;
                _multicastSession.Name = _group.Name;
                activeMulticastSessionServices.AddActiveMulticastSession(_multicastSession);
            }
            else
            {
                _multicastSession.Pid = pid;
                activeMulticastSessionServices.UpdateActiveMulticastSession(_multicastSession);
            }

            return(pid);
        }
コード例 #3
0
        public string Upload(int taskId, string fileName, int profileId, int userId, string hdNumber)
        {
            //no need to find and call com server, client should already be directly communicating with the correct imaging server
            var guid = ConfigurationManager.AppSettings["ComServerUniqueId"];

            _thisComServer = new ServiceClientComServer().GetServerByGuid(guid);

            if (_thisComServer == null)
            {
                log.Error($"Com Server With Guid {guid} Not Found");
                return("0");
            }

            var appPath = Path.Combine(HttpContext.Current.Server.MapPath("~"), "private", "apps");

            var task = new ServiceActiveImagingTask().GetTask(taskId);

            if (task == null)
            {
                return("0");
            }

            var imageProfile = new ServiceImageProfile().ReadProfile(profileId);

            var uploadPort = new ServicePort().GetNextPort(task.ComServerId);

            var path = _thisComServer.LocalStoragePath;


            try
            {
                var dir = Path.Combine(path, "images", imageProfile.Image.Name, $"hd{ hdNumber}");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            catch (Exception ex)
            {
                log.Error("Could Not Create Directory");
                log.Error(ex.Message);
                return("0");
            }

            path = Path.Combine(path, "images", imageProfile.Image.Name, $"hd{hdNumber}", fileName);
            string arguments    = " /c \"";
            var    receiverPath = Path.Combine(appPath, "udp-receiver.exe");

            arguments += $"{receiverPath}\" --portbase {uploadPort}";
            arguments += $" --interface {_thisComServer.ImagingIp} --file {path}";

            var pid = StartReceiver(arguments, imageProfile.Image.Name);
            //use multicast session even though it's not a multicast, uploads still use udpcast
            var activeMulticast = new EntityActiveMulticastSession();

            if (pid != 0)
            {
                activeMulticast.ImageProfileId = imageProfile.Id;
                activeMulticast.Name           = imageProfile.Image.Name;
                activeMulticast.Pid            = pid;
                activeMulticast.Port           = uploadPort;
                activeMulticast.ComServerId    = _thisComServer.Id;
                activeMulticast.UserId         = userId;
                activeMulticast.UploadTaskId   = task.Id;

                var result = new ServiceActiveMulticastSession().AddActiveMulticastSession(activeMulticast);
                if (result)
                {
                    return(uploadPort.ToString());
                }
            }
            return("0");
        }
コード例 #4
0
ファイル: Multicast.cs プロジェクト: theopenem/Toems
        public string Create()
        {
            _imageProfile = new ServiceImageProfile().ReadProfile(_group.ImageProfileId);
            if (_imageProfile == null)
            {
                return("The Image Profile Does Not Exist");
            }

            if (_imageProfile.Image == null)
            {
                return("The Image Does Not Exist");
            }

            _multicastServerId = _isOnDemand
                ? _comServerId
                : new GetMulticastServer(_group).Run();

            if (_multicastServerId == null)
            {
                return("Could Not Find Any Available Multicast Servers");
            }


            var comServer = new ServiceClientComServer().GetServer(Convert.ToInt32(_multicastServerId));

            if (string.IsNullOrEmpty(comServer.MulticastInterfaceIp))
            {
                return("The Com Server's Multicast Interface IP Address Is Not Populated");
            }


            _multicastSession.Port = new ServicePort().GetNextPort(_multicastServerId);
            if (_multicastSession.Port == 0)
            {
                return("Could Not Determine Current Port Base");
            }

            _multicastSession.ComServerId = Convert.ToInt32(_multicastServerId);
            _multicastSession.UserId      = _userId;

            if (_isOnDemand)
            {
                if (string.IsNullOrEmpty(_multicastSession.Name))
                {
                    _multicastSession.Name = _multicastSession.Port.ToString();
                }

                if (string.IsNullOrEmpty(_multicastSession.Name) || !_multicastSession.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-'))
                {
                    return("Multicast Session Name Is Not Valid");
                }

                _group.Name = _multicastSession.Name;
                var onDemandprocessArguments = GenerateProcessArguments();
                if (onDemandprocessArguments == 0)
                {
                    return("Could Not Start The Multicast Application");
                }

                var ondAuditLog = new EntityAuditLog();
                ondAuditLog.AuditType = EnumAuditEntry.AuditType.OnDemandMulticast;
                ondAuditLog.ObjectId  = _imageProfile.ImageId;
                var ondUser = new ServiceUser().GetUser(_userId);
                if (ondUser != null)
                {
                    ondAuditLog.UserName = ondUser.Name;
                }
                ondAuditLog.ObjectName = _imageProfile.Image.Name;
                ondAuditLog.UserId     = _userId;
                ondAuditLog.ObjectType = "Image";
                ondAuditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession);
                new ServiceAuditLog().AddAuditLog(ondAuditLog);
                return("Successfully Started Multicast " + _group.Name);
            }
            //End of the road for starting an on demand multicast


            //Continue On If multicast is for a group
            _multicastSession.Name = _group.Name;
            _computers             = new ServiceGroup().GetGroupMembers(_group.Id);
            if (_computers.Count < 1)
            {
                return("The Group Does Not Have Any Members");
            }

            var activeMulticastSessionServices = new ServiceActiveMulticastSession();

            if (!activeMulticastSessionServices.AddActiveMulticastSession(_multicastSession))
            {
                return("Could Not Create Multicast Database Task.  An Existing Task May Be Running.");
            }

            if (!CreateComputerTasks())
            {
                activeMulticastSessionServices.Delete(_multicastSession.Id);
                return("Could Not Create Computer Database Tasks.  A Computer May Have An Existing Task.");
            }

            if (!CreatePxeFiles())
            {
                activeMulticastSessionServices.Delete(_multicastSession.Id);
                return("Could Not Create Computer Boot Files");
            }

            if (!CreateTaskArguments())
            {
                activeMulticastSessionServices.Delete(_multicastSession.Id);
                return("Could Not Create Computer Task Arguments");
            }

            var processArguments = GenerateProcessArguments();

            if (processArguments == 0)
            {
                activeMulticastSessionServices.Delete(_multicastSession.Id);
                return("Could Not Start The Multicast Application");
            }

            foreach (var computer in _computers)
            {
                _computerServices.Wakeup(computer.Id);
            }

            var auditLog = new EntityAuditLog();

            auditLog.AuditType = EnumAuditEntry.AuditType.Multicast;
            auditLog.ObjectId  = _group.Id;
            var user = new ServiceUser().GetUser(_userId);

            if (user != null)
            {
                auditLog.UserName = user.Name;
            }
            auditLog.ObjectName = _group.Name;
            auditLog.UserId     = _userId;
            auditLog.ObjectType = "Group";
            auditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession);
            new ServiceAuditLog().AddAuditLog(auditLog);

            auditLog.ObjectId   = _imageProfile.ImageId;
            auditLog.ObjectName = _imageProfile.Image.Name;
            auditLog.ObjectType = "Image";
            new ServiceAuditLog().AddAuditLog(auditLog);

            return("Successfully Started Multicast " + _group.Name);
        }
コード例 #5
0
        public int?Run()
        {
            //Find the best multicast server to use

            var serverId = -1;


            if (_group.ClusterId == -1) //-1 is default cluster
            {
                _cluster = _uow.ComServerClusterRepository.GetFirstOrDefault(x => x.IsDefault);
                if (_cluster == null)
                {
                    return(null);
                }
            }
            else
            {
                _cluster = _uow.ComServerClusterRepository.GetById(_group.ClusterId);
                if (_cluster == null)
                {
                    return(null);
                }
            }


            var availableMulticastServers = _uow.ComServerClusterServerRepository.GetMulticastClusterServers(_cluster.Id);

            if (!availableMulticastServers.Any())
            {
                return(null);
            }

            var taskInUseDict = new Dictionary <int, int>();

            foreach (var mServer in availableMulticastServers)
            {
                var counter =
                    new ServiceActiveMulticastSession().GetAll()
                    .Count(x => x.ComServerId == mServer.ComServerId);

                taskInUseDict.Add(mServer.ComServerId, counter);
            }

            if (taskInUseDict.Count == 1)
            {
                serverId = taskInUseDict.Keys.First();
            }

            else if (taskInUseDict.Count > 1)
            {
                var orderedInUse = taskInUseDict.OrderBy(x => x.Value);

                if (taskInUseDict.Values.Distinct().Count() == 1)
                {
                    //all multicast server have equal tasks - randomly choose one.

                    var index = _random.Next(0, taskInUseDict.Count);
                    serverId = taskInUseDict[index];
                }
                else
                {
                    //Just grab the first one with the smallest queue, could be a duplicate but will eventually even out on it's own
                    serverId = orderedInUse.First().Key;
                }
            }
            return(serverId);
        }