summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/api
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-04-04 17:00:31 +0200
committerGitHub <noreply@github.com>2022-04-04 17:00:31 +0200
commit38769373c7e89783d33849283586bfa0b62e8251 (patch)
tree4fda128ee6b30018c1aa14c584cc53ade80e67f7 /opendc-web/opendc-web-ui/src/api
parent6021aa4278bebb34bf5603ead4b5daeabcdc4c19 (diff)
parent527ae2230f5c2dd22f496f45d5d8e3bd4acdb854 (diff)
merge: Migrate to Quarkus-based web API
This pull request changes the web API to a Quarkus-based version. Currently, the OpenDC web API is written in Python (using Flask). Although Python is a powerful language to develop web services, having another language next to Kotlin/Java and JavaScript introduces some challenges. For instance, the web API and UI lack integration with our Gradle-based build pipeline and require additional steps from the developer to start working with. Furthermore, deploying OpenDC requires having Python installed in addition to the JVM. By converting the web API into a Quarkus application, we can enjoy further integration with our Gradle-based build pipeline and simplify the development/deployment process of OpenDC, by requiring only the JVM and Node to work with OpenDC. ## Implementation Notes :hammer_and_pick: * Move build dependencies into version catalog * Design unified communication protocol * Add Quarkus API implementation * Add new web client implementation * Update runner to use new web client * Fix compatibility with React.js UI * Remove Python build steps from CI pipeline * Update Docker deployment for new web API * Remove obsolete database configuration ## External Dependencies :four_leaf_clover: * Quarkus ## Breaking API Changes :warning: * The new web API only supports SQL-based databases for storing user-data, as opposed to MongoDB currently. We intend to use H2 for development and Postgres for production.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/api')
-rw-r--r--opendc-web/opendc-web-ui/src/api/index.js2
-rw-r--r--opendc-web/opendc-web-ui/src/api/portfolios.js18
-rw-r--r--opendc-web/opendc-web-ui/src/api/prefabs.js39
-rw-r--r--opendc-web/opendc-web-ui/src/api/projects.js6
-rw-r--r--opendc-web/opendc-web-ui/src/api/scenarios.js20
-rw-r--r--opendc-web/opendc-web-ui/src/api/topologies.js19
6 files changed, 26 insertions, 78 deletions
diff --git a/opendc-web/opendc-web-ui/src/api/index.js b/opendc-web/opendc-web-ui/src/api/index.js
index 680d49ce..1a9877d0 100644
--- a/opendc-web/opendc-web-ui/src/api/index.js
+++ b/opendc-web/opendc-web-ui/src/api/index.js
@@ -47,5 +47,5 @@ export async function request(auth, path, method = 'GET', body) {
throw response.message
}
- return json.data
+ return json
}
diff --git a/opendc-web/opendc-web-ui/src/api/portfolios.js b/opendc-web/opendc-web-ui/src/api/portfolios.js
index 82ac0ced..d818876f 100644
--- a/opendc-web/opendc-web-ui/src/api/portfolios.js
+++ b/opendc-web/opendc-web-ui/src/api/portfolios.js
@@ -22,22 +22,18 @@
import { request } from './index'
-export function fetchPortfolio(auth, portfolioId) {
- return request(auth, `portfolios/${portfolioId}`)
+export function fetchPortfolio(auth, projectId, number) {
+ return request(auth, `projects/${projectId}/portfolios/${number}`)
}
-export function fetchPortfoliosOfProject(auth, projectId) {
+export function fetchPortfolios(auth, projectId) {
return request(auth, `projects/${projectId}/portfolios`)
}
-export function addPortfolio(auth, portfolio) {
- return request(auth, `projects/${portfolio.projectId}/portfolios`, 'POST', { portfolio })
+export function addPortfolio(auth, projectId, portfolio) {
+ return request(auth, `projects/${projectId}/portfolios`, 'POST', portfolio)
}
-export function updatePortfolio(auth, portfolioId, portfolio) {
- return request(auth, `portfolios/${portfolioId}`, 'PUT', { portfolio })
-}
-
-export function deletePortfolio(auth, portfolioId) {
- return request(auth, `portfolios/${portfolioId}`, 'DELETE')
+export function deletePortfolio(auth, projectId, number) {
+ return request(auth, `projects/${projectId}/portfolios/${number}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/prefabs.js b/opendc-web/opendc-web-ui/src/api/prefabs.js
deleted file mode 100644
index eb9aa23c..00000000
--- a/opendc-web/opendc-web-ui/src/api/prefabs.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-import { request } from './index'
-
-export function getPrefab(auth, prefabId) {
- return request(auth, `prefabs/${prefabId}`)
-}
-
-export function addPrefab(auth, prefab) {
- return request(auth, 'prefabs/', 'POST', { prefab })
-}
-
-export function updatePrefab(auth, prefab) {
- return request(auth, `prefabs/${prefab._id}`, 'PUT', { prefab })
-}
-
-export function deletePrefab(auth, prefabId) {
- return request(auth, `prefabs/${prefabId}`, 'DELETE')
-}
diff --git a/opendc-web/opendc-web-ui/src/api/projects.js b/opendc-web/opendc-web-ui/src/api/projects.js
index 4123b371..e7e095da 100644
--- a/opendc-web/opendc-web-ui/src/api/projects.js
+++ b/opendc-web/opendc-web-ui/src/api/projects.js
@@ -31,11 +31,7 @@ export function fetchProject(auth, projectId) {
}
export function addProject(auth, project) {
- return request(auth, 'projects/', 'POST', { project })
-}
-
-export function updateProject(auth, project) {
- return request(auth, `projects/${project._id}`, 'PUT', { project })
+ return request(auth, 'projects/', 'POST', project)
}
export function deleteProject(auth, projectId) {
diff --git a/opendc-web/opendc-web-ui/src/api/scenarios.js b/opendc-web/opendc-web-ui/src/api/scenarios.js
index 88516caa..7eeb8f28 100644
--- a/opendc-web/opendc-web-ui/src/api/scenarios.js
+++ b/opendc-web/opendc-web-ui/src/api/scenarios.js
@@ -22,22 +22,18 @@
import { request } from './index'
-export function fetchScenario(auth, scenarioId) {
- return request(auth, `scenarios/${scenarioId}`)
+export function fetchScenario(auth, projectId, scenarioId) {
+ return request(auth, `projects/${projectId}/scenarios/${scenarioId}`)
}
-export function fetchScenariosOfPortfolio(auth, portfolioId) {
- return request(auth, `portfolios/${portfolioId}/scenarios`)
+export function fetchScenariosOfPortfolio(auth, projectId, portfolioId) {
+ return request(auth, `projects/${projectId}/portfolios/${portfolioId}/scenarios`)
}
-export function addScenario(auth, scenario) {
- return request(auth, `portfolios/${scenario.portfolioId}/scenarios`, 'POST', { scenario })
+export function addScenario(auth, projectId, portfolioId, scenario) {
+ return request(auth, `projects/${projectId}/portfolios/${portfolioId}/scenarios`, 'POST', scenario)
}
-export function updateScenario(auth, scenarioId, scenario) {
- return request(auth, `scenarios/${scenarioId}`, 'PUT', { scenario })
-}
-
-export function deleteScenario(auth, scenarioId) {
- return request(auth, `scenarios/${scenarioId}`, 'DELETE')
+export function deleteScenario(auth, projectId, scenarioId) {
+ return request(auth, `projects/${projectId}/scenarios/${scenarioId}`, 'DELETE')
}
diff --git a/opendc-web/opendc-web-ui/src/api/topologies.js b/opendc-web/opendc-web-ui/src/api/topologies.js
index bd4e3bc4..0509c6d0 100644
--- a/opendc-web/opendc-web-ui/src/api/topologies.js
+++ b/opendc-web/opendc-web-ui/src/api/topologies.js
@@ -22,24 +22,23 @@
import { request } from './index'
-export function fetchTopology(auth, topologyId) {
- return request(auth, `topologies/${topologyId}`)
+export function fetchTopology(auth, projectId, number) {
+ return request(auth, `projects/${projectId}/topologies/${number}`)
}
-export function fetchTopologiesOfProject(auth, projectId) {
+export function fetchTopologies(auth, projectId) {
return request(auth, `projects/${projectId}/topologies`)
}
-export function addTopology(auth, topology) {
- return request(auth, `projects/${topology.projectId}/topologies`, 'POST', { topology })
+export function addTopology(auth, projectId, topology) {
+ return request(auth, `projects/${projectId}/topologies`, 'POST', topology)
}
export function updateTopology(auth, topology) {
- // eslint-disable-next-line no-unused-vars
- const { _id, ...data } = topology
- return request(auth, `topologies/${topology._id}`, 'PUT', { topology: data })
+ const { project, number, rooms } = topology
+ return request(auth, `projects/${project.id}/topologies/${number}`, 'PUT', { rooms })
}
-export function deleteTopology(auth, topologyId) {
- return request(auth, `topologies/${topologyId}`, 'DELETE')
+export function deleteTopology(auth, projectId, number) {
+ return request(auth, `projects/${projectId}/topologies/${number}`, 'DELETE')
}