Skip to content

Commit

Permalink
Merge pull request #183 from fisuda/improve/regproxy
Browse files Browse the repository at this point in the history
Refactor regproxy and update regproxy example
  • Loading branch information
fisuda committed Jul 22, 2021
2 parents 1e7928d + 09f4c1f commit 334f022
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 156 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NGSI Go v0.8.4-next

- Improve: Refactor regproxy and update regproxy example (#183)
- Improve: Add server, health and config sub-cmd to regproxy cmd (#182)
- Improve: Refactor token manager (#181)
- Improve: Set default FIWARE Service Path to "/" in cp command (#180)
Expand Down
15 changes: 9 additions & 6 deletions extras/registration_proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

FROM alpine:3.14 AS builder
FROM golang:1.16.0-alpine3.13 AS builder

RUN \
cd / && \
apk update && \
apk add --no-cache tar curl && \
curl -OL https://github.com/lets-fiware/ngsi-go/releases/download/v0.8.4/ngsi-v0.8.4-linux-amd64.tar.gz && \
tar zxvf ngsi-v0.8.4-linux-amd64.tar.gz -C /usr/local/bin
apk add --no-cache git make && \
git clone https://github.com/lets-fiware/ngsi-go.git && \
cd /ngsi-go && \
make bin/ngsi


FROM alpine:3.14 AS runner

COPY --from=builder /usr/local/bin/ngsi /usr/local/bin/ngsi
COPY --from=builder /ngsi-go/bin/ngsi /usr/local/bin/ngsi
COPY ./ngsi-go-config.json /opt/ngsi-go/ngsi-go-config.json

WORKDIR /opt/ngsi-go/
Expand All @@ -44,4 +47,4 @@ RUN chown -R nobody:nobody /opt/ngsi-go
USER nobody

ENTRYPOINT ["/usr/local/bin/ngsi"]
CMD ["--stderr", "info", "--config", "./ngsi-go-config.json", "--cache", "ngsi-go-token-cache.json", "regproxy", "--host", "remote-orion", "--verbose"]
CMD ["--stderr", "info", "--config", "./ngsi-go-config.json", "--cache", "./ngsi-go-token-cache.json", "regproxy", "server", "--host", "remote-orion", "--verbose"]
106 changes: 84 additions & 22 deletions extras/registration_proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ ngsi --config ngsi-go-config.json \
broker add \
--host remote-orion \
--ngsiType v2 \
--brokerHost https://remote-orion.letsfiware.jp/ \
--brokerHost http://remote-orion:1026 \
--idmType keyrock \
--idmHost https://keyrock/oauth2/token \
--username keyrock001@letsfiware.jp \
--password 0123456789 \
--clientId 00000000-1111-2222-3333-444444444444 \
--clientSecret 55555555-6666-7777-8888-999999999999
```

```
ngsi --config ngsi-go-config.json version --host remote-orion
--idmHost http://keyrock:3000/oauth2/token \
--username admin@test.com \
--password 1234 \
--clientId a1a6048b-df1d-4d4f-9a08-5cf836041d14 \
--clientSecret e4cc0147-e38f-4211-b8ad-8ae5e6a107f9
```

## Start up local broker
Expand All @@ -52,33 +48,75 @@ docker-compose ps
```
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------
registration_proxy_mongo_1 docker-entrypoint.sh --noj ... Up 27017/tcp
registration_proxy_orion_1 /usr/bin/contextBroker -fg ... Up 0.0.0.0:1026->1026/tcp,:::1026->1026/tcp
registration_proxy_regproxy_1 /usr/local/bin/ngsi --conf ... Up 0.0.0.0:1028->1028/tcp,:::1028->1028/tcp
registration_proxy_keyrock_1 /nodejs/bin/node ./bin/www Up (healthy) 0.0.0.0:3000->3000/tcp,:::3000->3000/tcp
registration_proxy_local-mongo_1 docker-entrypoint.sh --noj ... Up 27017/tcp
registration_proxy_local-orion_1 /usr/bin/contextBroker -fg ... Up 0.0.0.0:1026->1026/tcp,:::1026->1026/tcp
registration_proxy_mysql_1 docker-entrypoint.sh mysqld Up 3306/tcp, 33060/tcp
registration_proxy_orion-proxy_1 /nodejs/bin/node ./bin/www Up (unhealthy) 0.0.0.0:1027->1026/tcp,:::1027->1026/tcp, 1027/tcp
registration_proxy_regproxy_1 /usr/local/bin/ngsi --stde ... Up 0.0.0.0:1028->1028/tcp,:::1028->1028/tcp
registration_proxy_remote-mongo_1 docker-entrypoint.sh --noj ... Up 27017/tcp
registration_proxy_remote-orion_1 /usr/bin/contextBroker -fg ... Up 1026/tcp
```

## Add regproxy server

```
ngsi server add --host regproxy \
--serverType regproxy \
--serverHost http://localhost:1028
```

This following command is a regproxy sanity check.
The following command is a regproxy sanity check.

```
curl -sS http://localhost:1028/health
ngsi regproxy health --host regproxy --pretty
```

```
{
"ngsi-go": {
"version": "0.8.4 (git_hash:35ee7560911b403029880242789039f2532c817b)",
"csource": "https://remote-orion.letsfiware.jp/"
}
"ngsi-go": "regproxy",
"version": "0.8.4-next (git_hash:a86aaf88f0f9d08f8d5388f9e5e83b6ebb90e7f7)",
"health": "OK",
"csource": "http://remote-orion:1026",
"verbose": true,
"uptime": "0 d, 0 h, 0 m, 1 s",
"timesent": 0,
"success": 0,
"failure": 0
}
```

## Add registration
## Add a remote orion

Create a registration in a local broker.
```
ngsi broker add --host remote-orion \
--ngsiType v2 \
--brokerHost http://localhost:1027/ \
--idmType keyrock \
--idmHost http://localhost:3000/oauth2/token \
--username admin@test.com \
--password 1234 \
--clientId a1a6048b-df1d-4d4f-9a08-5cf836041d14 \
--clientSecret e4cc0147-e38f-4211-b8ad-8ae5e6a107f9
```

## Create a remote entity in the remote orion

```
ngsi create --host remote-orion \
--service federation \
--path /iot entity \
--keyValues \
--data '{"id":"urn:ngsi-ld:Device:device001","type":"Device","temperature":30}'
```

## Add registration in a loca broker

```
curl -sS http://localhost:1026/v2/registrations \
-H 'Content-Type: application/json' \
-H 'Fiware-Service: federation' \
-H 'Fiware-Servicepath: /iot' \
-H 'Accept: application/json' -d @- <<EOF
{
"dataProvided": {
Expand Down Expand Up @@ -106,5 +144,29 @@ EOF
You can get remote entities from remote orion by accessing a local broker as shown:

```
curl -sS http://localhost:1026/v2/entities
curl -sS http://localhost:1026/v2/entities?type=Device -H 'Fiware-Service: federation' -H 'Fiware-Servicepath: /iot'
```

```
[{"id":"urn:ngsi-ld:Device:device001","type":"Device","temperature":{"type":"Number","value":30,"metadata":{}}}]
```

## Check regproxy status

```
ngsi regproxy health --host regproxy --pretty
```

```
{
"ngsi-go": "regproxy",
"version": "0.8.4-next (git_hash:a86aaf88f0f9d08f8d5388f9e5e83b6ebb90e7f7)",
"health": "OK",
"csource": "http://remote-orion:1026",
"verbose": true,
"uptime": "0 d, 0 h, 9 m, 0 s",
"timesent": 1,
"success": 1,
"failure": 0
}
```
58 changes: 53 additions & 5 deletions extras/registration_proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,64 @@ services:
ports:
- "1028:1028"
depends_on:
- orion
- keyrock
- local-orion

orion:
local-orion:
image: fiware/orion:3.1.0
ports:
- "1026:1026"
depends_on:
- mongo
command: -dbhost mongo
- local-mongo
command: -dbhost local-mongo

mongo:
local-mongo:
image: mongo:4.4
command: --nojournal

keyrock:
image: fiware/idm:8.0.0-distroless
depends_on:
- mysql
ports:
- 3000:3000
environment:
- IDM_DB_HOST=mysql
- IDM_ADMIN_USER=admin
- IDM_ADMIN_EMAIL=admin@test.com
- IDM_ADMIN_PASS=1234

orion-proxy:
image: fiware/pep-proxy:8.0.0-distroless
depends_on:
- keyrock
- remote-orion
ports:
- 1027:1026
environment:
- PEP_PROXY_DEBUG=true
- PEP_PROXY_APP_HOST=remote-orion
- PEP_PROXY_APP_PORT=1026
- PEP_PROXY_PORT=1026
- PEP_PROXY_IDM_HOST=keyrock
- PEP_PROXY_IDM_PORT=3000
- PEP_PROXY_APP_ID=a1a6048b-df1d-4d4f-9a08-5cf836041d14
- PEP_PROXY_USERNAME=pep_proxy_58b1a6db-1bc0-4323-837e-f100511af19c
- PEP_PASSWORD=pep_proxy_1bad5dbf-7ae9-49a8-b0f6-c66e4570357a

remote-orion:
image: fiware/orion:3.1.0
depends_on:
- remote-mongo
command: -dbhost remote-mongo

remote-mongo:
image: mongo:4.4
command: --nojournal

mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=1234
volumes:
- ./mysql:/docker-entrypoint-initdb.d/:ro
Binary file added extras/registration_proxy/mysql/init.sql.gz
Binary file not shown.

0 comments on commit 334f022

Please sign in to comment.