Skip to content

Commit

Permalink
Reverted populating FogFlow for the tutorial
Browse files Browse the repository at this point in the history
Multiarch build
  • Loading branch information
Flavio Cirillo committed Jun 14, 2024
1 parent bf9f5af commit f776aa1
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 93 deletions.
5 changes: 5 additions & 0 deletions broker/Dockerfile_multiarch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine
ARG TARGETOS
ARG TARGETARCH
ADD /${TARGETOS}/${TARGETARCH}/broker /
CMD ["/broker"]
1 change: 1 addition & 0 deletions broker/build_k8s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker buildx build --platform linux/arm,linux/arm64,linux/amd64 --push -f ./Dockerfile_multiarch -t "fogflow/broker:k8s" .
1 change: 1 addition & 0 deletions designer/build_k8s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker image tag fogflow/designer:latest fogflow/designer:k8s
3 changes: 2 additions & 1 deletion designer/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"designer": {
"webSrvPort": 8080,
"agentPort": 1030
"agentPort": 1030,
"notRecreateSubscriptions": false
},
"rabbitmq": {
"port": 5672,
Expand Down
120 changes: 96 additions & 24 deletions designer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ if (!('host_ip' in globalConfigFile.broker)) {
var cloudBrokerURL = "http://" + globalConfigFile.broker.host_ip + ":" + globalConfigFile.broker.http_port
var ngsi10client = new NGSIClient.NGSI10Client(cloudBrokerURL + "/ngsi10");

config.notRecreateSubscriptions = globalConfigFile.designer.notRecreateSubscriptions;

var recheck_interval = 2000;
var timerID = setTimeout(function entityrestore(){
var url = cloudBrokerURL + "/version";
Expand All @@ -81,29 +83,58 @@ var timerID = setTimeout(function entityrestore(){
});
});

// create the persistent subscriptions at the FogFlow Cloud Broker
Object.values(db.data.subscriptions).forEach(subscription => {
var headers = {};

if (subscription.destination_broker == 'NGSI-LD') {
headers["Content-Type"] = "application/json";
headers["Destination"] = "NGSI-LD";
headers["NGSILD-Tenant"] = subscription.tenant;
} else if (subscription.destination_broker == 'NGSIv2') {
headers["Content-Type"] = "application/json";
headers["Destination"] = "NGSIv2";
}

var subscribeCtxReq = {};
subscribeCtxReq.entities = [{ type: subscription['entity_type'], isPattern: true }];
subscribeCtxReq.reference = subscription['reference_url'];
ngsi10client.subscribeContextWithHeaders(subscribeCtxReq, headers).then(function (subscriptionId) {
console.log("new subscription id = ", subscriptionId);
console.log(subscription)
}).catch(function (error) {
console.log('failed to subscribe context, ', error);
});
});

if (!config.notRecreateSubscriptions){

fetch(cloudBrokerURL + "/ngsi10/subscription").
then((response) => response.json()).
then(brokerSubscriptions => {

Object.keys(db.data.subscriptions).
forEach(key => {
console.log("checking if the following subscription is already in the broker: ",key)
if(brokerSubscriptions.hasOwnProperty(key)) {
//delete designerSubscriptions[key];
console.log("subscription already in the broker:", key)
} else {

var subscription = db.data.subscriptions[key]

var headers = {};

if (subscription.destination_broker == 'NGSI-LD') {
headers["Content-Type"] = "application/json";
headers["Destination"] = "NGSI-LD";
headers["NGSILD-Tenant"] = subscription.tenant;
} else if (subscription.destination_broker == 'NGSIv2') {
headers["Content-Type"] = "application/json";
headers["Destination"] = "NGSIv2";
}

var subscribeCtxReq = {};
subscribeCtxReq.entities = [{ type: subscription['entity_type'], isPattern: true }];
subscribeCtxReq.reference = subscription['reference_url'];
// it is necessary to send them out not at the same time for having different subID
// since the subID is based on timestamp
var delayBeforeSend = Math.floor(Math.random() * 1000)
setTimeout(function(){
//console.log("waited", delayBeforeSend);
ngsi10client.subscribeContextWithHeaders(subscribeCtxReq, headers).then(function (subscriptionId) {
console.log("new subscription id = ", subscriptionId);
console.log(subscription)
delete db.data.subscriptions[key];
db.data.subscriptions[subscriptionId] = subscription
db.write();
}).catch(function (error) {
console.log('failed to subscribe context, ', error);
});
}, delayBeforeSend);
}
});
})
} else {
console.log("not recreating subscriptions ", config.notRecreateSubscriptions);
}

}).catch(error=>{
console.log("try it again due to the error: ", error.code);
Expand Down Expand Up @@ -420,6 +451,39 @@ app.post('/operator', jsonParser, async function (req, res) {
res.sendStatus(200)
});

app.get('/dockerimage', async function (req, res) {
var operators = db.data.operators;
var dockers = {}
for (const [key, value] of Object.entries(operators)) {
if (value.hasOwnProperty('dockerimages') && value.dockerimages.length > 0){
dockers.key = value
}
}
res.json(dockers);

});

app.post('/dockerimage', jsonParser, async function (req, res) {
var dockerimages = req.body;
for (var i = 0; i < dockerimages.length; i++) {
var dockerimage = dockerimages[i];
var operatorName = dockerimage.operatorName

if (operatorName in db.data.operators) {
if (db.data.operators[operatorName].hasOwnProperty('dockerimages')){
db.data.operators[operatorName].dockerimages.push(dockerimage)
} else {
db.data.operators[operatorName].dockerimages = []
db.data.operators[operatorName].dockerimages.push(dockerimage)
}
}
}

await db.write();

res.sendStatus(200)
});

app.get('/dockerimage/:operator', async function (req, res) {
var operatorName = req.params.operator;
var operator = db.data.operators[operatorName];
Expand All @@ -430,8 +494,16 @@ app.post('/dockerimage/:operator', jsonParser, async function (req, res) {
var operatorName = req.params.operator;
var dockerimage = req.body;

console.log(operatorName in db.data.operators)
console.log(db.data.operators[operatorName])

if (operatorName in db.data.operators) {
db.data.operators[operatorName].dockerimages.push(dockerimage)
if (db.data.operators[operatorName].hasOwnProperty('dockerimages')){
db.data.operators[operatorName].dockerimages.push(dockerimage)
} else {
db.data.operators[operatorName].dockerimages = []
db.data.operators[operatorName].dockerimages.push(dockerimage)
}
}

await db.write();
Expand Down
2 changes: 1 addition & 1 deletion designer/public/js/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $(function() {
addMenuItem('FogFunction', 'Fog Function', showFogFunctions);
//addMenuItem('TaskInstance', 'Task Instance', showTaskInstances);

//initFogFunctionExamples();
initFogFunctionExamples();
showFogFunctions();

queryOperatorList();
Expand Down
33 changes: 22 additions & 11 deletions designer/public/js/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,58 @@ function defaultOperatorList(){
var operatorList = [{
name: "nodejs",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "python",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "iotagent",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "counter",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "anomaly",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "facefinder",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "connectedcar",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "recommender",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "privatesite",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "publicsite",
description: "",
parameters: []
parameters: [],
dockerimages: []
}, {
name: "dummy",
description: "",
parameters: []
parameters: [],
dockerimages: []
}];

return operatorList;
Expand Down
54 changes: 31 additions & 23 deletions designer/public/js/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ $(function() {
var handlers = {};

addMenuItem('Operator', 'Operator', showOperator);

initOperatorList();
initDockerImageList();

showOperator();

//initOperatorList();
//initDockerImageList();

$(window).on('hashchange', function() {
var hash = window.location.hash;
Expand Down Expand Up @@ -51,6 +51,7 @@ $(function() {
}

function initOperatorList(){
console.log("let's initialize the operator list")
fetch('/operator').then(res => res.json()).then(opList => {
if (Object.keys(opList).length === 0) {
var operators = defaultOperatorList();
Expand All @@ -73,6 +74,27 @@ $(function() {
})
}

function initDockerImageList(){
console.log("Initialize docker images list")
fetch('/dockerimage').then(res => res.json()).then(imageList => {
if (Object.keys(imageList).length === 0) {
var images = defaultDockerImageList();
fetch("/dockerimage", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(images)
})
.then(response => {
console.log("send the initial list of docker images: ", response.status)
})
.catch(err => console.log(err));
}
})
}

function queryOperatorList() {
fetch('/operator').then(res => res.json()).then(operators => {
Object.values(operators).forEach(operator => {
Expand Down Expand Up @@ -109,7 +131,11 @@ $(function() {
html += '<td>' + operator.description + '</td>';

html += '<td>';
html += operator.dockerimages.length;
if(operator.hasOwnProperty('dockerimages')){
html += operator.dockerimages.length;
} else {
html += 0;
}
html += '</td>';

if ('parameters' in operator) {
Expand Down Expand Up @@ -498,25 +524,7 @@ $(function() {
//// });
// }

// function initDockerImageList(){
// fetch('/dockerimage').then(res => res.json()).then(imageList => {
// if (Object.keys(imageList).length === 0) {
// var images = defaultDockerImageList();
// fetch("/dockerimage", {
// method: "POST",
// headers: {
// Accept: "application/json",
// "Content-Type": "application/json"
// },
// body: JSON.stringify(images)
// })
// .then(response => {
// console.log("send the initial list of docker images: ", response.status)
// })
// .catch(err => console.log(err));
// }
// })
// }


// function dockerImageRegistration() {
// $('#info').html('New docker image registration');
Expand Down
2 changes: 1 addition & 1 deletion designer/public/js/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ $(function() {
addMenuItem('Topology', 'Service Topology', showTopologies);
addMenuItem('Intent', 'Service Intent', showIntents);

//initTopologyExamples();
initTopologyExamples();
showTopologies();

queryOperatorList();
Expand Down
1 change: 1 addition & 0 deletions discovery/build_k8s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker image tag fogflow/discovery:latest fogflow/discovery:k8s
1 change: 1 addition & 0 deletions master/build_k8s
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker image tag fogflow/master:latest fogflow/master:k8s
1 change: 0 additions & 1 deletion master/config.json

This file was deleted.

4 changes: 2 additions & 2 deletions release/latest/cloud/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"my_hostip": "172.17.0.1",
"my_hostip": "10.1.99.17",
"physical_location":{
"longitude": 139,
"latitude": 35
Expand All @@ -13,7 +13,7 @@
},
"discovery": {
"http_port": 8090,
"storeOnDisk": false,
"storeOnDisk": true,
"delayStoreOnFile" : 3
},
"broker": {
Expand Down
Loading

0 comments on commit f776aa1

Please sign in to comment.