///---------------------------------------------------------------------------------
        protected void view_Save(object sender, EventArgs e)
        {
            bool isNew = false;
            if (agentId == 0)
            {
                isNew = true;

                agentId = ProxyHelper.GetUserAgentId(this.UserId);
                sosProfile.AgentId = agentId;

                AgentPool agentPool = (AgentPool)Application["AgentPool"];
                agentPool.RegisterAgent(agentId);
            }


            if (agentId != 0)
            {
                UCENTRIK.DATASETS.AgentDS.AgentDSDataTable dt = BllProxyAgent.SelectAgent(agentId);
                if (dt.Rows.Count != 0)
                {
                    string firstName = dt[0].first_name;
                    string lastName = dt[0].last_name;
                    string email = dt[0].email;
                    BllProxyUserHelper.UpdateUserDetails(this.UserId, firstName, lastName, email);

                }
            }

            if(isNew)
                this.Refresh();

        }
        protected void view_Save(object sender, EventArgs e)
        {
            AgentPool agentPool = (AgentPool)Application["AgentPool"];

            agentPool.SetAgentBusy(agentId, false);

            Response.Redirect("CallQueue.aspx");
        }
Пример #3
0
        public UcAppBot(AgentPool agentPool)
        {
            _agentPool = agentPool;

            Thread threadBot = new Thread(this._doRoutine);

            threadBot.Start();
        }
Пример #4
0
        private AgentPool GetAgentPool()
        {
            var agentPool = new AgentPool(
                name: Name,
                count: Count,
                vmSize: VmSize,
                osDiskSizeGB: OsDiskSize,
                type: VmSetType ?? "AvailabilitySet",
                vnetSubnetID: VnetSubnetID);

            if (this.IsParameterBound(c => c.KubernetesVersion))
            {
                agentPool.OrchestratorVersion = KubernetesVersion;
            }

            if (this.IsParameterBound(c => c.OsType))
            {
                agentPool.OsType = OsType;
            }
            if (this.IsParameterBound(c => c.MaxPodCount))
            {
                agentPool.MaxPods = MaxPodCount;
            }
            if (this.IsParameterBound(c => c.MinCount))
            {
                agentPool.MinCount = MinCount;
            }
            if (this.IsParameterBound(c => c.MaxCount))
            {
                agentPool.MaxCount = MaxCount;
            }
            if (EnableAutoScaling.IsPresent)
            {
                agentPool.EnableAutoScaling = EnableAutoScaling.ToBool();
            }
            if (EnableNodePublicIp.IsPresent)
            {
                agentPool.EnableNodePublicIP = EnableNodePublicIp.ToBool();
            }
            if (this.IsParameterBound(c => c.NodePublicIPPrefixID))
            {
                agentPool.NodePublicIPPrefixID = NodePublicIPPrefixID;
            }
            if (this.IsParameterBound(c => c.ScaleSetEvictionPolicy))
            {
                agentPool.ScaleSetEvictionPolicy = ScaleSetEvictionPolicy;
            }
            if (this.IsParameterBound(c => c.ScaleSetPriority))
            {
                agentPool.ScaleSetPriority = ScaleSetPriority;
            }
            if (this.IsParameterBound(c => c.AvailabilityZone))
            {
                agentPool.AvailabilityZones = AvailabilityZone;
            }

            return(agentPool);
        }
        protected void ucIncident_BackToList(object sender, EventArgs e)
        {
            Int32 agentId = ProxyHelper.GetUserAgentId(this.UserId);

            AgentPool agentPool = (AgentPool)Application["AgentPool"];

            agentPool.SetAgentBusy(agentId, false);

            this.hideVideo();
        }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Parameters"></param>
        /// <param name="Dim"></param>
        /// <param name="DimObjs"></param>
        /// <exception cref="ArgumentException">If <paramref name="Parameters"/> is not initialized.</exception>
        protected virtual void Init(FWParams Parameters, int Dim, int DimObjs)
        {
            if (!Parameters.IsParamsInit)
            {
                throw new ArgumentException("The parameters were created by the default constructor and have invalid values. You need to create parameters with a custom constructor.", nameof(Parameters));
            }

            _parameters = Parameters;

            _minDebrisCount = _parameters.Smin;
            _maxDebrisCount = _parameters.Smax;

            if (_coordNumbers == null)
            {
                _coordNumbers = new int[Dim];
            }
            else if (_coordNumbers.Length != Dim)
            {
                _coordNumbers = new int[Dim];
            }

            if (_chargePoints == null)
            {
                _chargePoints = new List <Agent>(_parameters.NP);
            }
            else
            {
                _chargePoints.Clear();
                _chargePoints.Capacity = _parameters.NP;
            }

            if (_debris == null)
            {
                InitDebris();
            }
            else if (_debris.Length != this.Parameters.NP)
            {
                InitDebris();
            }

            int newSizeMatrix = checked (_parameters.NP - 1 + _parameters.NP * _minDebrisCount);

            _weightedAgents = new List <WeightOfAgent>(newSizeMatrix);

            _pool = new AgentPool(_parameters.NP * _maxDebrisCount / 2, new AgenCreator(Dim, DimObjs));

            if (_matrixOfDistances == null)
            {
                _matrixOfDistances = new DynSymmetricMatrix(newSizeMatrix);
            }
        }
