prep for service dependency support

This commit is contained in:
Chris Cheetham 2020-03-25 19:45:57 -04:00
Родитель 1170f4837d
Коммит 84bd775056
11 изменённых файлов: 34 добавлений и 36 удалений

Просмотреть файл

@ -32,7 +32,7 @@ See Also:
{ {
public const string CommandName = "run"; public const string CommandName = "run";
[Option("-g|--generate-only", Description = "Only generate configuration files (don't run in Docker).")] [Option("-g|--generate-only", Description = "Only generate configuration files (don't run in Docker)")]
private bool GenerateOnly { get; } private bool GenerateOnly { get; }
public RunCommand(IConsole console) : base(console) public RunCommand(IConsole console) : base(console)

Просмотреть файл

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
using System.IO; using System.IO;
using Steeltoe.Tooling.Helpers;
using Steeltoe.Tooling.Models; using Steeltoe.Tooling.Models;
namespace Steeltoe.Tooling.Controllers namespace Steeltoe.Tooling.Controllers

Просмотреть файл

@ -12,10 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Steeltoe.Tooling.Models;
using Steeltoe.Tooling.Templaters; using Steeltoe.Tooling.Templaters;
namespace Steeltoe.Tooling.Controllers namespace Steeltoe.Tooling.Controllers

Просмотреть файл

@ -12,10 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using Steeltoe.Tooling.Helpers;
using Steeltoe.Tooling.Models; using Steeltoe.Tooling.Models;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;

Просмотреть файл

@ -12,9 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace Steeltoe.Tooling.Models namespace Steeltoe.Tooling.Models
@ -28,7 +26,13 @@ namespace Steeltoe.Tooling.Models
/// Project name. /// Project name.
/// </summary> /// </summary>
[YamlIgnore] [YamlIgnore]
public string Name { get; set; } public string Name
{
get => _name;
set => _name = value.ToLower();
}
private string _name;
/// <summary> /// <summary>
/// Project file path. /// Project file path.
@ -45,7 +49,7 @@ namespace Steeltoe.Tooling.Models
/// <summary> /// <summary>
/// Network ports. /// Network ports.
/// </summary> /// </summary>
[YamlMember(Alias = "services")] [YamlMember(Alias = "protocols")]
public List<Service> Services { get; set; } public List<Protocol> Protocols { get; set; }
} }
} }

Просмотреть файл

@ -18,10 +18,9 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Steeltoe.Tooling.Models;
using YamlDotNet.RepresentationModel; using YamlDotNet.RepresentationModel;
namespace Steeltoe.Tooling.Helpers namespace Steeltoe.Tooling.Models
{ {
/// <summary> /// <summary>
/// Helper for building a Project. /// Helper for building a Project.
@ -30,11 +29,11 @@ namespace Steeltoe.Tooling.Helpers
{ {
private static readonly ILogger Logger = Logging.LoggerFactory.CreateLogger<ProjectBuilder>(); private static readonly ILogger Logger = Logging.LoggerFactory.CreateLogger<ProjectBuilder>();
private static readonly List<Service> DefaultServices = new List<Service>(); private static readonly List<Protocol> DefaultServices = new List<Protocol>();
static ProjectBuilder() static ProjectBuilder()
{ {
DefaultServices.Add(new Service("http", 8080)); DefaultServices.Add(new Protocol("http", 8080));
} }
/// <summary> /// <summary>
@ -59,7 +58,7 @@ namespace Steeltoe.Tooling.Helpers
Name = Path.GetFileNameWithoutExtension(projectFile), Name = Path.GetFileNameWithoutExtension(projectFile),
File = Path.GetFileName(projectFile), File = Path.GetFileName(projectFile),
Framework = GetFramework(projectFile), Framework = GetFramework(projectFile),
Services = GetServices(projectFile) Protocols = GetServices(projectFile)
}; };
return project; return project;
} }
@ -83,7 +82,7 @@ namespace Steeltoe.Tooling.Helpers
throw new ToolingException("could not determine framework"); throw new ToolingException("could not determine framework");
} }
private List<Service> GetServices(string projectFile) private List<Protocol> GetServices(string projectFile)
{ {
var launchSettingsPath = var launchSettingsPath =
Path.Join(Path.GetDirectoryName(projectFile), "Properties", "launchSettings.json"); Path.Join(Path.GetDirectoryName(projectFile), "Properties", "launchSettings.json");
@ -115,7 +114,7 @@ namespace Steeltoe.Tooling.Helpers
return DefaultServices; return DefaultServices;
} }
var services = urls.Select(url => new Uri(url)).Select(uri => new Service(uri.Scheme, uri.Port)).ToList(); var services = urls.Select(url => new Uri(url)).Select(uri => new Protocol(uri.Scheme, uri.Port)).ToList();
services.Sort(); services.Sort();
return services; return services;
} }

