Skip to content

Commit ac83714

Browse files
authored
Merge branch 'main' into 169-light-deployment
2 parents 4048b48 + 2c1dd22 commit ac83714

File tree

24 files changed

+353
-244
lines changed

24 files changed

+353
-244
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @NASA-AMMOS/anms-developers

anms-core/anms/routes/ARIs/reports.py

Lines changed: 81 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@
3030
from sqlalchemy import select, and_
3131
from sqlalchemy.engine import Result
3232
from io import StringIO
33+
from urllib.parse import unquote
3334

3435
from anms.components.schemas import ARIs
3536
from anms.models.relational import get_async_session, get_session
3637

3738
from anms.models.relational.report import Report
3839
from anms.models.relational.execution_set import ExecutionSet
3940
from anms.shared.opensearch_logger import OpenSearchLogger
40-
41+
import io
4142

4243
import anms.routes.transcoder as transcoder
4344

45+
# for handling report set and exec set
46+
import ace
47+
import ace.models
48+
4449

4550
logger = OpenSearchLogger(__name__, log_console=True)
4651

@@ -80,10 +85,11 @@ async def report_def_by_id(agent_id: str):
8085
ari_val = ""
8186
if(res):
8287
ari_val = await transcoder.transcoder_put_cbor_await("ari:0x"+res.entries.hex())
83-
ari_val = ari_val['data']
84-
addition = {'exec_set': ari_val,'correlator_nonce':correlator_nonce}
85-
if addition not in final_res:
86-
final_res.append(addition)
88+
logger.info(ari_val)
89+
ari_val = ari_val['data']
90+
addition = {'exec_set': ari_val,'correlator_nonce':correlator_nonce}
91+
if addition not in final_res:
92+
final_res.append(addition)
8793

8894
return final_res
8995

@@ -94,6 +100,8 @@ async def report_def_by_id(agent_id: str):
94100
async def report_ac(agent_id: str, correlator_nonce: int):
95101
agent_id = agent_id.strip()
96102
final_res = []
103+
ari = None
104+
# Load in adms
97105
# get command that made the report as first entry
98106
stmt = select(ExecutionSet).where(and_(ExecutionSet.agent_id == agent_id, ExecutionSet.correlator_nonce == correlator_nonce) )
99107
async with get_async_session() as session:
@@ -102,42 +110,78 @@ async def report_ac(agent_id: str, correlator_nonce: int):
102110
exec_set_entry=["time"]
103111
if result:
104112
exec_set = result.entries.hex()
105-
exec_set = await transcoder.transcoder_put_cbor_await("ari:0x"+exec_set)
106-
exec_set = exec_set['data']
107-
# format
108-
# TODO HANDLE RPTT and split up multiple entries
109-
"ari:/EXECSET/n=12345;(//ietf/dtnma-agent/CTRL/inspect(//ietf/dtnma-agent/EDD/sw-version))"
110-
execset_pattern = r"ari:/EXECSET/n=.+;\((.*)\)"
111-
match = re.match(execset_pattern,exec_set)
112-
if match:
113-
exec_set_entry.extend(match.group(1).split(';'))
114-
else:
115-
exec_set_entry.extend([exec_set])
116-
final_res.append(exec_set_entry)
117-
113+
# use ACE to handle report set decoding
114+
in_text = '0x'+exec_set
115+
try:
116+
in_bytes = ace.cborutil.from_hexstr(in_text)
117+
dec = ace.ari_cbor.Decoder()
118+
ari = dec.decode(io.BytesIO(in_bytes))
119+
120+
except Exception as err:
121+
logger.info(err)
122+
123+
# current ARI should be an exection set
124+
if ari:
125+
logger.info(ari)
126+
if type(ari.value) == ace.ari.ExecutionSet:
127+
try:
128+
enc = ace.ari_text.Encoder()
129+
buf = io.StringIO()
130+
# run through targets and their parameters to get all things parts translated
131+
for targ in ari.value.targets:
132+
if targ.params:
133+
for param in targ.params:
134+
enc.encode(param, buf)
135+
out_text = buf.getvalue()
136+
ari_val = await transcoder.transcoder_put_await_str(out_text)
137+
exec_set_entry.append(ari_val['data'])
138+
else:
139+
enc.encode(targ, buf)
140+
out_text = buf.getvalue()
141+
ari_val = await transcoder.transcoder_put_await_str(out_text)
142+
exec_set_entry.append(ari_val['data'])
143+
144+
except Exception as err:
145+
logger.info(err)
146+
147+
148+
final_res.append(exec_set_entry)
149+
ari = None
118150
stmt = select(Report).where(and_(Report.agent_id == agent_id, Report.correlator_nonce == correlator_nonce) )
119151
async with get_async_session() as session:
120152
result: Result = await session.scalars(stmt)
121153
for res in result.all():
122-
# TODO translating the CBOR route might want to relook at currently cause large amount of transcoding vs just loading the string below
123-
# # translate the cbor
124-
# rpt_set = res.report_list_cbor.hex()
125-
# rpt_set = await transcoder.transcoder_put_cbor_await("ari:0x"+rpt_set)
126-
# rpt_set = rpt_set['data']
127-
rpt_set = res.report_list
128-
# match
129-
# ari:/RPTSET/n=12345;r=/TP/20250611T114420.009992304Z;(t=/TD/PT0S;s=//1/1/CTRL/5(//1/1/EDD/1);(%220.0…
130-
rptset_pattern = r"ari:/RPTSET/n=.+;r=.*;\(t=.*;s=.*;\((.*)\)\)"
131-
match = re.match(rptset_pattern,rpt_set)
132-
addition = [res.reference_time]
133-
if match:
134-
# report entries
135-
rpt_entr = match.group(1)
136-
addition.extend(rpt_entr.split(";"))
137-
else:
138-
addition.append(rpt_set)
154+
# used to hold final report set
155+
addition = [res.reference_time]
156+
rpt_set = res.report_list_cbor.hex()
157+
# Using Ace to translate CBOR into ARI object to process individual parts
158+
in_text = '0x'+rpt_set
159+
try:
160+
in_bytes = ace.cborutil.from_hexstr(in_text)
161+
dec = ace.ari_cbor.Decoder()
162+
ari = dec.decode(io.BytesIO(in_bytes))
163+
164+
except Exception as err:
165+
logger.error(err)
166+
167+
# current ARI should be an report set
168+
if ari:
169+
logger.info(ari)
170+
if type(ari.value) == ace.ari.ReportSet:
171+
for rpt in ari.value.reports:
172+
try:
173+
enc = ace.ari_text.Encoder()
174+
# running through and translating all parts of rptset
175+
for item in rpt.items:
176+
buf = io.StringIO()
177+
enc.encode(item, buf)
178+
out_text = buf.getvalue()
179+
ari_val = await transcoder.transcoder_put_await_str(out_text)
180+
addition.append(ari_val['data'])
181+
except Exception as err:
182+
logger.error(err)
139183

