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

Graphql #1589

Merged
merged 58 commits into from
Aug 11, 2022
Merged

Graphql #1589

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6963524
first integration
maty21 Sep 2, 2021
c6ac39e
first integration with mongo
maty21 Sep 2, 2021
f0acd88
refactoring
maty21 Sep 3, 2021
86db7c2
fix issues
maty21 Sep 4, 2021
1fc4ee1
fix
maty21 Sep 5, 2021
1ab9962
add discovery
maty21 Sep 11, 2021
8fa86b8
fix graph
maty21 Dec 29, 2021
7e17f45
fix graph
maty21 Jan 23, 2022
b702f60
add logs and fix issues
maty21 Jan 26, 2022
02326be
merge
maty21 Apr 26, 2022
88b0424
fix dependencies
maty21 Apr 28, 2022
1676749
Merge branch 'master' into graphql
maty21 May 8, 2022
aac1eb2
update version
maty21 May 8, 2022
f41ffe4
add introspection to config
maty21 May 11, 2022
27b7335
add to config
maty21 May 11, 2022
3fb0de1
Merge branch 'master' into graphql
maty21 May 11, 2022
c8c9ded
Merge branch 'master' into graphql
maty21 May 11, 2022
79690d5
fix config
maty21 May 11, 2022
33dfbfe
Merge branch 'graphql' of https://github.com/kube-HPC/hkube into graphql
maty21 May 11, 2022
c1b6922
fix introspection
maty21 May 12, 2022
f350846
add graphql implementation to preffered
maty21 May 15, 2022
12f8451
add graphql implementation to preffered
maty21 May 15, 2022
089a2bb
fix issue with pipelines
maty21 May 18, 2022
c0d2334
add states to schema
maty21 May 19, 2022
726d67b
fix issue with cpu change to float
maty21 May 19, 2022
df0d50f
merge
maty21 May 25, 2022
a215cc1
graphql:fix pipeline issue + fix build statuses
maty21 May 26, 2022
32e441a
fix prefered to float
maty21 May 26, 2022
40872f1
add dataSurces to graphql api
maty21 May 29, 2022
0b4d7e4
fix worker data adapter to an older version 1.0.20
maty21 May 29, 2022
2e4a882
+ add data to pipelined driver schema
maty21 May 29, 2022
20c581c
fix logging with cri
yehiyam May 30, 2022
712e5b9
fix ci
maty21 Jun 13, 2022
6be1540
revert to node 14
maty21 Jun 13, 2022
f527a09
add files for ci
maty21 Jun 13, 2022
5fb33c5
fix action
maty21 Jun 13, 2022
7669bf7
add data source api to graphql
maty21 Jun 15, 2022
c377027
fix datasource api
maty21 Jun 20, 2022
8aadb75
add node statistics to graphql api
maty21 Jun 20, 2022
7465b03
disk usage
maty21 Jun 20, 2022
8ed268c
fix disk space
maty21 Jun 20, 2022
24c0de6
fix disk space schema
maty21 Jun 20, 2022
83f2757
add errorlogs to graphql api
maty21 Jun 21, 2022
918631e
upgrade db version to 2.x
maty21 Jun 27, 2022
fe185d8
add api for counts
maty21 Jun 28, 2022
95115e7
fix algorithm count and add datasource count
maty21 Jul 10, 2022
d9c455a
add experiments
maty21 Jul 10, 2022
8f2b7de
fix dataSource count
maty21 Jul 10, 2022
fcc7613
add tests for graphql
maty21 Jul 12, 2022
b59a022
Merge branch 'graphql' of github.com:kube-HPC/hkube into graphql
maty21 Jul 12, 2022
a022596
add tests for graphql
maty21 Jul 12, 2022
621113c
add tests for graphql
maty21 Jul 12, 2022
47951dc
remove index.html
maty21 Aug 3, 2022
7da5c03
Merge branch 'graphql' of https://github.com/kube-HPC/hkube into graphql
maty21 Aug 3, 2022
808ae79
after review
maty21 Aug 9, 2022
e9c40b6
after merge from master
maty21 Aug 9, 2022
a74e75d
Merge branch 'graphql' of github.com:kube-HPC/hkube into graphql
maty21 Aug 9, 2022
6b0731c
after merge from master
maty21 Aug 9, 2022
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
12 changes: 6 additions & 6 deletions core/algorithm-queue/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/api-server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
quotes: ["error", "single"],
"comma-dangle": "off",
"no-underscore-dangle": "off",
"linebreake-style": "off",
"linebreak-style": "off",
"object-curly-newline": "off",
"newline-per-chained-call": "off",
"arrow-body-style": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const RestServer = require('@hkube/rest-server');
const log = require('@hkube/logger').GetLogFromContanier();
const { metrics } = require('@hkube/metrics');
const HttpStatus = require('http-status-codes');
const internal = require('./internal/index');
const validator = require('../../lib/validation/api-validator');
const component = require('../../lib/consts/componentNames').REST_API;
const internal = require('./rest-api/internal/index');
const validator = require('../lib/validation/api-validator');
const component = require('../lib/consts/componentNames').REST_API;
const rest = new RestServer();
const graphqlServer = require('./graphql/graphql-server');
const routeLogBlacklist = ['/metrics', '/swagger'];