Пример #7
0
        private void Initialization()
        {
            //监听IP数量
            AgentPool.IpsChange += (nums) =>
            {
                this.Invoke(new Action(() => lblIpsNums.Text = $"IP数量:{nums}"));
            };
            AgentPool.AddAgentIp(JsonConfig <AgentIp> .GetSiteConfigs());
            AgentPool.SaveIps();
            RefreshRoom();
            return;

            Task.Run(async() =>
            {
                while (true)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        await Task.Delay(2000);
                        try
                        {
                            using (HttpWebResponse httpWebResponse = await CCHttpRequest.CreateGetHttpResponseAsync("http://http.tiqu.alicdns.com/getip3?num=20&type=2&pro=&city=0&yys=0&port=2&pack=74963&ts=1&ys=1&cs=1&lb=1&sb=0&pb=45&mr=2&regions=&gm=4"))
                            {
                                //获取返回内容
                                string json = await httpWebResponse.GetResponseStream().ReadAllTextAsync();
                                MsgInfo(json);
                                //将JSON字符串转换为dynamic类型
                                dynamic obj = JsonConvert.DeserializeObject <dynamic>(json);
                                if (obj.success != true)
                                {
                                    continue;
                                }
                                List <AgentIp> ips = obj.data.ToObject <List <AgentIp> >();
                                AgentPool.AddAgentIp(ips);
                                AgentPool.SaveIps();
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"【获取IP错误】:{ex.Message}");
                            MsgError($"【获取IP错误】:{ex.Message}");
                        }
                    }
                    return;

                    await Task.Delay(10000);
                }
            });
        }
Пример #8
0
        /// <summary>
        /// 初始化连接是否成功
        /// </summary>
        /// <returns></returns>
        public bool Initialization()
        {
            try
            {
                //取消之前正在运行的线程
                if (source != null)
                {
                    source.Cancel();
                }
                source = new CancellationTokenSource();

                agent?.RemoveRoom(ROOM_ID);
                var ips = AgentPool.GetAgentIp(ROOM_ID);
                if (ips.Count > 0)
                {
                    agent = ips[0];
                    Console.WriteLine($"{agent.Ip}:{agent.Port}");
                }
                else
                {
                    agent = null;
                }
                AuthClient?.CloseAsync();
                DanmuClient?.CloseAsync();
                //创建实例
                AuthClient = CreateAuthSocket(source.Token);

                //认证
                Authentication();
                //认证通过开启心跳
                AuthKeepAlive(source.Token);

                DanmuClient = CreateDanmuSocket(source.Token);
                //tcpClient = SocketHelper.InitTcp(agent.Ip, agent.Port);
                //ConnectProxyServer(SERVER_DOMAIN, SERVER_PORT, tcpClient);

                //登录房间
                RoomLogin();
                //心跳维持
                DanmmuKeepAlive(source.Token);
                AppLog.Debug($"监控房间【{ROOM_ID}】成功");
                return(true);
            }
            catch (Exception ex)
            {
                AppLog.Error($"【房间:{ROOM_ID}】【监控失败】", ex);
                return(false);
            }
        }
