Skip to content

Commit

Permalink
Merge pull request #124 from smartfog/development
Browse files Browse the repository at this point in the history
all features merging into master after 1st may 2020
  • Loading branch information
showersky authored Sep 24, 2020
2 parents e482d7a + 0baef16 commit 5f80356
Show file tree
Hide file tree
Showing 82 changed files with 15,656 additions and 122 deletions.
71 changes: 71 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ language: go
go:
- 1.13.x

before install:
- sudo docker run --rm -it -d -p 8082:8080 -p 9082:9080 -p 8000:8000 -v ~/dgraph:/dgraph fogflow/dgraph:latest
- sudo docker run --rm -it -d --name mongodb -d mongo:3.4
- sudo docker run --rm -it -d --name orion1 --link mongodb:mongodb -p 1026:1026 fiware/orion -dbhost mongodb
- docker ps -a

install:
- docker --version

Expand Down Expand Up @@ -33,11 +39,76 @@ install:
- pwd
- sh build

- sudo apt-get update
- sudo apt-get install python-pip
- pip -V
- sudo pip install --upgrade pip
- pip install Flask
- pip install requests
- pip install -U pytest
- sudo apt-get install curl
- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
- sudo apt-get install nodejs
- node -v
- npm -v
- echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list
- wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
- sudo apt-get update
- sudo apt-get install rabbitmq-server
- sudo update-rc.d rabbitmq-server defaults
- sudo service rabbitmq-server start
- sudo systemctl enable rabbitmq-server
- sudo systemctl start rabbitmq-server
- sudo rabbitmqctl add_user admin mypass
- sudo rabbitmqctl set_user_tags admin administrator
- sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
- echo "Done"

before_script:
- go get -u golang.org/x/lint/golint


script:
- cd ../
- cd discovery/
- go get
- go build
- screen -d -m ./discovery
- cd ../
- cd broker/
- go get
- go build
- screen -d -m ./broker
- cd ../
- cd master/
- go get
- go build
- screen -d -m ./master
- cd ../
- cd worker/
- go get
- go build
- screen -d -m ./worker
- cd ../
- cd designer/
- npm install
- screen -d -m node main.js
- cd ../
- cd test/UnitTest/
- screen -d -m python accumulator.py
- cd ../
- cd UnitTest/v2/
- pytest -s -v
- cd ../
- cd v1/
- pytest -s -v
- cd ../
- cd NGSI-LD/
- pytest -s -v
- cd ../
- cd persistance/
- pytest -s -v
- echo "Testing Done !"

notifications:
email: false
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Contributing to FogFlow


### sign up your contributor agreement license

If you are interested to make any contribution to FogFlow, please download the contributor license agreement listed below and send us you signed agreement via email [email protected]


[FogFlow Entity Contributor License Agreement](https://github.com/smartfog/fogflow/blob/development/FogFlow-Entity.pdf)


[FogFlow Individual Contributor License Agreement](https://github.com/smartfog/fogflow/blob/development/FogFlow-Individual.pdf)

### contribute code to FogFlow

*Before opening a pull request*, review the
[Contributing to FogFlow guide](https://fogflow.readthedocs.io/en/latest/guideline.html).


Binary file added FogFlow-Entity.pdf
Binary file not shown.
Binary file added FogFlow-Individual.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion application/operator/face-counter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def object2Element(ctxObj):
ctxElement = {}

ctxElement['entityId'] = ctxObj['entityId'];

ctxElement['attributes'] = []
if 'attributes' in ctxObj:
for key in ctxObj['attributes']:
Expand Down
1 change: 1 addition & 0 deletions application/template/NGSILD/python/build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t "python-fog-function" .
8 changes: 8 additions & 0 deletions application/template/NGSILD/python/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"command": "CONNECT_BROKER",
"brokerURL": "http://180.179.214.208:8070"
}, {
"command": "SET_OUTPUTS",
"id": "Stream.ChildFound.01",
"type": "ChildFound"
}]
10 changes: 10 additions & 0 deletions application/template/NGSILD/python/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:2.7-alpine

RUN mkdir /task
ADD main.py /task
ADD requirements.txt /task
WORKDIR /task

RUN pip install -r requirements.txt

CMD ["python", "./main.py"]
206 changes: 206 additions & 0 deletions application/template/NGSILD/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
from flask import Flask, jsonify, abort, request, make_response
import requests
import json
import time
import datetime
import threading
import os

app = Flask(__name__, static_url_path='')

# global variables

brokerURL = ''
outputs = []
timer = None
lock = threading.Lock()
counter = 0
create = 0


@app.errorhandler(400)
def not_found(error):
return make_response(jsonify({'error': 'Bad request'}), 400)


@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)


@app.route('/admin', methods=['POST'])
def admin():
if not request.json:
abort(400)

configObjs = request.json
handleConfig(configObjs)

return jsonify({'responseCode': 200})


