private static int RunOptimize(Options options) { var geneticAlgorithm = new SampleGeneticAlgorithm(); try { var deploymentModelParser = JsonParserFactory.GetDeploymentModelParser(options.DeploymentModelFilePath); var version = JsonParserFactory.GetVersion(options.DeploymentModelFilePath); var deploymentModel = deploymentModelParser.Read(); var bestDeploymentModel = geneticAlgorithm.Run(deploymentModel); var outputPath = options.OutputDeploymentModelFilePath; if (string.IsNullOrEmpty(outputPath)) { var dirInfo = Path.GetDirectoryName(Path.GetFullPath(options.DeploymentModelFilePath)); var fileInfo = Path.GetFileName(options.DeploymentModelFilePath); outputPath = dirInfo + "/optimized_" + fileInfo; } Console.WriteLine("Outputting optimized deploymentmodel to " + outputPath); JsonDeploymentModelWriterFactory.Write(version, bestDeploymentModel, outputPath); } catch (Exception exception) { Console.WriteLine(exception.Message); return(1); } return(0); }
public void CreateJsonParser_WhenAskingForPartner2_ShouldCreateParser() { // Arrange var factory = new JsonParserFactory(); // Act var parser = factory.CreateJsonParser(ParserType.Partner2); // Assert Assert.AreEqual("Partner2", parser.PartnerName); }
public void ReadV3_Written_DeploymentModel_Returns_SameDeploymentModel() { var tmpFile = Path.GetTempFileName(); var deploymentModel = CreateDeploymentModel(); JsonDeploymentModelWriterFactory.Write(3, deploymentModel, tmpFile); var reader = JsonParserFactory.GetDeploymentModelParser(tmpFile); var version = JsonParserFactory.GetVersion(tmpFile); var readModel = reader.Read(); Assert.AreEqual(3, version); Assert.AreEqual(deploymentModel, readModel); }
public MiniJsonParser(JsonParserFactory jsonParserFactory) : this(jsonParserFactory.CreateParser()) { }
private static int RunVisualize(Options options) { try { var deploymentModelParser = JsonParserFactory.GetDeploymentModelParser(options.DeploymentModelFilePath); var deploymentModel = deploymentModelParser.Read(); var startInfo = new ProcessStartInfo { FileName = options.DotExePath, Arguments = $"-Tsvg -o {options.OutputPath}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true }; using (var process = Process.Start(startInfo)) { using (var standardInput = process.StandardInput) { standardInput.WriteLine("digraph G {"); standardInput.WriteLine("forcelabels=true;"); foreach (var microservice in deploymentModel.Microservices) { standardInput.WriteLine($"\tsubgraph cluster_{microservice.Id} {{"); standardInput.WriteLine($"\t\t label = \"{microservice.Id}\";"); foreach (var featureInstance in microservice) { var fillcolor = featureInstance.IsInternal ? "white" : "#b7c4d5"; standardInput.WriteLine($"\t\t{microservice.Id}_{featureInstance.Feature.Id}[shape=plaintext,label= <"); standardInput.WriteLine($"<table bgcolor=\"{fillcolor}\" BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">"); standardInput.WriteLine($"<tr><td ALIGN=\"CENTER\" COLSPAN=\"{featureInstance.Properties.Count()}\">{featureInstance.Name}</td></tr>"); standardInput.WriteLine("<tr>"); foreach (var property in featureInstance.Properties) { standardInput.WriteLine($"<td>{property.Name}</td>"); } standardInput.WriteLine("</tr>"); standardInput.WriteLine("</table>>]"); } standardInput.WriteLine($"\t}}"); } standardInput.WriteLine("}"); standardInput.Close(); } process.WaitForExit(); var exitCode = process.ExitCode; if (exitCode != 0) { var output = process.StandardError.ReadToEnd(); Console.WriteLine("An error occurred during visualization"); Console.WriteLine(); Console.WriteLine(output); return(1); } Console.WriteLine($"Deploymentmodel has been visualized in {options.OutputPath}"); return(0); } } catch (Exception e) { Console.WriteLine("An error occured"); Console.WriteLine(); Console.WriteLine(e.Message); return(1); } }