Skip to content

JSON API - stage I#934

Open
amd-pdebski wants to merge 4 commits intoOpen-CAS:masterfrom
amd-pdebski:json
Open

JSON API - stage I#934
amd-pdebski wants to merge 4 commits intoOpen-CAS:masterfrom
amd-pdebski:json

Conversation

@amd-pdebski
Copy link
Copy Markdown
Contributor

JSON API - ioctl handling, json requests handling, structuring and marshaling json responses, RESTful API early prototype

@CAS-Linux-Jenkins
Copy link
Copy Markdown

Can one of the admins verify this patch?

@rafalste
Copy link
Copy Markdown
Contributor

ok to test

@robertbaldyga
Copy link
Copy Markdown
Member

add to whitelist

Comment thread json/go.mod Outdated
…rshaling json responses, RESTful API early prototype

Signed-off-by: Piotr Debski <piotr.debski@intel.com>
Comment thread json/ioctl/strut_conv.go Outdated
Comment thread json/ioctl/strut_conv.go Outdated
Comment thread json/ioctl/strut_conv.go Outdated
Comment thread json/ioctl/strut_conv.go Outdated
Comment thread json/rest/compose_data.go Outdated
Comment thread json/rest/compose_data.go Outdated
Comment thread json/rest/compose_data.go Outdated
Comment thread json/ioctl/json_structs.go Outdated
Comment thread json/ioctl/strut_conv.go Outdated
Comment thread json/ioctl/strut_conv.go Outdated
Comment thread json/rest/compose_data.go Outdated
Comment thread json/rest/compose_data.go Outdated
Comment thread json/rest/rest.go Outdated
Comment thread json/rest/rest.go Outdated
@amd-pdebski amd-pdebski changed the title JSON API - ioctl handling, json requests handling, structuring and ma… JSON API - STAGE I Sep 2, 2021
@amd-pdebski amd-pdebski changed the title JSON API - STAGE I JSON API - stage I Sep 2, 2021
Comment thread json/api/compose_data.go Outdated
Comment thread json/api/compose_data.go Outdated
Comment thread json/ioctl/ioctl.go Outdated
Comment thread json/ioctl/ocf_types.go Outdated
Comment thread json/main.go Outdated
Comment thread json/api/request.go Outdated
/** Reads Request structure from file "request.json" */

func (req *Request) Read_req() {
data, err := ioutil.ReadFile("request.json")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We'd prefer to read input json from stdin instead of forcing user to create file containing the request.

Comment thread json/api/request.go Outdated

func (req *Request) Write_req() {
file, err := json.MarshalIndent(req, "", " ")
_ = ioutil.WriteFile("request.json", file, 0644)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here. We'd prefer to print output to stdout. It's much easier to integrate with other tools.

Comment thread json/api/request.go
Comment on lines +15 to +50
type Request struct {
Request_list_caches bool `json:"request list_caches"`
Request_get_stats bool `json:"request statistics"`
Get_stats_info Stats_request_info `json:"statistics request info"`
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would be better to have common request header (it may consist of a single field like "command", which would contain name of the command) and the rest of the request structure would be different for each command. Otherwise we will end up with request structure containing all the input for all variants of all commands.

That would require preparsing request json as a Header struct which may look like this:

type Header struct {
    Command string `json:"command"`
}

That would allow us to determine the command type, and then we would be able to parse the request as a specific command.

@arutk
Copy link
Copy Markdown
Contributor

arutk commented Oct 4, 2021

Please squash commits to hide review history (e.g. remove "Review fixes" commit" from the log)

@arutk
Copy link
Copy Markdown
Contributor

arutk commented Oct 5, 2021

General comment: I would suggest to make json application output to entirely conform to json syntax. Especially error information might be included in the json output itself.

Comment thread json/request.json Outdated
Comment on lines +6 to +7
"core_id": 0,
"io_class": 0,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would make sense to make "core_id" and "io_class" parameters optional

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Problem addressed trough increase granulation and making current parameters obligatory (different commands for each statistics level)

@Deixx
Copy link
Copy Markdown
Contributor

Deixx commented Oct 29, 2021

retest this please

Comment thread json/api/compose_data.go Outdated
@@ -0,0 +1,165 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please update license tag to SPDX-License-Identifier: BSD-3-Clause

Comment thread json/api/json_api.go Outdated
json_get_stats_core(*params)
}

if command == "opencas.ioclass.stats.get" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should be opencas.cache.ioclass.stats.get.

Comment thread json/api/json_api.go Outdated
json_get_stats_cache(*params)
}

if command == "opencas.core.stats.get" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should be opencas.cache.core.stats.get.

Comment thread json/api/json_api.go Outdated
json_get_cache_info(*params)
}

if command == "opencas.core.info.get" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

opencas.cache.core.info.get

Comment thread json/api/json_api.go Outdated
json_get_core_info(*params)
}

if command == "opencas.ioclass.info.get" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

opencas.cache.ioclass.info.get

@Open-CAS Open-CAS deleted a comment from pep8speaks Nov 9, 2021
@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Dec 23, 2021

Hello @pdebski21! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 18:59: E128 continuation line under-indented for visual indent
Line 21:45: E128 continuation line under-indented for visual indent

Line 48:53: E128 continuation line under-indented for visual indent
Line 54:61: E128 continuation line under-indented for visual indent

Comment last updated at 2022-01-04 09:28:29 UTC

KanagiAomori and others added 2 commits January 4, 2022 10:25
Signed-off-by: Piotr Debski <piotr.debski@intel.com>
Signed-off-by: Piotr Debski <piotr.debski@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants