orchestrator changes

This commit is contained in:
Ishaan Dey 2024-05-13 14:32:15 -07:00
parent aef8105bb0
commit eb629835d2
7 changed files with 879 additions and 4 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@google-cloud/container": "^5.12.0",
"@kubernetes/client-node": "^0.21.0", "@kubernetes/client-node": "^0.21.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",

View File

@ -76,7 +76,7 @@ spec:
name: <SANDBOX> name: <SANDBOX>
port: port:
number: 4000 number: 4000
- host: <SANDBOX>.s.ishaand.com - host: <SANDBOX>.sandbox.ishaand.com
http: http:
paths: paths:
- path: / - path: /

View File

@ -12,12 +12,14 @@ import {
NetworkingV1Api, NetworkingV1Api,
} from "@kubernetes/client-node" } from "@kubernetes/client-node"
import { z } from "zod" import { z } from "zod"
import container from '@google-cloud/container';
const app = express() const app = express()
const port = process.env.PORT || 4001 const port = process.env.PORT || 4001
app.use(express.json()) app.use(express.json())
dotenv.config() dotenv.config()
// const corsOptions = { // const corsOptions = {
// origin: ['http://localhost:3000', 'https://s.ishaand.com', 'http://localhost:4000', /\.ws\.ishaand\.com$/], // origin: ['http://localhost:3000', 'https://s.ishaand.com', 'http://localhost:4000', /\.ws\.ishaand\.com$/],
// } // }
@ -105,6 +107,26 @@ app.post("/test", async (req, res) => {
app.post("/start", async (req, res) => { app.post("/start", async (req, res) => {
const { sandboxId } = dataSchema.parse(req.body) const { sandboxId } = dataSchema.parse(req.body)
async function main() {
const client = new container.v1.ClusterManagerClient();
async function quickstart() {
const zone = 'us-central1-a';
const projectId = await client.getProjectId();
const request = {
projectId: projectId,
zone: zone,
};
const [response] = await client.listClusters(request);
console.log('Clusters: ', response);
}
quickstart();
}
main().catch(console.error);
try { try {
console.log("Creating resources for sandbox", sandboxId) console.log("Creating resources for sandbox", sandboxId)

View File

@ -418,6 +418,7 @@ io.on("connection", async (socket) => {
) )
socket.on("disconnect", async () => { socket.on("disconnect", async () => {
console.log("disconnected", data.userId, data.sandboxId)
if (data.isOwner) { if (data.isOwner) {
// console.log("deleting all terminals") // console.log("deleting all terminals")
Object.entries(terminals).forEach((t) => { Object.entries(terminals).forEach((t) => {
@ -445,11 +446,13 @@ io.on("connection", async (socket) => {
} }
}); });
}, 20000); }, 20000);
} else {
console.log("number of sockets", sockets.length)
} }
}) })
}) })
httpServer.listen(port, () => { httpServer.listen(port, () => {
console.log(`Server running on port ${port}`) console.log(`Server, running on port ${port}`)
}) })

View File

@ -198,7 +198,7 @@ ${code}`,
} }
export const stopServer = async (sandboxId: string, userId: string) => { export const stopServer = async (sandboxId: string, userId: string) => {
const res = await fetch("http://localhost:4001/stop", { const res = await fetch("https://sylvan-epoch-422219-f9.uc.r.appspot.com/stop", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@ -52,7 +52,7 @@ export function addNew(name: string, type: "file" | "folder", setFiles: React.Di
export async function startServer(sandboxId: string, userId: string, callback: (success: boolean) => void) { export async function startServer(sandboxId: string, userId: string, callback: (success: boolean) => void) {
try { try {
const res = await fetch("http://localhost:4001/start", { const res = await fetch("https://sylvan-epoch-422219-f9.uc.r.appspot.com/start", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",