public bool StartAssignment(HostAssignmentContext context)
        {
            if (!WebScriptHostManager.InStandbyMode)
            {
                _logger.LogError("Assign called while host is not in placeholder mode");
                return(false);
            }

            if (_assignmentContext == null)
            {
                lock (_assignmentLock)
                {
                    if (_assignmentContext != null)
                    {
                        return(_assignmentContext.Equals(context));
                    }
                    _assignmentContext = context;
                }

                // start the specialization process in the background
                _logger.LogInformation("Starting Assignment");
                Task.Run(async() => await Assign(context));

                return(true);
            }
            else
            {
                // No lock needed here since _assignmentContext is not null when we are here
                return(_assignmentContext.Equals(context));
            }
        }
Ejemplo n.º 2
0
        public bool StartAssignment(HostAssignmentContext assignmentContext)
        {
            if (!WebScriptHostManager.InStandbyMode)
            {
                return(false);
            }

            if (_assignmentContext == null)
            {
                lock (_assignmentLock)
                {
                    if (_assignmentContext != null)
                    {
                        return(_assignmentContext.Equals(assignmentContext));
                    }
                    _assignmentContext = assignmentContext;
                }

                // Queue the task in background, and return to caller immediately
                Task.Run(() => Specialize(assignmentContext));

                return(true);
            }
            else
            {
                // No lock needed here since _assignmentContext is not null when we are here
                return(_assignmentContext.Equals(assignmentContext));
            }
        }
Ejemplo n.º 3
0
        public bool StartAssignment(HostAssignmentContext context)
        {
            if (!_webHostEnvironment.InStandbyMode)
            {
                // This is only true when specializing pinned containers.
                if (!context.Environment.TryGetValue(EnvironmentSettingNames.ContainerStartContext, out string startContext))
                {
                    _logger.LogError("Assign called while host is not in placeholder mode and start context is not present.");
                    return(false);
                }
            }

            if (_environment.IsContainerReady())
            {
                _logger.LogError("Assign called while container is marked as specialized.");
                return(false);
            }

            if (context.IsWarmupRequest)
            {
                // Based on profiling download code jit-ing holds up cold start.
                // Pre-jit to avoid paying the cost later.
                Task.Run(async() => await Download(context.GetRunFromPkgContext()));
                return(true);
            }
            else if (_assignmentContext == null)
            {
                lock (_assignmentLock)
                {
                    if (_assignmentContext != null)
                    {
                        return(_assignmentContext.Equals(context));
                    }
                    _assignmentContext = context;
                }

                _logger.LogInformation($"Starting Assignment. Cloud Name: {_environment.GetCloudName()}");

                // set a flag which will cause any incoming http requests to buffer
                // until specialization is complete
                // the host is guaranteed not to receive any requests until AFTER assign
                // has been initiated, so setting this flag here is sufficient to ensure
                // that any subsequent incoming requests while the assign is in progress
                // will be delayed until complete
                _webHostEnvironment.DelayRequests();

                // start the specialization process in the background
                Task.Run(async() => await Assign(context));

                return(true);
            }
            else
            {
                // No lock needed here since _assignmentContext is not null when we are here
                return(_assignmentContext.Equals(context));
            }
        }
Ejemplo n.º 4
0
        public void DecryptedContextShouldMatchByEqual()
        {
            var encrypted = EncryptedHostAssignmentContext.Create(_context, _encryptionKey);
            var decrypted = encrypted.Decrypt(_encryptionKey);

            Assert.True(_context.Equals(decrypted));
        }
Ejemplo n.º 5
0
        public bool StartAssignment(HostAssignmentContext context, bool isWarmup)
        {
            if (!_webHostEnvironment.InStandbyMode)
            {
                _logger.LogError("Assign called while host is not in placeholder mode");
                return(false);
            }

            if (isWarmup)
            {
                return(true);
            }
            else if (_assignmentContext == null)
            {
                lock (_assignmentLock)
                {
                    if (_assignmentContext != null)
                    {
                        return(_assignmentContext.Equals(context));
                    }
                    _assignmentContext = context;
                }

                _logger.LogInformation("Starting Assignment");

                // set a flag which will cause any incoming http requests to buffer
                // until specialization is complete
                // the host is guaranteed not to receive any requests until AFTER assign
                // has been initiated, so setting this flag here is sufficient to ensure
                // that any subsequent incoming requests while the assign is in progress
                // will be delayed until complete
                _webHostEnvironment.DelayRequests();

                // start the specialization process in the background
                Task.Run(async() => await Assign(context));

                return(true);
            }
            else
            {
                // No lock needed here since _assignmentContext is not null when we are here
                return(_assignmentContext.Equals(context));
            }
        }
Ejemplo n.º 6
0
        public bool StartAssignment(HostAssignmentContext context)
        {
            if (!_linuxConsumptionEnv.InStandbyMode)
            {
                return(false);
            }

            if (_assignmentContext == null)
            {
                lock (_assignmentLock)
                {
                    if (_assignmentContext != null)
                    {
                        return(_assignmentContext.Equals(context));
                    }
                    _assignmentContext = context;
                }

                // set a flag which will cause any incoming http requests to buffer
                // until specialization is complete
                // the host is guaranteed not to receive any requests until AFTER assign
                // has been initiated, so setting this flag here is sufficient to ensure
                // that any subsequent incoming requests while the assign is in progress
                // will be delayed until complete
                _linuxConsumptionEnv.DelayRequests();

                // start the specialization process in the background
                Task.Run(async() => await Assign(context));

                return(true);
            }
            else
            {
                // No lock needed here since _assignmentContext is not null when we are here
                return(_assignmentContext.Equals(context));
            }
        }