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

Providers schema #53

Merged
merged 22 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ To install, either:
Once you have the vsix file, run `code --install-extension vscode*.vsix` to install the extension.
**Note: the file [build_vsix_dev.sh] is only to be used for development**

**Adding cloud instances to the Deployment Tab:** You can include information about the instances that you use thrugh the extension settings. There you will find an option named **providers** that accepts a list of urls separated by commas. Each url must be a JSON file that follows the schema speficied here : [schema](skyline-vscode/react-ui/src/schema/CloudProvidersSchema.js).<br/>
Addittionally, you need to add the necessary access so the extension can read the file.<br/>
**Adding cloud instances to the Deployment Tab:** You can include information about the instances that you use thrugh the extension settings. There you will find an option named **providers** that accepts a list of urls separated by commas. Each url must be a JSON file that follows the schema specified here : [schema](skyline-vscode/react-ui/src/schema/CloudProvidersSchema.js).<br/>
Additionally, you need to add the necessary access so the extension can read the file.<br/>
You can use an AWS S3 bucket to store your files. Change CORS settings in Permissions tab.

**CORS requirements**:
Expand Down
2 changes: 2 additions & 0 deletions skyline-vscode/react-ui/src/data/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export const deploymentScatterGraphColorSize = {
HIGHLIGHTSIZE: 280,
};

export const CENTML_CLOUD_PROVIDERS_URL = "https://deepview-explorer-public.s3.amazonaws.com/vscode-cloud-providers/providers.json";

51 changes: 19 additions & 32 deletions skyline-vscode/react-ui/src/utils/parsers.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import Ajv from "ajv";
import {
gpuPropertyList,
CENTML_CLOUD_PROVIDERS_URL,
deploymentScatterGraphColorSize,
} from "../data/properties";
import {fetchingURLErrors} from '../utils/utils';
import { cloudProviderSchema } from "../schema/CloudProvidersSchema";

const ajv = new Ajv({ allErrors: true }); // to report all validation errors (rather than failing on the first errors)
const validate = ajv.compile(cloudProviderSchema);

class ResponseBuffer {
constructor() {
this.instanceId = 0;
this.instanceArray = [];
this.cloudProviders = {};
this.errors = [];
}
}
export const loadJsonFiles = async (habitatData, additionalProviders) => {
Copy link

Choose a reason for hiding this comment

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

Function loadJsonFiles has 77 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could refactor by wrapping some repeated logic with helper functions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved logic to utils.js

Copy link

Choose a reason for hiding this comment

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

Function loadJsonFiles has 68 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

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

Function loadJsonFiles has 74 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

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

Function loadJsonFiles has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.

const buffer = new ResponseBuffer();
let instanceId = 0;
const instanceArray = [];
const cloudProviders = {};
const errors = [];

// const buffer = new cloudProviderAndInstancesBuilder();
let urlList = [
"https://deepview-explorer-public.s3.amazonaws.com/vscode-cloud-providers/providers.json",
CENTML_CLOUD_PROVIDERS_URL,
];
const additionalList = additionalProviders ? additionalProviders.split(","):[];
urlList = urlList.concat(additionalList);
Expand All @@ -34,7 +33,7 @@ export const loadJsonFiles = async (habitatData, additionalProviders) => {
const valid = validate(respJsonData);
if (valid) {
for (const cloudProvider of respJsonData) {
buffer.cloudProviders[cloudProvider.name.toLocaleLowerCase()] = {
cloudProviders[cloudProvider.name.toLocaleLowerCase()] = {
name: cloudProvider.name,
logo: cloudProvider.logo,
color: cloudProvider.color,
Expand All @@ -49,8 +48,8 @@ export const loadJsonFiles = async (habitatData, additionalProviders) => {
item.name.toLocaleLowerCase() ===
instanceData.gpu.toLocaleLowerCase()
);
buffer.instanceArray.push({
id: buffer.instanceId,
instanceArray.push({
id: instanceId,
x: found_in_habitat[1], // msec
y: (instanceData.cost / 3.6e6) * found_in_habitat[1], // cost per msec * habitatData = cost per 1 iteration
info: {
Expand All @@ -64,34 +63,22 @@ export const loadJsonFiles = async (habitatData, additionalProviders) => {
fill: cloudProvider.color,
z: deploymentScatterGraphColorSize.NORMALSIZE,
});
buffer.instanceId += 1;
instanceId += 1;
}
}
} else {
buffer.errors.push({
msg: `invalid data format from url: ${resp.url}`,
invalidFields: validate.errors.map((err) => ({
field: err.instancePath,
err: err.message,
})),
});
errors.push(fetchingURLErrors("schemaValidationErrors",resp,validate));
}
} catch (error) {
Copy link

Choose a reason for hiding this comment

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

Identical blocks of code found in 2 locations. Consider refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could encapsulate this into a helper function

buffer.errors.push({
msg: `error reading from url: ${resp.url}`,
code: `status: ${resp.statusText} | code: ${resp.status}`,
});
errors.push(fetchingURLErrors("noJsonResponseFromUrl",resp,null));
}
} else {
Copy link

Choose a reason for hiding this comment

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

Identical blocks of code found in 2 locations. Consider refactoring.

buffer.errors.push({
msg: `error reading from url: ${resp.url}`,
code: `status: ${resp.statusText} | code: ${resp.status}`,
});
errors.push(fetchingURLErrors(null,resp,null));
}
}
return {
cloudProviders: Object.keys(buffer.cloudProviders).length > 0 ? buffer.cloudProviders: null,
instanceArray: buffer.instanceArray.length > 0 ? buffer.instanceArray:null,
errors: buffer.errors.length > 0 ? buffer.errors:null,
cloudProviders: Object.keys(cloudProviders).length > 0 ? cloudProviders: null,
instanceArray: instanceArray.length > 0 ? instanceArray:null,
errors: errors.length > 0 ? errors:null,
};
};
Loading