Skip to content

Commit a6afc57

Browse files
authored
Merge branch 'main' into feature/light-compose-profile
2 parents 4541a4b + 63b5d63 commit a6afc57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+17143
-20038
lines changed

.github/workflows/anms-core.yaml

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,8 @@ on:
77
- anms-core/**
88

99
jobs:
10-
unit-test:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v4
15-
with:
16-
submodules: recursive
17-
- name: Set up Python
18-
uses: actions/setup-python@v5
19-
with:
20-
python-version: "3.10"
21-
- name: Install dependencies
22-
run: |
23-
pip3 install deps/dtnma-ace
24-
pip3 install deps/dtnma-camp
25-
- name: Install
26-
working-directory: anms-core
27-
run: pip3 install -e '.[test]'
28-
- name: Run test
29-
working-directory: anms-core
30-
run: PYTHONPATH=src python3 -m pytest --junit-xml=testresults.xml --cov=anms test
31-
3210
flake8:
33-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-24.04
3412
steps:
3513
- name: Checkout repository
3614
uses: actions/checkout@v4
@@ -39,7 +17,7 @@ jobs:
3917
- name: Set up Python
4018
uses: actions/setup-python@v5
4119
with:
42-
python-version: "3.10"
20+
python-version: "3.9"
4321
- name: Install dependencies
4422
run: |
4523
pip3 install deps/dtnma-ace

.github/workflows/aricodec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:
20-
python-version: "3.10"
20+
python-version: "3.9"
2121
- name: Install dependencies
2222
run: |
2323
pip3 install deps/dtnma-ace

.github/workflows/build-test.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ jobs:
4646
sudo mkdir /run/anms
4747
- name: Start
4848
run: |
49-
podman compose ${ANMS_COMPOSE_OPTS} up -d --force-recreate
50-
podman compose ${TESTENV_COMPOSE_OPTS} up -d --force-recreate
51-
sleep 5
49+
podman compose ${TESTENV_COMPOSE_OPTS} up -d --force-recreate --wait
50+
podman compose ${ANMS_COMPOSE_OPTS} up -d --force-recreate --wait
5251
- name: Status
5352
run: |
5453
for BADSTATUS in stopped restarting; do
@@ -99,7 +98,9 @@ jobs:
9998
echo "GITHUB_WORKSPACE=${{ github.workspace }}"
10099
ls -al ${{ github.workspace }}
101100
- name: Build Main
102-
run: docker compose ${ANMS_COMPOSE_OPTS} build
101+
run: |
102+
docker compose ${ANMS_COMPOSE_OPTS} build builder-base builder-init builder-acelib
103+
docker compose ${ANMS_COMPOSE_OPTS} build
103104
- name: Build Agents
104105
run: docker compose ${TESTENV_COMPOSE_OPTS} build
105106
- name: Build Volume
@@ -108,9 +109,8 @@ jobs:
108109
sudo mkdir /run/anms
109110
- name: Start
110111
run: |
111-
docker compose ${ANMS_COMPOSE_OPTS} up -d --force-recreate
112-
docker compose ${TESTENV_COMPOSE_OPTS} up -d --force-recreate
113-
sleep 5
112+
docker compose ${TESTENV_COMPOSE_OPTS} up -d --force-recreate --wait
113+
docker compose ${ANMS_COMPOSE_OPTS} up -d --force-recreate --wait
114114
- name: Status
115115
run: |
116116
for BADSTATUS in stopped restarting; do

.github/workflows/sonarcloud.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
sonarqube:
10+
name: SonarQube
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- name: SonarQube Scan
17+
uses: SonarSource/sonarqube-scan-action@v5
18+
env:
19+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/transcoder.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
flake8:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-24.04
1212
steps:
1313
- name: Checkout repository
1414
uses: actions/checkout@v4
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:
20-
python-version: "3.10"
20+
python-version: "3.9"
2121
- name: Install flake8
2222
working-directory: transcoder
2323
run: pip3 install flake8

anms-core/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ COPY --chmod=755 docker-entrypoint.sh /usr/local/bin/
4848
USER ${APP_USER}
4949
CMD ["/usr/local/bin/docker-entrypoint.sh"]
5050

51-
HEALTHCHECK --interval=60s --timeout=60s --retries=20 \
51+
HEALTHCHECK --start-period=10s --interval=60s --timeout=10s --retries=20 \
5252
CMD ["curl", "-sq", "-o/dev/null", "http://localhost:5555/hello"]

anms-core/anms/asgi/server.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,7 @@
3535
def main() -> None:
3636
config = ConfigBuilder.get_config()
3737

38-
# SSL Settings
39-
should_start_with_ssl = (
40-
config['SERVER_SSL'] is True
41-
and config['SERVER_BEHIND_PROXY'] is False
42-
and isinstance(config['SERVER_SSL_CRT'], str)
43-
and isinstance(config['SERVER_SSL_KEY'], str)
44-
)
45-
# Preferred method is to use NGINX/reverse proxy with SSL Termination
46-
if should_start_with_ssl:
47-
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) # disable SSLv3
48-
ssl_context.options |= ssl.OP_NO_TLSv1 # disable TLSv1
49-
ssl_context.options |= ssl.OP_NO_TLSv1_1 # disable TLSv1.1
50-
ssl_crt_path = config['SERVER_SSL_CRT']
51-
ssl_key_path = config['SERVER_SSL_KEY']
52-
ssl_key_pass = config['SERVER_SSL_PWD']
53-
# https://github.com/encode/uvicorn/issues/806
54-
uvicorn.run(f"{__name__}:app", host=config['SERVER_BIND'], port=config['SERVER_PORT'],
55-
log_config=None, log_level=config['LOGGER_LEVEL'], access_log=False, # We use our own logger
56-
reload=config['DEBUG'],
57-
ssl_certfile=ssl_crt_path, ssl_keyfile=ssl_key_path, ssl_keyfile_password=ssl_key_pass,
58-
ssl_version=ssl_context.protocol, ssl_ciphers=":".join(map(lambda c: c["name"], ssl_context.get_ciphers())) # type: ignore
59-
)
60-
else:
61-
uvicorn.run(f"{__name__}:app", host=config['SERVER_BIND'], port=config['SERVER_PORT'],
38+
uvicorn.run(f"{__name__}:app", host=config['SERVER_BIND'], port=config['SERVER_PORT'],
6239
log_config=None, log_level=config['LOGGER_LEVEL'], access_log=False, # We use our own logger
6340
reload=config['DEBUG'])
6441

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

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,26 @@ async def report_ac(agent_id: str, correlator_nonce: int):
101101
agent_id = agent_id.strip()
102102
final_res = []
103103
ari = None
104+
dec = ace.ari_cbor.Decoder()
105+
buf = io.StringIO()
104106
# Load in adms
105107
# get command that made the report as first entry
106108
stmt = select(ExecutionSet).where(and_(ExecutionSet.agent_id == agent_id, ExecutionSet.correlator_nonce == correlator_nonce) )
107109
async with get_async_session() as session:
108110
result: Result = await session.scalars(stmt)
109-
result = result.one_or_none()
110-
exec_set_entry=["time"]
111+
112+
# there should only be one execution per agent per correlator_nonce
113+
# in the event that two occur pull the latest one
114+
result = result.all()
115+
exec_set_dir = {}
116+
111117
if result:
118+
result = result[-1]
112119
exec_set = result.entries.hex()
113120
# use ACE to handle report set decoding
114121
in_text = '0x'+exec_set
115122
try:
116123
in_bytes = ace.cborutil.from_hexstr(in_text)
117-
dec = ace.ari_cbor.Decoder()
118124
ari = dec.decode(io.BytesIO(in_bytes))
119125

120126
except Exception as err:
@@ -125,26 +131,28 @@ async def report_ac(agent_id: str, correlator_nonce: int):
125131
if type(ari.value) == ace.ari.ExecutionSet:
126132
try:
127133
enc = ace.ari_text.Encoder()
128-
buf = io.StringIO()
129134
# run through targets and their parameters to get all things parts translated
130135
for targ in ari.value.targets:
131-
if targ.params:
132-
for param in targ.params:
133-
enc.encode(param, buf)
136+
buf = io.StringIO()
137+
exec_set_entry=["time"]
138+
enc.encode(targ, buf)
139+
out_text_targ = buf.getvalue()
140+
if targ is ace.LiteralARI and targ.type_id is ace.StructType.AC:
141+
for part in targ.value:
142+
buf = io.StringIO()
143+
enc.encode(part, buf)
134144
out_text = buf.getvalue()
135-
ari_val = await transcoder.transcoder_put_await_str(out_text)
136-
exec_set_entry.append(ari_val['data'])
145+
exec_set_entry.append(out_text)
137146
else:
138-
enc.encode(targ, buf)
139-
out_text = buf.getvalue()
140-
ari_val = await transcoder.transcoder_put_await_str(out_text)
141-
exec_set_entry.append(ari_val['data'])
142-
147+
exec_set_entry.append(out_text_targ)
148+
149+
exec_set_dir[out_text_targ] = [exec_set_entry]
150+
143151
except Exception as err:
144152
logger.info(err)
145153

146154

147-
final_res.append(exec_set_entry)
155+
# final_res.append(exec_set_entry)
148156
ari = None
149157
stmt = select(Report).where(and_(Report.agent_id == agent_id, Report.correlator_nonce == correlator_nonce) )
150158
async with get_async_session() as session:
@@ -157,7 +165,6 @@ async def report_ac(agent_id: str, correlator_nonce: int):
157165
in_text = '0x'+rpt_set
158166
try:
159167
in_bytes = ace.cborutil.from_hexstr(in_text)
160-
dec = ace.ari_cbor.Decoder()
161168
ari = dec.decode(io.BytesIO(in_bytes))
162169

163170
except Exception as err:
@@ -173,13 +180,17 @@ async def report_ac(agent_id: str, correlator_nonce: int):
173180
for item in rpt.items:
174181
buf = io.StringIO()
175182
enc.encode(item, buf)
176-
out_text = buf.getvalue()
177-
ari_val = await transcoder.transcoder_put_await_str(out_text)
178-
addition.append(ari_val['data'])
183+
out_text = buf.getvalue()
184+
addition.append(out_text)
185+
buf = io.StringIO()
186+
enc.encode(rpt.source, buf)
187+
out_text = buf.getvalue()
188+
189+
exec_set_dir[out_text].append(addition)
179190
except Exception as err:
180191
logger.error(err)
181-
182-
if addition not in final_res:
183-
final_res.append(addition)
184-
return final_res
192+
193+
194+
195+
return list(exec_set_dir.values())
185196

anms-core/anms/routes/network_manager.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ async def nm_register_agent(addr: Data):
8181
return request.status_code
8282

8383

84-
# PUT /agents/idx/{idx}/hex Body is CBOR-encoded HEX ARI to send. $idx is index of node from agents listing
85-
@router.put("/agents/idx/{idx}/hex", status_code=status.HTTP_200_OK)
86-
async def nm_put_hex_idx(idx: str, ari: Data):
87-
url = nm_url + "/agents/idx/{}/send?form=hex".format(idx)
88-
logger.info('post to nm manager %s with idx %s and data %s' % (url, idx, ari.data))
89-
try:
90-
request = requests.post(url=url, data=ari.data, headers={'Content-Type': 'text/plain'})
91-
except Exception:
92-
return status.HTTP_500_INTERNAL_SERVER_ERROR
93-
return request.status_code
94-
95-
9684
# PUT /agents/eid/{eid}/hex Body is CBOR-encoded HEX ARI to send. $eid is the agent to query
9785
@router.put("/agents/eid/{eid}/hex", status_code=status.HTTP_200_OK)
9886
def nm_put_hex_eid(eid: str, ari: Data):

anms-core/anms/routes/system_status.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,3 @@ async def sys_status_get_services_status():
137137
statuses = get_containers_status()
138138
logger.debug(f"Checking all services' status: {str(statuses)}")
139139
return json.dumps(statuses)
140-
141-
# POST /agents Register a new Agent at specified eid (in body of request)
142-
@router.post("/agents",status_code=status.HTTP_200_OK)
143-
async def nm_register_agent(addr: Address):
144-
url = nm_url + "/agents"
145-
logger.info('POST to nm manager %s with addr %s', url, addr)
146-
request = requests.post(url=url, data=addr.data)
147-
return request.status_code
148-
149-
# PUT /agents/eid/{addr}/clear_tables Clear all tables for given node
150-
@router.put("/agents/eid/{addr}/clear_tables",status_code=status.HTTP_200_OK)
151-
async def nm_clear_tables(addr: str):
152-
url = nm_url + "/agents/eid/{}/clear_tables".format(addr)
153-
logger.info('PUT to nm manager %s with addr %s', url, addr)
154-
request = requests.put(url=url)
155-
return request.status_code

0 commit comments

Comments
 (0)