Exemple #1
0
        public async Task <bool> Update(IEnumerable <AppIdentity> applicationsToRemove, IEnumerable <AppInstallConfig> applicationsToDeploy)
        {
            if (!applicationsToDeploy.Any() || !applicationsToRemove.Any())
            {
                throw new ArgumentException("An update must at least involve an application to remove and an application to deploy");
            }

            string appId = applicationsToDeploy.First().AppIdentity.Id;

            bool failed = false;

            try
            {
                await UnInstallApplications(applicationsToRemove);
                await InstallApplications(applicationsToDeploy);
            }
            catch (AggregateException e)
            {
                failed = true;
                TraceUtils.TraceAllErrors("Failed to update applications", e);
            }
            catch (Exception e)
            {
                failed = true;
                Trace.TraceError("Failed to update applications", e);
            }

            return(!failed);
        }
        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);
            }
        }
Exemple #3
0
        public async Task <bool> Update(string appId, IEnumerable <SemVersion> versionsToRemove, IEnumerable <SemVersion> versionsToDeploy)
        {
            if (!versionsToRemove.Any() || !versionsToDeploy.Any())
            {
                throw new ArgumentException("An update must at least involve an application to remove and an application to deploy");
            }

            IEnumerable <AppIdentity> applicationsToDeploy = versionsToDeploy.Select(v => new AppIdentity(appId, v));
            IEnumerable <AppIdentity> applicationsToRemove = versionsToRemove.Select(v => new AppIdentity(appId, v));

            bool failed = false;

            try
            {
                if (!await _updateSessionManager.TryStartUpdateSession(appId))
                {
                    Trace.TraceInformation("Couldn't start update session for app {0}", appId);
                    return(false);
                }

                await UnInstallApplications(applicationsToRemove);
                await InstallApplications(applicationsToDeploy);
            }
            catch (AggregateException e)
            {
                failed = true;
                TraceUtils.TraceAllErrors("Failed to update applications", e);
            }
            catch (Exception e)
            {
                failed = true;
                Trace.TraceError("Failed to update applications", e);
            }

            await _updateSessionManager.EndUpdateSession(appId);

            if (failed)
            {
                return(false);
            }
            return(true);
        }
        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();
            }
        }