Ejemplo n.º 1
0
        private static IEnumerable <Deployment> ListLaunchedActiveDeployments(DeploymentServiceClient client, string projectName)
        {
            var listDeploymentsResult = client.ListDeployments(new ListDeploymentsRequest
            {
                View        = ViewType.Basic,
                ProjectName = projectName,
                DeploymentStoppedStatusFilter = ListDeploymentsRequest.Types.DeploymentStoppedStatusFilter.NotStoppedDeployments,
                PageSize = 50
            });

            return(listDeploymentsResult.Where(deployment =>
            {
                var status = deployment.Status;
                if (status != Deployment.Types.Status.Starting && status != Deployment.Types.Status.Running)
                {
                    // Deployment not active - skip
                    return false;
                }

                if (!deployment.Tag.Contains(DEPLOYMENT_LAUNCHED_BY_LAUNCHER_TAG))
                {
                    // Deployment not launched by this launcher - skip
                    return false;
                }

                return true;
            }));
        }
Ejemplo n.º 2
0
 private Deployment GetDeploymentWithTag(DeploymentServiceClient deploymentServiceClient, string tag)
 {
     return(deploymentServiceClient
            .ListDeployments(new ListDeploymentsRequest
     {
         ProjectName = _project,
         DeploymentStoppedStatusFilter = ListDeploymentsRequest.Types.DeploymentStoppedStatusFilter
                                         .NotStoppedDeployments,
         View = ViewType.Basic,
         Filters =
         {
             new Filter
             {
                 TagsPropertyFilter = new TagsPropertyFilter
                 {
                     Operator = TagsPropertyFilter.Types.Operator.Equal,
                     Tag = tag
                 }
             },
             new Filter
             {
                 TagsPropertyFilter = new TagsPropertyFilter
                 {
                     Operator = TagsPropertyFilter.Types.Operator.Equal,
                     Tag = ReadyTag
                 }
             }
         }
     }).FirstOrDefault(d => d.Status == Deployment.Types.Status.Running));
 }
Ejemplo n.º 3
0
        public async Task <string> GetLoginToken(string pit)
        {
            var listDeploymentsRequest = new ListDeploymentsRequest
            {
                ProjectName = ProjectName,
                Filters     = { new Filter
                                {
                                    TagsPropertyFilter = new TagsPropertyFilter
                                    {
                                        Tag      = DeploymentTagFilter,
                                        Operator = TagsPropertyFilter.Types.Operator.Equal,
                                    },
                                } }
            };

            var suitableDeployment = deploymentServiceClient.ListDeployments(listDeploymentsRequest).First();

            var loginRequest = new CreateLoginTokenRequest
            {
                PlayerIdentityToken = pit,
                DeploymentId        = suitableDeployment.Id,
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 15, 0)),
                WorkerType          = "UnityClient"
            };

            var createLoginTokenResponse = await playerAuthServiceClient.CreateLoginTokenAsync(loginRequest);

            return(createLoginTokenResponse.LoginToken);
        }
Ejemplo n.º 4
0
        public async Task <object> CloneDeployment(dynamic data)
        {
            return(await Task.Run(() => {
                PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken);
                DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken);
                var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
                {
                    ProjectName = data._ProjectName
                }).First(d => d.Id.Contains(data._DeploymentID));

                var newDeployment = suitableDeployment.Clone();
                newDeployment.StartingSnapshotId = data._SnapshotID;
                newDeployment.Tag.Clear();
                newDeployment = _deploymentServiceClient.CreateDeployment(new CreateDeploymentRequest {
                    Deployment = newDeployment
                })
                                .PollUntilCompleted()
                                .GetResultOrNull();
                newDeployment.Tag.Add(data._ScenarioDeploymentTag);
                _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                    Deployment = newDeployment
                });
                return newDeployment.Id;
            }));
        }
 public static List <Deployment> ListDeployments(ListDeploymentsRequest request)
 {
     return(ExceptionHandler.HandleGrpcCall(() =>
     {
         var response = deploymentServiceClient.ListDeployments(request);
         return response.ToList();
     }));
 }
Ejemplo n.º 6
0
        protected override void Run()
        {
            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine("Choosing a deployment");
            var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            }).First(d => d.Tag.Contains(ScenarioDeploymentTag));

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = suitableDeployment.Id,
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine("Connecting to the deployment using the LoginToken and PlayerIdentityToken");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            using (var connectionFuture = locator.ConnectAsync(new ConnectionParameters
            {
                WorkerType = ScenarioWorkerType,
                Network = { ConnectionType = NetworkConnectionType.Tcp, UseExternalIp = true }
            }))
            {
                var connFuture = connectionFuture.Get(Convert.ToUInt32(Defaults.ConnectionTimeoutMillis));
                if (!connFuture.HasValue || !connFuture.Value.IsConnected)
                {
                    throw new Exception("No connection or connection not established");
                }
                Console.WriteLine($"Assigned worker ID: {connFuture.Value.GetWorkerId()}");
            }
        }
