made package POST endpoint compatible with original GK endpoint.
authorpeusterm <manuel.peuster@uni-paderborn.de>
Wed, 30 Mar 2016 17:55:01 +0000 (19:55 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Wed, 30 Mar 2016 17:55:01 +0000 (19:55 +0200)
src/emuvim/api/sonata/README.md
src/emuvim/api/sonata/dummygatekeeper.py

index a1708d4..30586e7 100644 (file)
@@ -22,20 +22,20 @@ The example starts a small network with two data centers.
 
 To upload the file `sonata-demo.son` (from son-schema repo) do:
 
-* `curl -i -X POST -F file=@sonata-demo.son http://127.0.0.1:5000/api/packages`
+* `curl -i -X POST -F package=@sonata-demo.son http://127.0.0.1:5000/packages`
 
 To list all uploaded packages do:
 
-* `curl http://127.0.0.1:5000/api/packages`
+* `curl http://127.0.0.1:5000/packages`
 
 To instantiate (start) a service do:
 
-* Specific service: `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"`
-* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:5000/api/instantiations -d "{}"`
+* Specific service: `curl -X POST http://127.0.0.1:5000/instantiations -d "{\"service_uuid\":\"59446b64-f941-40a8-b511-effb0512c21b\"}"`
+* Last uploaded service (makes manual tests easier): `curl -X POST http://127.0.0.1:5000/instantiations -d "{}"`
 
 To list all running services do:
 
-* `curl http://127.0.0.1:5000/api/instantiations`
+* `curl http://127.0.0.1:5000/instantiations`
 
 
 ## API definition
@@ -56,28 +56,28 @@ _Note: This API should converge to the API of the original GK as much as possibl
 <th>Response:</th>
 </tr>
 <tr>
-<td>/api/packages</td>
+<td>/packages</td>
 <td>POST</td>
 <td>-</td>
 <td>{file-content} as "content-type": "multipart/form-data"</td>
 <td>{"service_uuid": "c880aaab-f3b9-43ac-ac6b-3d27b46146b7", size=456, sha1=49ee6468dfa4ecbad440d669b249d523a38651be, error: null}</td>
 </tr>
 <tr>
-<td>/api/packages</td>
+<td>/packages</td>
 <td>GET</td>
 <td>-</td>
 <td></td>
 <td>{service_uuid_list: ["c880aaab-f3b9-43ac-ac6b-3d27b46146b7", "c880aaab-f3b9-43ac-ac6b-3d27b46146b8", "c880aaab-f3b9-43ac-ac6b-3d27b46146b9"]}</td>
 </tr>
 <tr>
-<td>/api/instantiations</td>
+<td>/instantiations</td>
 <td>POST</td>
 <td>-</td>
 <td>{service_uuid: "c880aaab-f3b9-43ac-ac6b-3d27b46146b7"}</td>
 <td>{service_instance_uuid: "de4567-f3b9-43ac-ac6b-3d27b461123"}</td>
 </tr>
 <tr>
-<td>/api/instantiations</td>
+<td>/instantiations</td>
 <td>GET</td>
 <td>-</td>
 <td></td>
index c69fd9a..6475044 100644 (file)
@@ -272,7 +272,13 @@ class Packages(fr.Resource):
         try:
             # get file contents
             print(request.files)
-            son_file = request.files['file']
+            # lets search for the package in the request
+            if "package" in request.files:
+                son_file = request.files["package"]
+            # elif "file" in request.files:
+            #     son_file = request.files["file"]
+            else:
+                return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed. file not found."}, 500
             # generate a uuid to reference this package
             service_uuid = str(uuid.uuid4())
             file_hash = hashlib.sha1(str(son_file)).hexdigest()
@@ -289,7 +295,7 @@ class Packages(fr.Resource):
             return {"service_uuid": service_uuid, "size": size, "sha1": file_hash, "error": None}
         except Exception as ex:
             LOG.exception("Service package upload failed:")
-            return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed"}
+            return {"service_uuid": None, "size": 0, "sha1": None, "error": "upload failed"}, 500
 
     def get(self):
         """
@@ -338,8 +344,8 @@ app = Flask(__name__)
 app.config['MAX_CONTENT_LENGTH'] = 512 * 1024 * 1024  # 512 MB max upload
 api = fr.Api(app)
 # define endpoints
-api.add_resource(Packages, '/api/packages')
-api.add_resource(Instantiations, '/api/instantiations')
+api.add_resource(Packages, '/packages')
+api.add_resource(Instantiations, '/instantiations')
 
 
 def start_rest_api(host, port, datacenters=dict()):