Пример #9
0
        public void AgentPool_Constructor_Hosted()
        {
            // Arrange
            var ps  = BaseTests.PrepPowerShell();
            var obj = BaseTests.LoadJson("Get-VSTeamPool.json");

            // Act
            var target = new AgentPool(obj[1], ps);

            // Assert
            Assert.AreEqual(2, target.Id, "Id");
            Assert.AreEqual(15, target.Count, "Count");
            Assert.AreEqual(true, target.IsHosted, "IsHosted");
            Assert.AreEqual("d-r-s-", target.DisplayMode, "DisplayMode");
        }
        protected AgentPool GetAgentPoolObject()
        {
            AgentPool pool = null;

            try
            {
                pool = Client.AgentPools.Get(ResourceGroupName, ClusterName, Name);
                WriteVerbose(string.Format(Resources.AgentPoolExists, pool != null));
            }
            catch (Exception)
            {
                WriteVerbose(Resources.AgentPoolDoesNotExist);
            }
            return(pool);
        }
Пример #11
0
        protected void Application_Start(object sender, EventArgs e)
        {
            UcGlobalHelper.UcApplicationStart(Application);
            //-----------------------------------------------------------


            UcTextChatController textChatController = new UcTextChatController();

            Application.Add("UcTextChatController", textChatController);

            AgentPool agentPool = new AgentPool();

            Application.Add("AgentPool", agentPool);

            UcAppBot appBot = new UcAppBot(agentPool);

            Application.Add("appBot", appBot);
        }
Пример #12
0
        public void AgentPool_GetChildItem()
        {
            // Arrange
            var ps     = BaseTests.PrepPowerShell();
            var pools  = BaseTests.LoadJson("Get-VSTeamPool.json");
            var agents = BaseTests.LoadJson("Get-VSTeamAgent-PoolId1.json");

            ps.Invoke().Returns(agents);

            var target = new AgentPool(pools[0], ps);

            // Act
            var actual = target.GetChildItem();

            // Assert
            Assert.AreEqual(4, actual.Length);
            ps.Received().AddCommand("Get-VSTeamAgent");
        }
Пример #13
0
        public Dispatcher(DispatcherConfig config)
        {
            using (Trace.Log())
            {
                Instance = this;

                var ipaddress = IPUtil.GetLocalIpAddress();

                this.Identifier = $"{Constants.Names.Dispatcher}_{Guid.NewGuid()}";
                this.SignalrUrl = $"{ipaddress}:{config.DispatcherPort}";
                this.WebUrl     = $"{ipaddress}:{config.WebPort}";
                this.Config     = config;

                Console.WriteLine($"Identifier: {Identifier}");

                this.Agents   = new AgentPool(this);
                this.jobQueue = new SortedList <int, Job>();

                this.Coordinator = new CoordinatorConnection($"http://{config.CoordinatorAddress}", Identifier, SignalrUrl, WebUrl, "DispatcherHub");
                this.Coordinator.EndpointAdded       += (info) => Agents.Add(info);
                this.Coordinator.EndpointRemoved     += (name) => Agents.Remove(name);
                this.Coordinator.EndpointListUpdated += (list) => Agents.Update(list);
                this.Coordinator.StateChanged        += OnCoordinatorStateChanged;
                this.Coordinator.Start();

                if (config.Monitor)
                {
                    Monitor = new DispatcherMonitor(this, config.WebPort);
                }

                var hostUrl = Permissions.GetHostUrl(Config.DispatcherPort);
                host = WebApp.Start(new StartOptions(hostUrl)
                {
                    AppStartup = typeof(DispatcherStartup).FullName
                });
                Console.WriteLine("Server running on {0}", hostUrl);
            }
        }
        protected void ucLogOn_LoggingOut(object sender, UcUserArgs e)
        {
            switch (e.UserRoleId)
            {
            case 1:     // Admin
                break;

            case 2:     // Agent
                Int32     agentId   = ProxyHelper.GetUserAgentId(e.UserId);
                AgentPool agentPool = (AgentPool)Application["AgentPool"];
                agentPool.UnRegisterAgent(agentId);
                break;

            case 3:     // Manager
                break;

            case 5:     // Supervisor
                break;

            default:
                break;
            }
        }
