Skip to content

Commit 635bd91

Browse files
committed
updated service description
1 parent d69e528 commit 635bd91

10 files changed

Lines changed: 361 additions & 210 deletions

File tree

cli/src/create-service.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DataFactory } from "rdf-data-factory";
33
import { Writer } from "n3";
44
import { config, updateConfig } from "./config.js";
55
import { AggregatorConfig } from "./config.template.js";
6+
import { format } from "path";
67

78
const df = new DataFactory();
89

@@ -62,37 +63,36 @@ async function parseServiceRequest(
6263
tf: string,
6364
params: Record<string, string>
6465
): Promise<string> {
65-
6666
const writer = new Writer({
67+
format: "turtle",
6768
prefixes: {
6869
trans: `${config.server.host}${config.server.tf}#`,
6970
fno: "https://w3id.org/function/ontology#",
71+
fnoc: "https://w3id.org/function/vocabulary/composition#",
7072
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
7173
xsd: "http://www.w3.org/2001/XMLSchema#",
74+
agg: "https://spec.knows.idlab.ugent.be/aggregator-protocol/latest/#"
7275
}
7376
});
7477

75-
const execution = df.namedNode(`${agg.id}/${name}`);
78+
const service = df.namedNode(`${agg.id}/${name}`);
79+
const fnoc = (local: string) => df.namedNode(`https://w3id.org/function/vocabulary/composition#${local}`);
80+
const aggNs = (local: string) => df.namedNode(`https://spec.knows.idlab.ugent.be/aggregator-protocol/latest/#${local}`);
7681

77-
writer.addQuad(
78-
execution,
79-
df.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
80-
df.namedNode("https://w3id.org/function/ontology#Execution")
82+
const paramBindings = Object.entries(params).map(([key, value]) =>
83+
writer.blank([
84+
{ predicate: fnoc("boundToTerm"), object: df.literal(value) },
85+
{ predicate: fnoc("boundParameter"), object: df.namedNode(`${config.server.host}${config.server.tf}#${key}`) },
86+
])
8187
);
8288

83-
writer.addQuad(
84-
execution,
85-
df.namedNode("https://w3id.org/function/ontology#executes"),
86-
df.namedNode(`${config.server.host}${config.server.tf}#${tf}`)
87-
);
89+
const application = writer.blank([
90+
{ predicate: fnoc("applies"), object: df.namedNode(`${config.server.host}${config.server.tf}#${tf}`) },
91+
...paramBindings.map(binding => ({ predicate: fnoc("parameterBinding"), object: binding })),
92+
]);
8893

89-
for (const [key, value] of Object.entries(params)) {
90-
writer.addQuad(
91-
execution,
92-
df.namedNode(`${config.server.host}${config.server.tf}#${key}`),
93-
df.literal(value)
94-
);
95-
}
94+
writer.addQuad(service, df.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), aggNs("Service"));
95+
writer.addQuad(service, aggNs("applies"), application);
9696

9797
return new Promise((resolve, reject) => {
9898
writer.end((error, result) => {

containers/aggregator/config/service_collection.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (collec *ServiceCollection) getServices(w http.ResponseWriter, _ *http.Requ
8989

9090
serviceList := []string{}
9191
for _, service := range collec.services {
92-
serviceList = append(serviceList, service.URI)
92+
serviceList = append(serviceList, service.FullPath)
9393
}
9494

9595
response := map[string][]string{
@@ -137,7 +137,7 @@ func generateServiceETag(repr []byte) string {
137137
func (collec *ServiceCollection) headService(w http.ResponseWriter, _ *http.Request, service model.Service) {
138138
logrus.WithFields(logrus.Fields{"service_id": service.InstanceID}).Debug("Request HEAD for service")
139139

140-
repr, err := service.FnORepresentation()
140+
repr, err := service.Description.FnORepresentation()
141141
if err != nil {
142142
logrus.WithError(err).Error("Failed to generate service FnO representation")
143143
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -154,7 +154,7 @@ func (collec *ServiceCollection) headService(w http.ResponseWriter, _ *http.Requ
154154
func (collec *ServiceCollection) getService(w http.ResponseWriter, _ *http.Request, service model.Service) {
155155
logrus.WithFields(logrus.Fields{"service_id": service.InstanceID}).Info("Request GET for service")
156156

157-
repr, err := service.FnORepresentation()
157+
repr, err := service.Description.FnORepresentation()
158158
if err != nil {
159159
logrus.WithError(err).Error("Failed to generate service FnO representation")
160160
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -199,7 +199,7 @@ func (collec *ServiceCollection) postService(w http.ResponseWriter, r *http.Requ
199199
}
200200

201201
// Extraxt service Path and Id
202-
servicePath, serviceId, err := services.ValidServiceUri(service.URI)
202+
aggPath, serviceId, err := services.ValidServicePath(service.FullPath)
203203
if err != nil {
204204
http.Error(w, fmt.Sprintf("Invalid execution URI: %v", err), http.StatusBadRequest)
205205
return
@@ -214,13 +214,9 @@ func (collec *ServiceCollection) postService(w http.ResponseWriter, r *http.Requ
214214
}
215215
collec.servicesMu.Unlock()
216216

217-
service.Path = servicePath
217+
service.AggPath = aggPath
218218
service.InstanceID = serviceId
219219
service.NamespaceID = serviceId + "-" + model.ID
220-
service.Outputs = make(map[string]string)
221-
for pred := range service.Application.Transformation.OutputMapping {
222-
service.Outputs[pred] = service.Application.Transformation.Base + pred
223-
}
224220

225221
// Create service
226222
err = services.DeployAggregatorService(service)
@@ -244,7 +240,7 @@ func (collec *ServiceCollection) postService(w http.ResponseWriter, r *http.Requ
244240
collec.servicesMu.Unlock()
245241

246242
// Create service endpoint
247-
err = collec.HandleFunc(servicePath, collec.HandleServiceEndpoint, []model.Scope{model.Read, model.Delete})
243+
err = collec.HandleFunc(aggPath, collec.HandleServiceEndpoint, []model.Scope{model.Read, model.Delete})
248244
if err != nil {
249245
logrus.WithError(err).Errorf("Error registering handler for service %s", serviceId)
250246
http.Error(w, "Failed to create service from request", http.StatusInternalServerError)
@@ -253,7 +249,7 @@ func (collec *ServiceCollection) postService(w http.ResponseWriter, r *http.Requ
253249

254250
// Create output endpoints
255251
for pred := range service.Application.Transformation.OutputMapping {
256-
path := servicePath + "/" + pred
252+
path := aggPath + "/" + pred
257253
predUri := service.Application.Transformation.Base + pred
258254
outputUri, exists := service.Application.Transformation.Predicates[predUri]
259255
if !exists {
@@ -273,7 +269,8 @@ func (collec *ServiceCollection) postService(w http.ResponseWriter, r *http.Requ
273269
// Return service information
274270
w.Header().Set("Content-Type", "text/turtle")
275271

276-
repr, err := service.FnORepresentation()
272+
service.InitDescription()
273+
repr, err := service.Description.FnORepresentation()
277274
if err != nil {
278275
logrus.WithError(err).Error("Failed to generate service FnO representation")
279276
http.Error(w, "Failed to serialize response", http.StatusInternalServerError)

containers/aggregator/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.0
55
toolchain go1.23.8
66

77
require (
8-
github.com/google/uuid v1.6.0 // indirect
8+
github.com/google/uuid v1.6.0
99
github.com/sirupsen/logrus v1.9.3
1010
golang.org/x/net v0.38.0 // indirect
1111
k8s.io/api v0.32.3

0 commit comments

Comments
 (0)