Skip to content

Commit

Permalink
refactoring done
Browse files Browse the repository at this point in the history
  • Loading branch information
kaganrua committed Aug 20, 2024
1 parent 60e313e commit ea666ac
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 224 deletions.
15 changes: 1 addition & 14 deletions frontend/server/blockSerialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,7 @@ export async function runTest(blockPath, blockKey) {
throw new Error(`Could not find script for running tests: ${scriptPath}`);
}

// return new Promise((resolve, reject) => {
// execFile(
// "python",
// [scriptPath, blockPath, blockKey],
// (error, stdout, stderr) => {
// if (error) {
// reject(error);
// }

// logger.debug(stdout);
// logger.error(stderr);
// resolve();
// },
// );
// });

return await runTestContainer(blockPath, blockKey)
}
18 changes: 4 additions & 14 deletions frontend/server/express.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ let anvilProcess = null;

function gracefullyStopAnvil() {
if (anvilProcess !== null) {
console.log("KILLING ANVIL")
anvilProcess.kill("SIGINT");
const sleep = new Promise((resolve) => setTimeout(resolve, 5000));
sleep().then((res) => {
console.log("schleepy shleep");
});

}
}

Expand Down Expand Up @@ -218,12 +216,7 @@ function startExpressServer() {
if (electronApp.isPackaged) {
agents = path.join(process.resourcesPath, "agents");
}
const scriptPath = path.join(
agents,
agentName,
"generate",
"computations.py",
);

if (agentName === "gpt-4_python_compute") {
try {
const result = await computeAgent(
Expand Down Expand Up @@ -369,7 +362,7 @@ function startExpressServer() {

runAnvilPromise
.then((response) => {
res.sendStatus(200);
res.status(200).send({success: response});
})
.catch((err) => {
res
Expand All @@ -395,7 +388,6 @@ function startExpressServer() {
if (anvilProcess !== null) {
anvilProcess.kill("SIGINT");
anvilProcess = null;
console.log("killed the process");
}

const anvilDir = path.join(process.resourcesPath, "server2");
Expand Down Expand Up @@ -478,8 +470,6 @@ function startExpressServer() {
reject(new Error(`Kubeservices not found: ${data.toString()}`));
}
});

anvilProcess.on("close", (code) => {});
});

const runAnvilPromise = Promise.race([anvilTimeoutPromise, runAnvil]);
Expand Down
201 changes: 95 additions & 106 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import SocketFetcher from "@/components/ui/SocketFetcher";

import "./styles/globals.scss";
import AnvilConfigurationsModal from "./components/ui/modal/AnvilConfigurationsModal";
import ClosableModal from "./components/ui/modal/ClosableModal";
import StatusModal from "./components/ui/modal/StatusModal";
import { useState, useEffect } from "react";
import axios from "axios";
import { useAtom } from "jotai";
import { isPackaged } from "@/atoms/kubecontextAtom";
import { availableKubeContexts } from "@/atoms/kubecontextAtom";
import { Loading } from "@carbon/react";
import { ping } from "./client/anvil";
import { activeConfigurationAtom } from "./atoms/anvilConfigurationsAtom";
import AnvilLauncherStatus from "./components/ui/AnvilLauncherStatus";

const serverAddress = import.meta.env.VITE_EXPRESS;

export default function App() {
const [appIsPackaged, setIsPackaged] = useState(false);
const [availableKubeContextsAtom, setAvailableKubeContexts] = useAtom(
const [_, setAvailableKubeContexts] = useAtom(
availableKubeContexts,
);
const [configOpen, setConfigOpen] = useState(false);
Expand All @@ -37,89 +38,100 @@ export default function App() {
const [loading, setIsLoading] = useState(false);
const [configuration] = useAtom(activeConfigurationAtom);


useEffect(() => {
const serverAddress = import.meta.env.VITE_EXPRESS;
const res = axios.get(`${serverAddress}/isPackaged`).then((response) => {
setIsPackaged(response.data);
if (response.data === true) {
ping(configuration)
.then((res) => {
if (!res) {
axios
.get(`${serverAddress}/get-kube-contexts`)
.then((res) => {
setAvailableKubeContexts(res.data);

axios
.get(`${serverAddress}/get-anvil-config`)
.then((res) => {
const data = res.data;
if (data.has_config == true) {
const config = data.config;
const bucketPort = config.Local.BucketPort;
const driver = config.Local.Driver;
const serverPort = config.ServerPort;
const context = config.KubeContext;
if (config.IsLocal === true) {
setConfirmationIsOpen(true);
const configText = [
"Are you sure you want to run anvil with the following configurations?",
"If you are using minikube driver, please make sure you've setted up your minikube cluster, and that it's running.",
`HOST: 127.0.0.1`,
`PORT: ${serverPort}`,
`Context: ${context}`,
`Driver: ${driver}`,
];
setConfirmationText(configText);
}
} else {
setConfigOpen(true);
setConfirmationIsOpen(false);
}
})
.catch((err) => {
setErrText([
"Your local anvil did not started as expected. Please select a config",
err.response?.data?.err,
err.response?.data?.kubeErr,
]);
setConfigOpen(true);
});
})
.catch((err) => {
setErrText([
"Cannot find kubectl or there's an error with kubectl command. Please try again or check if kubectl is in your path. You can ignore this message if you're using cloud anvil",
err.message,
]);
setErrModalOpen(true);
});

async function initialLaunch() {
let isPackaged = false

try {
const res = await axios.get(`${serverAddress}/isPackaged`)
isPackaged = res.data
setIsPackaged(res.data)
} catch(err) {
//do nothing
}

if(isPackaged) {
const canPing = await ping(configuration)
if(!canPing) {

try {
const kubeResponse = await axios.get(`${serverAddress}/get-kube-contexts`)
setAvailableKubeContexts(kubeResponse.data)
} catch(err) {
//once user set their cloud settings, this message won't display again.
setErrText([
"Cannot find kubectl or there's an error with kubectl command. Please try again or check if kubectl is in your path or check if your Docker daemon is running. You can ignore this message if you'll use cloud anvil",
err.message,
]);
setErrModalOpen(true);
}

try {
const anvilRes = await axios.get(`${serverAddress}/get-anvil-config`)
const data = anvilRes.data
if(data.has_config) {
const config = data.config;
const bucketPort = config.Local.BucketPort;
const driver = config.Local.Driver;
const serverPort = config.ServerPort;
const context = config.KubeContext;
if (config.IsLocal === true) {
setConfirmationIsOpen(true);
const configText = [
"Are you sure you want to run anvil locally with the following configurations?",
"If you are using minikube driver, please make sure you've setup up your minikube cluster, and that it's running.",
`HOST: 127.0.0.1`,
`PORT: ${serverPort}`,
`Context: ${context}`,
`Driver: ${driver}`,
];
setConfirmationText(configText);
}
} else {
//do nothing, because you can ping
setConfigOpen(false);
setConfigOpen(true)
setConfirmationIsOpen(false)
}
})
.catch((err) => {
setConfigOpen(true);
});
} else {
//do nothing, because either pip is the controller, or the user runs on dev, hence they're responsible for running anvil, setting kubectl context etc...
} catch(err) {
//once user set their cloud settings, this message won't display again.
setErrText([
"Error occurred while trying to find your local Anvil configrations. Please try again to set your configurations and relaunch. If you want to use cloud settings, you can set your configurations to cloud instance, and ignore this message.",
err.response?.data?.err,
err.response?.data?.kubeErr,
]);
setErrModalOpen(true)
}

}
}
});
}

initialLaunch()
}, []);

const confirmSettings = async () => {
setIsLoading(true);
const serverAddress = import.meta.env.VITE_EXPRESS;
try {
const res = await axios.post(`${serverAddress}/launch-anvil-from-config`);
setConfirmationIsOpen(false);
setIsLoading(false);
setConfigOpen(false)
} catch (err) {
setErrText([err.message]);
setErrModalOpen(true);
setIsLoading(false);
}
};

const closeConfirmation = () => {
console.log("CHECK HERE")
if(!loading) {
setConfirmationIsOpen(false);
setConfigOpen(true);
}
}

return (
<ProviderInjector>
<ForgeTheme>
Expand All @@ -136,46 +148,23 @@ export default function App() {
appIsPackaged={appIsPackaged}
/>

{/* Confirmation */}
<ClosableModal
modalHeading="Would you like to run your anvil locally with your existing settings"
size="md"
primaryButtonText="Yes"
secondaryButtonText="No"
onRequestSubmit={confirmSettings}
onRequestClose={() => {
setConfirmationIsOpen(false);
setConfigOpen(true);
}}
open={confirmationOpen}
>
<div className="flex flex-col gap-4 p-3">
{confirmationText.map((error, i) => {
return <p key={"error-msg-" + i}>{error}</p>;
})}
</div>
<Loading active={loading} />
</ClosableModal>

{/* Error */}
<ClosableModal
modalHeading="Following errors happened, please change your local config, or choose a cloud configuration"
size="md"
primaryButtonText="Yes"
secondaryButtonText="No"
passiveModal
onRequestClose={() => {
<AnvilLauncherStatus
confirmationHeader="Would you like to run your anvil locally with your existing settings"
confirmSettings={confirmSettings}
confirmationClose={closeConfirmation}
confirmationOpen={confirmationOpen}
confirmationMessage={confirmationText}
loading={loading}
errorHeader="Following errors happened, please change your local config, or choose a cloud configuration"
errorClose={() => {
setErrModalOpen(false);
setConfigOpen(true);
}}
open={errModalOpen}
>
<div className="flex flex-col gap-4 p-3">
{errText.map((error, i) => {
return <p key={"error-msg-" + i}>{error}</p>;
})}
</div>
</ClosableModal>
errorOpen={errModalOpen}
errorMessage={errText}
/>



<MainContent>
<DrawflowWrapper />
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/components/ui/AnvilLauncherStatus.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import StatusModal from "./modal/StatusModal";


export default function AnvilLauncherStatus(props) {

return (<>
<StatusModal
modalHeading={props.confirmationHeader}
onRequestSubmit={props.confirmSettings}
onRequestClose={props.confirmationClose}
open={props.confirmationOpen}
message={props.confirmationMessage}
hasLoading={true}
loading={props.loading}

/>


<StatusModal
modalHeading={props.errorHeader}
passiveModal
onRequestClose={props.errorClose}
open={props.errorOpen}
message={props.errorMessage}
hasLoading={false}
/>
</>)

}
Loading

0 comments on commit ea666ac

Please sign in to comment.