Skip to content

Commit 92f0043

Browse files
author
David Linko
committed
handling ADM upload and report printing
1 parent 3cb3fc8 commit 92f0043

File tree

24 files changed

+315
-306
lines changed

24 files changed

+315
-306
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ RENDERER_HOST_PORT=${DOCKER_CTR_PREFIX}grafana-image-renderer:${RENDERER_PORT}
5252
ION_MGR_PORT=8089
5353
HTTP_PORT:80
5454
SOCKDIR=/var/tmp/nm
55+
56+
ADM_PATH=deps/dtnma-ace/tests/adms

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,11 @@
2929

3030
# Shared properties
3131
class RptEntryBase(BaseModel):
32-
time: Optional[int] = None
32+
reference_time: Optional[str] = None
3333
agent_id: Optional[str] = None
34-
report_name: Optional[str] = None
35-
ADM: Optional[str] = None
36-
report_id: Optional[int] = None
37-
string_values: Optional[str] = None
38-
uint_values: Optional[str] = None
39-
int_values: Optional[str] = None
40-
real32_values: Optional[str] = None
41-
real64_values: Optional[str] = None
42-
uvast_values: Optional[str] = None
43-
vast_values: Optional[str] = None
44-
object_id_values: Optional[str] = None
45-
AC_id_values: Optional[str] = None
46-
TNVC_id_values: Optional[str] = None
34+
correlator_nonce: Optional[str] = None
35+
report_list: Optional[str] = None
36+
ari_rptset_id: Optional[int] = None
4737

4838

4939
class RptEntryBaseInDBBase(RptEntryBase):

anms-core/anms/components/schemas/adm.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525

2626
from pydantic import BaseModel
2727

28-
class NamespaceViewSchema(BaseModel):
28+
class DataModelSchema(BaseModel):
29+
data_model_id: int
30+
namespace_type: str
31+
name: str
2932
enumeration: int
30-
data_model_name: str
31-
name_string: Optional[str]
32-
version_name: Optional[str]
33-
use_desc: Optional[str]
33+
namespace: Optional[str] = ""
34+
version_name: Optional[str] = "0.0.0"
35+
use_desc: Optional[str] = ""

anms-core/anms/models/relational/adms/namespace_view.py renamed to anms-core/anms/models/relational/adms/data_model_view.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424
from typing import Any, Dict, Optional
2525

26-
from sqlalchemy import (Column, Integer, String, select)
26+
from sqlalchemy import (Column, Integer, String, select, and_)
2727
from sqlalchemy import exc
2828
from sqlalchemy.ext.asyncio import AsyncSession
2929

@@ -34,14 +34,16 @@
3434
logger = OpenSearchLogger(__name__).logger
3535
config = ConfigBuilder.get_config()
3636

37-
class Namespace(Model):
38-
__tablename__ = 'namespace'
37+
class DataModel(Model):
38+
__tablename__ = 'data_model'
3939
data_model_id = Column(Integer, unique=True, primary_key=True)
4040
namespace_type = Column(String)
41-
issuing_org = Column(String)
42-
name_string = Column(String)
41+
name = Column(String)
42+
enumeration = Column(Integer)
43+
namespace = Column(String)
4344
version_name = Column(String)
44-
45+
use_desc = Column(String)
46+
4547
def __repr__(self) -> str:
4648
return self.as_dict().__repr__()
4749

@@ -51,21 +53,10 @@ def as_dict(self) -> Dict[str, Any]:
5153
}
5254
return dict_obj
5355

