-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket #9 : Deploy & execute a function
- Loading branch information
Showing
46 changed files
with
1,148 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using FaasNet.CLI.Helpers; | ||
using System.Collections.Generic; | ||
|
||
namespace FaasNet.CLI.Commands | ||
{ | ||
public class ConfigurationCommand : IMenuItemCommand | ||
{ | ||
private List<IMenuItemCommand> _commands = new List<IMenuItemCommand> | ||
{ | ||
new ConfigurationUpdateCommand(), | ||
new ConfigurationGetCommand() | ||
}; | ||
|
||
public string Command => "configuration"; | ||
public string Description => "Manage configuration"; | ||
|
||
public void Execute(IEnumerable<string> args) | ||
{ | ||
MenuHelper.Execute(args, _commands); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using FaasNet.CLI.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FaasNet.CLI.Commands | ||
{ | ||
public class ConfigurationGetCommand : IMenuItemCommand | ||
{ | ||
public string Command => "-get"; | ||
public string Description => "Get the configuration"; | ||
|
||
public void Execute(IEnumerable<string> args) | ||
{ | ||
if (!args.Any()) | ||
{ | ||
Console.WriteLine("A Property with its value must be specified"); | ||
return; | ||
} | ||
|
||
var configuration = ConfigurationHelper.GetConfiguration(); | ||
if (configuration == null) | ||
{ | ||
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist"); | ||
return; | ||
} | ||
|
||
var key = args.First(); | ||
if (!ConfigurationHelper.HasKey(key)) | ||
{ | ||
Console.WriteLine($"The key '{key}' cannot be configured"); | ||
return; | ||
} | ||
|
||
if(key == ConfigurationHelper.GatewayKey) | ||
{ | ||
Console.WriteLine($"{key}={configuration.Provider.Gateway}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using FaasNet.CLI.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FaasNet.CLI.Commands | ||
{ | ||
public class ConfigurationUpdateCommand : IMenuItemCommand | ||
{ | ||
public string Command => "-set"; | ||
public string Description => "Update the configuration"; | ||
|
||
public void Execute(IEnumerable<string> args) | ||
{ | ||
if (!args.Any()) | ||
{ | ||
Console.WriteLine("A Property with its value must be specified"); | ||
return; | ||
} | ||
|
||
var splitted = args.First().Split('='); | ||
if (splitted.Count() != 2) | ||
{ | ||
Console.WriteLine("The argument is not correct, it must respect the format Key=Value"); | ||
return; | ||
} | ||
|
||
var configuration = ConfigurationHelper.GetConfiguration(); | ||
if (configuration == null) | ||
{ | ||
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist"); | ||
return; | ||
} | ||
|
||
var key = splitted.First(); | ||
var value = splitted.Last(); | ||
if (!ConfigurationHelper.HasKey(key)) | ||
{ | ||
Console.WriteLine($"The key '{key}' cannot be configured"); | ||
return; | ||
} | ||
|
||
if (key == ConfigurationHelper.GatewayKey) | ||
{ | ||
configuration.Provider.Gateway = value; | ||
} | ||
|
||
ConfigurationHelper.UpdateConfiguration(configuration); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using FaasNet.CLI.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FaasNet.CLI.Commands | ||
{ | ||
public class FunctionConfigurationCommand : IMenuItemCommand | ||
{ | ||
public string Command => "configuration"; | ||
public string Description => "Invoke a function"; | ||
|
||
public void Execute(IEnumerable<string> args) | ||
{ | ||
if (!args.Any()) | ||
{ | ||
Console.WriteLine("The name must be specified"); | ||
return; | ||
} | ||
|
||
var configuration = ConfigurationHelper.GetConfiguration(); | ||
if (configuration == null) | ||
{ | ||
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist"); | ||
return; | ||
} | ||
|
||
var name = args.First(); | ||
var gatewayClient = new GatewayClient(); | ||
var jObj = gatewayClient.GetConfiguration(configuration.Provider.Gateway, name); | ||
Console.WriteLine(jObj.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using FaasNet.CLI.Helpers; | ||
using FaasNet.CLI.Parameters; | ||
using FaasNet.Common.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FaasNet.CLI.Commands | ||
{ | ||
public class FunctionDeployCommand : IMenuItemCommand | ||
{ | ||
public string Command => "deploy"; | ||
public string Description => "Deploy the function into a local or remote Gateway"; | ||
|
||
public void Execute(IEnumerable<string> args) | ||
{ | ||
if (!args.Any() || args.Count() != 4) | ||
{ | ||
Console.WriteLine("The -name and -image must be specified"); | ||
return; | ||
} | ||
|
||
var configuration = ConfigurationHelper.GetConfiguration(); | ||
if (configuration == null) | ||
{ | ||
Console.WriteLine($"The configuration file '{ConfigurationHelper.ConfigurationFileName}' doesn't exist"); | ||
return; | ||
} | ||
|
||
string errorMessage; | ||
DeployFunctionParameter parameter; | ||
if (!InputParameterParser.TryParse(args, out errorMessage, out parameter)) | ||
{ | ||
Console.WriteLine(errorMessage); | ||
return; | ||
} | ||
|
||
var client = new GatewayClient(); | ||
client.PublishFunction(configuration.Provider.Gateway, parameter.Name, parameter.Image); | ||
configuration.Functions.Add(new FaasFunctionConfiguration | ||
{ | ||
Image = parameter.Image, | ||
Name = parameter.Name | ||
}); | ||
ConfigurationHelper.UpdateConfiguration(configuration); | ||
Console.WriteLine($"The function '{parameter.Name}' is published"); | ||
} | ||
} | ||
} |
Oops, something went wrong.