Skip to content

Commit 833fa3d

Browse files
d-linkoBrianSiposDavid Linko
authored
38 anms fun bld 007 edds ari selection on build tab (#194)
* Rework to split amp-manager from ION containers * Aligning ION config inputs, fixing proxy socket path * Fixing container build after merge * Fix compose config * Cleaning up CI config * Fixing access in CI * Update checkout test port * Fixing podman use and podman checkout CI job * Stop in opposite order from start * updating nm_host from ion-manger to anms-amp-manager-1. still having issues submitting reports * updated name to amp-manager, removed debug log * Renamed test containers file to testenv-compose to make its purpose more clear. Moved socket bind mount to an environment controlled path. * Fixing puppet testenv disable behavior * Fix hostname for the NM manager * Separate anms network from testenv network * Fix container name after merge * updated to dtnma-camp * updated to latest CAMP and DTNNA-TOOLS * Updating uses of ACE, CAMP, and REFDM to latest development * updated to latest dtnma libraries * updating to latest sql tables * handling ADM upload and report printing * working translation and report handling * updated for sending and viewing execsets * added status msg to transcoder route * added clearSearchOnSelect, added redundant transcoding check * updated report processing to use ACE and enhanced transcoding * removed un need nickname convertor --------- Co-authored-by: Brian Sipos <brian.sipos@jhuapl.edu> Co-authored-by: Brian Sipos <brian.sipos@gmail.com> Co-authored-by: David Linko <david.linko@jhuapl.edu>
1 parent e6153f5 commit 833fa3d

File tree

17 files changed

+225
-197
lines changed

17 files changed

+225
-197
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ ION_MGR_PORT=8089
5353
HTTP_PORT:80
5454
SOCKDIR=/var/tmp/nm
5555

56-
ADM_PATH=deps/dtnma-adms
56+
ADM_PATH=deps/dtnma-adms

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/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/management/agents/Agents.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ import { mapGetters, mapActions } from "vuex";
106106
import api from "../../../shared/api.js";
107107
import AgentModal from "./AgentModal.vue";
108108
import AgentsManageModal from "./AgentsManageModal.vue";
109+
import toastr from "toastr";
109110
110111
export default {
111112
name: "Agents",
@@ -215,9 +216,15 @@ export default {
215216
nodeList.forEach((node) => {
216217
api.methods
217218
.apiPostAgent(node.trim())
218-
.then((response) => (this.results = response.status + " " + response.statusText))
219+
.then((response) => {
220+
this.results = response.status + " " + response.statusText;
221+
toastr.success(this.results);
222+
223+
})
219224
.catch((error) => {
220225
console.error(error);
226+
toastr.error(error);
227+
221228
});
222229
});
223230
},

anms-ui/public/app/components/management/agents/AgentsManageModal.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</b-button>
3535
</b-col>
3636
<b-col cols="9">
37-
<build :cbor="cbor" @updateResult="updateResults($event)"></build>
37+
<build :cbor="cbor" :agentModal=true @updateResult="updateResults($event)"></build>
3838
</b-col>
3939
</b-row>
4040
</div>
@@ -126,7 +126,15 @@ export default {
126126
.then((response) => {
127127
if (response.data.parsed_as == "pending") {
128128
setTimeout(() => this.queryTranscoderLog(), 8000);
129-
} else {
129+
} else if(response.data.parsed_as == "ERROR") {
130+
console.log(`Error translating transcoder log ID: ${this.transcoderLogId}! See transcoder log table for details`);
131+
toastr.error(`Error translating transcoder log ID: ${this.transcoderLogId}! See transcoder log table for details`);
132+
this.loading = false;
133+
this.closeModal();
134+
this.ariCBOR = null;
135+
this.ariString=null;
136+
}
137+
else {
130138
this.ariCBOR = response.data.cbor;
131139
this.submitRawCommand2Agents();
132140
}

anms-ui/public/app/components/management/agents/reports.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
value="-1">-- Select Sent Reports --</b-form-select-option>
1717
<b-form-select-option v-for="rpt, index in rptts"
1818
:key="index"
19-
:value="index">{{ decodeURI(rpt) }}</b-form-select-option>
19+
:value="index">{{ rpt }}</b-form-select-option>
2020
</b-form-select>
2121
<b-table sticky-header
2222
hover

0 commit comments

Comments
 (0)