Exemple #1
0
    static void Run(CommandLineOptions options)
    {
        Console.WriteLine("Starting DeploymentServiceClient");
        DeploymentServiceClient = DeploymentServiceClient.Create();
        //Check if the deployment exists before waiting to get logs.
        var request = new GetRunningDeploymentByNameRequest()
        {
            DeploymentName = options.Deployment,
            ProjectName    = options.Project,
            View           = ViewType.Full
        };

        Console.WriteLine("Requesting deployment by name {0}", options.Deployment);
        var deploy = DeploymentServiceClient.GetRunningDeploymentByName(request);

        if (deploy == null)
        {
            Console.WriteLine("Requested deployment {0} does not exist in project {1}. Exiting.", options.Deployment, options.Project);
            return;
        }

        Console.WriteLine("Found deployment");
        {
            var testingFlag = new WorkerFlag()
            {
                Key        = "ExtendedTesting",
                Value      = "True",
                WorkerType = "UnrealWorker"
            };

            var flags = deploy.Deployment.WorkerFlags.Clone();

            flags.Add(testingFlag);

            DeploymentServiceClient.SetDeploymentWorkerFlags(new SetDeploymentWorkerFlagsRequest()
            {
                DeploymentId = deploy.Deployment.Id,
                WorkerFlags  = { flags }
            });
        }
        Console.WriteLine("Worker flag set, sleeping for {0} minutes", options.Delay);
        //Sleep for {delay} minutes.
        Thread.Sleep((int)(1000f * 60f * options.Delay));

        //Set testing flag to false
        {
            var testingFlag = new WorkerFlag()
            {
                Key        = "ExtendedTesting",
                Value      = "False",
                WorkerType = "UnrealWorker"
            };

            var flags = deploy.Deployment.WorkerFlags.Clone();
            flags.Remove(flags.FirstOrDefault(a => a.Key == "ExtendedTesting"));
            flags.Add(testingFlag);

            DeploymentServiceClient.SetDeploymentWorkerFlags(new SetDeploymentWorkerFlagsRequest()
            {
                DeploymentId = deploy.Deployment.Id,
                WorkerFlags  = { flags }
            });
        }
        //Wait one minute to allow server processes to print outcomes to the log after testing is stopped.
        Thread.Sleep(60 * 1000);

        //Get log
        var authValue = PlatformRefreshTokenCredential.AutoDetected.Token.AccessToken;

        using var wc = new WebClient();
        wc.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + authValue);
        List <string> log = null;

        #region AttemptDownloads
        try
        {
            log = wc.DownloadString(string.Format(WorkerLogPath, options.Project, options.Deployment, SimPathA)).Split('\n').ToList();
        }
        catch (WebException e)
        {
            if (e.Response.ToString().Contains("404"))
            {
                Console.WriteLine("Log file was not found on " + SimPathA);
            }
            else if (e.Response.ToString().Contains("401"))
            {
                Console.WriteLine(
                    "Unauthorized to access resource, check your refresh token and permission to access deployments in " +
                    options.Project);
                return;
            }
        }

        if (log == null)
        {
            try
            {
                log = wc.DownloadString(string.Format(WorkerLogPath, options.Project, options.Deployment, SimPathB)).Split('\n').ToList();
            }
            catch (WebException e)
            {
                if (e.Response.ToString().Contains("404"))
                {
                    Console.WriteLine("Log file was not found on " + SimPathB);
                }
                else if (e.Response.ToString().Contains("401"))
                {
                    Console.WriteLine(e.ToString());
                    return;
                }
            }
        }

        if (log == null)
        {
            try
            {
                log = wc.DownloadString(string.Format(WorkerLogPath, options.Project, options.Deployment, SimPathC)).Split('\n').ToList();
            }
            catch (WebException e)
            {
                if (e.Response.ToString().Contains("404"))
                {
                    Console.WriteLine("Log file was not found on " + SimPathC);
                }
                else if (e.Response.ToString().Contains("401"))
                {
                    Console.WriteLine(e.ToString());
                    return;
                }
            }
        }

        if (log == null)
        {
            try
            {
                log = wc.DownloadString(string.Format(WorkerLogPath, options.Project, options.Deployment, SimPathD)).Split('\n').ToList();
            }
            catch (WebException e)
            {
                if (e.Response.ToString().Contains("404"))
                {
                    Console.WriteLine("Log file was not found on " + SimPathD);
                }
                else if (e.Response.ToString().Contains("401"))
                {
                    Console.WriteLine(e.ToString());
                    return;
                }
            }
        }

        if (log == null)
        {
            Console.WriteLine("Raw worker log could not be found - Exiting.");
            return;
        }
        #endregion

        Dictionary <string, int> logEntries = new Dictionary <string, int>();
        //Build a dictionary so we can count the errors/warnings that are identical and present a nicer output, print them anyway in case we'd like to see them in order.
        foreach (var line in log)
        {
            if (line.ToLower().Contains("warning"))
            {
                Console.WriteLine("WARNING: " + line);
                var trimmedLine = line.Substring(line.IndexOf(']') + 1);
                if (logEntries.ContainsKey("WARNING: " + trimmedLine))
                {
                    logEntries["WARNING: " + trimmedLine]++;
                }
                else
                {
                    logEntries.Add("WARNING: " + trimmedLine, 1);
                }
            }

            if (line.ToLower().Contains("error"))
            {
                Console.WriteLine("ERROR: " + line);
                var trimmedLine = line.Substring(line.IndexOf(']') + 1);
                if (logEntries.ContainsKey("ERROR: " + trimmedLine))
                {
                    logEntries["ERROR: " + trimmedLine]++;
                }
                else
                {
                    logEntries.Add("ERROR: " + trimmedLine, 1);
                }
            }
        }

        Console.WriteLine("+++ Clean Error/Warning Output");
