Merge pull request #249 from OktopUSP/dev

frontend compose fixes + adapter fixer
This commit is contained in:
Leandro Antônio Farias Machado 2024-04-23 15:24:30 -03:00 committed by GitHub
commit 1a9294a677
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 66 additions and 20 deletions

View File

@ -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)

1
deploy/compose/.env.acs Normal file
View File

@ -0,0 +1 @@
NATS_URL=nats://msg_broker:4222

View File

@ -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 -------------------------- #

View File

@ -176,6 +176,17 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
- ./portainer_data:/data
acs:
image: oktopusp/acs
container_name: acs
ports:
- 9292:9292
env_file:
- .env.acs
networks:
usp_network:
ipv4_address: 172.16.235.16
networks:
usp_network:
driver: bridge

View File

@ -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")

View File

@ -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

View File

@ -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) {

View File

@ -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)

View File

@ -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()

View File

@ -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){

View File

@ -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)

View File

@ -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){