示例#1
0
        private Deployment(InlineDeploymentSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _projectName = settings.Project;
            _stackName   = settings.Stack;
            _isDryRun    = settings.IsDryRun;
            SetAllConfig(settings.Config);

            if (string.IsNullOrEmpty(settings.MonitorAddr) ||
                string.IsNullOrEmpty(settings.EngineAddr) ||
                string.IsNullOrEmpty(_projectName) ||
                string.IsNullOrEmpty(_stackName))
            {
                throw new InvalidOperationException("Inline execution was not provided the necessary parameters to run the Pulumi engine.");
            }

            Serilog.Log.Debug("Creating Deployment Engine.");
            Engine = new GrpcEngine(settings.EngineAddr);
            Serilog.Log.Debug("Created Deployment Engine.");

            Serilog.Log.Debug("Creating Deployment Monitor.");
            Monitor = new GrpcMonitor(settings.MonitorAddr);
            Serilog.Log.Debug("Created Deployment Monitor.");

            _runner = new Runner(this);
            _logger = new Logger(this, Engine);
        }
示例#2
0
        private Deployment(InlineDeploymentSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _projectName = settings.Project;
            _stackName   = settings.Stack;
            _isDryRun    = settings.IsDryRun;
            SetAllConfig(settings.Config, settings.ConfigSecretKeys);

            if (string.IsNullOrEmpty(settings.MonitorAddr) ||
                string.IsNullOrEmpty(settings.EngineAddr) ||
                string.IsNullOrEmpty(_projectName) ||
                string.IsNullOrEmpty(_stackName))
            {
                throw new InvalidOperationException("Inline execution was not provided the necessary parameters to run the Pulumi engine.");
            }

            var deploymentLogger = settings.Logger ?? CreateDefaultLogger();

            deploymentLogger.LogDebug("Creating deployment engine");
            Engine = new GrpcEngine(settings.EngineAddr);
            deploymentLogger.LogDebug("Created deployment engine");

            deploymentLogger.LogDebug("Creating deployment monitor");
            Monitor = new GrpcMonitor(settings.MonitorAddr);
            deploymentLogger.LogDebug("Created deployment monitor");

            _runner = new Runner(this, deploymentLogger);
            _logger = new EngineLogger(this, deploymentLogger, Engine);
        }
示例#3
0
        private Deployment(InlineDeploymentSettings settings)
        {
            if (settings is null)
                throw new ArgumentNullException(nameof(settings));

            _projectName = settings.Project;
            _stackName = settings.Stack;
            _isDryRun = settings.IsDryRun;
            SetAllConfig(settings.Config, settings.ConfigSecretKeys);

            if (string.IsNullOrEmpty(settings.MonitorAddr)
                || string.IsNullOrEmpty(settings.EngineAddr)
                || string.IsNullOrEmpty(_projectName)
                || string.IsNullOrEmpty(_stackName))
            {
                throw new InvalidOperationException("Inline execution was not provided the necessary parameters to run the Pulumi engine.");
            }

            var deploymentLogger = settings.Logger ?? CreateDefaultLogger();

            deploymentLogger.LogDebug("Creating deployment engine");
            Engine = new GrpcEngine(settings.EngineAddr);
            deploymentLogger.LogDebug("Created deployment engine");

            deploymentLogger.LogDebug("Creating deployment monitor");
            Monitor = new GrpcMonitor(settings.MonitorAddr);
            deploymentLogger.LogDebug("Created deployment monitor");

            // Tell the runner that we are running inside an inline automation program
            // in which case it shall not set/pollute the global process exit code 
            // when encountering unhandles exceptions
            var runnerOptions = new RunnerOptions { IsInlineAutomationProgram = true };
            _runner = new Runner(this, deploymentLogger, runnerOptions);
            _logger = new EngineLogger(this, deploymentLogger, Engine);
        }
示例#4
0
        internal static async Task <ExceptionDispatchInfo?> RunInlineAsync(InlineDeploymentSettings settings, Func <IRunner, Task <ExceptionDispatchInfo?> > func)
        {
            ExceptionDispatchInfo?exceptionDispatchInfo = null;

            await CreateRunnerAndRunAsync(
                () => new Deployment(settings),
                async runner =>
            {
                exceptionDispatchInfo = await func(runner).ConfigureAwait(false);
                return(1);
            })
            .ConfigureAwait(false);

            return(exceptionDispatchInfo);
        }
示例#5
0
        internal static async Task <InlineDeploymentResult> RunInlineAsync(InlineDeploymentSettings settings, Func <IRunner, Task <int> > runnerFunc)
        {
            var result = new InlineDeploymentResult();

            result.ExitCode = await CreateRunnerAndRunAsync(
                () => new Deployment(settings),
                async runner =>
            {
                int?exitCode = null;
                try
                {
                    exitCode = await runnerFunc(runner).ConfigureAwait(false);

                    // if there was swallowed exceptions from the in-flight tasks we want to either capture
                    // if it is single or re-throw as an aggregate exception if there is more than 1
                    if (runner.SwallowedExceptions.Count == 1)
                    {
                        ExceptionDispatchInfo.Throw(runner.SwallowedExceptions[0]);
                    }
                    else if (runner.SwallowedExceptions.Count > 1)
                    {
                        throw new AggregateException(runner.SwallowedExceptions);
                    }
                }
                // because we might be newing a generic, reflection comes in to
                // construct the instance. And if there is an exception in
                // the constructor of the user-provided TStack, it will be wrapped
                // in TargetInvocationException - which is not the exception
                // we want to throw to the consumer.
                catch (TargetInvocationException ex) when(ex.InnerException != null)
                {
                    result.ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(ex.InnerException);
                }
                catch (Exception ex)
                {
                    result.ExceptionDispatchInfo = ExceptionDispatchInfo.Capture(ex);
                }

                // return original exit code if we have it, otherwise fail
                return(exitCode ?? -1);
            })
                              .ConfigureAwait(false);

            return(result);
        }
示例#6
0
 internal static Task <ExceptionDispatchInfo?> RunInlineAsync(InlineDeploymentSettings settings, Func <IRunner, Task <ExceptionDispatchInfo?> > func)
 => func(CreateRunner(() => new Deployment(settings)));