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

Fix code executions #599

Merged
merged 6 commits into from
Sep 8, 2023
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
2 changes: 1 addition & 1 deletion docs/guides/userGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ to be up and running as soon as you boot up the Operating System.)
![Aliro Imager Install](https://media.githubusercontent.com/media/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_install.png?raw=true "Aliro Imager Install")
4. Once installed, you can run the **AliroEd Imager** from the Start Menu. When
the program starts up you will see this screen:
![Aliro Imager Start](https://media.githubusercontent.com/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_start.png?raw=true "Aliro Imager Start")
![Aliro Imager Start](https://media.githubusercontent.com/media/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_start.png?raw=true "Aliro Imager Start")
5. Click the **CHOOSE STORAGE** button and select your MicroSD Card from the
popup menu.
![Aliro Imager Choose Storage](https://media.githubusercontent.com/media/EpistasisLab/Aliro/master/docs/source/_static/aliro_imager_choose_storage.png?raw=true "Aliro Imager Choose Storage")
Expand Down
26 changes: 13 additions & 13 deletions lab/routes/execapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
} = require('../execapiutils');

router.post('/executions', async (req, res, next) => {
if (req.body.src_code === null) {
if (req.body.src_code == null) {
return res.status(400).json({ message: 'No src_code provided' });
}

Expand All @@ -34,17 +34,17 @@ router.post('/executions', async (req, res, next) => {
files: []
});

if (req.body.dataset_file_id !== null) {
if (req.body.dataset_file_id != null) {
execution._dataset_file_id = req.body.dataset_file_id;
} else if (req.body.dataset_id !== null) {
} else if (req.body.dataset_id != null) {
execution._dataset_id = req.body.dataset_id;
let dataset = await getDatasetById(req.body.dataset_id);
if (dataset !== null) {
if (dataset != null) {
execution._dataset_file_id = dataset.files[0]._id;
}
}

if (req.body.experiment_id !== null) {
if (req.body.experiment_id != null) {
execution._experiment_id = req.body.experiment_id;
}

Expand All @@ -67,7 +67,7 @@ router.post('/executions', async (req, res, next) => {
let machines;
try {
machines = await Machine.find({}, { address: 1 });
if (machines.length === 0) {
if (machines.length == 0) {
return res.status(400).json({ message: 'No machines available' });
}
// call the machine api
Expand Down Expand Up @@ -110,19 +110,19 @@ router.post('/executions', async (req, res, next) => {

router.post('/executions/install', async (req, res, next) => {

if (req.body.command !== 'install' && req.body.command !== 'freeze') {
if (req.body.command != 'install' && req.body.command != 'freeze') {
return res.status(400).json({ message: 'Invalid command' });
}

if ( (req.body.packages === null || req.body.packages.length === 0)
&& req.body.command !== 'freeze') {
if (req.body.command != 'freeze' && (req.body.packages == null ||
req.body.packages.length == 0)) {
return res.status(400).json({ message: 'No packages provided' });
}

let machines;
try {
machines = await Machine.find({}, { address: 1 });
if (machines.length === 0) {
if (machines.length == 0) {
return res.status(400).json({ message: 'No machines available' });
}
// call the machine api
Expand All @@ -147,13 +147,13 @@ router.get('/executions/:id', getExecutionById, async (req, res, next) => {
});

router.patch('/executions/:id', getExecutionById, async (req, res, next) => {
if (req.body.status !== null) {
if (req.body.status != null) {
res.execution.status = req.body.status;
}
if (req.body.result !== null) {
if (req.body.result != null) {
res.execution.result = req.body.result;
}
if (req.body.files !== null) {
if (req.body.files != null) {
res.execution.files = req.body.files;
}
try {
Expand Down
4 changes: 2 additions & 2 deletions machine/machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@ app.post("/code/run/install", jsonParser, (req, res) => {
pyProc.stdout.on("data", (data) => {
// result.exec_results = JSON.parse(data.toString());
console.log(`stdout: ${data}`);
result.exec_results.stdout = data.toString();
result.exec_results.stdout += data.toString();
});

pyProc.stderr.on("data", (data) => {
console.log(`stderr: ${data}`);
result.exec_results.stderr = data.toString();
result.exec_results.stderr += data.toString();
// try {
// result.exec_results = JSON.parse(data.toString());
// }
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/jest/labApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ export const getAiStatus = (datasetId) => get(`http://lab:5080/api/userdatasets/
export const fetchExperimentModel = (id) => get(`http://lab:5080/api/v1/experiments/${id}/model`);
export const fetchExperimentScript = (id) => get(`http://lab:5080/api/v1/experiments/${id}/script`);

export const postCodeExecutions = (params) => post('http://lab:5080/execapi/v1/executions', params)
export const postPackageInstall = (params) => post('http://lab:5080/execapi/v1/executions/install', params)
31 changes: 31 additions & 0 deletions tests/integration/jest/machineApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ describe('machine', () => {
expect(data.capacity).toEqual(1)
});

it('Test the code run API endpoint results are correct.', async () => {
var labCodeRun = await labApi.postCodeExecutions({ src_code: "print('hello world')" })
expect(labCodeRun.status).toBeTruthy()
expect(labCodeRun.status).toEqual('completed')
expect(labCodeRun._id).toBeTruthy()
expect(labCodeRun.result).toEqual('hello world\n')
});

// I'll need a specific dataset id for this test to work.
// it('Test code run API endpoint recognizes df.', async () => {
// var labCodeRun = await labApi.postCodeExecutions({ src_code: "print(df.head(1))", dataset_id: })
// expect(labCodeRun.status).toBeTruthy()
// expect(labCodeRun.status).toEqual('completed')
// expect(labCodeRun._id).toBeTruthy()
// expect(labCodeRun.result).toBeTruthy()
// });

// it('Test code run API endpoint recognizes model')

it('Test the package install API endpoint with good package.', async () => {
var labCodeInstall = await labApi.postPackageInstall({ command: 'install', packages: ['numpy'] })
expect(labCodeInstall.exec_results.code).toEqual(0)
expect(labCodeInstall.exec_results.stdout).toBeTruthy()
});

it('Test the package install API endpoint with a bad package.', async () => {
var labCodeInstall = await labApi.postPackageInstall({ command: 'install', packages: ['test'] })
expect(labCodeInstall.exec_results.code).toEqual(1)
expect(labCodeInstall.exec_results.stderr).toBeTruthy()
})

});

describe('startup validation', () =>
Expand Down