140-
if addition not in final_res:
141-
final_res.append(addition)
184+
if addition not in final_res:
185+
final_res.append(addition)
142186
return final_res
143187

anms-core/anms/routes/adms/adm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ async def getall():
8787
@router.get("/{enumeration}/{namespace}", status_code=status.HTTP_200_OK)
8888
async def get_adm(enumeration: int,namespace: str):
8989
async with get_async_session() as session:
90-
result_dm,_ = await DataModel.get(enumeration, namespace, session)
91-
result,_ = await AdmData.get(result_dm.data_model_id, session)
90+
result_dm = await DataModel.get(enumeration, namespace, session)
91+
result, _ = await AdmData.get(result_dm.data_model_id, session)
9292
if result:
9393
return result.data
9494

anms-core/anms/routes/transcoder.py

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,39 @@ async def transcoder_log_by_id(id: str):
6666
return TranscoderLog.query.filter_by(transcoder_log_id=id).first()
6767

6868
# PUT /ui/incoming/{cbor}/hex
69-
@router.put("/ui/incoming/{cbor}/hex", status_code=status.HTTP_200_OK)
70-
async def transcoder_put_cbor(cbor: str):
71-
msg = json.dumps({'uri': cbor})
69+
@router.put("/ui/incoming/{input_cbor}/hex", status_code=status.HTTP_200_OK)
70+
async def transcoder_put_input_cbor(input_cbor: str):
71+
msg = json.dumps({'uri': input_cbor})
7272
transcoder_log_id = None
7373
with get_session() as session:
74-
curr_uri = TranscoderLog.query.filter_by(input_string=cbor).first()
74+
curr_uri = TranscoderLog.query.filter(or_(TranscoderLog.input_string==input_cbor, TranscoderLog.cbor==input_cbor)).first()
7575
if curr_uri is None:
76-
c1 = TranscoderLog(input_string=cbor, parsed_as='pending')
76+
c1 = TranscoderLog(input_string=input_cbor, parsed_as='pending')
7777
session.add(c1)
7878
session.flush()
7979
session.refresh(c1)
8080
transcoder_log_id = c1.transcoder_log_id
8181
session.commit()
82+
status = "Submitted ARI to transcoder"
83+
else:
84+
# the input_ari has already been submitted
85+
status = "ARI previously submitted, check log"
86+
transcoder_log_id = curr_uri.transcoder_log_id
8287

