Esempio n. 1
0
        public async Task CheckForUpdates()
        {
            try
            {
                Trace.TraceInformation("Checking for updates");

                IEnumerable <AppDeploymentConfig> applicationDeployments = await _applicationDeploymentDirectory.FetchDeployments();

                IEnumerable <AppIdentity> runningApplications = _applicationPool.Applications.Select(app => app.Identity).ToList();

                IEnumerable <AppIdentity>         applicationsToRemove = FindApplicationsToRemove(runningApplications, applicationDeployments);
                IEnumerable <AppDeploymentConfig> applicationsToDeploy = FindApplicationsToDeploy(runningApplications, applicationDeployments);

                // download applications first
                await DownloadApplications(applicationsToDeploy);

                var allAppsIds = new HashSet <string>(applicationsToRemove.Select(identity => identity.Id));
                allAppsIds.UnionWith(applicationsToDeploy.Select(config => config.AppIdentity.Id));

                var tasks = new List <Task>();
                foreach (string appId in allAppsIds)
                {
                    IEnumerable <AppIdentity>         appRemovals    = applicationsToRemove.Where(identity => identity.Id.Equals(appId));
                    IEnumerable <AppDeploymentConfig> appDeployments = applicationsToDeploy.Where(config => config.AppIdentity.Id.Equals(appId));

                    // if an application has a removal(s) and deployment(s), we consider it an update
                    if (appRemovals.Any() && appDeployments.Any())
                    {
                        tasks.Add(_applicationInstaller.Update(appRemovals, appDeployments));
                    }
                    else
                    {
                        foreach (AppDeploymentConfig appDeploymentConfig in appDeployments)
                        {
                            tasks.Add(_applicationInstaller.Install(appDeploymentConfig));
                        }
                        foreach (AppIdentity appRemoval in appRemovals)
                        {
                            tasks.Add(_applicationInstaller.UnInstall(appRemoval));
                        }
                    }
                }
                await Task.WhenAll(tasks);
                await UpdateDeploymentStatus();
            }
            catch (AggregateException e)
            {
                TraceUtils.TraceAllErrors("Failures occured during updates", e);
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to perform update; Exception was: {0}", e);
            }
        }
Esempio n. 2
0
        public async Task CheckForUpdates()
        {
            try
            {
                Trace.TraceInformation("Checking for updates");

                IEnumerable <AppDeploymentConfig> applicationDeployments = await _applicationDeploymentDirectory.FetchDeployments();

                IEnumerable <AppIdentity> runningApplications = _applicationPool.Applications.Select(app => app.Identity).ToList();

                IEnumerable <AppIdentity>         applicationsToRemove = FindApplicationsToRemove(runningApplications, applicationDeployments);
                IEnumerable <AppDeploymentConfig> applicationsToDeploy = FindApplicationsToDeploy(runningApplications, applicationDeployments);

                if (!applicationsToDeploy.Any() && !applicationsToRemove.Any())
                {
                    return;
                }

                // download applications first
                await DownloadApplications(applicationsToDeploy);

                var allAppsIds = new HashSet <string>(applicationsToRemove.Select(identity => identity.Id));
                allAppsIds.UnionWith(applicationsToDeploy.Select(config => config.AppIdentity.Id));

                if (!await _updateSessionManager.TryStartUpdateSession())
                {
                    Trace.TraceInformation("Couldn't start update session");
                    return;
                }

                var tasks = new List <Task>();

                foreach (string appId in allAppsIds)
                {
                    IEnumerable <AppIdentity>         appRemovals    = applicationsToRemove.Where(identity => identity.Id.Equals(appId));
                    IEnumerable <AppDeploymentConfig> appDeployments = applicationsToDeploy.Where(config => config.AppIdentity.Id.Equals(appId));

                    // if an application has a removal(s) and deployment(s), we consider it an update
                    if (appRemovals.Any() && appDeployments.Any())
                    {
                        tasks.Add(_applicationInstaller.Update(appRemovals, appDeployments));
                    }
                    else
                    {
                        foreach (AppDeploymentConfig appDeploymentConfig in appDeployments)
                        {
                            tasks.Add(_applicationInstaller.Install(appDeploymentConfig));
                        }
                        foreach (AppIdentity appRemoval in appRemovals)
                        {
                            tasks.Add(_applicationInstaller.UnInstall(appRemoval));
                        }
                    }
                }
                await Task.WhenAll(tasks);

                // We will only end the update session if the update was successful. Otherwise, the update session will stay open and will prevent
                // the deployment from moving to the next update domain.
                await _updateSessionManager.EndUpdateSession();
            }
            catch (AggregateException e)
            {
                TraceUtils.TraceAllErrors("Failures occured during updates", e);
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to perform update; Exception: {0}", e);
            }
            finally
            {
                await UpdateDeploymentStatus();
            }
        }