Skip to content

Commit

Permalink
Added types for notebookimage and status (opendatahub-io#147)
Browse files Browse the repository at this point in the history
Updated with REST api notebook image endpoints and new notebook image types.
  • Loading branch information
dlabaj authored and tumido committed Mar 24, 2022
1 parent 69f6f28 commit 5ddc1ee
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
60 changes: 60 additions & 0 deletions backend/src/routes/api/notebook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import {
addNotebook,
deleteNotebook,
getNotebook,
getNotebooks,
updateNotebook,
} from './notebooksUtils';

export default async (fastify: FastifyInstance): Promise<void> => {
fastify.get('/', async (request: FastifyRequest, reply: FastifyReply) => {
return getNotebooks(fastify)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.get('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => {
return getNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.delete('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => {
return deleteNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.put('/:notebook', async (request: FastifyRequest, reply: FastifyReply) => {
return updateNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});

fastify.post('/', async (request: FastifyRequest, reply: FastifyReply) => {
return addNotebook(fastify, request)
.then((res) => {
return res;
})
.catch((res) => {
reply.send(res);
});
});
};
86 changes: 86 additions & 0 deletions backend/src/routes/api/notebook/notebooksUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { FastifyRequest } from 'fastify';
import { KubeFastifyInstance, Notebook } from '../../../types';

export const getNotebooks = async (
fastify: KubeFastifyInstance,
): Promise<{ notebooks: Notebook[]; error: string }> => {
const notebooks: Notebook[] = [];
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { notebooks: notebooks, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to retrieve notebook image(s): ' + e.toString());
return { notebooks: null, error: 'Unable to retrieve notebook image(s): ' + e.message };
}
}
};

export const getNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ notebooks: Notebook; error: string }> => {
const notebook: Notebook = {
name: '',
repo: '',
};
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { notebooks: notebook, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to retrieve notebook image(s): ' + e.toString());
return { notebooks: null, error: 'Unable to retrieve notebook image(s): ' + e.message };
}
}
};

export const addNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ success: boolean; error: string }> => {
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { success: true, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to add notebook image: ' + e.toString());
return { success: false, error: 'Unable to add notebook image: ' + e.message };
}
}
};

export const deleteNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ success: boolean; error: string }> => {
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { success: true, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to update notebook image: ' + e.toString());
return { success: false, error: 'Unable to update notebook image: ' + e.message };
}
}
};

export const updateNotebook = async (
fastify: KubeFastifyInstance,
request: FastifyRequest,
): Promise<{ success: boolean; error: string }> => {
// const coreV1Api = fastify.kube.coreV1Api;
// const namespace = fastify.kube.namespace;
try {
return { success: true, error: null };
} catch (e) {
if (e.response?.statusCode !== 404) {
fastify.log.error('Unable to update notebook image: ' + e.toString());
return { success: false, error: 'Unable to update notebook image: ' + e.message };
}
}
};
22 changes: 22 additions & 0 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,25 @@ export type BuildStatus = {
status: BUILD_PHASE;
timestamp?: string;
};

export enum NotebookStatus {
VALIDITING,
SUCCESS,
FAILED
}

export type Notebook = {
name: string;
repo: string;
description?: string;
status?: NotebookStatus;
user?: string;
uploaded?: Date;
visible?: boolean;
packages?: NotebookPackage[];
}

export type NotebookPackage = {
name: string;
version :string;
}
22 changes: 22 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ export type BuildStatus = {
status: BUILD_PHASE;
timestamp: string;
};

export enum NotebookStatus {
VALIDITING,
SUCCESS,
FAILED,
}

export type Notebook = {
name: string;
repo: string;
description?: string;
status?: NotebookStatus;
user?: string;
uploaded?: Date;
visible?: boolean;
packages?: NotebookPackage[];
};

export type NotebookPackage = {
name: string;
version: string;
};

0 comments on commit 5ddc1ee

Please sign in to comment.