Ejemplo n.º 1
0
        public async Task <IActionResult> Configure(string fullTypeName)
        {
            var app      = (IApp)Activator.CreateInstance(ResolveAppType(fullTypeName));
            var analyzer = new AppAnalyzer(app);
            var model    = new ConfigureAppModel();
            await model.InitializeAsync(analyzer);

            return(View(model));
        }
Ejemplo n.º 2
0
 private void PopulateParameters(YamlMappingNode appNode, ConfigureAppModel model)
 {
     foreach (var p in model.Parameters)
     {
         appNode.Add(p.Name, p.Value);
     }
     foreach (var dep in model.Dependencies)
     {
         var depNode = new YamlMappingNode();
         PopulateParameters(depNode, dep);
         appNode.Add(dep.Name, depNode);
     }
 }
Ejemplo n.º 3
0
        private string GenerateParametersYaml(ConfigureAppModel model)
        {
            var rootNode = new YamlMappingNode();
            var doc      = new YamlDocument(rootNode);
            var appNode  = new YamlMappingNode();

            rootNode.Add("settings", appNode);
            PopulateParameters(appNode, model);
            var yamlStream       = new YamlStream(doc);
            var parametersWriter = new StringWriter();

            yamlStream.Save(parametersWriter, false);
            return(parametersWriter.ToString());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Deploy(string fullTypeName, ConfigureAppModel model)
        {
            var app      = (IApp)Activator.CreateInstance(ResolveAppType(fullTypeName));
            var analyzer = new AppAnalyzer(app);

            model.ApplyTo(analyzer);

            var appBuilder = new AppBuilder();
            await analyzer.Build(appBuilder);

            var restoredModel = new ConfigureAppModel();
            await restoredModel.InitializeAsync(analyzer);

            restoredModel.RuntimeSettings.Clear();
            restoredModel.RuntimeSettings.AddRange(model.RuntimeSettings);
            // generate parameters
            var parametersYaml      = GenerateParametersYaml(restoredModel);
            var runtimeSettingsYaml = GenerateRuntimeSettingsYaml(restoredModel);


            var svcFile     = Path.GetTempFileName();
            var paramsFile  = Path.GetTempFileName();
            var runtimeFile = Path.GetTempFileName();

            try {
                using (var svcStream = System.IO.File.Create(svcFile)){
                    appBuilder.BuiltApp.WriteTo(svcStream);
                    await svcStream.FlushAsync();
                }
                await System.IO.File.WriteAllTextAsync(paramsFile, parametersYaml, Encoding.UTF8);

                await System.IO.File.WriteAllTextAsync(runtimeFile, runtimeSettingsYaml, Encoding.UTF8);

                await _backend.RunAsync(model.DeploymentName, svcFile, paramsFile, runtimeFile);
            } finally {
                System.IO.File.Delete(svcFile);
                System.IO.File.Delete(paramsFile);
                System.IO.File.Delete(runtimeFile);
            }

            return(RedirectToAction("List", "AppLibs"));
        }
Ejemplo n.º 5
0
        private string GenerateRuntimeSettingsYaml(ConfigureAppModel model)
        {
            var rootNode = new YamlMappingNode();
            var doc      = new YamlDocument(rootNode);
            var appNode  = new YamlMappingNode();

            rootNode.Add("runtime", appNode);

            foreach (var s in model.RuntimeSettings)
            {
                var svcNode = new YamlMappingNode();
                appNode.Add(s.Name, svcNode);
                if (s.Scale > 1)
                {
                    svcNode.Add("scale", s.Scale.ToString());
                }
                if (s.SetLimits)
                {
                    var limitsNode = new YamlMappingNode();
                    svcNode.Add("limits", limitsNode);
                    if (s.MemoryLimit > 0)
                    {
                        limitsNode.Add("memory", s.MemoryLimit.ToString());
                    }
                    if (s.CpuLimit > 0)
                    {
                        limitsNode.Add("cpu", s.CpuLimit.ToString());
                    }
                }
            }

            var yamlStream       = new YamlStream(doc);
            var parametersWriter = new StringWriter();

            yamlStream.Save(parametersWriter, false);
            return(parametersWriter.ToString());
        }