From b02d2463cf28f0789e8fa333db3cc71b58775c40 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Mon, 22 Apr 2024 13:42:41 -0300 Subject: [PATCH 1/6] feat(acs): deploy via docker compose --- deploy/compose/docker-compose.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deploy/compose/docker-compose.yaml b/deploy/compose/docker-compose.yaml index acf57fb..5e6e6c4 100644 --- a/deploy/compose/docker-compose.yaml +++ b/deploy/compose/docker-compose.yaml @@ -175,6 +175,15 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock - ./portainer_data:/data + + acs: + image: oktopusp/acs + container_name: acs + ports: + - 7547:7547 + networks: + usp_network: + ipv4_address: 172.16.235.16 networks: usp_network: From 4595c72e8404201c24eb6a971cedc8d2cd307643 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Mon, 22 Apr 2024 14:09:39 -0300 Subject: [PATCH 2/6] feat(acs): env file for compose deployment --- deploy/compose/.env.acs | 1 + deploy/compose/docker-compose.yaml | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 deploy/compose/.env.acs diff --git a/deploy/compose/.env.acs b/deploy/compose/.env.acs new file mode 100644 index 0000000..9af7128 --- /dev/null +++ b/deploy/compose/.env.acs @@ -0,0 +1 @@ +NATS_URL=nats://msg_broker:4222 \ No newline at end of file diff --git a/deploy/compose/docker-compose.yaml b/deploy/compose/docker-compose.yaml index 5e6e6c4..3abc763 100644 --- a/deploy/compose/docker-compose.yaml +++ b/deploy/compose/docker-compose.yaml @@ -181,6 +181,8 @@ services: container_name: acs ports: - 7547:7547 + env_file: + - .env.acs networks: usp_network: ipv4_address: 172.16.235.16 From aa58763ad31938829c61708ed5dacc0ff3394811 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Mon, 22 Apr 2024 14:26:48 -0300 Subject: [PATCH 3/6] chore: change acs port exposure --- deploy/compose/docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/compose/docker-compose.yaml b/deploy/compose/docker-compose.yaml index 3abc763..97a5f6c 100644 --- a/deploy/compose/docker-compose.yaml +++ b/deploy/compose/docker-compose.yaml @@ -180,7 +180,7 @@ services: image: oktopusp/acs container_name: acs ports: - - 7547:7547 + - 9292:9292 env_file: - .env.acs networks: From dc090a055bbe1e74f5cee2e0446c16485e61fb67 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Mon, 22 Apr 2024 17:37:30 -0300 Subject: [PATCH 4/6] fix(frontend): endpoint env vars --- frontend/src/contexts/auth-context.js | 4 ++-- frontend/src/contexts/socketio-context.js | 2 +- frontend/src/pages/auth/login.js | 2 +- frontend/src/pages/chat.js | 2 +- frontend/src/pages/devices.js | 8 ++++---- frontend/src/pages/index.js | 2 +- frontend/src/sections/devices/devices-discovery.js | 14 +++++++------- frontend/src/sections/devices/devices-rpc.js | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frontend/src/contexts/auth-context.js b/frontend/src/contexts/auth-context.js index 1b8f7a0..44d790a 100644 --- a/frontend/src/contexts/auth-context.js +++ b/frontend/src/contexts/auth-context.js @@ -146,7 +146,7 @@ export const AuthProvider = (props) => { redirect: 'follow' }; - let result = await fetch(process.env.NEXT_PUBLIC_REST_ENPOINT+"/auth/login", requestOptions) + let result = await fetch(process.env.NEXT_PUBLIC_REST_ENDPOINT+"/auth/login", requestOptions) if (result.status != 200) { throw new Error('Please check your email and password'); @@ -195,7 +195,7 @@ export const AuthProvider = (props) => { redirect: 'follow' }; - let result = await fetch(process.env.NEXT_PUBLIC_REST_ENPOINT+"/auth/admin/register", requestOptions) + let result = await fetch(process.env.NEXT_PUBLIC_REST_ENDPOINT+"/auth/admin/register", requestOptions) if (result.status == 200) { router.push("/auth/login") diff --git a/frontend/src/contexts/socketio-context.js b/frontend/src/contexts/socketio-context.js index e1996cb..04af45b 100644 --- a/frontend/src/contexts/socketio-context.js +++ b/frontend/src/contexts/socketio-context.js @@ -21,7 +21,7 @@ export const WsProvider = (props) => { const userVideo = useRef(); const connectionRef = useRef(); const auth = useAuth() - const socket = io(process.env.NEXT_PUBLIC_WS_ENPOINT) + const socket = io(process.env.NEXT_PUBLIC_WS_ENDPOINT) const initialize = async () => { // Prevent from calling twice in development mode with React.StrictMode enable diff --git a/frontend/src/pages/auth/login.js b/frontend/src/pages/auth/login.js index a38ebf4..6ecbaaa 100644 --- a/frontend/src/pages/auth/login.js +++ b/frontend/src/pages/auth/login.js @@ -83,7 +83,7 @@ const Page = () => { redirect: 'follow', }; - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/auth/admin/exists`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/auth/admin/exists`, requestOptions)) let content = await result.json() console.log("content: ", content) if (result.status != 200) { diff --git a/frontend/src/pages/chat.js b/frontend/src/pages/chat.js index 748e51d..bdd459c 100644 --- a/frontend/src/pages/chat.js +++ b/frontend/src/pages/chat.js @@ -35,7 +35,7 @@ const Page = () => { redirect: 'follow' }; - fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/users`,requestOptions) + fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/users`,requestOptions) .then(response => response.json()) .then(result => { // let teste = JSON.stringify(JSON.parse(result), null, 2) diff --git a/frontend/src/pages/devices.js b/frontend/src/pages/devices.js index 3606b40..158bf21 100644 --- a/frontend/src/pages/devices.js +++ b/frontend/src/pages/devices.js @@ -46,7 +46,7 @@ const Page = () => { redirect: 'follow' } - fetch(process.env.NEXT_PUBLIC_REST_ENPOINT+'/device', requestOptions) + fetch(process.env.NEXT_PUBLIC_REST_ENDPOINT+'/device', requestOptions) .then(response => { if (response.status === 401) router.push("/auth/login") @@ -86,7 +86,7 @@ const Page = () => { p = p - 1 p = p.toString() - fetch(process.env.NEXT_PUBLIC_REST_ENPOINT+'/device?page_number='+p, requestOptions) + fetch(process.env.NEXT_PUBLIC_REST_ENDPOINT+'/device?page_number='+p, requestOptions) .then(response => { if (response.status === 401) router.push("/auth/login") @@ -115,7 +115,7 @@ const Page = () => { } if (id == ""){ - return fetch(process.env.NEXT_PUBLIC_REST_ENPOINT+'/device', requestOptions) + return fetch(process.env.NEXT_PUBLIC_REST_ENDPOINT+'/device', requestOptions) .then(response => { if (response.status === 401) router.push("/auth/login") @@ -133,7 +133,7 @@ const Page = () => { }); } - let response = await fetch(process.env.NEXT_PUBLIC_REST_ENPOINT+'/device?id='+id, requestOptions) + let response = await fetch(process.env.NEXT_PUBLIC_REST_ENDPOINT+'/device?id='+id, requestOptions) if (response.status === 401) router.push("/auth/login") let json = await response.json() diff --git a/frontend/src/pages/index.js b/frontend/src/pages/index.js index c9a0352..ab87b58 100644 --- a/frontend/src/pages/index.js +++ b/frontend/src/pages/index.js @@ -38,7 +38,7 @@ const Page = () => { redirect: 'follow', }; - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/info/general`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/info/general`, requestOptions)) if (result.status === 401){ router.push("/auth/login") }else if (result.status != 200){ diff --git a/frontend/src/sections/devices/devices-discovery.js b/frontend/src/sections/devices/devices-discovery.js index 270e54d..d4280da 100644 --- a/frontend/src/sections/devices/devices-discovery.js +++ b/frontend/src/sections/devices/devices-discovery.js @@ -96,7 +96,7 @@ const addDeviceObj = async(obj, setShowLoading, router, updateDeviceParameters) body: raw }; setShowLoading(true) - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/add`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/add`, requestOptions)) if (result.status != 200) { if (result.status === 401){ router.push("/auth/login") @@ -131,7 +131,7 @@ const deleteDeviceObj = async(obj, setShowLoading, router, updateDeviceParameter body: raw }; setShowLoading(true) - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/del`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/del`, requestOptions)) if (result.status != 200) { if (result.status === 401){ router.push("/auth/login") @@ -481,7 +481,7 @@ const getDeviceParameters = async (raw) =>{ body: raw }; - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/parameters`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/parameters`, requestOptions)) if (result.status != 200) { if (result.status === 401){ router.push("/auth/login") @@ -505,7 +505,7 @@ const getDeviceParameterInstances = async (raw) =>{ body: raw }; - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/instances`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/instances`, requestOptions)) if (result.status != 200) { throw new Error('Please check your email and password'); }else if (result.status === 401){ @@ -778,7 +778,7 @@ const getDeviceParameterInstances = async (raw) =>{ body: raw }; - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/get`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/get`, requestOptions)) if (result.status != 200) { if (result.status === 401){ router.push("/auth/login") @@ -1028,7 +1028,7 @@ const getDeviceParameterInstances = async (raw) =>{ setOpen(false) setShowLoading(true) - let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/set`, requestOptions)) + let result = await (await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/set`, requestOptions)) if (result.status != 200) { if (result.status === 401){ router.push("/auth/login") @@ -1171,7 +1171,7 @@ const getDeviceParameterInstances = async (raw) =>{ body: raw }; setShowLoading(true) - let result = await fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/operate`, requestOptions) + let result = await fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/operate`, requestOptions) let content = await result.json() if (result.status != 200) { setShowLoading(false) diff --git a/frontend/src/sections/devices/devices-rpc.js b/frontend/src/sections/devices/devices-rpc.js index 08d52e6..6da1c33 100644 --- a/frontend/src/sections/devices/devices-rpc.js +++ b/frontend/src/sections/devices/devices-rpc.js @@ -84,7 +84,7 @@ const handleOpen = () => { } - fetch(`${process.env.NEXT_PUBLIC_REST_ENPOINT}/device/${router.query.id[0]}/any/${method}`, requestOptions) + fetch(`${process.env.NEXT_PUBLIC_REST_ENDPOINT}/device/${router.query.id[0]}/any/${method}`, requestOptions) .then(response => response.text()) .then(result => { if (result.status === 401){ From 7e5b9a682a21dd014230824ed841de7f8a5ce9dd Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 23 Apr 2024 14:03:51 -0300 Subject: [PATCH 5/6] fix: frotend env var typo --- deploy/compose/.env.frontend | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/compose/.env.frontend b/deploy/compose/.env.frontend index 32e4aa9..ff3f456 100644 --- a/deploy/compose/.env.frontend +++ b/deploy/compose/.env.frontend @@ -1,7 +1,7 @@ # ----------------------------- Local Environment ---------------------------- # -NEXT_PUBLIC_REST_ENPOINT="http://localhost:8000/api" -NEXT_PUBLIC_WS_ENPOINT="http://localhost:5000/" +NEXT_PUBLIC_REST_ENDPOINT="http://localhost:8000/api" +NEXT_PUBLIC_WS_ENPDOINT="http://localhost:5000/" # ---------------------------------------------------------------------------- # # -------------------------- Production Environment -------------------------- # From 28a0e3e4913cca7c16ed2415686e74f4ef531e26 Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 23 Apr 2024 15:22:49 -0300 Subject: [PATCH 6/6] fix(adapter): usp handler online status | closes #248 --- .../internal/events/usp_handler/status.go | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/backend/services/mtp/adapter/internal/events/usp_handler/status.go b/backend/services/mtp/adapter/internal/events/usp_handler/status.go index b9e2c40..af170f3 100644 --- a/backend/services/mtp/adapter/internal/events/usp_handler/status.go +++ b/backend/services/mtp/adapter/internal/events/usp_handler/status.go @@ -5,6 +5,9 @@ import ( "strconv" "github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/db" + "github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/usp" + "github.com/OktopUSP/oktopus/backend/services/mtp/adapter/internal/usp/usp_msg" + "google.golang.org/protobuf/proto" ) func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp string, ack func()) { @@ -15,6 +18,8 @@ func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp st } switch payload { + case ONLINE: + h.deviceOnline(device, mtp) case OFFLINE: h.deviceOffline(device, mtp) default: @@ -22,6 +27,35 @@ func (h *Handler) HandleDeviceStatus(device, subject string, data []byte, mtp st } } +func (h *Handler) deviceOnline(device, mtp string) { + + log.Printf("Device %s is online", device) + + msg := usp.NewGetMsg(usp_msg.Get{ + ParamPaths: []string{ + "Device.DeviceInfo.Manufacturer", + "Device.DeviceInfo.ModelName", + "Device.DeviceInfo.SoftwareVersion", + "Device.DeviceInfo.SerialNumber", + "Device.DeviceInfo.ProductClass", + }, + MaxDepth: 1, + }) + + payload, _ := proto.Marshal(&msg) + record := usp.NewUspRecord(payload, device, h.cid) + + tr369Message, err := proto.Marshal(&record) + if err != nil { + log.Fatalln("Failed to encode tr369 record:", err) + } + + err = h.nc.Publish(mtp+"-adapter.usp.v1."+device+".info", tr369Message) + if err != nil { + log.Printf("Failed to publish online device message: %v", err) + } +} + func (h *Handler) deviceOffline(device, mtp string) { log.Printf("Device %s is offline", device)