8388
logger.info('PUBLISH to transcode/CoreFacing/Outgoing, msg = %s' % msg)
8489
MQTT_CLIENT.publish("transcode/CoreFacing/Outgoing", msg)
8590

86-
return {"id": transcoder_log_id}
91+
return {"id": transcoder_log_id, "status": status}
92+
8793

88-
# get /ui/incoming/{cbor}/hex
8994
@router.get("/ui/incoming/await/{cbor}/hex", status_code=status.HTTP_200_OK)
9095
async def transcoder_put_cbor_await(cbor: str):
9196
curr_uri = ""
9297
msg = json.dumps({'uri': cbor})
9398
transcoder_log_id = None
9499
with get_session() as session:
95-
curr_uri = TranscoderLog.query.filter_by(input_string=cbor).first()
100+
curr_uri = TranscoderLog.query.filter(or_(TranscoderLog.input_string==cbor, TranscoderLog.cbor==cbor)).first()
101+
96102
if curr_uri is None:
97103
c1 = TranscoderLog(input_string=cbor, parsed_as='pending')
98104
session.add(c1)
@@ -115,27 +121,29 @@ async def transcoder_put_cbor_await(cbor: str):
115121
while True:
116122
with get_session() as session:
117123
curr_uri = TranscoderLog.query.filter_by(TranscoderLog.transcoder_log_id==transcoder_log_id).first()
118-
if curr_uri.parsed_as == "CBOR":
119-
curr_uri = curr_uri.uri
120-
break
121-
if curr_uri.parsed_as == "ERROR":
122-
curr_uri = "ARI://BADARI"
123-
break
124+
if curr_uri.parsed_as != "pending":
125+
if curr_uri.parsed_as == "ERROR":
126+
curr_uri = "ARI://BADARI"
127+
else:
128+
curr_uri = curr_uri.uri
129+
break
124130
time.sleep(1)
125131

126132

127133
return {"data": curr_uri}
128134

129135
# PUT /ui/incoming/str Body is str ARI to send to transcoder
130-
@router.get("/ui/incomin/await/str", status_code=status.HTTP_200_OK)
131-
def transcoder_put_await_str(ari: str):
132-
ari = ari.strip()
133-
msg = json.dumps({"uri": ari})
136+
@router.get("/ui/incoming/await/str", status_code=status.HTTP_200_OK)
137+
async def transcoder_put_await_str(input_ari: str):
138+
input_ari = input_ari.strip()
139+
msg = json.dumps({"uri": input_ari})
134140
transcoder_log_id = None
141+
curr_uri = None
135142
with get_session() as session:
136-
curr_uri = TranscoderLog.query.filter_by(input_string=ari).first()
143+
curr_uri = TranscoderLog.query.filter(or_(TranscoderLog.input_string==input_ari,TranscoderLog.ari==input_ari, TranscoderLog.cbor==input_ari)).first()
144+
137145
if curr_uri is None:
138-
c1 = TranscoderLog(input_string=ari, parsed_as='pending')
146+
c1 = TranscoderLog(input_string=input_ari, parsed_as='pending')
139147
session.add(c1)
140148
session.flush()
141149
session.refresh(c1)
@@ -145,45 +153,55 @@ def transcoder_put_await_str(ari: str):
145153
MQTT_CLIENT.publish("transcode/CoreFacing/Outgoing", msg)
146154
else:
147155
transcoder_log_id = curr_uri.transcoder_log_id
156+
if curr_uri.parsed_as != "pending":
157+
if curr_uri.parsed_as == "ERROR":
158+
curr_uri = "ARI://BADARI"
159+
else:
160+
curr_uri = curr_uri.uri
161+
return {"data": curr_uri}
162+
148163

149164

150165
while(True):
151166
with get_session() as session:
152167
curr_uri = TranscoderLog.query.filter_by(transcoder_log_id=transcoder_log_id).first()
153-
if curr_uri.parsed_as == "URI":
154-
curr_uri = curr_uri.uri
155-
break
156-
if curr_uri.parsed_as == "ERROR":
157-
curr_uri = "ARI://BADARI"
158-
break
159-
time.sleep(1)
168+
if curr_uri.parsed_as != "pending":
169+
if curr_uri.parsed_as == "ERROR":
170+
curr_uri = "ARI://BADARI"
171+
else:
172+
curr_uri = curr_uri.uri
173+
break
174+
time.sleep(1)
160175

