Skip to content

Commit

Permalink
updated static code
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsarkar97 committed Nov 27, 2021
1 parent 7aee405 commit e422d29
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
3 changes: 2 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ RUN chmod +x kubectl



CMD ["uvicorn" ,"application:application", "--host", "0.0.0.0", "--port" ,"5000"]
# CMD ["uvicorn" ,"application:application", "--host", "0.0.0.0", "--port" ,"5000"]
CMD [ "python", "application.py" ]
5 changes: 3 additions & 2 deletions api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from starlette_exporter import PrometheusMiddleware, handle_metrics


from routers import odin
from routers import odin

application = FastAPI()
application.include_router(odin.router)

application.add_middleware(PrometheusMiddleware, group_paths=True, buckets=[0.1, 0.25, 0.5, 0.9, 0.95, 0.995])
application.add_middleware(PrometheusMiddleware, group_paths=True, buckets=[
0.1, 0.25, 0.5, 0.9, 0.95, 0.995])
application.add_route("/metrics", handle_metrics)


Expand Down
21 changes: 14 additions & 7 deletions api/routers/odin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ async def deploy_service(deploy_request: DeployRequest):
"error": ""
}
except Exception as ex:
raise HTTPException(status_code=500, detail="Service deployment failed: " + str(ex))
raise HTTPException(
status_code=500, detail="Service deployment failed: " + str(ex))


@router.delete("/odin/service/{service_name}", tags=["odin"])
Expand All @@ -40,7 +41,8 @@ async def delete_service(service_name):
"error": ""
}
except Exception as ex:
raise HTTPException(status_code=500, detail="Service delete failed: " + str(ex))
raise HTTPException(
status_code=500, detail="Service delete failed: " + str(ex))


@router.get("/odin/service/{service_name}/status", tags=["odin"])
Expand All @@ -57,7 +59,8 @@ async def get_status(service_name):
"error": ""
}
except Exception as ex:
raise HTTPException(status_code=500, detail="Failed to fetch Service Status: " + str(ex))
raise HTTPException(
status_code=500, detail="Failed to fetch Service Status: " + str(ex))


@router.get("/odin/service/{service_name}/revisions", tags=["odin"])
Expand All @@ -70,7 +73,8 @@ async def get_revisions(service_name):
"error": ""
}
except Exception as ex:
raise HTTPException(status_code=500, detail="Failed to fetch Service Revisions: " + str(ex))
raise HTTPException(
status_code=500, detail="Failed to fetch Service Revisions: " + str(ex))


@router.post("/odin/service/rollback", tags=["odin"])
Expand All @@ -85,17 +89,20 @@ async def rollback_service(rollback_request: RollbackRequest):
"error": ""
}
except Exception as ex:
raise HTTPException(status_code=500, detail="Service deployment failed: " + str(ex))
raise HTTPException(
status_code=500, detail="Service deployment failed: " + str(ex))


@router.get("/odin/services/", tags=["odin"])
async def get_all_services():
try:
service_list = Utils.getJsonValue(etcd, 'service_list')
# service_list = Utils.getJsonValue(etcd, 'service_list')
service_list = Utils.getJson(Helm.listAllServices())
return {
"status": "200",
"metadata": service_list,
"error": ""
}
except Exception as ex:
raise HTTPException(status_code=500, detail="Failed to fetch all services: " + str(ex))
raise HTTPException(
status_code=500, detail="Failed to fetch all services: " + str(ex))
23 changes: 11 additions & 12 deletions deployments/backend-dep.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

apiVersion: v1
kind: Pod
metadata:
Expand All @@ -9,28 +8,28 @@ spec:
containers:
- image: anuragsarkar250/backend:1
name: titan-odin
env:
- name: "ETCD3_URL"
value: "http://etcd-client:2379"
env:
- name: "ETCD3_URL"
value: "http://etcd-client:2379"
ports:
- containerPort: 5000
name: titan-odin
protocol: TCP
- containerPort: 5000
name: titan-odin
protocol: TCP
restartPolicy: Always

---

apiVersion: v1
kind: Service
metadata:
labels:
app: titan-odin
name: titan-odin
spec:
type: LoadBalancer
ports:
- name: titan-odin
port: 5000
protocol: TCP
targetPort: 5000
- name: titan-odin
port: 5000
protocol: TCP
targetPort: 5000
selector:
app: titan-odin
2 changes: 1 addition & 1 deletion ui/server/api/odin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let endpoints = {
DEPLOY_SERVICE_ENDPOINT: '/odin/service',
UPDATE_SERVICE_ENDPOINT: '/odin/service',
GET_SERVICE_ENDPOINT: '/odin/service/',
GET_ALL_SERVICES_ENDPOINT: '/odin/services',
GET_ALL_SERVICES_ENDPOINT: '/odin/services/',
DELETE_SERVICE_ENDPOINT: '/odin/service/',
ROLLBACK_SERVICE_ENDPOINT: '/odin/service/rollback',
WORKSPACE_INFORMATION_ENDPOINT: '/details/workspace/info/',
Expand Down
7 changes: 2 additions & 5 deletions ui/server/db/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const {Etcd3} = require('etcd3');
const client = new Etcd3({hosts: process.env.ETCD3_URL});

const {Etcd3} = require('etcd3');
const client = new Etcd3({hosts: globals.DB_URL});
const { Etcd3 } = require('etcd3');
const client = new Etcd3({ hosts: process.env.ETCD3_URL });

async function get(key) {
try {
Expand Down
5 changes: 2 additions & 3 deletions ui/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ users.createDefaultAdminUser()
console.log(res)
})
.catch(err => {
console.log("Error creating default user. Error caused : "+ err)
console.log("Error creating default user. Error caused : " + err)
console.log("stopping Server . Db not available ")
process.exit(1)
})

app
.use(function(req, res, next) {
.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Expose-Headers", "x-access-token, Uid")
Expand All @@ -33,7 +33,6 @@ app
.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "..", "build/index.html"));
})
.use(cors)
.listen(constants.PORT, () => console.log(`Server started http://localhost:${constants.PORT}`));

app.timeout = 2000;

0 comments on commit e422d29

Please sign in to comment.