Ejemplo n.º 7
0
        public async Task <object> GetDeploymentIDByTag(dynamic data)
        {
            return(await Task.Run(() => {
                PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken);
                DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken);
                var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
                {
                    ProjectName = data._ProjectName,
                    DeploymentName = data._DeploymentName
                }).First(d => d.Tag.Contains(data._ScenarioDeploymentTag));

                return suitableDeployment.Id;
            }));
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("GO and check!");
            Dictionary <string, string[]> resultMap = readCustomerProjectInfo();

            foreach (KeyValuePair <string, string[]> entry in resultMap)
            {
                Boolean  isWorkflagUsed = false;
                var      customer_name  = entry.Key;
                string[] projectNames   = entry.Value;
                Console.WriteLine(customer_name);
                for (int i = 1; i < projectNames.Length; i++)
                {
                    string projectName = projectNames[i];
                    Console.WriteLine(projectName);
                    var template = $"auth_client account elevate [email protected] {projectName} --message=\"ryan support\"";
                    Console.WriteLine(template);
                    // elevate permission
                    ExecuteCommandSync(template);
                    var listDeploymentsRequest = new ListDeploymentsRequest
                    {
                        ProjectName = projectName,
                        View        = ViewType.Full,
                    };
                    try
                    {
                        var deployments = DeploymentServiceClient.ListDeployments(listDeploymentsRequest);
                        foreach (var deployment in deployments)
                        {
                            int count = deployment.WorkerFlags.Count;
                            if (count > 0)
                            {
                                isWorkflagUsed = true;
                                break;
                            }
                        }

                        if (isWorkflagUsed)
                        {
                            Console.WriteLine("Customer:{0}, Project:{1} is using workflag.", customer_name, projectName);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public async Task <object> ChangeDeploymentCapacity(dynamic data)
        {
            return(await Task.Run(() => {
                PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken);
                DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken);
                var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
                {
                    ProjectName = data._ProjectName
                }).First(d => d.Id.Contains(data._DeploymentID));

                suitableDeployment.WorkerConnectionCapacities.Clear();
                suitableDeployment.WorkerConnectionCapacities.Add(new WorkerCapacity
                {
                    WorkerType = data._ScenarioWorkerType,
                    MaxCapacity = data._DeploymentCapacity
                });
                _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                    Deployment = suitableDeployment
                });
                return suitableDeployment.Id;
            }));
        }
Ejemplo n.º 10
0
 public IEnumerable <Deployment> ListDeployments()
 {
     return(deploymentServiceClient
            .ListDeployments(new ListDeploymentsRequest
     {
         ProjectName = spatialProject,
         PageSize = 50,
         DeploymentStoppedStatusFilter = ListDeploymentsRequest.Types.DeploymentStoppedStatusFilter
                                         .NotStoppedDeployments,
         View = ViewType.Basic,
         Filters =
         {
             new Filter
             {
                 TagsPropertyFilter = new TagsPropertyFilter
                 {
                     Operator = TagsPropertyFilter.Types.Operator.Equal,
                     Tag = matchType
                 }
             }
         }
     }));
 }
Ejemplo n.º 11
0
 public async Task <object> SetDeploymentMaintenance(dynamic data)
 {
     return(await Task.Run(() => {
         PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken);
         DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken);
         var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
         {
             ProjectName = data._ProjectName,
             DeploymentName = data._DeploymentName
         }).First(d => d.Id.Contains(data._DeploymentID));
         suitableDeployment.Tag.Remove(data._ScenarioDeploymentTag);
         suitableDeployment.WorkerFlags.Add(new WorkerFlag
         {
             Key = "maintenance",
             Value = "true",
             WorkerType = data._ScenarioWorkerType
         });
         _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
             Deployment = suitableDeployment
         });
         return suitableDeployment.Id;
     }));
 }