Просмотреть файл

@ -20,13 +20,13 @@ namespace Steeltoe.Tooling.Models
/// <summary> /// <summary>
/// A network port. /// A network port.
/// </summary> /// </summary>
public class Service : IComparable public class Protocol : IComparable
{ {
/// <summary> /// <summary>
/// Service protocol. /// Service protocol.
/// </summary> /// </summary>
[YamlMember(Alias = "protocol")] [YamlMember(Alias = "name")]
public string Protocol { get; } public string Name { get; }
/// <summary> /// <summary>
/// Service port. /// Service port.
@ -35,26 +35,26 @@ namespace Steeltoe.Tooling.Models
public int Port { get; } public int Port { get; }
/// <summary> /// <summary>
/// Create a new service. /// Create a new Protocol.
/// </summary> /// </summary>
/// <param name="protocol">Service protocol.</param> /// <param name="name">Protocol name.</param>
/// <param name="port">Service port.</param> /// <param name="port">Protocol port.</param>
public Service(string protocol, int port) public Protocol(string name, int port)
{ {
Protocol = protocol; Name = name;
Port = port; Port = port;
} }
/// <summary> /// <summary>
/// Returns a comparison of the Services' protocols, and if equal, a comparison of the ports. /// Returns a comparison of the Protocols' names, and if equal, a comparison of the ports.
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj">Protocol against which to compare.</param>
/// <returns></returns> /// <returns>&lt;0, 0, &gt;0.</returns>
public int CompareTo(object obj) public int CompareTo(object obj)
{ {
var svc = (Service) obj; var svc = (Protocol) obj;
var compare = Protocol.CompareTo(svc.Protocol); var compare = Name.CompareTo(svc.Name);
if (compare != 0) if (compare != 0)
{ {
return compare; return compare;

Просмотреть файл

@ -24,7 +24,7 @@ namespace Steeltoe.Tooling.Templaters
/// </summary> /// </summary>
public class TemplateManager public class TemplateManager
{ {
private static readonly object Locker = new object(); private static readonly object TemplaterLock = new object();
/// <summary> /// <summary>
/// Gets the named template. /// Gets the named template.
@ -38,14 +38,14 @@ namespace Steeltoe.Tooling.Templaters
var template = File.ReadAllText(path); var template = File.ReadAllText(path);
try try
{ {
lock (Locker) // StringTemplate doesn't seem to be tread safe lock (TemplaterLock) // AntlrStringTemplate doesn't seem to be thread safe
{ {
return new AntlrStringTemplate(template); return new AntlrStringTemplate(template);
} }
} }
catch (Exception e) catch (Exception e)
{ {
throw new ToolingException($"failed to load template '{name}': {e.Message}"); throw new ToolingException($"failed to load template: {name} [{e.Message}]");
} }
} }

Просмотреть файл

@ -1,6 +1,6 @@
version: "3.7" version: "3.7"
services: services:
show: <project.Name>:
build: . build: .
ports: ports:
<project.Services: {svc|- "<svc.Port>:<svc.Port>"}; separator="\n"> <project.Services: {svc|- "<svc.Port>:<svc.Port>"}; separator="\n">

Просмотреть файл

@ -30,6 +30,7 @@ namespace Steeltoe.Cli.Test
"Runs project in the local Docker environment", "Runs project in the local Docker environment",
$"Usage: {Program.Name} run [options]", $"Usage: {Program.Name} run [options]",
"Options:", "Options:",
"-g|--generate-only Only generate configuration files (don't run in Docker)",
"-?|-h|--help Show help information", "-?|-h|--help Show help information",
"Overview:", "Overview:",
"Starts the project application and its dependencies in the local Docker environment.", "Starts the project application and its dependencies in the local Docker environment.",