class AppServer {
Expand All @@ -28,16 +29,16 @@ class AppServer {
const { prefix, port, rateLimit, poweredBy, bodySizeLimit } = options.rest;
const routes = internal();
routes.push(metrics.getRouter());
const versions = await fse.readdir(path.join(__dirname, 'routes'));
const versions = await fse.readdir(path.join(__dirname, './rest-api/routes'));

await Promise.all(versions.map(async (v) => {
swagger.servers.push({ url: path.join('/', options.swagger.path, prefix, v) });
const routers = await fse.readdir(path.join(__dirname, 'routes', v));
const routers = await fse.readdir(path.join(__dirname, './rest-api/routes', v));
routers.forEach((f) => {
const file = path.basename(f, '.js');
routes.push({
route: path.join('/', prefix, v, file),
router: require('./' + path.join('routes', v, file))({ ...options, version: v, file }) // eslint-disable-line
router: require('./' + path.join('rest-api/routes', v, file))({ ...options, version: v, file }) // eslint-disable-line
});
});
}));
Expand Down Expand Up @@ -66,7 +67,9 @@ class AppServer {
}
}
};

const data = await rest.start(opt);
graphqlServer(rest._app, rest._server, options.port, options.graphql);
log.info(`🚀 ${data.message}`, { component });
}
}
Expand Down
51 changes: 51 additions & 0 deletions core/api-server/api/graphql/graphql-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { gql } = require('apollo-server');
const jobTypeDefs = require('./schemas/job-schema');
const discoveryTypeDefs = require('./schemas/discovery-schema');
const algorithmTypeDefs = require('./schemas/algorithm-schema');
const pipelineTypeDefs = require('./schemas/pipeline-schema');
const experimentTypeDefs = require('./schemas/experiment-schema');
const nodeStatisticTypeDefs = require('./schemas/node-statistic-schema');
const diskSpaceTypeDefs = require('./schemas/disk-space-schema');
const pipelineStatsTypeDefs = require('./schemas/pipeline-stats-schema');
const dataSourcesTypeDefs = require('./schemas/datasource-schema');
const algorithmBuildsTypeDefs = require('./schemas/algorithm-builder-schema');
const logsTypeDefs = require('./schemas/log-schema');
const preferedTypeDefs = require('./schemas/prefered-schema');
const errorLogsTypeDefs = require('./schemas/error-logs-schema');
const SubscriptionIncNumbersTypeDefs = gql`
type Subscription {
numberIncremented: Int
}
`;

const Query = gql`
type Query {
currentNumber: Int
}
`;
const Subscription = gql`
type Subscription {
numberIncremented: Int
numberIncrementedOdd(number: Int): Int
}
`;
const types = [
dataSourcesTypeDefs,
algorithmBuildsTypeDefs,
jobTypeDefs,
algorithmTypeDefs,
pipelineTypeDefs,
experimentTypeDefs,
logsTypeDefs,
nodeStatisticTypeDefs,
diskSpaceTypeDefs,
discoveryTypeDefs,
pipelineStatsTypeDefs,
SubscriptionIncNumbersTypeDefs,
preferedTypeDefs,
errorLogsTypeDefs,
Query,
Subscription
];

module.exports = types;
47 changes: 47 additions & 0 deletions core/api-server/api/graphql/graphql-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { ApolloServer } = require('apollo-server-express');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const log = require('@hkube/logger').GetLogFromContanier();
const component = require('../../lib/consts/componentNames').GRAPHQL_SERVER;

const _typeDefs = require('./graphql-schema');
const _resolvers = require('./resolvers');

async function startApolloServer(typeDefs, resolvers, app, httpServer, port, config) {
try {
const schema = makeExecutableSchema({
typeDefs,
resolvers,

});

const server = new ApolloServer({
schema,
plugins: [{
async serverWillStart() {
return {
async drainServer() {
// subscriptionServer.close();
}
};
}
}],
introspection: config.introspection
});
await server.start();
server.applyMiddleware({ app });

log.info(`🚀 Query endpoint ready at http://localhost:${port}${server.graphqlPath}`, { component });
log.info(`🚀 Subscription endpoint ready at ws://localhost:${port}${server.graphqlPath}`, { component });
}
catch (error) {
log.error(`Error on running gr ${error}`,);
}
}

