public ApplicationUpdateManagerTest() { string id1 = "appId1"; var v1 = SemVersion.Parse("1.0.0"); var v2 = SemVersion.Parse("2.0.0"); var v3 = SemVersion.Parse("3.0.0"); var v4 = SemVersion.Parse("4.0.0"); var v5 = SemVersion.Parse("5.0.0"); app1v1 = new AppIdentity(id1, v1); app1v2 = new AppIdentity(id1, v2); app1v3 = new AppIdentity(id1, v3); app1v4 = new AppIdentity(id1, v4); app1v5 = new AppIdentity(id1, v5); downloadedApps = new List <AppIdentity>(); applicationDownloader = new StubIApplicationDownloader() .DownloadApplication(appIdentity => { downloadedApps.Add(appIdentity); return(Task.FromResult(true)); } ); applicationPool = new ApplicationPoolStub(); applicationInstaller = new ApplicationInstallerStub(applicationPool, "path"); instanceDeploymentStatus = new InstanceDeploymentStatus(); deploymentStatusWriterStub = new StubIDeploymentStatusWriter() .PublishInstanceDeploymentStatus((clusterId, instanceId, status) => { instanceDeploymentStatus = status; return(Task.CompletedTask); }); }
public Task PublishInstanceDeploymentStatus(string clusterId, string instanceId, InstanceDeploymentStatus instanceDeploymentStatus) { CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(GetInstanceStatusRelativePath(clusterId, instanceId)); string data = _deploymentStatusSerializer.Serialize(instanceDeploymentStatus); return(blob.UploadTextAsync(data)); }
private void VerifyThatDeploymentStatusHasBeenUpdated(InstanceDeploymentStatus instanceDeploymentStatus, AppIdentity appIdentity, string clusterId, string instanceId) { var appDeploymentStatus = instanceDeploymentStatus.GetAppDeploymentStatus(appIdentity); Assert.NotNull(appDeploymentStatus); Assert.Equal(appIdentity, appDeploymentStatus.AppIdentity); Assert.Equal(clusterId, appDeploymentStatus.ClusterId); Assert.Equal(instanceId, appDeploymentStatus.InstanceId); Assert.NotNull(appDeploymentStatus.UtcTimeStamp); }
private async Task UpdateDeploymentStatus() { DateTime utcNow = DateTime.UtcNow; var instanceDeploymentStatus = new InstanceDeploymentStatus(); foreach (IApplication app in _applicationPool.Applications) { var appDeploymentStatus = new AppDeploymentStatus(app.Identity, _clusterId, _instanceId, utcNow); instanceDeploymentStatus.SetAppDeploymentStatus(appDeploymentStatus); } await _deploymentStatusWriter.PublishInstanceDeploymentStatus(_clusterId, _instanceId, instanceDeploymentStatus); }
public Task PublishInstanceDeploymentStatus(string clusterId, string instanceId, InstanceDeploymentStatus instanceDeploymentStatus) { string path = GetInstanceDeploymentStatusPath(clusterId, instanceId); string parentDirPath = Path.GetDirectoryName(path); if (!Directory.Exists(parentDirPath)) { Directory.CreateDirectory(parentDirPath); } File.WriteAllText(path, _deploymentStatusSerializer.Serialize(instanceDeploymentStatus)); return(Task.CompletedTask); }
public async Task TestMultipleUpdates() { const string ClusterId = "clusterId1"; const string InstanceId = "instanceId"; var yamsConfig = new YamsConfigBuilder(ClusterId, "1", InstanceId, _applicationsInstallPath).SetUseShellExecute(false).Build(); InitializeYamsService(yamsConfig); IApplicationUpdateManager applicationUpdateManager = _yamsDiModule.Container.Resolve <IApplicationUpdateManager>(); await applicationUpdateManager.CheckForUpdates(); AssertThatApplicationIsRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), "TestProcess"); AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0)), "TestProcess"); AssertThatApplicationIsRunning(new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")), "TestProcess"); AssertThatApplicationIsRunning(new AppIdentity("test.app3", new SemVersion(1, 1, 0)), "TestProcess"); UploadDeploymentConfig("DeploymentConfigUpdate.json"); await applicationUpdateManager.CheckForUpdates(); AssertThatApplicationIsNotRunning(new AppIdentity("test.app1", new SemVersion(1, 0, 0))); AssertThatApplicationIsNotRunning(new AppIdentity("test.app2", new SemVersion(1, 1, 0))); AppIdentity app1v101 = new AppIdentity("test.app1", new SemVersion(1, 0, 1)); AppIdentity app2v200beta = new AppIdentity("test.app2", new SemVersion(2, 0, 0, "beta")); AppIdentity app3v100 = new AppIdentity("test.app3", new SemVersion(1, 0, 0)); AppIdentity app3v110 = new AppIdentity("test.app3", new SemVersion(1, 1, 0)); AppIdentity app4v100 = new AppIdentity("test.app4", new SemVersion(1, 0, 0)); AssertThatApplicationIsRunning(app1v101, "TestProcess"); AssertThatApplicationIsRunning(app2v200beta, "TestProcess"); AssertThatApplicationIsRunning(app3v100, "TestProcess"); AssertThatApplicationIsRunning(app3v110, "TestProcess"); AssertThatApplicationIsRunning(app4v100, "TestProcess"); AssertThatNumberOfApplicationsRunningIs(5); InstanceDeploymentStatus deploymentStatus = await _deploymentRepository.FetchInstanceDeploymentStatus(ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app1v101, ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app2v200beta, ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app3v100, ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app3v110, ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(deploymentStatus, app4v100, ClusterId, InstanceId); }
private async Task UpdateDeploymentStatus() { try { DateTime utcNow = DateTime.UtcNow; var instanceDeploymentStatus = new InstanceDeploymentStatus(); foreach (IApplication app in _applicationPool.Applications) { var appDeploymentStatus = new AppDeploymentStatus(app.Identity, _clusterId, _instanceId, utcNow); instanceDeploymentStatus.SetAppDeploymentStatus(appDeploymentStatus); } await _deploymentStatusWriter.PublishInstanceDeploymentStatus(_clusterId, _instanceId, instanceDeploymentStatus); Trace.TraceInformation("DeploymentStatus updated"); } catch (Exception e) { Trace.TraceError("Failed to update the deployment status; Exception: {0}", e); } }
public async Task <ClusterDeploymentStatus> FetchClusterDeploymentStatus(string clusterId, int ttlSeconds) { ClusterDeploymentStatus clusterDeploymentStatus = new ClusterDeploymentStatus();; CloudBlobDirectory instancesBlobDir = _blobContainer.GetDirectoryReference(GetClusterStatusRelativePath(clusterId)); if (!await instancesBlobDir.ExistsAsync()) { return(clusterDeploymentStatus); } IEnumerable <IListBlobItem> instancesBlobList = await instancesBlobDir.ListBlobsAsync(); foreach (var blob in instancesBlobList) { CloudBlockBlob instanceBlob = blob as CloudBlockBlob; if (instanceBlob == null) { Trace.TraceWarning($"Unexpected blob {blob.Uri} in cluster status directory"); continue; } double secondsSinceModified = DateTimeOffset.UtcNow.Subtract(instanceBlob.Properties.LastModified.Value).TotalSeconds; if (secondsSinceModified > ttlSeconds) { continue; } try { InstanceDeploymentStatus instanceDeploymentStatus = await FetchInstanceDeploymentStatus(instanceBlob); string instanceId = instanceBlob.Name; clusterDeploymentStatus.SetInstanceDeploymentStatus(instanceId, instanceDeploymentStatus); } catch (Exception e) { Trace.TraceError($"Could not read instance deployment status {instanceBlob.Uri}, Exception: {e}"); } } return(clusterDeploymentStatus); }
public async Task TestMultipleUpdates() { string id1 = "appId1"; var v1 = SemVersion.Parse("1.0.0"); var v2 = SemVersion.Parse("2.0.0"); var v3 = SemVersion.Parse("3.0.0"); var v4 = SemVersion.Parse("4.0.0"); var v5 = SemVersion.Parse("5.0.0"); AppIdentity app1v1 = new AppIdentity(id1, v1); AppIdentity app1v2 = new AppIdentity(id1, v2); AppIdentity app1v3 = new AppIdentity(id1, v3); AppIdentity app1v4 = new AppIdentity(id1, v4); AppIdentity app1v5 = new AppIdentity(id1, v5); IEnumerable <AppIdentity> appsToDeploy = new[] { app1v3, app1v4, app1v5 }; IEnumerable <string> clusters = new[] { "clusterId1" }; IApplicationDeploymentDirectory applicationDeploymentDirectory = new StubIApplicationDeploymentDirectory() .FetchDeployments(() => Task.FromResult(appsToDeploy.Select(identity => new AppDeploymentConfig(identity, clusters)))); IApplicationPool applicationPool = new ApplicationPoolStub(); string path = Path.GetTempPath(); await applicationPool.AddApplication(new ApplicationStub(app1v1, path)); await applicationPool.AddApplication(new ApplicationStub(app1v2, path)); await applicationPool.AddApplication(new ApplicationStub(app1v3, path)); var downloadedApps = new List <AppIdentity>(); IApplicationDownloader applicationDownloader = new StubIApplicationDownloader() .DownloadApplication(appIdentity => { downloadedApps.Add(appIdentity); return(Task.FromResult(true)); } ); IApplicationInstaller applicationInstaller = new StubIApplicationInstaller() .Install(config => { applicationPool.AddApplication(new ApplicationStub(config.AppIdentity, "path")); return(Task.FromResult(true)); }) .UnInstall(appIdentity => { applicationPool.RemoveApplication(appIdentity); return(Task.FromResult(true)); }) .Update((applicationsToRemove, applicationsToInstall) => { foreach (var appIdentity in applicationsToRemove) { applicationPool.RemoveApplication(appIdentity); } foreach (var appInstallConfig in applicationsToInstall) { applicationPool.AddApplication(new ApplicationStub(appInstallConfig.AppIdentity, "path")); } return(Task.FromResult(true)); } ); var instanceDeploymentStatus = new InstanceDeploymentStatus(); IDeploymentStatusWriter deploymentStatusWriterStub = new StubIDeploymentStatusWriter() .PublishInstanceDeploymentStatus((clusterId, instanceId, status) => { instanceDeploymentStatus = status; return(Task.CompletedTask); }); const string ClusterId = "clusterId"; const string InstanceId = "instanceId"; ApplicationUpdateManager applicationUpdateManager = new ApplicationUpdateManager(ClusterId, InstanceId, applicationDeploymentDirectory, applicationPool, applicationDownloader, applicationInstaller, deploymentStatusWriterStub); await applicationUpdateManager.CheckForUpdates(); Assert.Equal(3, applicationPool.Applications.Count()); Assert.True(applicationPool.HasApplication(app1v3)); Assert.True(applicationPool.HasApplication(app1v4)); Assert.True(applicationPool.HasApplication(app1v5)); Assert.Equal(3, instanceDeploymentStatus.Applications.Count()); VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v3, ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v4, ClusterId, InstanceId); VerifyThatDeploymentStatusHasBeenUpdated(instanceDeploymentStatus, app1v5, ClusterId, InstanceId); }
public Task PublishInstanceDeploymentStatus(string clusterId, string instanceId, InstanceDeploymentStatus instanceDeploymentStatus) { return(Task.CompletedTask); }