Skip to content

Commit 5f93175

Browse files
author
David Linko
committed
updated to lastest tool and new SQL schema
1 parent cd32a52 commit 5f93175

File tree

20 files changed

+98
-82
lines changed

20 files changed

+98
-82
lines changed

anms-core/anms/components/schemas/ARIs/registered_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
# Shared properties
3333
class RegisteredAgentBase(BaseModel):
34-
agent_id_string: Optional[str] = None
34+
agent_endpoint_uri: Optional[str] = None
3535
first_registered: Optional[datetime] = None
3636
last_registered: Optional[datetime] = None
3737

anms-core/anms/models/relational/execution_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
class ExecutionSet(Model):
3636
__tablename__ = 'vw_execution_set'
3737
execution_set_id = Column(Integer, primary_key=True)
38-
correlator_nonce = Column(Integer)
38+
nonce_cbor = Column(LargeBinary)
3939
use_desc = Column(String)
4040
agent_id = Column(String)
4141
num_entries = Column(Integer)
@@ -47,7 +47,7 @@ def __repr__(self) -> str:
4747
def as_dict(self) -> Dict[str, Any]:
4848
dict_obj = {
4949
'execution_set_id': getattr(self, 'execution_set_id'),
50-
'correlator_nonce': getattr(self, 'correlator_nonce'),
50+
'nonce_cbor': getattr(self, 'nonce_cbor'),
5151
'use_desc': getattr(self, 'use_desc'),
5252
'agent_id': getattr(self, 'agent_id'),
5353
'num_entries': getattr(self, 'num_entries'),

anms-core/anms/models/relational/registered_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RegisteredAgent(Model):
3737
__tablename__ = 'registered_agents'
3838

3939
registered_agents_id = Column(Integer, primary_key=True)
40-
agent_id_string = Column(
40+
agent_endpoint_uri = Column(
4141
String(128),
4242
default='ipn:0.0',
4343
unique=True,

anms-core/anms/models/relational/report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
class Report(Model):
3636
__tablename__ = 'ari_rptset'
3737
ari_rptset_id = Column(Integer, primary_key=True)
38-
correlator_nonce = Column(Integer)
38+
nonce_cbor = Column(LargeBinary)
3939
reference_time = Column(Integer)
4040
report_list = Column(String)
4141
report_list_cbor = Column(LargeBinary)
42-
agent_id = Column(String)
42+
agent_id = Column(Integer)
4343
def __repr__(self) -> str:
4444
return self.as_dict().__repr__()
4545

4646
def as_dict(self) -> Dict[str, Any]:
4747
dict_obj = {
4848
'ari_rptset_id': getattr(self, 'ari_rptset_id'),
49-
'correlator_nonce': getattr(self, 'correlator_nonce'),
49+
'nonce_cbor': getattr(self, 'nonce_cbor'),
5050
'reference_time': getattr(self, 'reference_time'),
5151
'report_list': getattr(self, 'report_list'),
5252
'report_list_cbor': getattr(self, 'report_list_cbor'),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ async def registered_agent_by_id(registered_agents_id: int):
6262
return result.one_or_none()
6363

6464

65-
@router.get("/name/{agent_id_string}", status_code=status.HTTP_200_OK, response_model=ARIs.RegisteredAgent)
66-
async def registered_agent_by_name(agent_id_string: str):
67-
stmt = select(RegisteredAgent).where(RegisteredAgent.agent_id_string == agent_id_string)
65+
@router.get("/name/{agent_endpoint_uri}", status_code=status.HTTP_200_OK, response_model=ARIs.RegisteredAgent)
66+
async def registered_agent_by_name(agent_endpoint_uri: str):
67+
stmt = select(RegisteredAgent).where(RegisteredAgent.agent_endpoint_uri == agent_endpoint_uri)
6868
async with get_async_session() as session:
6969
result: Result = await session.scalars(stmt)
7070
return result.one_or_none()
@@ -75,7 +75,7 @@ async def paged_registered_agents(query: str, params: Params = Depends()):
7575
async with get_async_session() as session:
7676
query = '%' + query + '%'
7777
return await paginate(session, select(RegisteredAgent).where(or_(
78-
RegisteredAgent.agent_id_string.ilike(query),
78+
RegisteredAgent.agent_endpoint_uri.ilike(query),
7979
RegisteredAgent.first_registered.cast(String).ilike(query),
8080
RegisteredAgent.last_registered.cast(String).ilike(query)
8181
)).order_by(RegisteredAgent.registered_agents_id), params)

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

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@
2222
# subcontract 1658085.
2323
#
2424
from typing import List
25-
import re
25+
2626
from fastapi import APIRouter, Depends
2727
from fastapi import status
2828
from fastapi_pagination import Page, Params
2929
from fastapi_pagination.ext.async_sqlalchemy import paginate
3030
from sqlalchemy import select, and_
3131
from sqlalchemy.engine import Result
32-
from io import StringIO
32+
3333
from urllib.parse import unquote
3434

3535
from anms.components.schemas import ARIs
3636
from anms.models.relational import get_async_session, get_session
3737

3838
from anms.models.relational.report import Report
3939
from anms.models.relational.execution_set import ExecutionSet
40+
from anms.models.relational.registered_agent import RegisteredAgent
41+
4042
from anms.shared.opensearch_logger import OpenSearchLogger
4143
import io
4244

4345
import anms.routes.transcoder as transcoder
4446

4547
# for handling report set and exec set
4648
import ace
47-
import ace.models
48-
4949

5050
logger = OpenSearchLogger(__name__, log_console=True)
5151

@@ -69,47 +69,64 @@ async def all_report_name():
6969

7070
@router.get("/entry/name/{agent_id}", status_code=status.HTTP_200_OK, response_model=list,
7171
tags=["REPORTS"])
72-
async def report_def_by_id(agent_id: str):
72+
async def report_def_by_id(agent_id: int):
7373
# select all reports belonging to the agent
74-
agent_id = agent_id.strip()
7574
final_res = []
75+
agent_id_str = ""
7676
stmt = select(Report).where(Report.agent_id == agent_id)
77+
agent_id_stmt = select(RegisteredAgent).where(RegisteredAgent.registered_agents_id == agent_id)
7778
async with get_async_session() as session:
7879
result: Result = await session.scalars(stmt)
80+
# Execution set uses URI as agent_id
81+
result_agent: Result = await session.scalars(agent_id_stmt)
82+
agent_id_str = result_agent.one_or_none()
83+
agent_id_str = agent_id_str.agent_endpoint_uri
7984
for res in result.all():
8085
# select from exec_set
81-
correlator_nonce = res.correlator_nonce
82-
stmt = select(ExecutionSet).where(and_(ExecutionSet.agent_id == agent_id, ExecutionSet.correlator_nonce == correlator_nonce) )
83-
result: Result = await session.scalars(stmt)
84-
exc_set = result.all()
85-
for res in exc_set:
86-
ari_val = ""
87-
if(res):
88-
ari_val = await transcoder.transcoder_put_cbor_await("0x"+res.entries.hex())
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)
86+
nonce_cbor = res.nonce_cbor
87+
try:
88+
stmt = select(ExecutionSet).where(and_(ExecutionSet.agent_id == agent_id_str, ExecutionSet.nonce_cbor == nonce_cbor) )
89+
result: Result = await session.scalars(stmt)
90+
exc_set = result.all()
91+
for res in exc_set:
92+
ari_val = ""
93+
if(res):
94+
hex_str = "0x"+res.entries.hex()
95+
hex_str = hex_str.upper()
96+
ari_val = await transcoder.transcoder_put_cbor_await(hex_str)
97+
ari_val = ari_val['data']
98+
addition = {'exec_set': ari_val,'nonce_cbor':nonce_cbor}
99+
if addition not in final_res:
100+
final_res.append(addition)
101+
except Exception as e:
102+
logger.error(f"Error {e}, while processing nonce:{nonce_cbor} for agent: {agent_id_str}")
93103

94104
return final_res
95105

96106

97107
# entries tabulated returns header and values in correct order
98-
@router.get("/entries/table/{agent_id}/{correlator_nonce}", status_code=status.HTTP_200_OK,
108+
@router.get("/entries/table/{agent_id}/{nonce_cbor}", status_code=status.HTTP_200_OK,
99109
response_model=list)
100-
async def report_ac(agent_id: str, correlator_nonce: int):
101-
agent_id = agent_id.strip()
110+
async def report_ac(agent_id: int, nonce_cbor: bytes):
102111
final_res = []
103112
ari = None
104113
dec = ace.ari_cbor.Decoder()
105-
buf = io.StringIO()
114+
buf = nonce_cbor
115+
116+
agent_id_str =""
117+
agent_id_stmt = select(RegisteredAgent).where(RegisteredAgent.registered_agents_id == agent_id)
118+
async with get_async_session() as session:
119+
result_agent: Result = await session.scalars(agent_id_stmt)
120+
agent_id_str = result_agent.one_or_none()
121+
agent_id_str = agent_id_str.agent_endpoint_uri
122+
106123
# Load in adms
107124
# get command that made the report as first entry
108-
stmt = select(ExecutionSet).where(and_(ExecutionSet.agent_id == agent_id, ExecutionSet.correlator_nonce == correlator_nonce) )
125+
stmt = select(ExecutionSet).where(and_(ExecutionSet.agent_id == agent_id_str, ExecutionSet.nonce_cbor == nonce_cbor) )
109126
async with get_async_session() as session:
110127
result: Result = await session.scalars(stmt)
111128

112-
# there should only be one execution per agent per correlator_nonce
129+
# there should only be one execution per agent per nonce_cbor
113130
# in the event that two occur pull the latest one
114131
result = result.all()
115132
exec_set_dir = {}
@@ -154,7 +171,7 @@ async def report_ac(agent_id: str, correlator_nonce: int):
154171

155172
# final_res.append(exec_set_entry)
156173
ari = None
157-
stmt = select(Report).where(and_(Report.agent_id == agent_id, Report.correlator_nonce == correlator_nonce) )
174+
stmt = select(Report).where(and_(Report.agent_id == agent_id, Report.nonce_cbor == nonce_cbor) )
158175
async with get_async_session() as session:
159176
result: Result = await session.scalars(stmt)
160177
for res in result.all():

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def handle_adm(admset: ace.AdmSet, adm_file: ace.models.AdmModule, session
156156
# Use CAmPython to generate sql
157157
out_path = "" # This is empty string since we don't need to write the generated sql to a file
158158
sql_dialect = 'pgsql'
159-
writer = create_sql.Writer(admset, adm_file, out_path, False, dialect=sql_dialect)
159+
writer = create_sql.Writer(admset, adm_file, out_path, sql_dialect)
160160
string_buffer = io.StringIO()
161161
writer.write(string_buffer)
162162

@@ -252,7 +252,7 @@ async def update_adm(file: UploadFile, request: Request):
252252
logger.info(f"{info_message} adm: {adm_file.norm_name}")
253253
out_path = "" # This is empty string since we don't need to write the generated sql to a file
254254
sql_dialect = 'pgsql'
255-
writer = create_sql.Writer(admset, adm_file, out_path, dialect=sql_dialect)
255+
writer = create_sql.Writer(admset, adm_file, out_path, sql_dialect)
256256
string_buffer = io.StringIO()
257257
try: # catching error in sql creation
258258
writer.write(string_buffer)

anms-core/anms/routes/agent_parameter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ def send_parameter(agent_id: int, agent_parameter_id: int, command_parameters: d
9999
try:
100100
session.add(in_stm)
101101
session.commit()
102-
# getting agent_id_string
103-
agent_id_string = session.execute(select(RegisteredAgent.agent_id_string).where(
102+
# getting agent_endpoint_uri
103+
agent_endpoint_uri = session.execute(select(RegisteredAgent.agent_endpoint_uri).where(
104104
RegisteredAgent.registered_agents_id == agent_id))
105-
agent_id_string = agent_id_string.one_or_none()[0]
105+
agent_endpoint_uri = agent_endpoint_uri.one_or_none()[0]
106106
err = process_command(agent_parameter_id, command_parameters,
107-
AGENT_PARAMETER.get_agent(),agent_id_string)
107+
AGENT_PARAMETER.get_agent(),agent_endpoint_uri)
108108
if not err:
109109
return err
110110
except IntegrityError:

anms-core/integration_test/integration_tests.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@
17281728
}
17291729
],
17301730
"cookie": [],
1731-
"body": "{\n \"items\": [\n {\n \"agent_id_string\": \"Lorem incididunt quis ullamco\",\n \"first_registered\": \"1957-10-13T19:33:33.148Z\",\n \"last_registered\": \"2014-05-02T06:21:44.543Z\",\n \"registered_agents_id\": 80685875\n },\n {\n \"agent_id_string\": \"ut cillum qui sunt\",\n \"first_registered\": \"1964-03-19T12:57:01.700Z\",\n \"last_registered\": \"1954-11-14T02:14:25.881Z\",\n \"registered_agents_id\": -62745836\n }\n ],\n \"total\": 73937038,\n \"page\": 72027872,\n \"size\": 73888144\n}"
1731+
"body": "{\n \"items\": [\n {\n \"agent_endpoint_uri\": \"Lorem incididunt quis ullamco\",\n \"first_registered\": \"1957-10-13T19:33:33.148Z\",\n \"last_registered\": \"2014-05-02T06:21:44.543Z\",\n \"registered_agents_id\": 80685875\n },\n {\n \"agent_endpoint_uri\": \"ut cillum qui sunt\",\n \"first_registered\": \"1964-03-19T12:57:01.700Z\",\n \"last_registered\": \"1954-11-14T02:14:25.881Z\",\n \"registered_agents_id\": -62745836\n }\n ],\n \"total\": 73937038,\n \"page\": 72027872,\n \"size\": 73888144\n}"
17321732
},
17331733
{
17341734
"name": "Validation Error",
@@ -1828,7 +1828,7 @@
18281828
}
18291829
],
18301830
"cookie": [],
1831-
"body": "[\n {\n \"agent_id_string\": \"cupidatat dolor ex\",\n \"first_registered\": \"1971-07-16T15:25:55.040Z\",\n \"last_registered\": \"1986-11-15T21:36:02.558Z\",\n \"registered_agents_id\": -13167962\n },\n {\n \"agent_id_string\": \"ea labore reprehenderit\",\n \"first_registered\": \"1969-05-15T01:43:07.486Z\",\n \"last_registered\": \"1982-06-22T00:28:08.921Z\",\n \"registered_agents_id\": 26003950\n }\n]"
1831+
"body": "[\n {\n \"agent_endpoint_uri\": \"cupidatat dolor ex\",\n \"first_registered\": \"1971-07-16T15:25:55.040Z\",\n \"last_registered\": \"1986-11-15T21:36:02.558Z\",\n \"registered_agents_id\": -13167962\n },\n {\n \"agent_endpoint_uri\": \"ea labore reprehenderit\",\n \"first_registered\": \"1969-05-15T01:43:07.486Z\",\n \"last_registered\": \"1982-06-22T00:28:08.921Z\",\n \"registered_agents_id\": 26003950\n }\n]"
18321832
}
18331833
]
18341834
},
@@ -1907,7 +1907,7 @@
19071907
}
19081908
],
19091909
"cookie": [],
1910-
"body": "{\n \"agent_id_string\": \"dolor ut culpa\",\n \"first_registered\": \"1959-08-06T13:00:08.389Z\",\n \"last_registered\": \"1963-05-07T15:20:50.166Z\",\n \"registered_agents_id\": -37321482\n}"
1910+
"body": "{\n \"agent_endpoint_uri\": \"dolor ut culpa\",\n \"first_registered\": \"1959-08-06T13:00:08.389Z\",\n \"last_registered\": \"1963-05-07T15:20:50.166Z\",\n \"registered_agents_id\": -37321482\n}"
19111911
},
19121912
{
19131913
"name": "Validation Error",
@@ -1969,18 +1969,18 @@
19691969
}
19701970
],
19711971
"url": {
1972-
"raw": "{{baseUrl}}/agents/name/:agent_id_string",
1972+
"raw": "{{baseUrl}}/agents/name/:agent_endpoint_uri",
19731973
"host": [
19741974
"{{baseUrl}}"
19751975
],
19761976
"path": [
19771977
"agents",
19781978
"name",
1979-
":agent_id_string"
1979+
":agent_endpoint_uri"
19801980
],
19811981
"variable": [
19821982
{
1983-
"key": "agent_id_string",
1983+
"key": "agent_endpoint_uri",
19841984
"value": "consequat proident culpa quis sed",
19851985
"description": "(Required) "
19861986
}
@@ -1994,18 +1994,18 @@
19941994
"method": "GET",
19951995
"header": [],
19961996
"url": {
1997-
"raw": "{{baseUrl}}/agents/name/:agent_id_string",
1997+
"raw": "{{baseUrl}}/agents/name/:agent_endpoint_uri",
19981998
"host": [
19991999
"{{baseUrl}}"
20002000
],
20012001
"path": [
20022002
"agents",
20032003
"name",
2004-
":agent_id_string"
2004+
":agent_endpoint_uri"
20052005
],
20062006
"variable": [
20072007
{
2008-
"key": "agent_id_string",
2008+
"key": "agent_endpoint_uri",
20092009
"value": "consequat proident culpa quis sed",
20102010
"description": "(Required) "
20112011
}
@@ -2022,26 +2022,26 @@
20222022
}
20232023
],
20242024
"cookie": [],
2025-
"body": "{\n \"agent_id_string\": \"dolor ut culpa\",\n \"first_registered\": \"1959-08-06T13:00:08.389Z\",\n \"last_registered\": \"1963-05-07T15:20:50.166Z\",\n \"registered_agents_id\": -37321482\n}"
2025+
"body": "{\n \"agent_endpoint_uri\": \"dolor ut culpa\",\n \"first_registered\": \"1959-08-06T13:00:08.389Z\",\n \"last_registered\": \"1963-05-07T15:20:50.166Z\",\n \"registered_agents_id\": -37321482\n}"
20262026
},
20272027
{
20282028
"name": "Validation Error",
20292029
"originalRequest": {
20302030
"method": "GET",
20312031
"header": [],
20322032
"url": {
2033-
"raw": "{{baseUrl}}/agents/name/:agent_id_string",
2033+
"raw": "{{baseUrl}}/agents/name/:agent_endpoint_uri",
20342034
"host": [
20352035
"{{baseUrl}}"
20362036
],
20372037
"path": [
20382038
"agents",
20392039
"name",
2040-
":agent_id_string"
2040+
":agent_endpoint_uri"
20412041
],
20422042
"variable": [
20432043
{
2044-
"key": "agent_id_string",
2044+
"key": "agent_endpoint_uri",
20452045
"value": "consequat proident culpa quis sed",
20462046
"description": "(Required) "
20472047
}
@@ -2157,7 +2157,7 @@
21572157
}
21582158
],
21592159
"cookie": [],
2160-
"body": "{\n \"items\": [\n {\n \"agent_id_string\": \"pariatur sed Lorem nostrud aliquip\",\n \"first_registered\": \"2011-08-09T03:14:19.673Z\",\n \"last_registered\": \"2014-02-12T10:02:52.538Z\",\n \"registered_agents_id\": 62347121\n },\n {\n \"agent_id_string\": \"minim aliquip velit dolore laborum\",\n \"first_registered\": \"1947-06-29T16:55:50.710Z\",\n \"last_registered\": \"1943-07-15T07:03:23.307Z\",\n \"registered_agents_id\": -37869581\n }\n ],\n \"total\": 23463388,\n \"page\": 94004728,\n \"size\": 47500231\n}"
2160+
"body": "{\n \"items\": [\n {\n \"agent_endpoint_uri\": \"pariatur sed Lorem nostrud aliquip\",\n \"first_registered\": \"2011-08-09T03:14:19.673Z\",\n \"last_registered\": \"2014-02-12T10:02:52.538Z\",\n \"registered_agents_id\": 62347121\n },\n {\n \"agent_endpoint_uri\": \"minim aliquip velit dolore laborum\",\n \"first_registered\": \"1947-06-29T16:55:50.710Z\",\n \"last_registered\": \"1943-07-15T07:03:23.307Z\",\n \"registered_agents_id\": -37869581\n }\n ],\n \"total\": 23463388,\n \"page\": 94004728,\n \"size\": 47500231\n}"
21612161
},
21622162
{
21632163
"name": "Validation Error",

anms-core/integration_test/openapi.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@
148148
}
149149
}
150150
},
151-
"/agents/name/{agent_id_string}": {
151+
"/agents/name/{agent_endpoint_uri}": {
152152
"get": {
153153
"tags": [
154154
"ARIs"
155155
],
156156
"summary": "Registered Agent By Name",
157-
"operationId": "registered_agent_by_name_agents_name__agent_id_string__get",
157+
"operationId": "registered_agent_by_name_agents_name__agent_endpoint_uri__get",
158158
"parameters": [
159159
{
160160
"required": true,
161161
"schema": {
162162
"title": "Agent Id String",
163163
"type": "string"
164164
},
165-
"name": "agent_id_string",
165+
"name": "agent_endpoint_uri",
166166
"in": "path"
167167
}
168168
],
@@ -4187,7 +4187,7 @@
41874187
"title": "RegisteredAgent",
41884188
"type": "object",
41894189
"properties": {
4190-
"agent_id_string": {
4190+
"agent_endpoint_uri": {
41914191
"title": "Agent Id String",
41924192
"type": "string"
41934193
},

0 commit comments

Comments
 (0)