const graphqlServer = (app, httpServer, port, config) => {
startApolloServer(_typeDefs, _resolvers.getResolvers(), app, httpServer, port, config).catch(err => {
log.error(err, { component });
});
};

module.exports = graphqlServer;
48 changes: 48 additions & 0 deletions core/api-server/api/graphql/queries/board-querier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const storageManager = require('@hkube/storage-manager');

const _mapBoards = (boards, key, innerKey) => {
return ((boards.length > 0) && boards.reduce((map, board) => {
const { id, status, boardReference } = board;
// eslint-disable-next-line no-param-reassign
map[board[key]] = map[board[key]] || {};
// eslint-disable-next-line no-param-reassign
map[board[key]][board[innerKey]] = { id, status, boardReference };
return map;
}, {})) || {};
};
const mapBoards = (boards) => {
const batch = boards.filter(board => (!board.taskId) && board.jobId);
const batchMap = _mapBoards(batch, 'jobId', 'nodeName');
const task = boards.filter(board => (board.taskId));
const taskMap = (_mapBoards(task, 'jobId', 'taskId'));
const node = boards.filter(board => (!board.jobId));
const nodeMap = _mapBoards(node, 'pipelineName', 'nodeName');
return { batchMap, taskMap, nodeMap };
};

const addHasMetricsToMap = async (nodeMap) => {
const pipelines = await storageManager.hkubeAlgoMetrics.listPipelines();
await Promise.all(pipelines.map(async pipeline => {
// eslint-disable-next-line no-param-reassign
nodeMap[pipeline] = nodeMap[pipeline] || {};
const nodes = await storageManager.hkubeAlgoMetrics.listNodes(pipeline);
nodes.forEach(nodeName => {
// eslint-disable-next-line no-param-reassign
nodeMap[pipeline][nodeName] = nodeMap[pipeline][nodeName] || {};
// eslint-disable-next-line no-param-reassign
nodeMap[pipeline][nodeName].hasMetrics = true;
});
}));
};

const getBoards = ({ node, job, batchMap, taskMap }) => {
if (node.batch && node.batch.some(task => (task.metricsPath && task.metricsPath.tensorboard.path))) {
return batchMap[job.key] && batchMap[job.key][node.nodeName] && [{ tensorboard: { board: batchMap[job.key][node.nodeName] } }];
}
if (node.metricsPath && node.metricsPath.tensorboard.path) {
return taskMap[job.key] && taskMap[job.key][node.taskId] && [{ tensorboard: { board: taskMap[job.key][node.taskId] } }];
}
return [];
};

module.exports = { mapBoards, getBoards, addHasMetricsToMap };
68 changes: 68 additions & 0 deletions core/api-server/api/graphql/queries/dataSource-querier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const { default: axios } = require('axios');
const log = require('@hkube/logger').GetLogFromContainer();
const component = require('../../../lib/consts/componentNames').GRAPHQL_SERVER;
class DataSourceQuerier {
init(config) {
const { protocol, host, port, prefix } = config.dataSourceService;
this._baseUrl = `${protocol}://${host}:${port}/${prefix}`;
this.pathGenerator = {
dataSources: () => `${this._baseUrl}`,
dataSourceFiles: name => `${this._baseUrl}/${name}`,
versions: name => `${this._baseUrl}/${name}/versions`,
snapshot: name => `${this._baseUrl}/${name}/snapshot`,
// post
preview: id => `${this._baseUrl}/id/${id}/snapshot/preview`,
};
}

getDataSourcesList() {
return this._getRequest(this.pathGenerator.dataSources());
}

getDataSource(options) {
return this._getRequest(this.pathGenerator.dataSourceFiles(options.name), options);
}

getDataSourceVersions(options) {
return this._getRequest(this.pathGenerator.versions(options.name));
}

getDataSourceSnapshots(options) {
return this._getRequest(this.pathGenerator.snapshot(options.name));
}

postDataSourcePreviewQuery(options) {
return this._postRequest(this.pathGenerator.preview(options.id), options);
}

async getDataSourcesCount() {
const data = await this._getRequest(this.pathGenerator.dataSources());
if (data) {
return data.length;
}
return 0;
}

async _getRequest(url, options) {
try {
const { data } = await axios.get(url, { params: options });
return data;
}
catch (error) {
log.error(error.message, { component });
}
return null;
}

async _postRequest(url, options) {
try {
const { data } = await axios.post(url, options);
return data;
}
catch (error) {
log.error(error.message, { component });
}
return null;
}
}
module.exports = new DataSourceQuerier();
Loading