StartPrint:
        if (logEntries.Count > 0)
        {
            var entry = logEntries.ElementAt(0);
            logEntries.Remove(entry.Key);
            Console.WriteLine("( {0} ) {1}", entry.Value, entry.Key);
            goto StartPrint;
        }
    }
Exemple #2
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 the current running deployment");
            var currentLiveDeployment = DeploymentServiceClient.GetRunningDeploymentByName(new GetRunningDeploymentByNameRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName,
            });

            Console.WriteLine("Putting the deployment to maintenance mode");
            currentLiveDeployment.Deployment.Tags.Remove("my_live_tag");
            var setTagsRequest = new SetDeploymentTagsRequest
            {
                DeploymentId = currentLiveDeployment.Deployment.Id,
                Tags         = { currentLiveDeployment.Deployment.Tags },
            };

            DeploymentServiceClient.SetDeploymentTags(setTagsRequest);


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

            Console.WriteLine("Stopping the deployment");
            DeploymentServiceClient.DeleteDeployment(new DeleteDeploymentRequest
            {
                Id = currentLiveDeployment.Deployment.Id,
            }).PollUntilCompleted();

            Console.WriteLine("Starting a new deployment with empty tags");
            var newDeployment = DeploymentServiceClient.CreateDeployment(new CreateDeploymentRequest
            {
                DeploymentName     = currentLiveDeployment.Deployment.DeploymentName,
                ProjectName        = currentLiveDeployment.Deployment.ProjectName,
                StartingSnapshotId = latestSnapshot.Id,
                LaunchConfig       = currentLiveDeployment.Deployment.LaunchConfig,
                AssemblyName       = currentLiveDeployment.Deployment.AssemblyName,
            })
                                .PollUntilCompleted()
                                .GetResultOrNull();

            Console.WriteLine("Putting the new deployment to live");
            var setLiveTagsRequest = new SetDeploymentTagsRequest
            {
                DeploymentId = newDeployment.Id,
            };

            setTagsRequest.Tags.Add("my_live_tag");
            DeploymentServiceClient.SetDeploymentTags(setLiveTagsRequest);

            Cleanup(newDeployment);
        }
Exemple #3
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");
            _runningDeployment = _deploymentServiceClient.GetRunningDeploymentByName(new GetRunningDeploymentByNameRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            }).Deployment;
            Console.WriteLine($"Found deployment {_runningDeployment.Id}");

            Console.WriteLine("Setting capacity limit to 2");
            var setWorkerCapacitiesRequest = new SetDeploymentWorkerCapacitiesRequest
            {
                DeploymentId = _runningDeployment.Id,
            };

            setWorkerCapacitiesRequest.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 2
            });
            _deploymentServiceClient.SetDeploymentWorkerCapacities(setWorkerCapacitiesRequest);

            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        = _runningDeployment.Id.ToString(),
                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");
            setWorkerCapacitiesRequest = new SetDeploymentWorkerCapacitiesRequest
            {
                DeploymentId = _runningDeployment.Id,
            };
            setWorkerCapacitiesRequest.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 3
            });
            _deploymentServiceClient.SetDeploymentWorkerCapacities(setWorkerCapacitiesRequest);

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