Пример #1
0
        public async Task EnableSshAsync(Gamelet gamelet, Metrics.IAction action)
        {
            var sshKey = await sshKeyLoader.LoadOrCreateAsync();

            sshKnownHostsWriter.CreateOrUpdate(gamelet);
            action.UpdateEvent(new DeveloperLogEvent
            {
                GameletData = GameletData.FromGamelet(gamelet)
            });

            // Try to optimistically connect, but only if we already have a key file.
            try
            {
                await remoteCommand.RunWithSuccessAsync(new SshTarget(gamelet), "/bin/true");

                return;
            }
            catch (ProcessException e)
            {
                Trace.WriteLine("Optimistic SSH check failed; fallback to calling EnableSSH; " +
                                "error: " + e.ToString());
            }

            // Generate a new key, if necessary, and upload it to the gamelet.
            var gameletClient = gameletClientFactory.Create(cloudRunner.Intercept(action));
            await gameletClient.EnableSshAsync(gamelet.Id, sshKey.PublicKey);
        }
Пример #2
0
        public int AddPort(IDebugPortRequest2 request, out IDebugPort2 port)
        {
            var debugSessionMetrics = new DebugSessionMetrics(_metrics);

            debugSessionMetrics.UseNewDebugSessionId();
            var actionRecorder = new ActionRecorder(debugSessionMetrics);

            port = null;

            if (request.GetPortName(out string gameletIdOrName) != VSConstants.S_OK)
            {
                return(VSConstants.E_FAIL);
            }

            var action        = actionRecorder.CreateToolAction(ActionType.GameletGet);
            var gameletClient = _gameletClientFactory.Create(_cloudRunner.Intercept(action));
            var gameletTask   = _cancelableTaskFactory.Create(
                "Querying instance...",
                async() => await gameletClient.LoadByNameOrIdAsync(gameletIdOrName));

            try
            {
                gameletTask.RunAndRecord(action);
            }
            catch (CloudException e)
            {
                Trace.WriteLine(e.ToString());
                _dialogUtil.ShowError(e.Message);
                return(VSConstants.S_OK);
            }

            var debugPort = _debugPortFactory.Create(gameletTask.Result, this,
                                                     debugSessionMetrics.DebugSessionId);

            _ports.Add(debugPort);
            port = debugPort;
            return(VSConstants.S_OK);
        }
Пример #3
0
        /// <summary>
        /// Stop a gamelet and wait for it to return to the reserved state.
        /// </summary>
        Gamelet StopGamelet(Gamelet gamelet)
        {
            IAction         action   = _actionRecorder.CreateToolAction(ActionType.GameletStop);
            ICancelableTask stopTask =
                _cancelableTaskFactory.Create(TaskMessages.WaitingForGameStop, async(task) => {
                IGameletClient gameletClient =
                    _gameletClientFactory.Create(_runner.Intercept(action));
                try
                {
                    await gameletClient.StopGameAsync(gamelet.Id);
                }
                catch (CloudException e) when((e.InnerException as RpcException)
                                              ?.StatusCode == StatusCode.FailedPrecondition)
                {
                    // FailedPreconditions likely means there is no game session to stop.
                    // For details see (internal).
                    Trace.WriteLine("Potential race condition while stopping game; " +
                                    $"ignoring RPC error: {e.InnerException.Message}");
                }
                while (!task.IsCanceled)
                {
                    gamelet = await gameletClient.GetGameletByNameAsync(gamelet.Name);
                    if (gamelet.State == GameletState.Reserved)
                    {
                        break;
                    }
                    await Task.Delay(1000);
                }
            });

            if (stopTask.RunAndRecord(action))
            {
                return(gamelet);
            }
            return(null);
        }
Пример #4
0
        List <Gamelet> ListInstances()
        {
            try
            {
                var action        = _actionRecorder.CreateToolAction(ActionType.GameletsList);
                var gameletClient = _gameletClientFactory.Create(_cloudRunner.Intercept(action));
                var queryTask     = _cancelableTaskFactory.Create(
                    "Querying instances...",
                    async() => await gameletClient.ListGameletsAsync(false));
                if (!queryTask.RunAndRecord(action))
                {
                    return(null);
                }

                return(queryTask.Result);
            }
            catch (CloudException e)
            {
                Trace.Write("An exception was thrown while querying instances." +
                            Environment.NewLine + e);
                GameletMessageTextBox.Text = ErrorStrings.FailedToRetrieveGamelets(e.Message);
                return(null);
            }
        }