Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added job scheduling page #23

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/App.tsx
Expand Up @@ -13,7 +13,7 @@ import Nodes from "./pages/Nodes";
import Node from "./pages/Node";
import StatsNodesLock from "./pages/StatsNodesLock";
import StatsNodesJobs from "./pages/StatsNodesJobs";
import { ErrorBoundary } from "react-error-boundary";
import Schedule from "./pages/Schedule";

import "./App.css";
import ErrorFallback from "./components/ErrorFallback";
Expand All @@ -39,21 +39,20 @@ function App(props: AppProps) {
</header>
<Drawer drawerOpen={drawerOpen} setDrawerOpen={setDrawerOpen} />
<div className="App-body">
<ErrorBoundary FallbackComponent={ErrorFallback} >
<Routes>
<Route path="/" element={<Runs />} />
<Route path="/nodes" element={<Nodes />} />
<Route path="/nodes/:name" element={<Node />} />
<Route path="/stats/nodes/jobs" element={<StatsNodesJobs />} />
<Route path="/stats/nodes/lock" element={<StatsNodesLock />} />
<Route path="/runs" element={<Runs />} />
<Route path="/runs/:name" element={<Run />} />
<Route path="/runs/:name/jobs/:job_id" element={<Job />} />
<Route path="/queue" element={<Queue />} />
<Route path="/:name" element={<Run />} />
<Route path="/:name/:job_id" element={<Job />} />
</Routes>
</ErrorBoundary>
<Routes>
<Route path="/" element={<Runs />} />
<Route path="/nodes" element={<Nodes />} />
<Route path="/nodes/:name" element={<Node />} />
<Route path="/stats/nodes/jobs" element={<StatsNodesJobs />} />
<Route path="/stats/nodes/lock" element={<StatsNodesLock />} />
<Route path="/runs" element={<Runs />} />
<Route path="/runs/:name" element={<Run />} />
<Route path="/runs/:name/jobs/:job_id" element={<Job />} />
<Route path="/queue" element={<Queue />} />
<Route path="/schedule" element={<Schedule />} />
<Route path="/:name" element={<Run />} />
<Route path="/:name/:job_id" element={<Job />} />
</Routes>
</div>
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/Drawer/index.jsx
Expand Up @@ -77,7 +77,6 @@ export default function Drawer(props) {
<RouterLink to="/runs" className={classes.drawerLink}>
Runs
</RouterLink>
<Divider />
<RouterLink to="/nodes?machine_type=smithi" className={classes.drawerLink}>
Nodes
</RouterLink>
Expand All @@ -87,7 +86,9 @@ export default function Drawer(props) {
<RouterLink to="/stats/nodes/jobs" className={classes.drawerLink}>
Node Jobs Stats
</RouterLink>
<Divider />
<RouterLink to="/schedule" className={classes.drawerLink}>
Schedule
</RouterLink>
</StyledSwipeableDrawer>
);
}
31 changes: 25 additions & 6 deletions src/lib/teuthologyAPI.ts
Expand Up @@ -3,28 +3,46 @@ import { useQuery } from "@tanstack/react-query";
import { Cookies } from "react-cookie";
import type { UseQueryResult } from "@tanstack/react-query";

const TEUTHOLOGY_API_SERVER =
const TEUTHOLOGY_API_SERVER =
import.meta.env.VITE_TEUTHOLOGY_API || "";
const GH_USER_COOKIE = "GH_USER";

function getURL(relativeURL: URL|string): string {
if ( ! TEUTHOLOGY_API_SERVER ) return "";
function getURL(relativeURL: URL | string): string {
if (!TEUTHOLOGY_API_SERVER) return "";
return new URL(relativeURL, TEUTHOLOGY_API_SERVER).toString();
}

function doLogin() {
const url = getURL("/login/");
if ( url ) window.location.href = url;
if (url) window.location.href = url;
}

function doLogout() {
const cookies = new Cookies();
cookies.remove(GH_USER_COOKIE);

const url = getURL("/logout/");
window.location.href = url;
}

async function useSchedule(commandValue: any) {
const url = getURL("/suite?logs=true");
const username = useUserData().get("username");
if (username) {
commandValue['--owner'] = username;
}
return await axios.post(url, commandValue, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamoltat
In order to kill a run scheduled by pulpito-ng's schedule feature, teuthology would look for owner (which is set by "--owner" parameter). If no "--owner" is passed in teuthology-suite command, teuthology sets it as scheduled_<machine username>@<machine hostname>.
In teuthology-api and pulpito-ng setup, I think it'll work out well if we set commandValue['--owner'] = github_username on pulpito-ng before sending request to t-api. This way we would be able to recognise the owner as github username when we try to kill the run later.

Also, I think we can skip "--user" checks entirely since we merged https://github.com/ceph/teuthology-api/pull/47/files#diff-d64c10972091566c2a44e7e643a8e41b7a4781efb8cddb9516b0cfe320ff648f in which we set "--user" as github username in teuthology-api.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, new commit should address this.

withCredentials: true,
headers: { "Content-Type": "application/json" },
}).then((resp) => {
console.log(resp);
return resp;
}, (error) => {
console.log(error);
throw error;
});
}

function useSession(): UseQueryResult {
const url = getURL("/");
const query = useQuery({
Expand Down Expand Up @@ -59,6 +77,7 @@ function useUserData(): Map<string, string> {
export {
doLogin,
doLogout,
useSchedule,
useSession,
useUserData
useUserData,
}