Пример #15
0
 /// <summary>
 /// Creates an agent pool for a container registry with the specified
 /// parameters.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group to which the container registry belongs.
 /// </param>
 /// <param name='registryName'>
 /// The name of the container registry.
 /// </param>
 /// <param name='agentPoolName'>
 /// The name of the agent pool.
 /// </param>
 /// <param name='agentPool'>
 /// The parameters of an agent pool that needs to scheduled.
 /// </param>
 public static AgentPool Create(this IAgentPoolsOperations operations, string resourceGroupName, string registryName, string agentPoolName, AgentPool agentPool)
 {
     return(operations.CreateAsync(resourceGroupName, registryName, agentPoolName, agentPool).GetAwaiter().GetResult());
 }
Пример #16
0
 /// <summary>
 /// Creates an agent pool for a container registry with the specified
 /// parameters.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group to which the container registry belongs.
 /// </param>
 /// <param name='registryName'>
 /// The name of the container registry.
 /// </param>
 /// <param name='agentPoolName'>
 /// The name of the agent pool.
 /// </param>
 /// <param name='agentPool'>
 /// The parameters of an agent pool that needs to scheduled.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async System.Threading.Tasks.Task <AgentPool> BeginCreateAsync(this IAgentPoolsOperations operations, string resourceGroupName, string registryName, string agentPoolName, AgentPool agentPool, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateWithHttpMessagesAsync(resourceGroupName, registryName, agentPoolName, agentPool, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            AgentPool          pool     = null;
            ResourceIdentifier resource = null;

            switch (ParameterSetName)
            {
            case Constants.IdParameterSet:
                resource          = new ResourceIdentifier(Id);
                ResourceGroupName = resource.ResourceGroupName;
                ClusterName       = Utilities.GetParentResourceName(resource.ParentResource, nameof(Id));
                Name = resource.ResourceName;
                break;

            case Constants.InputObjectParameterSet:
                WriteVerbose(Resources.UsingAgentPoolFromPipeline);
                pool              = PSMapper.Instance.Map <AgentPool>(InputObject);
                resource          = new ResourceIdentifier(pool.Id);
                ResourceGroupName = resource.ResourceGroupName;
                ClusterName       = Utilities.GetParentResourceName(resource.ParentResource, nameof(InputObject));
                Name              = resource.ResourceName;
                break;

            case Constants.ParentObjectParameterSet:
                resource          = new ResourceIdentifier(ClusterObject.Id);
                ResourceGroupName = resource.ResourceGroupName;
                ClusterName       = ClusterObject.Name;
                break;
            }

            var msg = $"{Name} for {ClusterName} in {ResourceGroupName}";

            if (ShouldProcess(msg, Resources.UpdateAgentPool))
            {
                RunCmdLet(() =>
                {
                    {
                        //Put agentPool in the block to avoid referencing it incorrectly.
                        var agentPool = GetAgentPoolObject();
                        if (agentPool == null)
                        {
                            WriteErrorWithTimestamp(Resources.AgentPoolDoesNotExist);
                            return;
                        }

                        if (pool == null)
                        {
                            pool = agentPool;
                        }
                    }

                    if (this.IsParameterBound(c => c.KubernetesVersion))
                    {
                        pool.OrchestratorVersion = KubernetesVersion;
                    }
                    if (this.IsParameterBound(c => c.MinCount))
                    {
                        pool.MinCount = MinCount;
                    }
                    if (this.IsParameterBound(c => c.MaxCount))
                    {
                        pool.MaxCount = MaxCount;
                    }
                    if (this.IsParameterBound(c => c.EnableAutoScaling))
                    {
                        pool.EnableAutoScaling = EnableAutoScaling.ToBool();
                    }
                    if (this.IsParameterBound(c => c.NodeCount))
                    {
                        pool.Count = NodeCount;
                    }

                    if (this.IsParameterBound(c => c.NodeImageOnly))
                    {
                        if (this.IsParameterBound(c => c.KubernetesVersion))
                        {
                            throw new AzPSArgumentException(Resources.UpdateKubernetesVersionAndNodeImageOnlyConflict, "KubernetesVersion");
                        }
                        if (!ShouldProcess(Resources.ConfirmOnlyUpgradeNodeVersion, ""))
                        {
                            return;
                        }

                        var upgradedPool = Client.AgentPools.UpgradeNodeImageVersion(ResourceGroupName, ClusterName, Name);
                        WriteObject(PSMapper.Instance.Map <PSNodePool>(upgradedPool));
                        return;
                    }

                    var updatedPool = Client.AgentPools.CreateOrUpdate(ResourceGroupName, ClusterName, Name, pool);
                    WriteObject(PSMapper.Instance.Map <PSNodePool>(updatedPool));
                });
            }
        }
 /// <summary>
 /// Creates or updates an agent pool.
 /// </summary>
 /// <remarks>
 /// Creates or updates an agent pool in the specified managed cluster.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='resourceName'>
 /// The name of the managed cluster resource.
 /// </param>
 /// <param name='agentPoolName'>
 /// The name of the agent pool.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create or Update an agent pool operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <AgentPool> BeginCreateOrUpdateAsync(this IAgentPoolsOperations operations, string resourceGroupName, string resourceName, string agentPoolName, AgentPool parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, resourceName, agentPoolName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates or updates an agent pool.
 /// </summary>
 /// <remarks>
 /// Creates or updates an agent pool in the specified managed cluster.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='resourceName'>
 /// The name of the managed cluster resource.
 /// </param>
 /// <param name='agentPoolName'>
 /// The name of the agent pool.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create or Update an agent pool operation.
 /// </param>
 public static AgentPool BeginCreateOrUpdate(this IAgentPoolsOperations operations, string resourceGroupName, string resourceName, string agentPoolName, AgentPool parameters)
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, resourceName, agentPoolName, parameters).GetAwaiter().GetResult());
 }