@app.route('/notifyContext', methods=['POST'])
def notifyContext():
print '=============notify============='
if not request.json:
abort(400)

objs = readContextElements(request.json)
global counter
counter = counter + 1

print objs

handleNotify(objs)

return jsonify({'responseCode': 200})


def element2Object(element):
ctxObj = {}
for key in element:
ctxObj[key] = element[key]
return ctxObj


def object2Element(ctxObj):
ctxElement = {}

for key in ctxObj:
ctxElement[key] = ctxObj[key]
return ctxElement


def readContextElements(data):

ctxObjects = []

for response in data['contextResponses']:
if response['statusCode']['code'] == 200:
ctxObj = element2Object(response['contextElement'])
ctxObjects.append(ctxObj)
return ctxObjects


def handleNotify(contextObjs):
for ctxObj in contextObjs:
processInputStreamData(ctxObj)


def processInputStreamData(obj):
print '===============receive context entity===================='
print obj

global counter
counter = counter + 1


def handleConfig(configurations):
global brokerURL
global num_of_outputs
for config in configurations:
if config['command'] == 'CONNECT_BROKER':
brokerURL = config['brokerURL']
if config['command'] == 'SET_OUTPUTS':
outputs.append({'id': config['id'], 'type': config['type']})


def handleTimer():
global timer

# publish the counting result

entity = {}
entity['id'] = 'urn:ngsi-ld:result.01'
entity['type'] = 'Result'
entity['counter'] = counter

publishResult(entity)
timer = threading.Timer(10, handleTimer)
timer.start()


# update request on broker

def update(resultCtxObj):
global brokerURL
if brokerURL.endswith('/ngsi10') == True:
brokerURL = brokerURL.rsplit('/', 1)[0]
if brokerURL == '':
return

ctxElement = object2Element(resultCtxObj)

id = ctxElement['id']
ctxElement.pop('id')
ctxElement.pop('type')
headers = {'Accept': 'application/ld+json',
'Content-Type': 'application/ld+json'}
response = requests.patch(brokerURL + '/ngsi-ld/v1/entities/' + id
+ '/attrs', data=json.dumps(ctxElement),
headers=headers)
return response.status_code


def sendDataToBroker(resultCtxObj):
global create
if create == 0:
response = cretaeRequest(resultCtxObj)
if response != 201:
print 'failed to send the create request'
else:
print 'Entity already has been created trying for update request....'
response = update(resultCtxObj)
if response != 204:
print 'failed to send the updte request'


def publishResult(result):
resultCtxObj = {}
resultCtxObj['id'] = result['id']
resultCtxObj['type'] = result['type']
data = {}
data['type'] = 'Property'
data['value'] = result['counter']
resultCtxObj['count'] = data
sendDataToBroker(resultCtxObj)


# create request on broker

def cretaeRequest(ctxObj):
global brokerURL
global create
if brokerURL.endswith('/ngsi10') == True:
brokerURL = brokerURL.rsplit('/', 1)[0]
if brokerURL == '':
return

ctxElement = object2Element(ctxObj)

headers = {'Accept': 'application/ld+json',
'Content-Type': 'application/ld+json',
'Link': '<{{link}}>; rel="https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"; type="application/ld+json"'}
response = requests.post(brokerURL + '/ngsi-ld/v1/entities/',
data=json.dumps(ctxElement),
headers=headers)
if response.status_code == 201:
create = create + 1
if response.status_code != 201:
create = 1
return response.status_code


if __name__ == '__main__':
handleTimer()

myport = int(os.environ['myport'])

myCfg = os.environ['adminCfg']
adminCfg = json.loads(myCfg)
handleConfig(adminCfg)

app.run(host='0.0.0.0', port=myport)

# timer.cancel()

2 changes: 2 additions & 0 deletions application/template/NGSILD/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==1.0.2
requests>=2.20.0
10 changes: 10 additions & 0 deletions application/template/NGSILD/python/subscription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"entities": [
{
"type": "Camera",
"isPattern": false,
"id": "Stream.Camera.02"
}
],
"reference": "http://192.168.1.102:36772"
}
10 changes: 10 additions & 0 deletions application/template/NGSILD/python/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#start a container for test
#docker run -p 8009:8080 -t -i facefinder /bin/bash

#configurate
curl -X POST "http://192.168.1.80:8009/admin" -d @config.json --header "Content-Type:application/json" --header "Accept:application/json"

#issue a subscription to get the input data
curl -X POST "http://192.168.1.80:8091/ngsi10/subscribeContext" -d @subscriptionCamera.json --header "Content-Type:application/json" --header "Accept:application/json"
curl -X POST "http://192.168.1.80:8091/ngsi10/subscribeContext" -d @subscriptionChildLost.json --header "Content-Type:application/json" --header "Accept:application/json"

2 changes: 1 addition & 1 deletion broker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM scratch
FROM alpine
ADD broker /
CMD ["/broker"]

Loading

0 comments on commit 5f80356

Please sign in to comment.