Ejemplo n.º 12
0
        protected override void Run()
        {
            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine("Verifying PlayerIdentityToken");
            var decodePlayerIdentityTokenResponse = _playerAuthServiceClient.DecodePlayerIdentityToken(
                new DecodePlayerIdentityTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken
            });
            var playerIdentityToken = decodePlayerIdentityTokenResponse.PlayerIdentityToken;

            if (playerIdentityToken.Provider != "provider")
            {
                throw new Exception("Provider not recognised.");
            }
            if (playerIdentityToken.ProjectName != ProjectName)
            {
                throw new Exception("Project not recognised.");
            }
            if (DateTime.Now.CompareTo(playerIdentityToken.ExpiryTime.ToDateTime()) > 0)
            {
                throw new Exception("PlayerIdentityToken expired.");
            }

            Console.WriteLine("Choosing a deployment");
            var listDeploymentsRequest = new ListDeploymentsRequest
            {
                ProjectName = ProjectName,
                Filters     = { new Filter
                                {
                                    TagsPropertyFilter = new TagsPropertyFilter
                                    {
                                        Tag      = "player_auth_tag",
                                        Operator = TagsPropertyFilter.Types.Operator.Equal,
                                    },
                                } }
            };
            var suitableDeployment = _deploymentServiceClient.ListDeployments(listDeploymentsRequest).First();

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = suitableDeployment.Id.ToString(),
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine("Connecting to the deployment using the LoginToken and PlayerIdentityToken");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            using (var connectionFuture = locator.ConnectAsync(new ConnectionParameters
            {
                WorkerType = ScenarioWorkerType,
                Network = { ConnectionType = NetworkConnectionType.Tcp, UseExternalIp = true }
            }))
            {
                var connFuture = connectionFuture.Get(Convert.ToUInt32(Defaults.ConnectionTimeoutMillis));
                if (!connFuture.HasValue || !connFuture.Value.IsConnected)
                {
                    throw new Exception("No connection or connection not established");
                }
                Console.WriteLine($"Assigned worker ID: {connFuture.Value.GetWorkerId()}");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     This contains the implementation of the "Game maintenance" scenario.
        ///     1. Get the currently running cloud deployment that needs taking down for maintenance.
        ///     2. Lock down the deployment by removing the `live` tag and setting the worker flag.
        ///     3. Take a snapshot of the deployment.
        ///     4. Stop the deployment.
        ///     5. Start a new cloud deployment based on the old deployment, but with clean tags.
        ///     6. Mark the new cloud deployment live by adding the `live` tag.
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            Setup();

            Console.WriteLine("Finding a current running deployment with live tag");
            var currentLiveDeployment = DeploymentServiceClient
                                        .ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            })
                                        .First(d => d.Status == Deployment.Types.Status.Running && d.Tag.Contains("my_live_tag"));

            Console.WriteLine("Putting the deployment to maintenance mode");
            currentLiveDeployment.Tag.Remove("my_live_tag");
            currentLiveDeployment.WorkerFlags.Add(new WorkerFlag
            {
                Key        = "maintenance",
                Value      = "true",
                WorkerType = "unity"
            });
            DeploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = currentLiveDeployment
            });

            Console.WriteLine("Taking a cloud snapshot");
            var latestSnapshot = SnapshotServiceClient.TakeSnapshot(new TakeSnapshotRequest
            {
                Snapshot = new Snapshot
                {
                    ProjectName    = currentLiveDeployment.ProjectName,
                    DeploymentName = currentLiveDeployment.Name
                }
            }).PollUntilCompleted()
                                 .GetResultOrNull();

            Console.WriteLine("Stopping the deployment");
            DeploymentServiceClient.StopDeployment(new StopDeploymentRequest
            {
                Id          = currentLiveDeployment.Id,
                ProjectName = currentLiveDeployment.ProjectName
            });

            Console.WriteLine("Starting a new deployment with empty tags");
            var newDeployment = currentLiveDeployment.Clone();

            newDeployment.StartingSnapshotId = latestSnapshot.Id;
            newDeployment.Tag.Clear();
            newDeployment = DeploymentServiceClient
                            .CreateDeployment(new CreateDeploymentRequest {
                Deployment = newDeployment
            })
                            .PollUntilCompleted()
                            .GetResultOrNull();

            Console.WriteLine("Putting the new deployment to live");
            newDeployment.Tag.Add("my_live_tag");
            DeploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = newDeployment
            });

            Cleanup(newDeployment);
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     This contains the implementation of the "Capacity limiting" scenario.
        ///     1. Gets the currently running cloud deployment that has a capacity limit.
        ///     2. Tests that connecting more clients than the capacity limit fails.
        ///     3. Updates the deployment to increase the capacity limit.
        ///     4. Tests that additional clients are now able to connect to the deployment.
        /// </summary>
        protected override void Run()
        {
            Console.WriteLine("Finding current running deployment");
            _deployment = _deploymentServiceClient
                          .ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            })
                          .First(d => d.Status == Deployment.Types.Status.Running);
            Console.WriteLine($"Found deployment {_deployment.Id}");

            Console.WriteLine("Setting capacity limit to 2");
            _deployment.WorkerConnectionCapacities.Clear();
            _deployment.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 2
            });
            _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = _deployment
            });

            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine(JsonConvert.SerializeObject(playerIdentityTokenResponse));

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = _deployment.Id,
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine(JsonConvert.SerializeObject(createLoginTokenResponse));

            Console.WriteLine("Connecting 3 workers to the deployment. Expecting only 2 to succeed");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            for (var i = 0; i < 3; i++)
            {
                var connectionSucceeded = TryConnectWorker(locator);
                if (!connectionSucceeded && i != 2)
                {
                    throw new Exception("Expected worker to connect successfully");
                }
                if (connectionSucceeded && i == 2)
                {
                    throw new Exception("Expected worker to fail to connect");
                }
            }

            Console.WriteLine("Increasing capacity limit to 3");
            _deployment.WorkerConnectionCapacities.Clear();
            _deployment.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 3
            });
            _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = _deployment
            });

            Console.WriteLine("Connecting another worker");
            if (!TryConnectWorker(locator))
            {
                throw new Exception("Expected worker to be able to connect after capacity increase");
            }
        }