161176

162177
return {"data": curr_uri}
163178

164179

165180
# PUT /ui/incoming/str Body is str ARI to send to transcoder
166181
@router.put("/ui/incoming/str", status_code=status.HTTP_200_OK)
167-
def transcoder_put_str(ari: str):
168-
ari = ari.strip()
169-
msg = json.dumps({"uri": ari})
182+
async def transcoder_put_str(input_ari: str):
183+
input_ari = input_ari.strip()
184+
msg = json.dumps({"uri": input_ari})
170185
transcoder_log_id = None
171186
with get_session() as session:
172-
curr_uri = TranscoderLog.query.filter_by(input_string=ari).first()
187+
curr_uri = TranscoderLog.query.filter(or_(TranscoderLog.input_string==input_ari,TranscoderLog.ari==input_ari, TranscoderLog.cbor==input_ari)).first()
173188
if curr_uri is None:
174-
c1 = TranscoderLog(input_string=ari, parsed_as='pending')
189+
c1 = TranscoderLog(input_string=input_ari, parsed_as='pending')
175190
session.add(c1)
176191
session.flush()
177192
session.refresh(c1)
178193
transcoder_log_id = c1.transcoder_log_id
179194
session.commit()
195+
status = "Submitted ARI to transcoder"
180196
else:
197+
# the input_ari has already been submitted
198+
status = "ARI previously submitted, check log"
181199
transcoder_log_id = curr_uri.transcoder_log_id
182200

183201
logger.info('PUBLISH to transcode/CoreFacing/Outgoing, msg = %s' % msg)
184202
MQTT_CLIENT.publish("transcode/CoreFacing/Outgoing", msg)
185203

186-
return {"id": transcoder_log_id}
204+
return {"id": transcoder_log_id, "status": status}
187205

188206

189207

anms-core/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ dependencies = [
3131
"email-validator ~=1.3",
3232
"fastapi ~=0.86.0",
3333
"fastapi-pagination ~=0.9.1",
34-
"grpcio ~=1.50.0",
35-
"grpcio-tools ~=1.50.0",
3634
"gunicorn ~=23.0.0",
3735
"httpx ~=0.24.0",
3836
"itsdangerous ~=2.1.2",

anms-ui/public/app/components/adm/Adm.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
<table class="table table-striped table-hover table-bordered table-sm text-center">
55
<thead class="table-dark">
66
<tr>
7-
<th class="text-info">Enum</th>
8-
<th class="text-info">Adm Name</th>
9-
<th class="text-info">Name String</th>
7+
<th class="text-info">enumeration</th>
8+
<th class="text-info">Name</th>
9+
<th class="text-info">Namespace</th>
1010
<th class="text-info">Version</th>
1111
<th class="text-info">Use Description</th>
1212
</tr>
1313
</thead>
1414
<tbody>
1515
<template v-for="(adm, index) in adms">
1616
<tr :key="index">
17-
<td>{{ adm.adm_enum }}</td>
17+
<td>{{ adm.enumeration }}</td>
1818
<td v-b-tooltip.hover
19-
title="Download ADM JSON" @click="download(adm)" ><b>{{ adm.data_model_name }}</b></td>
20-
<td>{{ adm.name_string }}</td>
19+
title="Download ADM YANG" @click="download(adm)" ><b>{{ adm.name }}</b></td>
20+
<td>{{ adm.namespace }}</td>
2121
<td>{{ adm.version_name }}</td>
2222
<td>{{ adm.use_desc }}</td>
2323
</tr>
@@ -118,20 +118,21 @@ export default {
118118
}),
119119
download(adm){
120120
let json = {};
121-
api_adm.apiGetAdm(adm.adm_enum).then(res => {
121+
api_adm.apiGetAdm(adm.enumeration, adm.namespace).then(res => {
122122
json= res.data;
123123
const jsonData = json;
124124
const blob = new Blob([jsonData], { type: 'application/json' });
125125
const url = URL.createObjectURL(blob);
126126
const link = document.createElement('a');
127127
link.href = url;
128-
link.download = adm.data_model_name +".json";
128+
link.download = adm.name +".yang";
129129
link.click();
130130
URL.revokeObjectURL(url);
131131
})
132132
.catch(function (error) {
133133
console.error("No ADM to downlaod ")
134134
console.error(error)
135+
toastr.error(("No ADM to downlaod "))
135136
});
136137
},
137138
async uploadAdms() {

0 commit comments

Comments
 (0)