54-
55-
56-
57-
class NamespaceView(Model):
58-
__tablename__ = 'vw_namespace'
59-
enumeration = Column(Integer, unique=True, primary_key=True)
60-
data_model_name = Column(String)
61-
name_string = Column(String)
62-
version_name = Column(String)
63-
use_desc = Column(String)
64-
6556
@classmethod
6657
async def getall(
6758
cls, session: AsyncSession = None
68-
) -> Optional["NamespaceView"]:
59+
) -> Optional["DataModel"]:
6960
'''
7061
Retrieve all adms
7162
@@ -78,37 +69,37 @@ async def getall(
7869
async with get_async_session() as session:
7970
result = await session.execute(stmt)
8071
except exc.SQLAlchemyError as e:
81-
logger.error(f"NamespaceView::getall SQLAlchemyError: {str(e.args)}")
72+
logger.error(f"DataModel::getall SQLAlchemyError: {str(e.args)}")
8273
return None
8374

84-
namespace_view_rows = result.all()
85-
namespace_views = None
86-
if namespace_view_rows != None:
87-
namespace_views = [row['NamespaceView'] for row in namespace_view_rows]
75+
data_model_view_rows = result.all()
76+
data_model_views = None
77+
if data_model_view_rows != None:
78+
data_model_views = [row['DataModel'] for row in data_model_view_rows]
8879

89-
return namespace_views
80+
return data_model_views
9081

9182
@classmethod
9283
async def get(
93-
cls, enumeration: Integer, session: AsyncSession = None
94-
) -> Optional["NamespaceView"]:
84+
cls, enumeration: Integer, namespace: String, session: AsyncSession = None
85+
) -> Optional["DataModel"]:
9586
'''
9687
Retrieve all adms
9788
9889
'''
99-
stmt = select(cls).where(cls.enumeration == enumeration)
90+
stmt = select(cls).where(and_(cls.enumeration == enumeration, cls.namespace == namespace))
10091
try:
10192
if session:
10293
result = await session.execute(stmt)
10394
else:
10495
async with get_async_session() as session:
10596
result = await session.execute(stmt)
10697
except exc.SQLAlchemyError as e:
107-
logger.error(f"NamespaceView::get SQLAlchemyError: {str(e.args)}")
98+
logger.error(f"DataModel::get SQLAlchemyError: {str(e.args)}")
10899
return None
109100

110-
namespace_view_row = result.scalar_one_or_none()
111-
return namespace_view_row
101+
data_model_view_row = result.scalar_one_or_none()
102+
return data_model_view_row
112103

113104
def __repr__(self) -> str:
114105
return self.as_dict().__repr__()

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -81,45 +81,6 @@ def as_dict(self) -> Dict[str, Any]:
8181
return dict_obj
8282

8383

84-
class ADM(Model):
85-
__tablename__ = 'adm'
86-
data_model_id = Column(Integer, primary_key=True)
87-
data_model_name = Column(String)
88-
enumeration = Column(Integer)
89-
namespace_type = Column(String)
90-
use_desc = Column(String)
91-
92-
def __repr__(self) -> str:
93-
return self.as_dict().__repr__()
94-
95-
def as_dict(self) -> Dict[str, Any]:
96-
dict_obj = {
97-
c.name: getattr(self, c.name) for c in self.__table__.columns
98-
}
99-
100-
return dict_obj
101-
102-
@classmethod
103-
async def get(
104-
cls, enumeration: Integer, session: AsyncSession = None
105-
) -> Optional["adm"]:
106-
'''
107-
Retrieve all adms
108-
109-
'''
110-
stmt = select(cls).where(cls.enumeration == enumeration)
111-
try:
112-
if session:
113-
result = await session.execute(stmt)
114-
else:
115-
async with get_async_session() as session:
116-
result = await session.execute(stmt)
117-
except exc.SQLAlchemyError as e:
118-
logger.error(f"ADM::get SQLAlchemyError: {str(e.args)}")
119-
return None
120-
121-
adm_row = result.scalar_one_or_none()
122-
return adm_row
12384

12485

12586
class ObjMetadata(Model):
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2023 The Johns Hopkins University Applied Physics
5+
# Laboratory LLC.
6+
#
7+
# This file is part of the Asynchronous Network Management System (ANMS).
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# This work was performed for the Jet Propulsion Laboratory, California
20+
# Institute of Technology, sponsored by the United States Government under
21+
# the prime contract 80NM0018D0004 between the Caltech and NASA under
22+
# subcontract 1658085.
23+
#
24+
from typing import Any
25+
from typing import Dict
26+
27+
from anms.models.relational import Model
28+
from sqlalchemy import Column
29+
from sqlalchemy import Integer
30+
from sqlalchemy import String
31+
from sqlalchemy import LargeBinary
32+
33+
34+
# class for vw_ctrl_definition used for build ari
35+
class ExecutionSet(Model):
36+
__tablename__ = 'vw_execution_set'
37+
execution_set_id = Column(Integer, primary_key=True)
38+
correlator_nonce = Column(Integer)
39+
use_desc = Column(String)
40+
agent_id = Column(String)
41+
num_entries = Column(Integer)
42+
entries = Column(LargeBinary)
43+
44+
def __repr__(self) -> str:
45+
return self.as_dict().__repr__()
46+
47+
def as_dict(self) -> Dict[str, Any]:
48+
dict_obj = {
49+
'execution_set_id': getattr(self, 'execution_set_id'),
50+
'correlator_nonce': getattr(self, 'correlator_nonce'),
51+
'use_desc': getattr(self, 'use_desc'),
52+
'agent_id': getattr(self, 'agent_id'),
53+
'num_entries': getattr(self, 'num_entries'),
54+
'entries': getattr(self, 'entries')
55+
}
56+
57+
return dict_obj

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@
3333

3434
# class for vw_ctrl_definition used for build ari
3535
class Report(Model):
36-
__tablename__ = 'ari_rpt_set'
37-
reference_time = Column(Integer, nullable=False)
38-
correlator_nonce = Column(Integer)
39-
agent_id = Column(String)
36+
__tablename__ = 'ari_rptset'
4037
ari_rptset_id = Column(Integer, primary_key=True)
38+
correlator_nonce = Column(Integer)
39+
reference_time = Column(Integer)
4140
report_list = Column(String)
4241
report_list_cbor = Column(LargeBinary)
43-
42+
agent_id = Column(String)
4443
def __repr__(self) -> str:
4544
return self.as_dict().__repr__()
4645

4746
def as_dict(self) -> Dict[str, Any]:
48-
dict_obj = {'ari_rpt_set.reference_time': getattr(self, 'reference_time'),
49-
'ari_rpt_set.correlator_nonce': getattr(self, 'correlator_nonce'),
50-
'ari_rpt_set.agent_id': getattr(self, 'agent_id'),
51-
'ari_rpt_set.ari_rptset_id': getattr(self, 'ari_rptset_id'),
52-
'ari_rpt_set.report_list': getattr(self, 'report_list'),
53-
'ari_rpt_set.report_list_cbor': getattr(self, 'report_list_cbor'),
47+
dict_obj = {
48+
'ari_rptset.ari_rptset_id': getattr(self, 'ari_rptset_id'),
49+
'ari_rptset.correlator_nonce': getattr(self, 'correlator_nonce'),
50+
'ari_rptset.reference_time': getattr(self, 'reference_time'),
51+
'ari_rptset.report_list': getattr(self, 'report_list'),
52+
# 'ari_rptset.report_list_cbor': getattr(self, 'report_list_cbor'),
53+
'ari_rptset.agent_id': getattr(self, 'agent_id')
5454
}
5555

5656
return dict_obj

0 commit comments

Comments
 (0)