Пример #20
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            ManagedCluster cluster = null;

            switch (ParameterSetName)
            {
            case IdParameterSet:
            {
                var resource = new ResourceIdentifier(Id);
                ResourceGroupName = resource.ResourceGroupName;
                Name = resource.ResourceName;
                break;
            }

            case InputObjectParameterSet:
            {
                WriteVerbose(Resources.UsingClusterFromPipeline);
                cluster = PSMapper.Instance.Map <ManagedCluster>(InputObject);
                var resource = new ResourceIdentifier(cluster.Id);
                ResourceGroupName = resource.ResourceGroupName;
                Name = resource.ResourceName;
                break;
            }
            }

            var msg = $"{Name} in {ResourceGroupName}";

            if (ShouldProcess(msg, Resources.UpdateOrCreateAManagedKubernetesCluster))
            {
                RunCmdLet(() =>
                {
                    AcsServicePrincipal acsServicePrincipal;
                    if (Exists())
                    {
                        if (cluster == null)
                        {
                            cluster = Client.ManagedClusters.Get(ResourceGroupName, Name);
                        }

                        if (this.IsParameterBound(c => c.Location))
                        {
                            throw new AzPSArgumentException(
                                Resources.LocationCannotBeUpdateForExistingCluster,
                                nameof(Location),
                                desensitizedMessage: Resources.LocationCannotBeUpdateForExistingCluster);
                        }

                        if (this.IsParameterBound(c => c.DnsNamePrefix))
                        {
                            WriteVerbose(Resources.UpdatingDnsNamePrefix);
                            cluster.DnsPrefix = DnsNamePrefix;
                        }

                        if (this.IsParameterBound(c => c.SshKeyValue))
                        {
                            WriteVerbose(Resources.UpdatingSshKeyValue);
                            cluster.LinuxProfile.Ssh.PublicKeys = new List <ContainerServiceSshPublicKey>
                            {
                                new ContainerServiceSshPublicKey(GetSshKey(SshKeyValue))
                            };
                        }
                        if (this.IsParameterBound(c => c.ServicePrincipalIdAndSecret))
                        {
                            WriteVerbose(Resources.UpdatingServicePrincipal);
                            acsServicePrincipal = EnsureServicePrincipal(ServicePrincipalIdAndSecret.UserName, ServicePrincipalIdAndSecret.Password?.ConvertToString());

                            var spProfile = new ManagedClusterServicePrincipalProfile(
                                acsServicePrincipal.SpId,
                                acsServicePrincipal.ClientSecret);
                            cluster.ServicePrincipalProfile = spProfile;
                        }

                        if (this.IsParameterBound(c => c.LinuxProfileAdminUserName))
                        {
                            WriteVerbose(Resources.UpdatingAdminUsername);
                            cluster.LinuxProfile.AdminUsername = LinuxProfileAdminUserName;
                        }

                        if (NeedUpdateNodeAgentPool())
                        {
                            ManagedClusterAgentPoolProfile defaultAgentPoolProfile;

                            string nodePoolName = "default";
                            if (this.IsParameterBound(c => c.NodeName))
                            {
                                nodePoolName = NodeName;
                            }

                            if (cluster.AgentPoolProfiles.Any(x => x.Name == nodePoolName))
                            {
                                defaultAgentPoolProfile = cluster.AgentPoolProfiles.First(x => x.Name == nodePoolName);
                            }
                            else
                            {
                                throw new AzPSArgumentException(
                                    Resources.SpecifiedAgentPoolDoesNotExist,
                                    nameof(Name),
                                    desensitizedMessage: Resources.SpecifiedAgentPoolDoesNotExist);
                            }

                            if (this.IsParameterBound(c => c.NodeMinCount))
                            {
                                defaultAgentPoolProfile.MinCount = NodeMinCount;
                            }
                            if (this.IsParameterBound(c => c.NodeMaxCount))
                            {
                                defaultAgentPoolProfile.MaxCount = NodeMaxCount;
                            }
                            if (this.IsParameterBound(c => c.EnableNodeAutoScaling))
                            {
                                defaultAgentPoolProfile.EnableAutoScaling = EnableNodeAutoScaling.ToBool();
                            }
                            if (this.IsParameterBound(c => c.NodeVmSize))
                            {
                                WriteVerbose(Resources.UpdatingNodeVmSize);
                                defaultAgentPoolProfile.VmSize = NodeVmSize;
                            }

                            if (this.IsParameterBound(c => c.NodeCount))
                            {
                                WriteVerbose(Resources.UpdatingNodeCount);
                                defaultAgentPoolProfile.Count = NodeCount;
                            }

                            if (this.IsParameterBound(c => c.NodeOsDiskSize))
                            {
                                WriteVerbose(Resources.UpdatingNodeOsDiskSize);
                                defaultAgentPoolProfile.OsDiskSizeGB = NodeOsDiskSize;
                            }

                            if (this.IsParameterBound(c => c.NodePoolMode))
                            {
                                WriteVerbose(Resources.UpdatingNodePoolMode);
                                defaultAgentPoolProfile.Mode = NodePoolMode;
                            }
                        }

                        if (this.IsParameterBound(c => c.KubernetesVersion) && this.IsParameterBound(c => c.NodeImageOnly))
                        {
                            throw new AzPSArgumentException(Resources.UpdateKubernetesVersionAndNodeImageOnlyConflict, "KubernetesVersion");
                        }

                        bool allAgentPoolVirtualMachineScaleSets = cluster.AgentPoolProfiles.All(c => c.Type.ToLower().Equals("virtualmachinescalesets"));
                        if (this.IsParameterBound(c => c.NodeImageOnly))
                        {
                            if (!ShouldProcess(Resources.ConfirmOnlyUpgradeNodeVersion, ""))
                            {
                                return;
                            }

                            foreach (var agentPoolProfile in cluster.AgentPoolProfiles)
                            {
                                if (!allAgentPoolVirtualMachineScaleSets)
                                {
                                    throw new AzPSApplicationException(Resources.NotUsingVirtualMachineScaleSets);
                                }
                                var agentPoolClient = Client.AgentPools.Get(ResourceGroupName, Name, agentPoolProfile.Name);
                                AgentPool parameter = new AgentPool
                                {
                                    Count               = agentPoolClient.Count,
                                    VmSize              = agentPoolClient.VmSize,
                                    OsDiskSizeGB        = agentPoolClient.OsDiskSizeGB,
                                    MaxPods             = agentPoolClient.MaxPods,
                                    Mode                = agentPoolClient.Mode,
                                    OsType              = agentPoolClient.OsType,
                                    OrchestratorVersion = cluster.KubernetesVersion,
                                };
                                Client.AgentPools.CreateOrUpdate(ResourceGroupName, Name, agentPoolProfile.Name, parameter);
                            }
                            cluster = Client.ManagedClusters.Get(ResourceGroupName, Name);
                            WriteObject(PSMapper.Instance.Map <PSKubernetesCluster>(cluster));
                            return;
                        }
                        if (this.IsParameterBound(c => c.KubernetesVersion))
                        {
                            WriteVerbose(Resources.UpdatingKubernetesVersion);
                            cluster.KubernetesVersion = KubernetesVersion;
                        }
                        bool upgradeAllNode = false;
                        if (cluster.MaxAgentPools < 8 || !allAgentPoolVirtualMachineScaleSets)
                        {
                            if (this.IsParameterBound(c => c.ControlPlaneOnly))
                            {
                                if (!ShouldProcess(string.Format(Resources.ConfirmControlPlaneOnlyInVMASCluster, KubernetesVersion), ""))
                                {
                                    return;
                                }
                            }
                            upgradeAllNode = true;
                        }
                        else
                        {
                            if (!this.IsParameterBound(c => c.ControlPlaneOnly))
                            {
                                if (!ShouldProcess(string.Format(Resources.ConfirmNotControlPlaneOnly, KubernetesVersion), ""))
                                {
                                    return;
                                }
                                upgradeAllNode = true;
                            }
                            else
                            {
                                if (!ShouldProcess(string.Format(Resources.ConfirmControlPlaneOnly, KubernetesVersion), ""))
                                {
                                    return;
                                }
                            }
                        }
                        if (upgradeAllNode)
                        {
                            cluster.AgentPoolProfiles.ForEach(c => c.OrchestratorVersion = KubernetesVersion);
                        }

                        if (this.IsParameterBound(c => c.Tag))
                        {
                            WriteVerbose(Resources.UpdatingTags);
                            cluster.Tags = TagsConversionHelper.CreateTagDictionary(Tag, true);
                        }

                        //To avoid server error: for agentPoolProfiles.availabilityZones, server will expect
                        //$null instead of empty collection, otherwise it will throw error.
                        foreach (var profile in cluster.AgentPoolProfiles)
                        {
                            if (profile.AvailabilityZones?.Count == 0)
                            {
                                profile.AvailabilityZones = null;
                            }
                        }

                        WriteVerbose(Resources.UpdatingYourManagedKubernetesCluster);
                    }
                    else
                    {
                        WriteVerbose(Resources.PreparingForDeploymentOfYourNewManagedKubernetesCluster);
                        cluster = BuildNewCluster();
                    }

                    if (this.IsParameterBound(c => c.AcrNameToAttach) ||
                        this.IsParameterBound(c => c.AcrNameToDetach))
                    {
                        acsServicePrincipal = EnsureServicePrincipal(ServicePrincipalIdAndSecret?.UserName, ServicePrincipalIdAndSecret?.Password?.ConvertToString());
                        if (this.IsParameterBound(c => c.AcrNameToAttach))
                        {
                            AddAcrRoleAssignment(AcrNameToAttach, nameof(AcrNameToAttach), acsServicePrincipal);
                        }
                        if (this.IsParameterBound(c => c.AcrNameToDetach))
                        {
                            RemoveAcrRoleAssignment(AcrNameToDetach, nameof(AcrNameToDetach), acsServicePrincipal);
                        }
                    }
                    cluster.NetworkProfile         = SetNetworkProfile(cluster.NetworkProfile);
                    cluster.ApiServerAccessProfile = CreateOrUpdateApiServerAccessProfile(cluster.ApiServerAccessProfile);
                    if (this.IsParameterBound(c => c.FqdnSubdomain))
                    {
                        cluster.FqdnSubdomain = FqdnSubdomain;
                    }

                    var kubeCluster = Client.ManagedClusters.CreateOrUpdate(ResourceGroupName, Name, cluster);

                    WriteObject(PSMapper.Instance.Map <PSKubernetesCluster>(kubeCluster));
                });
            }
        }
Пример #21
0
 protected void Page_Init(object sender, EventArgs e)
 {
     agentPool = (AgentPool)Application["AgentPool"];
 }