From c8a19f8ec5e63545ee23f71aa980d90e4e0fdc8f Mon Sep 17 00:00:00 2001 From: eefspan Date: Thu, 29 Feb 2024 11:55:20 +0100 Subject: [PATCH] POC of Sending Eiffel Events within Nordix (#190-community) --- .github/workflows/ci.yaml | 41 +++++++++++++-- utilities/eiffel/ei_subscriptions.bash | 46 +++++++++++++++++ utilities/eiffel/er_events.bash | 42 +++++++++++++++ utilities/eiffel/jq_query.bash | 19 +++++++ utilities/eiffel/remrem_publish_event.bash | 59 ++++++++++++++++++++++ 5 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 utilities/eiffel/ei_subscriptions.bash create mode 100644 utilities/eiffel/er_events.bash create mode 100644 utilities/eiffel/jq_query.bash create mode 100644 utilities/eiffel/remrem_publish_event.bash diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f89347a..2184fc6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,8 +9,11 @@ on: - master env: - NAMESPACE: ci-eiffel + DOMAIN: eiffel4eiffel.nordix.org + NAMESPACE: eiffel + TARGET: Kubernetes BUNDLE: Eiffel + PATH_TO_BUNDLE: ./bundles READY_POD_TIMEOUT: 120s jobs: @@ -31,7 +34,7 @@ jobs: kubectl create ns $NAMESPACE : # Install the BUNDLE via easy2use - ./easy2use start -t Kubernetes -d cluster.local -e ./bundles -n $NAMESPACE $BUNDLE -y + ./easy2use start -t $TARGET -d $DOMAIN -e $PATH_TO_BUNDLE -n $NAMESPACE $BUNDLE -y : # Wait until all pods are running kubectl wait pod \ @@ -53,12 +56,44 @@ jobs: kubectl get pods -n $NAMESPACE kubectl get ingress -n $NAMESPACE + : # Wait for a while + echo "Waiting..." && sleep 30 + + - name: Get the EI-frontend subscriptions + run: | + cd ./utilities/eiffel && \ + bash ei_subscriptions.bash -d $DOMAIN -n $NAMESPACE + + - name: POST an Eiffel ArtC event + run: | + cd ./utilities/eiffel && \ + bash remrem_publish_event.bash -d $DOMAIN -n $NAMESPACE + + : # Wait for a while until the processing of the events + echo "Waiting..." && sleep 60 + + - name: Ensure that Jenkins jobs executed successfully + run: | + : # The ArtC event should trigger three different jobs. + : # ei-artifact-triggered-job, ei-artifact-triggered-parameterized-job + : # and event-triggered-job + cd ./utilities/eiffel && \ + output=$(bash er_events.bash -d $DOMAIN -n $NAMESPACE -l 8 | bash jq_query.bash | wc -l) + echo "Output: ${output}" + + if [ $output -eq 3 ]; + then + echo "Jenkins jobs passed." + else + echo "Jenkins jobs failed." && exit 1 + fi + - name: Remove Easy2Use from cluster id: removal if: always() run: | : # Remove the BUNDLE from the cluster via easy2use - ./easy2use remove -t Kubernetes -d cluster.local -e ./bundles -n $NAMESPACE $BUNDLE -y + ./easy2use remove -t $TARGET -d $DOMAIN -e $PATH_TO_BUNDLE -n $NAMESPACE $BUNDLE -y : # Delete the NAMESPACE kubectl delete ns $NAMESPACE diff --git a/utilities/eiffel/ei_subscriptions.bash b/utilities/eiffel/ei_subscriptions.bash new file mode 100644 index 0000000..2782a24 --- /dev/null +++ b/utilities/eiffel/ei_subscriptions.bash @@ -0,0 +1,46 @@ +# +# Copyright 2024 Ericsson AB. +# For a full list of individual contributors, please see the commit history. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Get the flag values +echo -e "----------------------" +echo "Configuration settings" +echo -e "----------------------\n" +while getopts ":d:n:" opt; do + case $opt in + d) + echo "Eiffel domain: $OPTARG" >&2 + EIFFEL_DOMAIN="$OPTARG" + ;; + n) + echo "Namespace: $OPTARG" >&2 + EIFFEL_NAMESPACE="$OPTARG" + ;; + \?) + echo "Invalid flag: -$OPTARG" >&2 + exit 1 + ;; + :) echo "Flag -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# cURL request +echo -e "\n--------------------" +echo "GET EI Subscriptions" +echo -e "--------------------\n" +curl -X GET -H "Content-type: application/json" "http://eiffel-frontend-${EIFFEL_NAMESPACE}.${EIFFEL_DOMAIN}:80/subscriptions" diff --git a/utilities/eiffel/er_events.bash b/utilities/eiffel/er_events.bash new file mode 100644 index 0000000..2bb3d85 --- /dev/null +++ b/utilities/eiffel/er_events.bash @@ -0,0 +1,42 @@ +# +# Copyright 2024 Ericsson AB. +# For a full list of individual contributors, please see the commit history. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Get the flags +while getopts ":d:n:l:" opt; do + case $opt in + d) + EIFFEL_DOMAIN="$OPTARG" + ;; + n) + EIFFEL_NAMESPACE="$OPTARG" + ;; + l) + LIMIT="$OPTARG" + ;; + \?) + echo "Invalid flag: -$OPTARG" >&2 + exit 1 + ;; + :) echo "Flag -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# cURL request +curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d 'db.events.find({})' \ + "http://eiffel-er-${EIFFEL_NAMESPACE}.${EIFFEL_DOMAIN}:80/datastore/query?pageNo=1&pageSize=${LIMIT}&pageStartTime=1" diff --git a/utilities/eiffel/jq_query.bash b/utilities/eiffel/jq_query.bash new file mode 100644 index 0000000..bbc51ab --- /dev/null +++ b/utilities/eiffel/jq_query.bash @@ -0,0 +1,19 @@ +# +# Copyright 2024 Ericsson AB. +# For a full list of individual contributors, please see the commit history. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# JQ command +jq -r '[.items] | .[0] | .[] | select(.meta.type=="EiffelActivityFinishedEvent") | select(.data.outcome.conclusion=="SUCCESSFUL") | length' diff --git a/utilities/eiffel/remrem_publish_event.bash b/utilities/eiffel/remrem_publish_event.bash new file mode 100644 index 0000000..447f059 --- /dev/null +++ b/utilities/eiffel/remrem_publish_event.bash @@ -0,0 +1,59 @@ +# +# Copyright 2024 Ericsson AB. +# For a full list of individual contributors, please see the commit history. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Get the flag values +echo -e "----------------------" +echo "Configuration settings" +echo -e "----------------------\n" +while getopts ":d:n:" opt; do + case $opt in + d) + echo "Eiffel domain: $OPTARG" >&2 + EIFFEL_DOMAIN="$OPTARG" + ;; + n) + echo "Namespace: $OPTARG" >&2 + EIFFEL_NAMESPACE="$OPTARG" + ;; + \?) + echo "Invalid flag: -$OPTARG" >&2 + exit 1 + ;; + :) echo "Flag -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# cURL request +echo -e "\n-----------------" +echo "POST Eiffel ArtC Event" +echo -e "-----------------\n" +curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ + "meta": { + "type": "EiffelArtifactCreatedEvent", + "version": "3.0.0", + "time": 1234567890, + "id": "77a7f4e7-9847-44a6-9bf0-3a19a9528ccd", + "source": { + "serializer": "pkg:maven/com.mycompany.tools/eiffel-serializer%401.0.3" + } + }, + "data": { + "identity": "pkg:maven/com.othercompany.library/required@required" + } + }' "http://eiffel-remrem-publish-${EIFFEL_NAMESPACE}.${EIFFEL_DOMAIN}:80/producer/msg?mp=eiffelsemantics"