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 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);
     }
 }
Exemple #3
0
        public async Task Install(AppInstallConfig appInstallConfig)
        {
            IApplication application =
                await _applicationFactory.CreateApplication(appInstallConfig, GetApplicationAbsolutePath(appInstallConfig.AppIdentity));

            await _applicationPool.AddApplication(application);
        }
        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;
        }
Exemple #5
0
        public async Task Install(AppInstallConfig appInstallConfig)
        {
            IApplication application =
                await _applicationFactory.CreateApplication(appInstallConfig, GetApplicationAbsolutePath(appInstallConfig.AppIdentity));

            try
            {
                await _applicationPool.AddApplication(application);
            }
            catch (Exception)
            {
                await DeleteAppBinaries(appInstallConfig.AppIdentity);

                throw;
            }
        }
        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 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);
 }
Exemple #8
0
        public async Task Install(AppInstallConfig appInstallConfig)
        {
            AppIdentity appIdentity = appInstallConfig.AppIdentity;

            Trace.TraceInformation($"Installing application {appIdentity}");
            IApplication application =
                await _applicationFactory.CreateApplication(appInstallConfig,
                                                            GetApplicationAbsolutePath(appInstallConfig.AppIdentity));

            try
            {
                await _applicationPool.AddApplication(application);

                Trace.TraceInformation($"Application {appIdentity} installed");
            }
            catch (Exception e)
            {
                await DeleteAppBinaries(appInstallConfig.AppIdentity);

                throw new Exception($"Failed to install application {appIdentity}", e);
            }
        }
 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<IApplication> CreateApplication(AppInstallConfig appInstallConfig, string appPath)
 {
     return Task.FromResult((IApplication)new ApplicationStub(appInstallConfig.AppIdentity, appPath));
 }
 public async Task Install(AppInstallConfig appInstallConfig)
 {
     IApplication application =
         await _applicationFactory.CreateApplication(appInstallConfig, GetApplicationAbsolutePath(appInstallConfig.AppIdentity));
     await _applicationPool.AddApplication(application);
 }
 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);
 }