public async Task TestThatOnlyOneUpdateDomainCanUpdateAtATime()
        {
            Assert.True(await _updateSessionManager.TryStartUpdateSession());
            IUpdateSessionManager otherUpdateSessionManager = CreateUpdateSessionManager("superClusterId", "instanceId2", "2");

            Assert.False(await otherUpdateSessionManager.TryStartUpdateSession());
        }
Example #2
0
        public async Task TestThatDiffentAppsCanUpdateIndependently()
        {
            Assert.True(await _updateSessionManager.TryStartUpdateSession("app1"));
            IUpdateSessionManager otherUpdateSessionManager = CreateUpdateSessionManager("clusterId1", "instanceId2", "2");

            Assert.True(await otherUpdateSessionManager.TryStartUpdateSession("app2"));
        }
        public async Task TestThatDifferentDeploymentsCanUpdateIndependently()
        {
            Assert.True(await _updateSessionManager.TryStartUpdateSession());

            IUpdateSessionManager otherUpdateSessionManager = CreateUpdateSessionManager("superClusterId2", "instanceId2", "2");

            Assert.True(await otherUpdateSessionManager.TryStartUpdateSession());
        }
        public async Task TestThatMultipleInstancesInTheSameUpdateDomainCanUpdateSimultaneously()
        {
            Assert.True(await _updateSessionManager.TryStartUpdateSession());

            IUpdateSessionManager otherUpdateSessionManager = CreateUpdateSessionManager("superClusterId", "instanceId2", "1");

            Assert.True(await otherUpdateSessionManager.TryStartUpdateSession());
        }
        public async Task TestThatEndUpdateSessionWorks()
        {
            Assert.True(await _updateSessionManager.TryStartUpdateSession());

            await _updateSessionManager.EndUpdateSession();

            IUpdateSessionManager otherUpdateSessionManager = CreateUpdateSessionManager("superClusterId", "instanceId2", "2");

            Assert.True(await otherUpdateSessionManager.TryStartUpdateSession());
        }
Example #6
0
        public async Task TestThatEndUpdateSessionWorks()
        {
            Assert.True(await _updateSessionManager.TryStartUpdateSession("app1"));

            await _updateSessionManager.EndUpdateSession("app1");

            IUpdateSessionManager otherUpdateSessionManager = CreateUpdateSessionManager("deploymentId", "instanceId2", "2");

            Assert.True(await otherUpdateSessionManager.TryStartUpdateSession("app1"));
        }
Example #7
0
        public async Task <bool> TryStartUpdateSession(string applicationId)
        {
            int count = 0;

            while (count <= _retryCount)
            {
                if (await _updateSessionManager.TryStartUpdateSession(applicationId))
                {
                    return(true);
                }

                ++count;
                if (count <= _retryCount)
                {
                    await Task.Delay(_retryInterval);
                }
            }
            return(false);
        }
Example #8
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);
        }
Example #9
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
            {
                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);

            return(!failed);
        }
 public async Task TestStartUpdateSessionSimple()
 {
     Assert.True(await _updateSessionManager.TryStartUpdateSession());
 }
 public Task <bool> TryStartUpdateSession(string applicationId)
 {
     return(_retryPolicy.ExecuteAsync(async() => await _updateSessionManager.TryStartUpdateSession(applicationId)));
 }
 public Task <bool> TryStartUpdateSession()
 {
     return(_retryPolicy.ExecuteAsync(async() => await _updateSessionManager.TryStartUpdateSession()));
 }
Example #13
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();
            }
        }