Skip to content

Commit

Permalink
Stats Endpoint (#301)
Browse files Browse the repository at this point in the history
* Add new landing page in the portal
* Add stats endpoint
  • Loading branch information
fdelavega authored Oct 29, 2024
1 parent d12e06a commit 29589c8
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 17 deletions.
90 changes: 90 additions & 0 deletions controllers/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* Copyright (c) 2024 Future Internet Consulting and Development Solutions S.L.
*
* This file belongs to the business-ecosystem-logic-proxy of the
* Business API Ecosystem
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const axios = require('axios')
const cron = require('node-cron')
const utils = require('../lib/utils')
const statsSchema = require('../db/schemas/stats')

const logger = require('./../lib/logger').logger.getLogger('TMF')


function stats() {

const loadStats = async function() {
// Get the list of launched offering
const productUrl = utils.getAPIProtocol('catalog') + '://' + utils.getAPIHost('catalog') + ':' + utils.getAPIPort('catalog') + '/productOffering?lifecycleStatus=Launched&fields=name'
const offers = await axios.request({
method: 'GET',
url: productUrl
})

// Get the list of organizations
const partyUrl = utils.getAPIProtocol('party') + '://' + utils.getAPIHost('party') + ':' + utils.getAPIPort('party') + '/organization?fields=tradingName'
const parties = await axios.request({
method: 'GET',
url: partyUrl
})

// Save data in MongoDB
const res = await statsSchema.findOne()
const services = offers.data.map((off) => {
return off.name
})

const organizations = parties.data.map((part) => {
return part.tradingName
})

if (res) {
res.services = services
res.organizations = organizations
await res.save()
} else {
const newStat = new statsSchema()
newStat.services = services
newStat.organizations = organizations
await newStat.save()
}
}

const getStats = function(req, res) {
statsSchema.findOne().then((result) => {
res.send(result)
})
}

const init = function() {
return loadStats()
.catch((err) => {
console.log(err)
logger.error('Stats could not be loaded')
})
.finally(() => {
cron.schedule('0 3 * * *', loadStats);
})
}

return {
getStats: getStats,
init: init
}
}

exports.stats = stats
28 changes: 28 additions & 0 deletions db/schemas/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (c) 2024 Future Internet Consulting and Development Solutions S.L.
*
* This file belongs to the business-ecosystem-logic-proxy of the
* Business API Ecosystem
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const statsSchema = new Schema({
services: { type: Array, default: [] },
organizations: { type: Array, default: [] }
});

module.exports = mongoose.model('stats', statsSchema);
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
"i18n-2": "^0.7.2",
"jade": "^1.11.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "6.1.0",
"jwks-rsa": "^3.0.1",
"log4js": "^6.9.1",
"lru-cache": "^6.0.0",
"merge-dirs": "^0.2.1",
"moment": "^2.29.1",
"mongodb": "6.1.0",
"mongoose": "^7.6.3",
"node-cache": "^5.1.2",
"node-cron": "^3.0.3",
"node-fetch": "^2.6.1",
"node-minify": "^3.6.0",
"normalize-url": "^1.8.0",
Expand Down
17 changes: 11 additions & 6 deletions portal/bae-frontend/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"_no": "No",
"DASHBOARD": {
"_title": "DOME Marketplace is out! See what's new",
"_header": "DOME Marketplace: Cloud & Edge Services you can Trust",
"_subheader": "Welcome to the first open distributed marketplace ecosystem for cloud, edge & AI services in Europe",
"_header": "Digital Trust to move forward",
"_subheader": "Join the first open distributed marketplace ecosystem for cloud, edge & AI services in europe.",
"_new": "New",
"_learn_more": "Learn more",
"_video": "Watch video",
Expand All @@ -15,7 +15,8 @@
"_smart_cities": "Smart cities",
"_search_ph": "Search Cloud Services, Edge Services, Providers...",
"_search": "Search",
"_not_found": "No offers found"
"_not_found": "No offers found",
"_browse_serv": "Browse services"
},
"FEATURED": {
"_title": "Featured offerings",
Expand Down Expand Up @@ -110,7 +111,7 @@
"_updates_desc": "Stay informed with the latest developments, service enhancements and industry insights directly from the 'DOME' Project's website.",
"_resources_title": "Resources & Reports",
"_resources_desc": "Access our library of resources, detailed reports and case studies to gain a deep understanding of the cloud and edge market landscape and 'DOME' Project's impact.",
"_go": "Go to 'DOME' Project's Site"
"_go": "DOME Project"
},
"CARD": {
"_details": "View details",
Expand Down Expand Up @@ -170,6 +171,7 @@
"_home": "Home",
"_catalogs": "Catalogues",
"_search": "Search",
"_browse": "Browse",
"_cloud": "Cloud Services",
"_smart_ports": "Smart ports",
"_smart_cities": "Smart cities",
Expand All @@ -186,9 +188,12 @@
"_ticketing": "Ticketing System",
"_change_session": "Change session",
"_admin": "Administration",
"_publish": "Publish your product",
"_publish": "Publish your service",
"_register": "Register",
"_about": "About",
"_guidelines": "Guidelines",
"_onboarding": "Onboarding",
"_about": "About DOME",
"_verify": "Verify and publish",
"_info": "Info"
},
"PRODUCT_DETAILS": {
Expand Down
17 changes: 11 additions & 6 deletions portal/bae-frontend/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"_no": "No",
"DASHBOARD": {
"_title": "DOME Marketplace is out! See what's new",
"_header": "DOME Marketplace: Cloud & Edge Services you can Trust",
"_subheader": "Welcome to the first open distributed marketplace ecosystem for cloud, edge & AI services in Europe",
"_header": "Digital Trust to move forward",
"_subheader": "Join the first open distributed marketplace ecosystem for cloud, edge & AI services in europe.",
"_new": "New",
"_learn_more": "Learn more",
"_video": "Watch video",
Expand All @@ -15,7 +15,8 @@
"_smart_cities": "Smart cities",
"_search_ph": "Search Cloud Services, Edge Services, Providers...",
"_search": "Search",
"_not_found": "No offers found"
"_not_found": "No offers found",
"_browse_serv": "Browse services"
},
"FEATURED": {
"_title": "Featured offerings",
Expand Down Expand Up @@ -110,7 +111,7 @@
"_updates_desc": "Stay informed with the latest developments, service enhancements and industry insights directly from the 'DOME' Project's website.",
"_resources_title": "Resources & Reports",
"_resources_desc": "Access our library of resources, detailed reports and case studies to gain a deep understanding of the cloud and edge market landscape and 'DOME' Project's impact.",
"_go": "Go to 'DOME' Project's Site"
"_go": "DOME Project"
},
"CARD": {
"_details": "View details",
Expand Down Expand Up @@ -170,6 +171,7 @@
"_home": "Home",
"_catalogs": "Catalogues",
"_search": "Search",
"_browse": "Browse",
"_cloud": "Cloud Services",
"_smart_ports": "Smart ports",
"_smart_cities": "Smart cities",
Expand All @@ -186,9 +188,12 @@
"_ticketing": "Ticketing System",
"_change_session": "Change session",
"_admin": "Administration",
"_publish": "Publish your product",
"_publish": "Publish your service",
"_register": "Register",
"_about": "About",
"_guidelines": "Guidelines",
"_onboarding": "Onboarding",
"_about": "About DOME",
"_verify": "Verify and publish",
"_info": "Info"
},
"PRODUCT_DETAILS": {
Expand Down
4 changes: 2 additions & 2 deletions portal/bae-frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
document.documentElement.classList.remove('dark')
}
</script>
<style>*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}html{font-family:Blinker,system-ui,sans-serif}*,:before,:after{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(63 131 248 / .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.h-screen{height:100vh}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255 / var(--tw-bg-opacity))}:root{--blockquote-border-color:#ccc;--blockquote-bg-color:#dde6f6;--blockquote-text-color:black}@media (prefers-color-scheme: dark){:root{--blockquote-border-color:#171717;--blockquote-bg-color:#0c1c38;--blockquote-text-color:#eee}}</style><link rel="stylesheet" href="styles.1ed4cd4165fa09e2.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.1ed4cd4165fa09e2.css"></noscript></head>
<style>*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}html{font-family:Blinker,system-ui,sans-serif}*,:before,:after{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgb(63 131 248 / .5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }.h-screen{height:100vh}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255 / var(--tw-bg-opacity))}:root{--blockquote-border-color:#ccc;--blockquote-bg-color:#dde6f6;--blockquote-text-color:black}@media (prefers-color-scheme: dark){:root{--blockquote-border-color:#171717;--blockquote-bg-color:#0c1c38;--blockquote-text-color:#eee}}</style><link rel="stylesheet" href="styles.0db97be566ccda0e.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.0db97be566ccda0e.css"></noscript></head>
<body class="h-screen bg-white dark:bg-gray-900"> <!-- class="dark:bg-gray-900" style="background-image: url('assets/logos/dome-logo-element-colour.png');"-->
<app-root></app-root>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/flowbite.min.js"></script>-->
<script src="runtime.a6c447aa891d1500.js" type="module"></script><script src="polyfills.91ffa46fa0a1d50f.js" type="module"></script><script src="main.b93f580b2f4df552.js" type="module"></script></body>
<script src="runtime.a6c447aa891d1500.js" type="module"></script><script src="polyfills.91ffa46fa0a1d50f.js" type="module"></script><script src="main.a4b2f5ac2bf8a59e.js" type="module"></script></body>
</html>
1 change: 1 addition & 0 deletions portal/bae-frontend/main.a4b2f5ac2bf8a59e.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion portal/bae-frontend/main.b93f580b2f4df552.js

This file was deleted.

1 change: 1 addition & 0 deletions portal/bae-frontend/styles.0db97be566ccda0e.css

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion portal/bae-frontend/styles.1ed4cd4165fa09e2.css

This file was deleted.

7 changes: 7 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const shoppingCart = require('./controllers/shoppingCart').shoppingCart;
const management = require('./controllers/management').management;
const tmf = require('./controllers/tmf').tmf();
const admin = require('./controllers/admin').admin();
const stats = require('./controllers/stats').stats();
const trycatch = require('trycatch');
const url = require('url');
const utils = require('./lib/utils');
Expand Down Expand Up @@ -394,6 +395,8 @@ app.get('/config', (_, res) => {
})
})

app.get('/stats', stats.getStats)

/////////////////////////////////////////////////////////////////////
/////////////////////////// SHOPPING CART ///////////////////////////
/////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -725,5 +728,9 @@ function onlistening() {
logger.error("Cannot connect to the charging backend");
setTimeout(onlistening, 5000);
});

stats.init().then(() => {
logger.info("Stats info loaded")
})
}
})();

0 comments on commit 29589c8

Please sign in to comment.