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

refactor: use API code generators for sessions v2 #3513

Merged
merged 12 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.css
*.svg
# Generated files should not be linted
src/features/dataConnectorsV2/api/data-connectors.api.ts
src/features/projectsV2/api/projectV2.api.ts
src/features/projectsV2/api/storagesV2.api.ts
src/features/dataConnectorsV2/api/data-connectors.api.ts
src/features/sessionsV2/api/sessionLaunchersV2.generated-api.ts
src/features/sessionsV2/api/sessionsV2.generated-api.ts
src/features/usersV2/api/users.generated-api.ts
6 changes: 4 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
"storybook-wait-server": "wait-on http://127.0.0.1:6006",
"storybook-test": "test-storybook",
"storybook-compile-and-test": "concurrently -k -s first -n 'BUILD,TEST' -c 'magenta,blue' 'npm run storybook-build && npm run storybook-start-server' 'npm run storybook-wait-server && npm run storybook-test'",
"generate-api": "npm run generate-api:connectedServices && npm run generate-api:data-connectors && npm run generate-api:namespaceV2 && npm run generate-api:projectV2 && npm run generate-api:platform && npm run generate-api:searchV2 && npm run generate-api:users",
"generate-api": "npm run generate-api:connectedServices && npm run generate-api:data-connectors && npm run generate-api:namespaceV2 && npm run generate-api:platform && npm run generate-api:projectV2 && npm run generate-api:searchV2 && npm run generate-api:sessionLaunchersV2 && npm run generate-api:sessionsV2 && npm run generate-api:users",
"generate-api:connectedServices": "rtk-query-codegen-openapi src/features/connectedServices/api/connectedServices.api-config.ts",
"generate-api:data-connectors": "rtk-query-codegen-openapi src/features/dataConnectorsV2/api/data-connectors.api-config.ts",
"generate-api:namespaceV2": "rtk-query-codegen-openapi src/features/projectsV2/api/namespace.api-config.ts",
"generate-api:projectV2": "rtk-query-codegen-openapi src/features/projectsV2/api/projectV2.api-config.ts",
"generate-api:platform": "rtk-query-codegen-openapi src/features/platform/api/platform.api-config.ts",
"generate-api:projectV2": "rtk-query-codegen-openapi src/features/projectsV2/api/projectV2.api-config.ts",
"generate-api:searchV2": "rtk-query-codegen-openapi src/features/searchV2/api/searchV2.api-config.ts",
"generate-api:sessionLaunchersV2": "rtk-query-codegen-openapi src/features/sessionsV2/api/sessionLaunchersV2.api-config.ts",
"generate-api:sessionsV2": "rtk-query-codegen-openapi src/features/sessionsV2/api/sessionsV2.api-config.ts",
"generate-api:users": "rtk-query-codegen-openapi src/features/usersV2/api/users.api-config.ts"
},
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion client/src/features/dashboardV2/DashboardV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import CreateProjectV2Button from "../projectsV2/new/CreateProjectV2Button";
import GroupShortHandDisplay from "../projectsV2/show/GroupShortHandDisplay";
import ProjectShortHandDisplay from "../projectsV2/show/ProjectShortHandDisplay";
import SearchV2Bar from "../searchV2/components/SearchV2Bar";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../sessionsV2/sessionsV2.api";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../sessionsV2/api/sessionsV2.api";
import { useGetUserQuery } from "../usersV2/api/users.api";
import UserAvatar from "../usersV2/show/UserAvatar";
import DashboardV2Sessions from "./DashboardV2Sessions";
Expand Down
4 changes: 2 additions & 2 deletions client/src/features/dashboardV2/DashboardV2Sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { Col, ListGroup, Row } from "reactstrap";
import { Loader } from "../../components/Loader";
import EnvironmentLogsV2 from "../../components/LogsV2";
import { RtkErrorAlert } from "../../components/errors/RtkErrorAlert";
import { useGetProjectSessionLauncherQuery } from "../../features/sessionsV2/sessionsV2.api";
import { ABSOLUTE_ROUTES } from "../../routing/routes.constants";
import useAppSelector from "../../utils/customHooks/useAppSelector.hook";
import { useGetProjectsByProjectIdQuery } from "../projectsV2/api/projectV2.enhanced-api";
import { useGetSessionLaunchersByLauncherIdQuery as useGetProjectSessionLauncherQuery } from "../sessionsV2/api/sessionLaunchersV2.api";
import ActiveSessionButton from "../sessionsV2/components/SessionButton/ActiveSessionButton";
import {
SessionStatusV2Description,
Expand Down Expand Up @@ -122,7 +122,7 @@ function DashboardSession({ session }: DashboardSessionProps) {
projectId ? { projectId } : skipToken
);
const { data: launcher } = useGetProjectSessionLauncherQuery(
launcherId ? { id: launcherId } : skipToken
launcherId ? { launcherId } : skipToken
);

const projectUrl = project
Expand Down
8 changes: 4 additions & 4 deletions client/src/features/session/components/SessionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ function SessionRowProject({ annotations }: SessionRowProjectProps) {

export interface SessionLauncherResources {
name?: string;
cpu: number;
memory: number;
gpu: number;
storage: number;
cpu?: number;
memory?: number;
gpu?: number;
storage?: number;
}
interface SessionRowResourceRequestsProps {
resourceRequests: Session["resources"]["requests"] | SessionLauncherResources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

import { useEffect, useMemo, useState } from "react";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../sessionsV2/api/sessionsV2.api";
import { useGetSessionsQuery } from "./sessions.api";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../sessionsV2/sessionsV2.api";
import { SessionStatusState } from "./sessions.types";

const DEFAULT_POLLING_INTERVAL_MS = 5_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { useCallback, useEffect } from "react";
import { Trash, XLg } from "react-bootstrap-icons";
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from "reactstrap";

import { WarnAlert } from "../../components/Alert";
import { RtkErrorAlert } from "../../components/errors/RtkErrorAlert";
import { useDeleteSessionLauncherMutation } from "./sessionsV2.api";
import { useDeleteSessionLaunchersByLauncherIdMutation as useDeleteSessionLauncherMutation } from "./api/sessionLaunchersV2.api";
import { SessionLauncher } from "./sessionsV2.types";
import { WarnAlert } from "../../components/Alert";

interface DeleteSessionLauncherModalProps {
isOpen: boolean;
Expand Down
21 changes: 13 additions & 8 deletions client/src/features/sessionsV2/PauseOrDeleteSessionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ import {
useParams,
} from "react-router-dom-v5-compat";
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from "reactstrap";

import { Loader } from "../../components/Loader";
import { User } from "../../model/renkuModels.types";
import { NOTIFICATION_TOPICS } from "../../notifications/Notifications.constants";
import { NotificationsManager } from "../../notifications/notifications.types";
import { ABSOLUTE_ROUTES } from "../../routing/routes.constants";
import AppContext from "../../utils/context/appContext";
import useLegacySelector from "../../utils/customHooks/useLegacySelector.hook";
import styles from "../session/components/SessionModals.module.scss";
import { useWaitForSessionStatusV2 } from "../session/useWaitForSessionStatus.hook";
import {
usePatchSessionMutation,
useStopSessionMutation,
} from "../sessionsV2/sessionsV2.api";
usePatchSessionsBySessionIdMutation as usePatchSessionMutation,
useDeleteSessionsBySessionIdMutation as useStopSessionMutation,
} from "./api/sessionsV2.api";
import { SessionV2 } from "./sessionsV2.types";
import { Loader } from "../../components/Loader";

import styles from "../session/components/SessionModals.module.scss";

interface PauseOrDeleteSessionModalProps {
action?: "pause" | "delete";
Expand Down Expand Up @@ -107,7 +109,7 @@ function AnonymousDeleteSessionModal({
const [isStopping, setIsStopping] = useState(false);

const onStopSession = useCallback(async () => {
stopSession({ session_id: sessionName });
stopSession({ sessionId: sessionName });
setIsStopping(true);
}, [sessionName, stopSession]);

Expand Down Expand Up @@ -226,7 +228,10 @@ function PauseSessionModalContent({
const [isStopping, setIsStopping] = useState(false);

const onHibernateSession = useCallback(async () => {
patchSession({ session_id: sessionName, state: "hibernated" });
patchSession({
sessionId: sessionName,
sessionPatchRequest: { state: "hibernated" },
});
setIsStopping(true);
}, [patchSession, sessionName]);

Expand Down Expand Up @@ -335,7 +340,7 @@ function DeleteSessionModalContent({
const [isStopping, setIsStopping] = useState(false);

const onStopSession = useCallback(async () => {
stopSession({ session_id: sessionName });
stopSession({ sessionId: sessionName });
setIsStopping(true);
}, [sessionName, stopSession]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import { useCallback, useMemo } from "react";

import useLocationHash from "../../../utils/customHooks/useLocationHash.hook";
import { Project } from "../../projectsV2/api/projectV2.api";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../sessionsV2.api";
import { SessionView } from "../SessionView/SessionView";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../api/sessionsV2.api";
import { SessionLauncher } from "../sessionsV2.types";
import { SessionView } from "../SessionView/SessionView";
import SessionItem from "./SessionItem";

interface SessionLauncherDisplayProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { NOTIFICATION_TOPICS } from "../../../notifications/Notifications.consta
import type { NotificationsManager } from "../../../notifications/notifications.types";
import { ABSOLUTE_ROUTES } from "../../../routing/routes.constants";
import AppContext from "../../../utils/context/appContext";
import { usePatchSessionMutation } from "../sessionsV2.api";
import { usePatchSessionsBySessionIdMutation as usePatchSessionMutation } from "../api/sessionsV2.api";
import type { SessionV2 } from "../sessionsV2.types";

interface SessionPausedProps {
Expand All @@ -46,7 +46,10 @@ export default function SessionPaused({ session }: SessionPausedProps) {
const [isResuming, setIsResuming] = useState(false);

const onResumeSession = useCallback(() => {
patchSession({ session_id: sessionName, state: "running" });
patchSession({
sessionId: sessionName,
sessionPatchRequest: { state: "running" },
});
setIsResuming(true);
}, [patchSession, sessionName]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
ModalHeader,
UncontrolledTooltip,
} from "reactstrap";

import { Loader } from "../../../components/Loader";
import EnvironmentLogsV2 from "../../../components/LogsV2";
import { TimeCaption } from "../../../components/TimeCaption";
Expand All @@ -57,18 +58,17 @@ import { displaySlice, resetFavicon, setFavicon } from "../../display";
import { useGetNamespacesByNamespaceProjectsAndSlugQuery } from "../../projectsV2/api/projectV2.enhanced-api";
import SessionUnavailable from "../../session/components/SessionUnavailable";
import { SessionRowResourceRequests } from "../../session/components/SessionsList";
import styles from "../../session/components/ShowSession.module.scss";
import { StartSessionProgressBarV2 } from "../../session/components/StartSessionProgressBar";
import PauseOrDeleteSessionModal from "../PauseOrDeleteSessionModal";
import { useGetProjectsByProjectIdSessionLaunchersQuery as useGetProjectSessionLaunchersQuery } from "../api/sessionLaunchersV2.api";
import { useGetSessionsQuery } from "../api/sessionsV2.api";
import { getSessionFavicon } from "../session.utils";
import {
useGetProjectSessionLaunchersQuery,
useGetSessionsQuery,
} from "../sessionsV2.api";
import { SessionV2 } from "../sessionsV2.types";
import SessionIframe from "./SessionIframe";
import SessionPaused from "./SessionPaused";

import styles from "../../session/components/ShowSession.module.scss";

export default function ShowSessionPage() {
const dispatch = useAppDispatch();
const {
Expand Down Expand Up @@ -432,18 +432,20 @@ function SessionDetails({
</Link>
</p>
</div>
<div>
<p className="mb-0">
<Clock className={cx("bi", "me-2")} />
<span className="fw-bold">
<TimeCaption
prefix="Launched"
datetime={session.started}
className={cx("fs-6")}
/>
</span>
</p>
</div>
{session.started && (
<div>
<p className="mb-0">
<Clock className={cx("bi", "me-2")} />
<span className="fw-bold">
<TimeCaption
prefix="Launched"
datetime={session.started}
className={cx("fs-6")}
/>
</span>
</p>
</div>
)}
<div
className={cx(
"d-block",
Expand Down
17 changes: 10 additions & 7 deletions client/src/features/sessionsV2/SessionStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
useParams,
useSearchParams,
} from "react-router-dom-v5-compat";

import { ErrorAlert } from "../../components/Alert";
import PageLoader from "../../components/PageLoader";
import {
Expand Down Expand Up @@ -57,12 +58,12 @@ import { useGetNamespacesByNamespaceProjectsAndSlugQuery } from "../projectsV2/a
import { storageSecretNameToFieldName } from "../secretsV2/secrets.utils";
import DataConnectorSecretsModal from "./DataConnectorSecretsModal";
import SessionSecretsModal from "./SessionSecretsModal";
import { SelectResourceClassModal } from "./components/SessionModals/SelectResourceClass";
import { useGetProjectsByProjectIdSessionLaunchersQuery as useGetProjectSessionLaunchersQuery } from "./api/sessionLaunchersV2.api";
import {
useGetDockerImageQuery,
useGetProjectSessionLaunchersQuery,
useLaunchSessionMutation,
} from "./sessionsV2.api";
useGetSessionsImagesQuery as useGetDockerImageQuery,
usePostSessionsMutation as useLaunchSessionMutation,
} from "./api/sessionsV2.api";
import { SelectResourceClassModal } from "./components/SessionModals/SelectResourceClass";
import { SessionLauncher } from "./sessionsV2.types";
import startSessionOptionsV2Slice from "./startSessionOptionsV2.slice";
import {
Expand Down Expand Up @@ -224,7 +225,9 @@ function SessionStarting({ launcher, project }: StartSessionFromLauncherProps) {
// Request session
useEffect(() => {
if (isLoadingStartSession || session != null || isError) return;
startSessionV2(launcherToStart);
startSessionV2({
sessionPostRequest: launcherToStart,
});
dispatch(setFavicon("waiting"));
}, [
isLoadingStartSession,
Expand Down Expand Up @@ -453,7 +456,7 @@ function StartSessionFromLauncher({
isError: isErrorDockerImageStatus,
error: errorDockerImageStatus,
} = useGetDockerImageQuery(
containerImage ? { image_url: containerImage } : skipToken
containerImage ? { imageUrl: containerImage } : skipToken
);

const needsCredentials = startSessionOptionsV2.cloudStorage?.some(
Expand Down
6 changes: 2 additions & 4 deletions client/src/features/sessionsV2/SessionsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ import DeleteSessionV2Modal from "./DeleteSessionLauncherModal";
import SessionItem from "./SessionList/SessionItem";
import { SessionItemDisplay } from "./SessionList/SessionItemDisplay";
import { SessionView } from "./SessionView/SessionView";
import { useGetProjectsByProjectIdSessionLaunchersQuery as useGetProjectSessionLaunchersQuery } from "./api/sessionLaunchersV2.api";
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "./api/sessionsV2.api";
import UpdateSessionLauncherModal from "./components/SessionModals/UpdateSessionLauncherModal";
import {
useGetProjectSessionLaunchersQuery,
useGetSessionsQuery as useGetSessionsQueryV2,
} from "./sessionsV2.api";
import { SessionLauncher, SessionV2 } from "./sessionsV2.types";

// Required for logs formatting
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*!
* Copyright 2025 - Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Run `npm run generate-api:sessionLaunchersV2` to generate the API
import type { ConfigFile } from "@rtk-query/codegen-openapi";
import path from "path";

const config: ConfigFile = {
apiFile: "./sessionLaunchersV2.empty-api.ts",
apiImport: "sessionLaunchersV2EmptyApi",
outputFile: "./sessionLaunchersV2.generated-api.ts",
exportName: "sessionLaunchersV2GeneratedApi",
hooks: true,
schemaFile: path.join(__dirname, "sessionLaunchersV2.openapi.json"),
};

export default config;
Loading
Loading