public async Task <ApplicationConfig> ParseFile(string path, AppInstallConfig appInstallConfig) { using (StreamReader r = new StreamReader(path)) { return(await Parse(await _jsonSerializer.DeserializeAsync <ApplicationConfigData>(await r.ReadToEndAsync()), appInstallConfig)); } }
public async Task <IApplication> CreateApplication(AppInstallConfig appInstallConfig, string appPath) { string appConfigPath = Path.Combine(appPath, Constants.AppConfigFileName); ApplicationConfig appConfig = await _appConfigParser.ParseFile(appConfigPath, appInstallConfig); return(new ConfigurableApplication(appPath, appConfig, _processFactory, _processStopper)); }
private async Task AddApplication(AppInstallConfig appInstallConfig) { IApplication application = await _applicationFactory.CreateApplication(appInstallConfig, GetApplicationPath(appInstallConfig.AppIdentity)); await _applicationPool.AddApplication(application); }
public async Task TestThatClusterPropertiesAreUsedToMatchDeployments() { UploadDeploymentConfig("DeploymentConfigWithProperties.json"); var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId", _applicationsInstallPath).SetShowApplicationProcessWindow(false) .AddClusterProperty("NodeType", "Test") .AddClusterProperty("Region", "East").Build(); AppInstallConfig appInstallConfig = null; var applicationInstallerStub = new StubIApplicationInstaller().Install( (config) => { Assert.Null(appInstallConfig); appInstallConfig = config; return(Task.CompletedTask); }); ContainerBuilder builder = InitializeContainerBuilder(yamsConfig); builder.RegisterInstance <IApplicationInstaller>(applicationInstallerStub); InitializeYamsService(builder.Build()); IApplicationUpdateManager applicationUpdateManager = _yamsDiModule.Container.Resolve <IApplicationUpdateManager>(); await applicationUpdateManager.CheckForUpdates(); Assert.Equal(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), appInstallConfig.AppIdentity); Assert.True(appInstallConfig.Properties.ContainsKey("NodeType")); Assert.Equal("Test", appInstallConfig.Properties["NodeType"]); Assert.True(appInstallConfig.Properties.ContainsKey("Region")); Assert.Equal("East", appInstallConfig.Properties["Region"]); }
public async Task TestThatAddExistingApplicationThrowsAnException() { await Assert.ThrowsAsync <ArgumentException>(async() => { AppIdentity appIdentity = new AppIdentity("test.myapp", new SemVersion(1, 0, 0)); AppInstallConfig config = new AppInstallConfig(appIdentity); await AddApplication(config); await AddApplication(config); }); }
public async Task TestAddApplication() { AppIdentity appIdentity = new AppIdentity("test.myapp", new SemVersion(1, 0, 0)); AppInstallConfig config = new AppInstallConfig(appIdentity); await AddApplication(config); Assert.NotNull(_applicationPool.GetApplication(appIdentity)); Assert.Equal("TestProcess.exe foo1 foo2", GetOutput(appIdentity)); }
public async Task TestThatAppPropertiesOverwritesClusterProperties() { var resolver = new ApplicationConfigSymbolResolver("clusterId", "instanceId", new Dictionary <string, string>() { { "propKey", "clusterPropValue" } }); var appInstallConfig = new AppInstallConfig(new AppIdentity("app", "1.0.0-test"), new Dictionary <string, string> { { "propKey", "appPropValue" } }); Assert.Equal("appPropValue", await resolver.ResolveSymbol(appInstallConfig, "propKey")); }
public Task <string> ResolveSymbol(AppInstallConfig appInstallConfig, string symbol) { string symbolValue = symbol; AppIdentity appIdentity = appInstallConfig.AppIdentity; switch (symbol) { case "Id": symbolValue = appIdentity.Id; break; case "Version": symbolValue = appIdentity.Version.ToString(); break; case "Version.Major": symbolValue = appIdentity.Version.Major.ToString(); break; case "Version.Minor": symbolValue = appIdentity.Version.Minor.ToString(); break; case "Version.Build": symbolValue = appIdentity.Version.Patch.ToString(); break; case "Version.Prerelease": symbolValue = appIdentity.Version.Prerelease; break; case "ClusterId": symbolValue = _clusterId; break; // TODO: This has been kept for backward compatibility; remove at some point case "DeploymentId": symbolValue = _clusterId; break; case "InstanceId": symbolValue = _instanceId; break; default: if (!appInstallConfig.Properties.TryGetValue(symbol, out symbolValue)) { _clusterProperties.TryGetValue(symbol, out symbolValue); } break; } return(Task.FromResult(symbolValue)); }
public Task <string> ResolveSymbol(AppInstallConfig appInstallConfig, string symbol) { string symbolValue = symbol; AppIdentity appIdentity = appInstallConfig.AppIdentity; switch (symbol) { case "Id": symbolValue = appIdentity.Id; break; case "Version": symbolValue = appIdentity.Version.ToString(); break; case "Version.Major": symbolValue = appIdentity.Version.Major.ToString(); break; case "Version.Minor": symbolValue = appIdentity.Version.Minor.ToString(); break; case "Version.Build": symbolValue = appIdentity.Version.Patch.ToString(); break; case "Version.Prerelease": symbolValue = appIdentity.Version.Prerelease; break; case "ClusterId": symbolValue = _clusterId; break; case "InstanceId": symbolValue = _instanceId; break; default: if (!appInstallConfig.Properties.TryGetValue(symbol, out symbolValue)) { _clusterProperties.TryGetValue(symbol, out symbolValue); } break; } return(Task.FromResult(symbolValue)); }
private async Task <string> SubstituteSymbols(string str, AppInstallConfig appInstallConfig) { ISet <string> symbols = new HashSet <string>(); const string pattern = @"\{(.*?)\}"; foreach (Match m in Regex.Matches(str, pattern)) { symbols.Add(m.Groups[1].ToString()); } foreach (string symbol in symbols) { str = await SubstitueSymbol(str, symbol, appInstallConfig); } return(str); }
public async Task TestResolve() { var resolver = new ApplicationConfigSymbolResolver("clusterId", "instanceId", new Dictionary <string, string>() { { "clusterPropKey", "clusterPropValue" } }); var appInstallConfig = new AppInstallConfig(new AppIdentity("app", "1.0.0-test"), new Dictionary <string, string> { { "appPropKey", "appPropValue" } }); Assert.Equal("clusterId", await resolver.ResolveSymbol(appInstallConfig, "ClusterId")); Assert.Equal("instanceId", await resolver.ResolveSymbol(appInstallConfig, "InstanceId")); Assert.Equal("app", await resolver.ResolveSymbol(appInstallConfig, "Id")); Assert.Equal("1.0.0-test", await resolver.ResolveSymbol(appInstallConfig, "Version")); Assert.Equal("1", await resolver.ResolveSymbol(appInstallConfig, "Version.Major")); Assert.Equal("0", await resolver.ResolveSymbol(appInstallConfig, "Version.Minor")); Assert.Equal("0", await resolver.ResolveSymbol(appInstallConfig, "Version.Build")); Assert.Equal("test", await resolver.ResolveSymbol(appInstallConfig, "Version.Prerelease")); Assert.Equal("clusterPropValue", await resolver.ResolveSymbol(appInstallConfig, "clusterPropKey")); Assert.Equal("appPropValue", await resolver.ResolveSymbol(appInstallConfig, "appPropKey")); }
public async Task TestThatClusterPropertiesAreUsedToMatchDeployments() { UploadDeploymentConfig("DeploymentConfigWithProperties.json"); var yamsConfig = new YamsConfigBuilder("clusterId1", "1", "instanceId", _applicationsInstallPath).SetUseShellExecute(false) .AddClusterProperty("NodeType", "Test") .AddClusterProperty("Region", "East").Build(); var installedApps = new List <AppInstallConfig>(); var applicationInstallerStub = new StubIApplicationInstaller().Install( (config) => { installedApps.Add(config); return(Task.CompletedTask); }); ContainerBuilder builder = InitializeContainerBuilder(yamsConfig); builder.RegisterInstance <IApplicationInstaller>(applicationInstallerStub); InitializeYamsService(builder.Build()); IApplicationUpdateManager applicationUpdateManager = _yamsDiModule.Container.Resolve <IApplicationUpdateManager>(); await applicationUpdateManager.CheckForUpdates(); Assert.Equal(2, installedApps.Count); Assert.True(installedApps.Any(config => config.AppIdentity == new AppIdentity("test.app1", "1.0.0"))); Assert.True(installedApps.Any(config => config.AppIdentity == new AppIdentity("test.app2", "2.0.0-beta"))); AppInstallConfig appInstallConfig = installedApps.Find(config => config.AppIdentity.Id == "test.app1"); Assert.Equal(new AppIdentity("test.app1", new SemVersion(1, 0, 0)), appInstallConfig.AppIdentity); Assert.True(appInstallConfig.Properties.ContainsKey("NodeType")); Assert.Equal("Test", appInstallConfig.Properties["NodeType"]); Assert.True(appInstallConfig.Properties.ContainsKey("Region")); Assert.Equal("East", appInstallConfig.Properties["Region"]); }
public Task <IApplication> CreateApplication(AppInstallConfig appInstallConfig, string appPath) { return(Task.FromResult((IApplication) new ApplicationStub(appInstallConfig.AppIdentity, appPath))); }
private async Task <string> SubstitueSymbol(string str, string symbol, AppInstallConfig appInstallConfig) { string symbolValue = await _symbolResolver.ResolveSymbol(appInstallConfig, symbol); return(str.Replace(string.Format("${{{0}}}", symbol), symbolValue)); }
private async Task <ApplicationConfig> Parse(ApplicationConfigData appConfigData, AppInstallConfig appInstallConfig) { string args = await SubstituteSymbols(appConfigData.ExeArgs, appInstallConfig); return(new ApplicationConfig(appInstallConfig.AppIdentity, appConfigData.ExeName, args)); }
public Task Install(AppInstallConfig appInstallConfig) { _applicationPool.AddApplication(new ApplicationStub(appInstallConfig.AppIdentity, GetAppPath(appInstallConfig))); return(Task.CompletedTask); }
private async Task <ApplicationConfig> Parse(ApplicationConfigData appConfigData, AppInstallConfig appInstallConfig) { string args = await SubstituteSymbols(appConfigData.ExeArgs, appInstallConfig); return(new ApplicationConfig(appInstallConfig.AppIdentity, appConfigData.ExeName, args, appConfigData.MonitorInitialization, appConfigData.MonitorHealth, appConfigData.GracefulShutdown)); }
private string GetAppPath(AppInstallConfig appInstallConfig) { return($"{path}\\{appInstallConfig.AppIdentity.Id}\\{appInstallConfig.AppIdentity.Version}"); }