Skip to content

Commit

Permalink
bug fix and rollback table update
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsarkar97 committed Jun 12, 2021
1 parent fab2ddf commit b03490a
Show file tree
Hide file tree
Showing 11 changed files with 583 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ hs_err_pid*
node_modules/
.vscode/
.DS_STORE
**build/
442 changes: 442 additions & 0 deletions ui/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@monaco-editor/react": "^4.0.11",
"@react-firebase/auth": "^0.2.10",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^12.6.3",
Expand All @@ -15,6 +16,7 @@
"bunyan": "^1.8.15",
"etcd3": "^1.1.0",
"express": "^4.17.1",
"firebase": "^8.6.7",
"jsonwebtoken": "^8.5.1",
"jwt-simple": "^0.5.6",
"node-env-run": "^4.0.2",
Expand All @@ -33,7 +35,8 @@
},
"scripts": {
"start": "PORT=3001 react-scripts start",
"build": "react-scripts build",
"build": "npm ci && react-scripts build",
"prod": "node server/index.js",
"test": "react-scripts test",
"eject": "react-scripts eject",
"dev": "concurrently \"react-scripts start\" \"node server/index.js\""
Expand Down
101 changes: 41 additions & 60 deletions ui/server/api/odin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,45 @@ const express = require("express");
const axios = require("axios");
const app = express.Router();
const logger = require('./../../logger');
const globals = require('./../../constants')

let endpoints = {
ODIN_SERVICE_URL: process.env.ODIN_SERVICE_URL || 'http://odin',
DEPLOY_WORKSPACE_ENDPOINT: '/odin/deploy/workspace',
DELETE_WORKSPACE_ENDPOINT: '/odin/remove/workspace/',
DEPLOY_SERVICE_ENDPOINT: '/odin/service',
UPDATE_SERVICE_ENDPOINT: '/odin/service',
GET_SERVICE_ENDPOINT: '/odin/service/',
GET_ALL_SERVICES_ENDPOINT: '/odin/services',
DELETE_SERVICE_ENDPOINT: '/odin/service/',
ROLLBACK_SERVICE_ENDPOINT: '/odin/service/rollback',
WORKSPACE_INFORMATION_ENDPOINT: '/details/workspace/info/',
ALL_WORKSPACES_ENDPOINT: '/details/workspaces/',
ALL_SERVICES_IN_WORKSPACE_ENDPOINT: '/odin/services',
ALL_DEPLOYMENTS_ENDPOINT: '/details/deployments/',
SERVICE_INFORMATION_ENDPOINT: '/details/service/info/',
CURRENT_CONFIGURATION_ENDPOINT: '/details/service/configuration/',
ALL_CONFIGURATIONS_ENDPOINT: '/details/service/configurationall',
DETAILS_HEALTH_CHECK_ENDPOINT: '/health',
POLLING_CREATE_WORKSPACE_ENDPOINT: '/polling/deploy/workspace/',
POLLING_DELETE_WORKSPACE_ENDPOINT: '/polling/remove/workspace/',
POLLING_DEPLOY_SERVICE_ENDPOINT: '/polling/deploy/service/',
POLLING_UPDATE_SERVICE_ENDPOINT: '/polling/update/service/',
POLLING_DELETE_SERVICE_ENDPOINT: '/polling/delete/service'
}

// Deploy a service
app.post('/odin/service', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + globals.DEPLOY_SERVICE_ENPOINT;
let apiUrl = endpoints.ODIN_SERVICE_URL + endpoints.DEPLOY_SERVICE_ENDPOINT;
let logObj = {
'path': globals.DEPLOY_SERVICE_ENPOINT,
'path': endpoints.DEPLOY_SERVICE_ENDPOINT,
'method': 'POST',
'headers': req.headers,
'input': req.body
}

let payload = req.body;

if(Object.entries(payload).length === 0) {
if (Object.entries(payload).length === 0) {
res.status(400);
res.send({
'msg': 'Bad Request. No payload found.'
Expand All @@ -36,12 +60,6 @@ app.post('/odin/service', (req, res, next) => {
}).catch(err => {
logObj.note = 'Exception encountered = '.concat(err.response);
logger.error(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand All @@ -51,11 +69,11 @@ app.post('/odin/service', (req, res, next) => {

// Delete a service with serviceId
app.delete('/odin/service/:serviceId', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + globals.DELETE_SERVICE_ENDPOINT
+ req.params.serviceId;
let apiUrl = endpoints.ODIN_SERVICE_URL + endpoints.DELETE_SERVICE_ENDPOINT
+ req.params.serviceId;

let logObj = {
'path': globals.DELETE_SERVICE_ENDPOINT + req.params.serviceId,
'path': endpoints.DELETE_SERVICE_ENDPOINT + req.params.serviceId,
'method': 'DELETE',
'headers': req.headers,
'input': req.params.serviceId
Expand All @@ -75,12 +93,6 @@ app.delete('/odin/service/:serviceId', (req, res, next) => {
}).catch(err => {
logObj.note = 'Exception encountered = '.concat(JSON.stringify(err.message));
logger.info(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand All @@ -91,10 +103,10 @@ app.delete('/odin/service/:serviceId', (req, res, next) => {

// Get all existing services
app.get('/odin/services/', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + globals.GET_ALL_SERVICES_ENDPOINT;
let apiUrl = endpoints.ODIN_SERVICE_URL + endpoints.GET_ALL_SERVICES_ENDPOINT;

let logObj = {
'path': globals.GET_ALL_SERVICES_ENDPOINT,
'path': endpoints.GET_ALL_SERVICES_ENDPOINT,
'method': 'GET',
'headers': req.headers,
'input': ''
Expand All @@ -114,12 +126,6 @@ app.get('/odin/services/', (req, res, next) => {
}).catch(err => {
logObj.note = 'Error encountered = '.concat(err.message);
logger.info(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand All @@ -129,18 +135,18 @@ app.get('/odin/services/', (req, res, next) => {

// Update a service with parameters
app.put('/odin/service', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + globals.UPDATE_SERVICE_ENDPOINT;
let apiUrl = endpoints.ODIN_SERVICE_URL + endpoints.UPDATE_SERVICE_ENDPOINT;

let logObj = {
'path': globals.UPDATE_SERVICE_ENDPOINT,
'path': endpoints.UPDATE_SERVICE_ENDPOINT,
'method': 'PUT',
'headers': req.headers,
'input': req.body
}

let payload = req.body;

if(Object.entries(payload).length === 0) {
if (Object.entries(payload).length === 0) {
res.status(400);
res.send({
'msg': 'Bad request. No payload found.'
Expand All @@ -162,12 +168,6 @@ app.put('/odin/service', (req, res, next) => {
}).catch(err => {
logObj.note = 'Error encountered = '.concat(err.message);
logger.error(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand All @@ -177,16 +177,16 @@ app.put('/odin/service', (req, res, next) => {

// Service rollback API
app.post('/odin/service/rollback', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + globals.ROLLBACK_SERVICE_ENDPOINT;
let apiUrl = endpoints.ODIN_SERVICE_URL + endpoints.ROLLBACK_SERVICE_ENDPOINT;

let logObj = {
'path': globals.ROLLBACK_SERVICE_ENDPOINT,
'path': endpoints.ROLLBACK_SERVICE_ENDPOINT,
'method': 'POST',
'headers': req.headers,
'input': req.body
}

if(Object.entries(req.body).length === 0) {
if (Object.entries(req.body).length === 0) {
logObj.note = 'Bad input. No payload found.';
logger.error(logObj);
res.status(400);
Expand All @@ -210,12 +210,6 @@ app.post('/odin/service/rollback', (req, res, next) => {
}).catch(err => {
logObj.note = 'Error encountered = '.concat(err.message);
logger.error(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand All @@ -225,7 +219,7 @@ app.post('/odin/service/rollback', (req, res, next) => {

// Get service status
app.get('/odin/service/:serviceName/status', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + '/odin/service/' + req.params.serviceName + '/status/';
let apiUrl = endpoints.ODIN_SERVICE_URL + '/odin/service/' + req.params.serviceName + '/status/';

let logObj = {
'path': apiUrl,
Expand All @@ -248,12 +242,6 @@ app.get('/odin/service/:serviceName/status', (req, res, next) => {
}).catch(err => {
logObj.note = 'Error encountered = '.concat(err.message);
logger.error(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand All @@ -262,9 +250,8 @@ app.get('/odin/service/:serviceName/status', (req, res, next) => {
});



app.get('/details/health', (req, res, next) => {
let apiUrl = globals.ODIN_SERVICE_URL + globals.DETAILS_HEALTHCHECK_ENDPOINT;
let apiUrl = endpoints.ODIN_SERVICE_URL + endpoints.DETAILS_HEALTH_CHECK_ENDPOINT;
let logObj = {
'path': '/details/health',
'method': 'GET',
Expand All @@ -285,12 +272,6 @@ app.get('/details/health', (req, res, next) => {
}).catch(err => {
logObj.note = 'Error encountered = '.concat(err.message);
logger.error(logObj);
/*
res.status(err.status);
res.send({
'msg': err.response.statusText
})
*/
res.status(500);
res.send({
'msg': 'Something went wrong'
Expand Down
34 changes: 6 additions & 28 deletions ui/server/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
module.exports = Object.freeze({
ADMIN_EMAIL_ADDRESS: process.env.JWT_SECRET || 'admin',
ADMIN_ACL_TOKEN: process.env.ADMIN_ACL_TOKEN || 'admin',
JWT_SECRET : process.env.JWT_SECRET || 'VmYq3t6v9y$B&E)H@McQfTjWnZr4u7x!',
SERVICE_NAME : process.env.SERVICE_NAME || 'titan-ui-middleware',
PORT : process.env.PORT || 8083,
DB_URL : process.env.ETCD3_URL || '127.0.0.1:2379',
TEST_JWT : process.env.TEST_JWT || 'yJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbEFkZHJlc3MiOiJhbnVyYWcuc2Fya2FyMjUwQGdtYWlsLmNvbSIsImFjbFRva2VuIjoiYWJjMTIzIn0.8AXDnR87Pk2S4__uoAVpb7GTh2E6LhuglsKSsOeHRBo',
JWT_SECRET: process.env.JWT_SECRET || 'VmYq3t6v9y$B&E)H@McQfTjWnZr4u7x!',
SERVICE_NAME: process.env.SERVICE_NAME || 'titan-ui-middleware',
PORT: process.env.PORT || 8083,
DB_URL: process.env.ETCD3_URL || '127.0.0.1:2379',
TEST_JWT: process.env.TEST_JWT || 'yJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbEFkZHJlc3MiOiJhbnVyYWcuc2Fya2FyMjUwQGdtYWlsLmNvbSIsImFjbFRva2VuIjoiYWJjMTIzIn0.8AXDnR87Pk2S4__uoAVpb7GTh2E6LhuglsKSsOeHRBo',
APP_COMMON_SECRET: process.env.APP_COMMON_SECRET || 'kaiyo@123',
SAMPLE_ACL_TOKEN : process.env.SAMPLE_ACL_TOKEN || 'ar3i89wensdkwe23s',
ODIN_SERVICE_URL: process.env.ODIN_SERVICE_URL || 'http://eba4ab5049ce.ngrok.io',
DEPLOY_WORKSPACE_ENDPOINT: process.env.DEPLOY_WORKSPACE_ENDPOINT || '/odin/deploy/workspace',
DELETE_WORKSPACE_ENDPOINT: process.env.DELETE_WORKSPACE_ENDPOINT || '/odin/remove/workspace/',
DEPLOY_SERVICE_ENPOINT: process.env.DEPLOY_SERVICE_ENDPOINT || '/odin/service',
UPDATE_SERVICE_ENDPOINT: process.env.UPDATE_SERVICE_ENDPOINT || '/odin/service',
GET_SERVICE_ENDPOINT: process.env.GET_SERVICE_ENDPOINT || '/odin/service/',
GET_ALL_SERVICES_ENDPOINT: process.env.GET_ALL_SERVICES_ENDPOINT || '/odin/services',
DELETE_SERVICE_ENDPOINT: process.env.DELETE_SERVICE_ENDPOINT || '/odin/service/',
ROLLBACK_SERVICE_ENDPOINT: process.env.ROLLBACK_SERVICE_ENDPOINT || '/odin/service/rollback',
WORKSPACE_INFORMATION_ENDPOINT: process.env.WORKSPACE_INFORMATION_ENDPOINT || '/details/workspace/info/',
ALL_WORKSPACES_ENDPOINT: process.env.ALL_WORKSPACES_ENDPOINT || '/details/workspaces/',
ALL_SERVICES_IN_WORKSPACE_ENDPOINT: process.env.ALL_SERVICES_IN_WORKSPACE_ENDPOINT || '/odin/services',
ALL_DEPLOYMENTS_ENDPOINT: process.env.ALL_DEPLOYMENTS_ENDPOINT || '/details/deployments/',
SERVICE_INFORMATION_ENDPOINT: process.env.SERVICE_INFORMATION_ENDPOINT || '/details/service/info/',
CURRENT_CONFIGURATION_ENDPOINT: process.env.CURRENT_CONFIGURATION_ENDPOINT || '/details/service/configuration/',
ALL_CONFIGURATIONS_ENDPOINT: process.env.ALL_CONFIGURATIONS_ENDPOINT || '/details/service/configurationall',
DETAILS_HEALTHCHECK_ENDPOINT: process.env.DETAILS_HEALTHCHECK_ENDPOINT || '/health',
POLLING_CREATE_WORKSPACE_ENDPOINT: process.env.POLLING_CREATE_WORKSPACE_ENDPOINT || '/polling/deploy/workspace/',
POLLING_DELETE_WORKSPACE_ENDPOINT: process.env.POLLING_DELETE_WORKSPACE_ENDPOINT || '/polling/remove/workspace/',
POLLING_DEPLOY_SERVICE_ENDPOINT: process.env.POLLING_DEPLOY_SERVICE_ENDPOINT || '/polling/deploy/service/',
POLLING_UPDATE_SERVICE_ENDPOINT: process.env.POLLING_UPDATE_SERVICE_ENDPOINT || '/polling/update/service/',
POLLING_DELETE_SERVICE_ENDPOINT: process.env.POLLING_DELETE_SERVICE_ENDPOINT || '/polling/delete/service'
SAMPLE_ACL_TOKEN: process.env.SAMPLE_ACL_TOKEN || 'ar3i89wensdkwe23s',
});
14 changes: 9 additions & 5 deletions ui/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ const bodyParser = require("body-parser");
const express = require("express");
const cors = require("cors");
const path = require("path");
const logger = require("./logger");
const api = require("./api");
const users = require("./users");
const constants = require("./constants")
const app = express();

logger.info(path.join(__dirname, "..", "build"));

users.createDefaultAdminUser()
.then(res => {
console.log(res)
})
.catch(err => {
console.log("Error creating default user. Error caused : "+ err)
console.log("stopping Server . Db not available ")
process.exit(1)
})

app
.options('*', cors())
.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
Expand All @@ -23,10 +27,10 @@ app
.get("/health-check", (req, res) => res.send("OK"))
.use("/api", api)
.use("/users", users)
.use(cors())
.use(express.static(path.join(__dirname, "..", "build")))
.use(bodyParser.json())
.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "..", "build/index.html"));
})
.use(cors)
.listen(constants.PORT, () => console.log(`Server started http://localhost:${constants.PORT}`));
Loading

0 comments on commit b03490a

Please sign in to comment.