Skip to content
Snippets Groups Projects
Commit f6120f0b authored by torrespel's avatar torrespel
Browse files

Celery in services folder

parent f47caf83
No related branches found
No related tags found
1 merge request!120Ocf120 implement eventreq 2
Pipeline #13145 passed
......@@ -60,6 +60,7 @@ class EventSubscriptionsOperations(Resource):
def __check_event_req(self, event_subscription):
current_app.logger.debug("Checking event requirement.")
expired_at = None
if event_subscription.event_req.mon_dur:
if event_subscription.event_req.mon_dur > datetime.now(timezone.utc):
expired_at = event_subscription.event_req.mon_dur
......
FROM labs.etsi.org:5050/ocf/capif/python:3-slim-bullseye
WORKDIR /celery_app
WORKDIR /celery
COPY requirements.txt /celery_app/
COPY requirements.txt /celery/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /celery_app
COPY . /celery
RUN chmod +x /celery_app/start_celery.sh
RUN chmod +x /celery/start_celery.sh
CMD ["/celery_app/start_celery.sh"]
CMD ["/celery/start_celery.sh"]
# celery/tasks.py
from celery import Celery
from datetime import datetime, timedelta, timezone
from datetime import datetime, timezone
import pymongo
import os
from bson.codec_options import CodecOptions
from config import Config
import aiohttp
import asyncio
from dateutil import parser
# Celery Configuration
# celery = Celery(
# "notifications",
# broker=os.environ.get("CELERY_BROKER_URL", "redis://redis:6379/0"),
# backend=os.environ.get("CELERY_RESULT_BACKEND", "redis://redis:6379/0")
# )
celery = Celery(
"notifications",
broker=os.environ.get("CELERY_BROKER_URL", "redis://redis:6379/0"),
backend=os.environ.get("CELERY_RESULT_BACKEND", "redis://redis:6379/0")
broker=f"redis://{os.getenv("REDIS_HOST")}:{os.getenv("REDIS_PORT")}/0",
backend=f"redis://{os.getenv("REDIS_HOST")}:{os.getenv("REDIS_PORT")}/0"
)
celery.conf.beat_schedule = {
......@@ -103,7 +108,7 @@ async def send(url, data):
@celery.task(name="celery.tasks.check_notifications_collection")
def my_periodic_task():
print("Checking notifications collection...")
# print("Checking notifications collection...")
while True:
try:
notification_data = notifications_col.find_one_and_delete(
......@@ -121,4 +126,4 @@ def my_periodic_task():
except Exception as e:
print(f"Error sending notification: {e}")
print("Finished processing notifications.")
# print("Finished processing notifications.")
......@@ -177,23 +177,25 @@ services:
celery_worker:
build:
context: ${SERVICES_DIR}/TS29222_CAPIF_Events_API/capif_events/celery_app
context: ${SERVICES_DIR}/celery
environment:
- CELERY_MODE=worker
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
- redis
- mongo
celery_beat:
build:
context: ${SERVICES_DIR}/TS29222_CAPIF_Events_API/capif_events/celery_app
context: ${SERVICES_DIR}/celery
environment:
- CELERY_MODE=beat
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
- redis
- mongo
api-invocation-logs:
build:
context: ${SERVICES_DIR}/TS29222_CAPIF_Logging_API_Invocation_API
......
......@@ -52,221 +52,6 @@ Invoker subscribe to Service API Available
${notification_events_on_mock_server}= Set Variable ${resp.json()}
Invoker subscribe to Service API Availables
[Tags] event_filter-7 mockserver smoke
# Initialize Mock server
Init Mock Server
# Register Providers
## Default Provider 1 Registration
${register_user_info_provider_1}= Provider Default Registration provider_username=${PROVIDER_USERNAME}_1
${aef_id_1}= Set Variable
... ${register_user_info_provider_1['aef_roles']['${AEF_PROVIDER_USERNAME}_1']['aef_id']}
## Publish service_1 API
${service_api_description_published_1}
... ${provider_resource_url_1}
... ${provider_request_body_1}=
... Publish Service Api
... ${register_user_info_provider_1}
... service_name=service_1
## Default Provider 2 Registration
${register_user_info_provider_2}= Provider Default Registration provider_username=${PROVIDER_USERNAME}_2
${aef_id_2}= Set Variable
... ${register_user_info_provider_2['aef_roles']['${AEF_PROVIDER_USERNAME}_2']['aef_id']}
## Publish service_2 API
${service_api_description_published_2}
... ${provider_resource_url_2}
... ${provider_request_body_2}=
... Publish Service Api
... ${register_user_info_provider_2}
... service_name=service_2
## Store apiId1 and apiId2 for further use
${service_api_id_1}= Set Variable ${service_api_description_published_1['apiId']}
${service_api_id_2}= Set Variable ${service_api_description_published_2['apiId']}
# Register Invokers
## Default Invoker 1 Registration and Onboarding
${register_user_info_invoker_1} ${invoker_url_1} ${request_body_1}= Invoker Default Onboarding
... invoker_username=${INVOKER_USERNAME}_1
## Default Invoker 2 Registration and Onboarding
${register_user_info_invoker_2} ${invoker_url_2} ${request_body_2}= Invoker Default Onboarding
... invoke_username=${INVOKER_USERNAME}_2
## Store apiInvokerIds for further use
${api_invoker_id_1}= Set Variable ${register_user_info_invoker_1['api_invoker_id']}
${api_invoker_id_2}= Set Variable ${register_user_info_invoker_2['api_invoker_id']}
# Subscribe to events
## Event lists
${events_list}= Create List SERVICE_API_INVOCATION_SUCCESS SERVICE_API_INVOCATION_FAILURE
## Event filters
${event_filter_empty}= Create Capif Event Filter
${event_filter_api_invoker_ids}= Create Capif Event Filter apiInvokerIds=${api_invoker_id_1}
${event_filter_api_ids}= Create Capif Event Filter apiIds=${service_api_id_1}
${event_filter_aef_ids}= Create Capif Event Filter aefIds=${aef_id_2}
${event_filter_api_ids_and_aef_ids}= Create Capif Event Filter
... apiIds=${service_api_id_2}
... aefIds=${aef_id_2}
${event_filter_api_ids_and_api_invoker_ids}= Create Capif Event Filter
... apiInvokerIds=${api_invoker_id_2}
... apiIds=${service_api_id_2}
${event_filter_aef_ids_and_api_invoker_ids}= Create Capif Event Filter
... apiInvokerIds=${api_invoker_id_2}
... aefIds=${aef_id_1}
${event_filter_api_ids_aef_ids_and_api_invoker_ids}= Create Capif Event Filter
... apiInvokerIds=${api_invoker_id_2}
... aefIds=${aef_id_2}
... apiIds=${service_api_id_2}
## Subscription to Events 1
${event_filters}= Create List ${event_filter_api_ids} ${event_filter_api_ids}
${subscription_id_1}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
## Subscription to Events 2
${event_filters}= Create List ${event_filter_aef_ids} ${event_filter_aef_ids}
${subscription_id_2}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
## Subscription to Events 3
${event_filters}= Create List ${event_filter_api_invoker_ids} ${event_filter_api_invoker_ids}
${subscription_id_3}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
## Subscription to Events 4
${event_filters}= Create List ${event_filter_api_ids_and_aef_ids} ${event_filter_api_ids_and_aef_ids}
${subscription_id_4}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
## Subscription to Events 5
${event_filters}= Create List
... ${event_filter_api_ids_and_api_invoker_ids}
... ${event_filter_api_ids_and_api_invoker_ids}
${subscription_id_5}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
## Subscription to Events 6
${event_filters}= Create List
... ${event_filter_aef_ids_and_api_invoker_ids}
... ${event_filter_aef_ids_and_api_invoker_ids}
${subscription_id_6}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
## Subscription to Events 7
${event_filters}= Create List
... ${event_filter_api_ids_aef_ids_and_api_invoker_ids}
... ${event_filter_api_ids_aef_ids_and_api_invoker_ids}
${subscription_id_7}=
... Subscribe provider ${register_user_info_provider_1} to events ${events_list} with event filters ${event_filters}
# 1.Log entry for service_1 and invoker_1
${request_body_log_1}= Send Log Message to CAPIF
... ${service_api_id_1}
... service_1
... ${register_user_info_invoker_1}
... ${register_user_info_provider_1}
... 200
... 400
# 2.Log entry for service_2 and invoker_1
${request_body_log_2}= Send Log Message to CAPIF
... ${service_api_id_2}
... service_2
... ${register_user_info_invoker_1}
... ${register_user_info_provider_2}
... 200
# 3.Log entry for service_2 and invoker_2
${request_body_log_3}= Send Log Message to CAPIF
... ${service_api_id_2}
... service_2
... ${register_user_info_invoker_2}
... ${register_user_info_provider_2}
... 200
# 4.Log entry for service_1 and invoker_2
${request_body_log_4}= Send Log Message to CAPIF
... ${service_api_id_1}
... service_1
... ${register_user_info_invoker_2}
... ${register_user_info_provider_1}
... 400
# Check Event Notifications
## Create check Events to ensure all notifications were received
### Subscription 1 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_1}
... ${request_body_log_1}
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_1}
... ${request_body_log_4}
... events_expected=${events_expected}
### Subcription 2 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_2}
... ${request_body_log_2}
... events_expected=${events_expected}
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_2}
... ${request_body_log_3}
... events_expected=${events_expected}
# Subscription 3 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_3}
... ${request_body_log_1}
... events_expected=${events_expected}
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_3}
... ${request_body_log_2}
... events_expected=${events_expected}
# Subscription 4 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_4}
... ${request_body_log_2}
... events_expected=${events_expected}
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_4}
... ${request_body_log_3}
... events_expected=${events_expected}
# Subscription 5 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_5}
... ${request_body_log_3}
... events_expected=${events_expected}
# Subscription 6 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_6}
... ${request_body_log_4}
... events_expected=${events_expected}
# Subscription 7 Checks
${events_expected}= Create Events From InvocationLogs
... ${subscription_id_7}
... ${request_body_log_3}
... events_expected=${events_expected}
Log List ${events_expected}
## Check Events Expected towards received notifications at mock server
Wait Until Keyword Succeeds 5x 5s Check Mock Server Notification Events ${events_expected}
*** Keywords ***
Create Security Context between ${invoker_info} and ${provider_info}
# Discover APIs by invoker
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment