From 837b726a76403197c248244623bfa7bfe73153eb Mon Sep 17 00:00:00 2001 From: Enyinna Ochulor Date: Mon, 16 Sep 2019 18:45:29 +0000 Subject: [PATCH] Revert "Patch 1431" This reverts commit 316f4dbb4033cf3278880bd0661fbe8533621a40. Change-Id: Iea85ba5083b26f2e75ca7aee5eeed3d6bc4e79a4 --- cmd/bpa-restapi-agent/README.md | 181 ---------------------------- cmd/bpa-restapi-agent/api/imagehandler.go | 82 +++++++++++-- cmd/bpa-restapi-agent/internal/app/image.go | 69 ++--------- cmd/bpa-restapi-agent/sample.json | 6 +- 4 files changed, 84 insertions(+), 254 deletions(-) diff --git a/cmd/bpa-restapi-agent/README.md b/cmd/bpa-restapi-agent/README.md index 70555cb..a74434c 100644 --- a/cmd/bpa-restapi-agent/README.md +++ b/cmd/bpa-restapi-agent/README.md @@ -4,184 +4,3 @@ To run the server, follow these simple steps: ``` go run main.go ``` -Integrated Cloud Native (ICN) RESTful API - -This is a Golang application providing a RESTful API to interact with and upload image objects. - -The API application source files are in the icn/cmd/bpa-restapi-agent directory. - -While the database back-end is extensible, this initial release requires mongodb. - -Install - -Install and start mongodb. For instructions: https://docs.mongodb.com/manual/installation/ - -git clone "https://gerrit.akraino.org/r/icn" -cd icn/cmd/bpa-restapi-agent - -Run the application -go run main.go - -Output without a config file: - -2019/08/22 14:08:41 Error loading config file. Using defaults -2019/08/22 14:08:41 Starting Integrated Cloud Native API - -RESTful API usage examples - -Sample Post Request - -curl -i -F "metadata=//jsonfile -X POST http://NODE_IP:9015//baremetalcluster/{owner}/{clustername}/ - -#image type can be binary_image, container_image, or os_image - -Example requests and responses: - -Create image - POST - -#Using a json file called sample.json -#image_length in sample.json can be determined with the command -ls -al - -Request - -curl -i -F "metadata=/{imgname} - - -example: -#continuing with our container image from above - -Request - -curl -i -X GET http://localhost:9015/v1/baremetalcluster/alpha/beta/container_images/asdf246 - -Response - -HTTP/1.1 200 OK -Content-Type: application/json -Date: Thu, 22 Aug 2019 22:57:10 GMT -Content-Length: 239 - -{"owner":"alpha","cluster_name":"beta","type":"container","image_name":"asdf246","image_offset":0,"image_length":29718177,"upload_complete":false,"description":{"image_records":[{"image_record_name":"iuysdi1234","repo":"icn","tag":"1"}]}} - -Upload container image - PATCH -Request - -curl --request PATCH --data-binary "@/home/enyi/workspace/icn/cmd/bpa-restapi-agent/sample_image" http://localhost:9015/v1/baremetalcluster/alpha/beta/container_images/asdf246 --header "Upload-Offset: 0" --header "Expect:" -i - - -Response - -HTTP/1.1 204 No Content -Upload-Offset: 29718177 -Date: Thu, 22 Aug 2019 23:19:44 GMT - -Check uploaded image - GET - -Request - -curl -i -X GET http://localhost:9015/v1/baremetalcluster/alpha/beta/container_images/asdf246 - -Response - -HTTP/1.1 200 OK -Content-Type: application/json -Date: Fri, 23 Aug 2019 17:12:07 GMT -Content-Length: 245 - -{"owner":"alpha","cluster_name":"beta","type":"container","image_name":"asdf246","image_offset":29718177,"image_length":29718177,"upload_complete":true,"description":{"image_records":[{"image_record_name":"iuysdi1234","repo":"icn","tag":"1"}]}} - -#after the upload, the image_offset is now the same as image_length and upload_complete changed to true -#if upload was incomplete - -Resumable upload instructions - -Resumable upload -PATCH - -#this is the current resumable upload mechanism - -Request - -curl --request PATCH --data-binary "@/home/enyi/workspace/icn/cmd/bpa-restapi-agent/sample_image" http://localhost:9015/v1/baremetalcluster/alpha/beta/container_images/asdf246 --header "Upload-Offset: 0" --header "Expect:" -i --limit-rate 200K - -#the above request limits transfer for testing purposes -#'ctl c' out after a few seconds, to stop file transfer -#check image_offset with a GET - -Check upload - GET - -Request - -curl -i -X GET http://localhost:9015/v1/baremetalcluster/alpha/beta/container_images/asdf246 - -Response - -HTTP/1.1 200 OK -Content-Type: application/json -Date: Sat, 24 Aug 2019 00:30:00 GMT -Content-Length: 245 - -{"owner":"alpha","cluster_name":"beta","type":"container","image_name":"asdf246","image_offset":4079616,"image_length":29718177,"upload_complete":false,"description":{"image_records":[{"image_record_name":"iuysdi1234","repo":"icn","tag":"2"}]}} - -#from our response you can see that image_offset is still less than image_length and #upload_complete is still false -#next we use the dd command (no limiting this time) - -Request - -dd if=/home/enyi/workspace/icn/cmd/bpa-restapi-agent/sample_image skip=4079616 bs=1 | curl --request PATCH --data-binary @- http://localhost:9015/v1/baremetalcluster/alpha/beta/container_images/asdf246 --header "Upload-Offset: 4079616" --header "Expect:" -i - -#the request skips already uploaded 4079616 bytes of data - -Response - -25638561+0 records in -25638561+0 records out -25638561 bytes (26 MB, 24 MiB) copied, 207.954 s, 123 kB/s -HTTP/1.1 204 No Content -Upload-Offset: 29718177 -Date: Sat, 24 Aug 2019 00:43:18 GMT - -Update image description - PUT - -# let's change the tag in description from 1 to latest -# once the change is made in sample.json (or your json file) - -Request - -curl -i -F "metadata=