Skip to content

Commit 737fd51

Browse files
Ticket #2 : Can call the operation /clients
1 parent 1d201a5 commit 737fd51

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

FaasNetDoc.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Avant de commencer, lancer le container "registry" :
22
docker run -d -p 5000:5000 --restart=always --name registry registry:2
33

4+
# Comment déployer SQLSERVER
5+
6+
kubectl apply -f ./kubernetes/run-mssql.yml --namespace=faas
7+
kubectl apply -f ./kubernetes/mssql-external-svc.yml --namespace=faas
8+
kubectl apply -f ./kubernetes/mssql-internal-svc.yml --namespace=faas
9+
10+
Il est possible ensuite de se connecter à la BDD avec : 127.0.0.1, 30002
11+
412
# Construire l'image du runtime
513

614
Construire l'image et la nommer "localhost:5000/getsql" && "localhost:5000/transform" :

kubernetes/mssql-external-svc.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: mssql-service
5+
spec:
6+
type: NodePort
7+
selector:
8+
app: mssql
9+
ports:
10+
- port: 1433
11+
protocol: TCP
12+
targetPort: 1433
13+
nodePort: 30002

kubernetes/mssql-internal-svc.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: mssql-entry
5+
spec:
6+
type: ClusterIP
7+
selector:
8+
app: mssql
9+
ports:
10+
- port: 1433
11+
protocol: TCP
12+
targetPort: 1433

kubernetes/run-mssql.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: mssql-deployment
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: mssql
10+
strategy:
11+
type: Recreate
12+
template:
13+
metadata:
14+
labels:
15+
app: mssql
16+
spec:
17+
terminationGracePeriodSeconds: 10
18+
securityContext:
19+
fsGroup: 1000
20+
containers:
21+
- name: mssql
22+
image: mcr.microsoft.com/mssql/server
23+
env:
24+
- name: ACCEPT_EULA
25+
value: "Y"
26+
- name: SA_PASSWORD
27+
value: "D54DE7hHpkG9"

src/FaasNet.Gateway.Startup/DefaultConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class DefaultConfiguration
2121
new ApiDefinitionFunction
2222
{
2323
Function = "getsql",
24-
SerializedConfiguration = "{\r\n \"ConnectionString\": \"Data Source=DESKTOP-F641MIJ\\\\SQLEXPRESS;Initial Catalog=OpenID;Integrated Security=True\",\r\n \"SqlQuery\": \"SELECT * FROM [dbo].[Acrs]\"\r\n}"
24+
SerializedConfiguration = "{\r\n \"ConnectionString\": \"Data Source=mssql-entry.faas.svc.cluster.local;Initial Catalog=OpenID;User ID=sa;Password=D54DE7hHpkG9\",\r\n \"SqlQuery\": \"SELECT * FROM [dbo].[Acrs]\"\r\n}"
2525
},
2626
new ApiDefinitionFunction
2727
{
2828
Function = "transform",
29-
SerializedConfiguration = "{ \"mappings\": [ { \"input\": \"content.name\", \"output\": \"name\" } ] }"
29+
SerializedConfiguration = "{ \"mappings\": [ { \"input\": \"content[*].Name\", \"output\": \"name\" } ] }"
3030
}
3131
},
3232
SequenceFlows = new List<ApiDefinitionSequenceFlow>

src/FaasNet.Runtime.Transform/FunctionHandler.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FaasNet.Runtime.Parameters;
22
using Newtonsoft.Json.Linq;
3+
using System.Linq;
34
using System.Threading.Tasks;
45

56
namespace FaasNet.Runtime.Transform
@@ -11,12 +12,18 @@ public Task<JObject> Handle(FunctionParameter<TransformConfiguration> parameter)
1112
var result = new JObject();
1213
foreach(var mapping in parameter.Configuration.Mappings)
1314
{
14-
var token = parameter.Input.SelectToken(mapping.Input);
15-
if (token != null)
15+
var tokens = parameter.Input.SelectTokens(mapping.Input);
16+
if (tokens.Count() == 1)
1617
{
17-
result.Add(mapping.Output, token);
18+
result.Add(mapping.Output, tokens.First());
19+
}
20+
else if (tokens.Count() > 1)
21+
{
22+
var jArr = new JArray(tokens);
23+
result.Add(mapping.Output, jArr);
1824
}
1925
}
26+
2027
return Task.FromResult(result);
2128
}
2229
}

0 commit comments

Comments
 (0)