Release version 0.1.0
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Tue, 9 Oct 2018 14:20:36 +0000 (16:20 +0200)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Fri, 12 Oct 2018 08:42:51 +0000 (10:42 +0200)
Change-Id: I93d02f936e619418c1c06b326e60f89a33484847
Signed-off-by: Alexander Mazuruk <a.mazuruk@samsung.com>
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
18 files changed:
.gometalinter.json
ChangeLog [new file with mode: 0644]
Gopkg.lock
Gopkg.toml
cmd/weles-server/main.go
server/configure_weles.go
server/doc.go
server/embedded_spec.go
server/operations/general/version.go [new file with mode: 0644]
server/operations/general/version_parameters.go [new file with mode: 0644]
server/operations/general/version_responses.go [new file with mode: 0644]
server/operations/general/version_urlbuilder.go [new file with mode: 0644]
server/operations/weles_api.go
server/version_handler.go [new file with mode: 0644]
server/version_handler_test.go [new file with mode: 0644]
swagger.yml
version.go [new file with mode: 0644]
weles.go

index 69ad74a..9a2fd58 100644 (file)
@@ -49,5 +49,6 @@
     "job_info.go",
     "job_sort_by.go",
     "job_status.go",
-    "sort_order.go"]
+    "sort_order.go",
+    "version.go"]
 }
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..fe10558
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,20 @@
+Release 0.1.0 - Fri Oct. 12 2018 - PaweÅ‚ Wieczorek <p.wieczorek2@samsung.com>
+=============================================================================
+* Basic LAVA YAML job description support:
+  - Deploy (including partition mapping)
+  - Boot (with login and prompt variants)
+  - Test (run/push/pull actions)
+* Requesting DUT from Boruta based on "device_type" capability
+* Obtaining and storing job assets and artifacts locally
+* Sharing assets and artifacts with reverse SSHFS
+* Dryad requirements (under /usr/local/bin path):
+  - stm (for power controlling actions: -dut/-ts/-tick)
+  - fota (supporting mapping-based selective flashing)
+  - dut_boot.sh
+  - dut_login.sh
+  - dut_copyto.sh
+  - dut_copyfrom.sh
+  - dut_exec.sh
+* HTTP API v1:
+  - jobs: create new, cancel, list with filtering and sorting (paginated)
+  - artifacts: list with filtering and sorting (paginated)
index 3011dab..d3d858b 100644 (file)
@@ -18,8 +18,7 @@
   revision = "de5bf2ad457846296e2031421a34e2568e304e35"
 
 [[projects]]
-  branch = "master"
-  digest = "1:21e19132c685b8bad36ed74108e27f572a03e4d4a45ae11d592351de87808b49"
+  digest = "1:dddcbd3558fd08155e8a65399c5453777cdc726cce88ea746cee1902ec47819c"
   name = "github.com/SamsungSLAV/boruta"
   packages = [
     ".",
@@ -27,7 +26,8 @@
     "http/client",
   ]
   pruneopts = ""
-  revision = "3dd45a88179118f23e5e097ceec5483c493748aa"
+  revision = "0303d3264d97bc7af3151f570dff6ddc7e1dd900"
+  version = "v0.1.0"
 
 [[projects]]
   digest = "1:d8a2bb36a048d1571bcc1aee208b61f39dc16c6c53823feffd37449dde162507"
index 7f663f7..04fe012 100644 (file)
@@ -33,6 +33,10 @@ required = [
            ]
 
 [[constraint]]
+name = "github.com/SamsungSLAV/boruta"
+version = "v0.1.0"
+
+[[constraint]]
 name = "github.com/golang/mock"
 version = "v1.1.1"
 
index 0d8b982..afc5343 100644 (file)
@@ -25,6 +25,7 @@ import (
        flag "github.com/spf13/pflag"
 
        "github.com/SamsungSLAV/boruta/http/client"
+       "github.com/SamsungSLAV/weles"
        "github.com/SamsungSLAV/weles/artifacts"
        "github.com/SamsungSLAV/weles/controller"
        "github.com/SamsungSLAV/weles/manager"
@@ -41,6 +42,7 @@ var (
        artifactDownloadQueueCap int
        activeWorkersCap         int
        notifierChannelCap       int
+       version                  bool
 )
 
 // This file was generated by the swagger tool.
@@ -84,6 +86,8 @@ func main() {
 
        flag.IntVar(&notifierChannelCap, "notifier-channel-cap", 100, "Notifier channel capacity.")
 
+       flag.BoolVar(&version, "version", false, "Print Weles server version and exit.")
+
        //TODO: input validation
 
        flag.Usage = func() {
@@ -102,6 +106,11 @@ func main() {
        // parse the CLI flags
        flag.Parse()
 
+       if version {
+               fmt.Println("weles version", weles.SrvVersion)
+               os.Exit(0)
+       }
+
        var yap parser.Parser
        am, err := artifacts.NewArtifactManager(
                artifactDBName,
index c9601af..f5440b3 100644 (file)
@@ -24,11 +24,18 @@ import (
        "github.com/go-openapi/errors"
        "github.com/go-openapi/runtime"
 
+       "github.com/SamsungSLAV/weles"
        "github.com/SamsungSLAV/weles/server/operations"
        "github.com/SamsungSLAV/weles/server/operations/artifacts"
+       "github.com/SamsungSLAV/weles/server/operations/general"
        "github.com/SamsungSLAV/weles/server/operations/jobs"
 )
 
+const (
+       apiVersion = "v1"
+       apiState   = weles.VersionStateDevel
+)
+
 func configureFlags(api *operations.WelesAPI) {
        // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
 }
@@ -58,6 +65,8 @@ func welesConfigureAPI(api *operations.WelesAPI, a *APIDefaults) http.Handler {
 
        api.ArtifactsArtifactListerHandler = artifacts.ArtifactListerHandlerFunc(a.ArtifactLister)
 
+       api.GeneralVersionHandler = general.VersionHandlerFunc(a.Version)
+
        api.ServerShutdown = func() {}
 
        return setupGlobalMiddleware(api.Serve(setupMiddlewares))
index 41796c5..5defa69 100644 (file)
@@ -28,7 +28,7 @@ http://tbd.tbd/terms/
       http
     Host: localhost:8088
     BasePath: /api/v1
-    Version: 0.0.0
+    Version: v1
     License: Apache 2.0 http://www.apache.org/licenses/LICENSE-2.0.html
     Contact: <tbd@tbd.com>
 
index 51041de..b0a831f 100644 (file)
@@ -54,7 +54,7 @@ func init() {
       "name": "Apache 2.0",
       "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
     },
-    "version": "0.0.0"
+    "version": "v1"
   },
   "host": "localhost:8088",
   "basePath": "/api/v1",
@@ -387,6 +387,44 @@ func init() {
           }
         }
       }
+    },
+    "/version": {
+      "get": {
+        "description": "Version and state of API (e.g. v1 obsolete, v2 stable, v3 devel) and server version.",
+        "produces": [
+          "application/json"
+        ],
+        "tags": [
+          "general"
+        ],
+        "summary": "Show current version of Weles internals",
+        "operationId": "Version",
+        "responses": {
+          "200": {
+            "description": "OK",
+            "schema": {
+              "$ref": "#/definitions/Version"
+            },
+            "headers": {
+              "Weles-API-State": {
+                "type": "string",
+                "description": "State of Weles API."
+              },
+              "Weles-API-Version": {
+                "type": "string",
+                "description": "Version of Weles API."
+              },
+              "Weles-Server-Version": {
+                "type": "string",
+                "description": "Version of Weles server."
+              }
+            }
+          },
+          "500": {
+            "$ref": "#/responses/InternalServer"
+          }
+        }
+      }
     }
   },
   "definitions": {
@@ -657,6 +695,29 @@ func init() {
         "Ascending",
         "Descending"
       ]
+    },
+    "Version": {
+      "description": "defines version of Weles API (and its state) and server.\n",
+      "type": "object",
+      "properties": {
+        "API": {
+          "description": "Version of Weles API.",
+          "type": "string"
+        },
+        "Server": {
+          "description": "Version of Weles server.",
+          "type": "string"
+        },
+        "State": {
+          "description": "State of Weles API.",
+          "type": "string",
+          "enum": [
+            "devel",
+            "stable",
+            "deprecated"
+          ]
+        }
+      }
     }
   },
   "responses": {
@@ -705,6 +766,10 @@ func init() {
     {
       "description": "Info about all artifacts used by Weles jobs.",
       "name": "artifacts"
+    },
+    {
+      "description": "Info about Weles (e.g. version)",
+      "name": "general"
     }
   ],
   "externalDocs": {
@@ -734,7 +799,7 @@ func init() {
       "name": "Apache 2.0",
       "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
     },
-    "version": "0.0.0"
+    "version": "v1"
   },
   "host": "localhost:8088",
   "basePath": "/api/v1",
@@ -1103,6 +1168,47 @@ func init() {
           }
         }
       }
+    },
+    "/version": {
+      "get": {
+        "description": "Version and state of API (e.g. v1 obsolete, v2 stable, v3 devel) and server version.",
+        "produces": [
+          "application/json"
+        ],
+        "tags": [
+          "general"
+        ],
+        "summary": "Show current version of Weles internals",
+        "operationId": "Version",
+        "responses": {
+          "200": {
+            "description": "OK",
+            "schema": {
+              "$ref": "#/definitions/Version"
+            },
+            "headers": {
+              "Weles-API-State": {
+                "type": "string",
+                "description": "State of Weles API."
+              },
+              "Weles-API-Version": {
+                "type": "string",
+                "description": "Version of Weles API."
+              },
+              "Weles-Server-Version": {
+                "type": "string",
+                "description": "Version of Weles server."
+              }
+            }
+          },
+          "500": {
+            "description": "Internal Server error",
+            "schema": {
+              "$ref": "#/definitions/ErrResponse"
+            }
+          }
+        }
+      }
     }
   },
   "definitions": {
@@ -1373,6 +1479,29 @@ func init() {
         "Ascending",
         "Descending"
       ]
+    },
+    "Version": {
+      "description": "defines version of Weles API (and its state) and server.\n",
+      "type": "object",
+      "properties": {
+        "API": {
+          "description": "Version of Weles API.",
+          "type": "string"
+        },
+        "Server": {
+          "description": "Version of Weles server.",
+          "type": "string"
+        },
+        "State": {
+          "description": "State of Weles API.",
+          "type": "string",
+          "enum": [
+            "devel",
+            "stable",
+            "deprecated"
+          ]
+        }
+      }
     }
   },
   "responses": {
@@ -1421,6 +1550,10 @@ func init() {
     {
       "description": "Info about all artifacts used by Weles jobs.",
       "name": "artifacts"
+    },
+    {
+      "description": "Info about Weles (e.g. version)",
+      "name": "general"
     }
   ],
   "externalDocs": {
diff --git a/server/operations/general/version.go b/server/operations/general/version.go
new file mode 100644 (file)
index 0000000..2955ed1
--- /dev/null
@@ -0,0 +1,75 @@
+// Code generated by go-swagger; DO NOT EDIT.
+
+// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+//
+
+package general
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the generate command
+
+import (
+       "net/http"
+
+       middleware "github.com/go-openapi/runtime/middleware"
+)
+
+// VersionHandlerFunc turns a function with the right signature into a version handler
+type VersionHandlerFunc func(VersionParams) middleware.Responder
+
+// Handle executing the request and returning a response
+func (fn VersionHandlerFunc) Handle(params VersionParams) middleware.Responder {
+       return fn(params)
+}
+
+// VersionHandler interface for that can handle valid version params
+type VersionHandler interface {
+       Handle(VersionParams) middleware.Responder
+}
+
+// NewVersion creates a new http.Handler for the version operation
+func NewVersion(ctx *middleware.Context, handler VersionHandler) *Version {
+       return &Version{Context: ctx, Handler: handler}
+}
+
+/*Version swagger:route GET /version general version
+
+Show current version of Weles internals
+
+Version and state of API (e.g. v1 obsolete, v2 stable, v3 devel) and server version.
+
+*/
+type Version struct {
+       Context *middleware.Context
+       Handler VersionHandler
+}
+
+func (o *Version) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
+       route, rCtx, _ := o.Context.RouteInfo(r)
+       if rCtx != nil {
+               r = rCtx
+       }
+       var Params = NewVersionParams()
+
+       if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
+               o.Context.Respond(rw, r, route.Produces, route, err)
+               return
+       }
+
+       res := o.Handler.Handle(Params) // actually handle the request
+
+       o.Context.Respond(rw, r, route.Produces, route, res)
+
+}
diff --git a/server/operations/general/version_parameters.go b/server/operations/general/version_parameters.go
new file mode 100644 (file)
index 0000000..8552984
--- /dev/null
@@ -0,0 +1,60 @@
+// Code generated by go-swagger; DO NOT EDIT.
+
+// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+//
+
+package general
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the swagger generate command
+
+import (
+       "net/http"
+
+       "github.com/go-openapi/errors"
+       "github.com/go-openapi/runtime/middleware"
+)
+
+// NewVersionParams creates a new VersionParams object
+// no default values defined in spec.
+func NewVersionParams() VersionParams {
+
+       return VersionParams{}
+}
+
+// VersionParams contains all the bound params for the version operation
+// typically these are obtained from a http.Request
+//
+// swagger:parameters Version
+type VersionParams struct {
+
+       // HTTP Request Object
+       HTTPRequest *http.Request `json:"-"`
+}
+
+// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
+// for simple values it will use straight method calls.
+//
+// To ensure default values, the struct must have been initialized with NewVersionParams() beforehand.
+func (o *VersionParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
+       var res []error
+
+       o.HTTPRequest = r
+
+       if len(res) > 0 {
+               return errors.CompositeValidationError(res...)
+       }
+       return nil
+}
diff --git a/server/operations/general/version_responses.go b/server/operations/general/version_responses.go
new file mode 100644 (file)
index 0000000..d425d10
--- /dev/null
@@ -0,0 +1,183 @@
+// Code generated by go-swagger; DO NOT EDIT.
+
+// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+//
+
+package general
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the swagger generate command
+
+import (
+       "net/http"
+
+       "github.com/go-openapi/runtime"
+
+       weles "github.com/SamsungSLAV/weles"
+)
+
+// VersionOKCode is the HTTP code returned for type VersionOK
+const VersionOKCode int = 200
+
+/*VersionOK OK
+
+swagger:response versionOK
+*/
+type VersionOK struct {
+       /*State of Weles API.
+
+        */
+       WelesAPIState string `json:"Weles-API-State"`
+       /*Version of Weles API.
+
+        */
+       WelesAPIVersion string `json:"Weles-API-Version"`
+       /*Version of Weles server.
+
+        */
+       WelesServerVersion string `json:"Weles-Server-Version"`
+
+       /*
+         In: Body
+       */
+       Payload *weles.Version `json:"body,omitempty"`
+}
+
+// NewVersionOK creates VersionOK with default headers values
+func NewVersionOK() *VersionOK {
+
+       return &VersionOK{}
+}
+
+// WithWelesAPIState adds the welesApiState to the version o k response
+func (o *VersionOK) WithWelesAPIState(welesAPIState string) *VersionOK {
+       o.WelesAPIState = welesAPIState
+       return o
+}
+
+// SetWelesAPIState sets the welesApiState to the version o k response
+func (o *VersionOK) SetWelesAPIState(welesAPIState string) {
+       o.WelesAPIState = welesAPIState
+}
+
+// WithWelesAPIVersion adds the welesApiVersion to the version o k response
+func (o *VersionOK) WithWelesAPIVersion(welesAPIVersion string) *VersionOK {
+       o.WelesAPIVersion = welesAPIVersion
+       return o
+}
+
+// SetWelesAPIVersion sets the welesApiVersion to the version o k response
+func (o *VersionOK) SetWelesAPIVersion(welesAPIVersion string) {
+       o.WelesAPIVersion = welesAPIVersion
+}
+
+// WithWelesServerVersion adds the welesServerVersion to the version o k response
+func (o *VersionOK) WithWelesServerVersion(welesServerVersion string) *VersionOK {
+       o.WelesServerVersion = welesServerVersion
+       return o
+}
+
+// SetWelesServerVersion sets the welesServerVersion to the version o k response
+func (o *VersionOK) SetWelesServerVersion(welesServerVersion string) {
+       o.WelesServerVersion = welesServerVersion
+}
+
+// WithPayload adds the payload to the version o k response
+func (o *VersionOK) WithPayload(payload *weles.Version) *VersionOK {
+       o.Payload = payload
+       return o
+}
+
+// SetPayload sets the payload to the version o k response
+func (o *VersionOK) SetPayload(payload *weles.Version) {
+       o.Payload = payload
+}
+
+// WriteResponse to the client
+func (o *VersionOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
+
+       // response header Weles-API-State
+
+       welesAPIState := o.WelesAPIState
+       if welesAPIState != "" {
+               rw.Header().Set("Weles-API-State", welesAPIState)
+       }
+
+       // response header Weles-API-Version
+
+       welesAPIVersion := o.WelesAPIVersion
+       if welesAPIVersion != "" {
+               rw.Header().Set("Weles-API-Version", welesAPIVersion)
+       }
+
+       // response header Weles-Server-Version
+
+       welesServerVersion := o.WelesServerVersion
+       if welesServerVersion != "" {
+               rw.Header().Set("Weles-Server-Version", welesServerVersion)
+       }
+
+       rw.WriteHeader(200)
+       if o.Payload != nil {
+               payload := o.Payload
+               if err := producer.Produce(rw, payload); err != nil {
+                       panic(err) // let the recovery middleware deal with this
+               }
+       }
+}
+
+// VersionInternalServerErrorCode is the HTTP code returned for type VersionInternalServerError
+const VersionInternalServerErrorCode int = 500
+
+/*VersionInternalServerError Internal Server error
+
+swagger:response versionInternalServerError
+*/
+type VersionInternalServerError struct {
+
+       /*
+         In: Body
+       */
+       Payload *weles.ErrResponse `json:"body,omitempty"`
+}
+
+// NewVersionInternalServerError creates VersionInternalServerError with default headers values
+func NewVersionInternalServerError() *VersionInternalServerError {
+
+       return &VersionInternalServerError{}
+}
+
+// WithPayload adds the payload to the version internal server error response
+func (o *VersionInternalServerError) WithPayload(payload *weles.ErrResponse) *VersionInternalServerError {
+       o.Payload = payload
+       return o
+}
+
+// SetPayload sets the payload to the version internal server error response
+func (o *VersionInternalServerError) SetPayload(payload *weles.ErrResponse) {
+       o.Payload = payload
+}
+
+// WriteResponse to the client
+func (o *VersionInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
+
+       rw.WriteHeader(500)
+       if o.Payload != nil {
+               payload := o.Payload
+               if err := producer.Produce(rw, payload); err != nil {
+                       panic(err) // let the recovery middleware deal with this
+               }
+       }
+}
diff --git a/server/operations/general/version_urlbuilder.go b/server/operations/general/version_urlbuilder.go
new file mode 100644 (file)
index 0000000..d185d09
--- /dev/null
@@ -0,0 +1,102 @@
+// Code generated by go-swagger; DO NOT EDIT.
+
+// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+//
+
+package general
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the generate command
+
+import (
+       "errors"
+       "net/url"
+       golangswaggerpaths "path"
+)
+
+// VersionURL generates an URL for the version operation
+type VersionURL struct {
+       _basePath string
+}
+
+// WithBasePath sets the base path for this url builder, only required when it's different from the
+// base path specified in the swagger spec.
+// When the value of the base path is an empty string
+func (o *VersionURL) WithBasePath(bp string) *VersionURL {
+       o.SetBasePath(bp)
+       return o
+}
+
+// SetBasePath sets the base path for this url builder, only required when it's different from the
+// base path specified in the swagger spec.
+// When the value of the base path is an empty string
+func (o *VersionURL) SetBasePath(bp string) {
+       o._basePath = bp
+}
+
+// Build a url path and query string
+func (o *VersionURL) Build() (*url.URL, error) {
+       var result url.URL
+
+       var _path = "/version"
+
+       _basePath := o._basePath
+       if _basePath == "" {
+               _basePath = "/api/v1"
+       }
+       result.Path = golangswaggerpaths.Join(_basePath, _path)
+
+       return &result, nil
+}
+
+// Must is a helper function to panic when the url builder returns an error
+func (o *VersionURL) Must(u *url.URL, err error) *url.URL {
+       if err != nil {
+               panic(err)
+       }
+       if u == nil {
+               panic("url can't be nil")
+       }
+       return u
+}
+
+// String returns the string representation of the path with query string
+func (o *VersionURL) String() string {
+       return o.Must(o.Build()).String()
+}
+
+// BuildFull builds a full url with scheme, host, path and query string
+func (o *VersionURL) BuildFull(scheme, host string) (*url.URL, error) {
+       if scheme == "" {
+               return nil, errors.New("scheme is required for a full url on VersionURL")
+       }
+       if host == "" {
+               return nil, errors.New("host is required for a full url on VersionURL")
+       }
+
+       base, err := o.Build()
+       if err != nil {
+               return nil, err
+       }
+
+       base.Scheme = scheme
+       base.Host = host
+       return base, nil
+}
+
+// StringFull returns the string representation of a complete url
+func (o *VersionURL) StringFull(scheme, host string) string {
+       return o.Must(o.BuildFull(scheme, host)).String()
+}
index a2dfa45..1ca5ea9 100644 (file)
@@ -35,6 +35,7 @@ import (
        "github.com/go-openapi/swag"
 
        "github.com/SamsungSLAV/weles/server/operations/artifacts"
+       "github.com/SamsungSLAV/weles/server/operations/general"
        "github.com/SamsungSLAV/weles/server/operations/jobs"
 )
 
@@ -68,6 +69,9 @@ func NewWelesAPI(spec *loads.Document) *WelesAPI {
                JobsJobListerHandler: jobs.JobListerHandlerFunc(func(params jobs.JobListerParams) middleware.Responder {
                        return middleware.NotImplemented("operation JobsJobLister has not yet been implemented")
                }),
+               GeneralVersionHandler: general.VersionHandlerFunc(func(params general.VersionParams) middleware.Responder {
+                       return middleware.NotImplemented("operation GeneralVersion has not yet been implemented")
+               }),
        }
 }
 
@@ -109,6 +113,8 @@ type WelesAPI struct {
        JobsJobCreatorHandler jobs.JobCreatorHandler
        // JobsJobListerHandler sets the operation handler for the job lister operation
        JobsJobListerHandler jobs.JobListerHandler
+       // GeneralVersionHandler sets the operation handler for the version operation
+       GeneralVersionHandler general.VersionHandler
 
        // ServeError is called when an error is received, there is a default handler
        // but you can set your own with this
@@ -192,6 +198,10 @@ func (o *WelesAPI) Validate() error {
                unregistered = append(unregistered, "jobs.JobListerHandler")
        }
 
+       if o.GeneralVersionHandler == nil {
+               unregistered = append(unregistered, "general.VersionHandler")
+       }
+
        if len(unregistered) > 0 {
                return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
        }
@@ -313,6 +323,11 @@ func (o *WelesAPI) initHandlerCache() {
        }
        o.handlers["POST"]["/jobs/list"] = jobs.NewJobLister(o.context, o.JobsJobListerHandler)
 
+       if o.handlers["GET"] == nil {
+               o.handlers["GET"] = make(map[string]http.Handler)
+       }
+       o.handlers["GET"]["/version"] = general.NewVersion(o.context, o.GeneralVersionHandler)
+
 }
 
 // Serve creates a http handler to serve the API over HTTP
diff --git a/server/version_handler.go b/server/version_handler.go
new file mode 100644 (file)
index 0000000..67b6427
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+package server
+
+import (
+       "github.com/go-openapi/runtime/middleware"
+
+       "github.com/SamsungSLAV/weles"
+       "github.com/SamsungSLAV/weles/server/operations/general"
+)
+
+// Version is Weles version information API endpoint handler.
+func (a *APIDefaults) Version(params general.VersionParams) middleware.Responder {
+       var v = &weles.Version{
+               Server: weles.SrvVersion,
+               API:    apiVersion,
+               State:  apiState,
+       }
+
+       return general.NewVersionOK().WithPayload(v).
+               WithWelesAPIState(v.State).WithWelesAPIVersion(v.API).WithWelesServerVersion(v.Server)
+}
diff --git a/server/version_handler_test.go b/server/version_handler_test.go
new file mode 100644 (file)
index 0000000..d0e02f5
--- /dev/null
@@ -0,0 +1,83 @@
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+package server_test
+
+import (
+       "encoding/json"
+       "io/ioutil"
+       "net/http"
+       "net/http/httptest"
+
+       . "github.com/onsi/ginkgo"
+       . "github.com/onsi/gomega"
+
+       "github.com/SamsungSLAV/weles"
+)
+
+var _ = Describe("VersionHandler", func() {
+       var (
+               testserver *httptest.Server
+               v1on010    = &weles.Version{
+                       API:    "v1",
+                       State:  "devel",
+                       Server: "0.1.0",
+               }
+       )
+
+       BeforeEach(func() {
+               _, _, _, _, testserver = testServerSetup()
+       })
+
+       AfterEach(func() {
+               testserver.Close()
+       })
+
+       Describe("obtaining information on API and server version", func() {
+               getClientResp := func() (resp *http.Response) {
+                       client := testserver.Client()
+
+                       req, err := http.NewRequest(http.MethodGet, testserver.URL+"/api/v1/version", nil)
+                       Expect(err).ToNot(HaveOccurred())
+
+                       resp, err = client.Do(req)
+                       Expect(err).ToNot(HaveOccurred())
+
+                       return resp
+               }
+
+               Context("request to v0.1.0 API on v0.1.0 server", func() {
+                       It("should respond with proper body and 200 Status Code", func() {
+                               resp := getClientResp()
+                               Expect(resp.StatusCode).To(Equal(200))
+                               Expect(resp.Header).To(HaveKeyWithValue("Weles-Api-Version", []string{v1on010.API}))
+                               Expect(resp.Header).To(HaveKeyWithValue("Weles-Api-State", []string{v1on010.State}))
+                               Expect(resp.Header).To(HaveKeyWithValue("Weles-Server-Version", []string{v1on010.Server}))
+
+                               respBody, err := ioutil.ReadAll(resp.Body)
+                               Expect(err).ToNot(HaveOccurred())
+                               defer resp.Body.Close()
+
+                               versionEncoded, err := json.Marshal(weles.Version{
+                                       API:    v1on010.API,
+                                       State:  v1on010.State,
+                                       Server: v1on010.Server,
+                               })
+                               Expect(err).ToNot(HaveOccurred())
+
+                               Expect(string(respBody)).To(MatchJSON(string(versionEncoded)))
+                       })
+               })
+       })
+})
index d056c50..58f2e60 100644 (file)
@@ -3,7 +3,7 @@ info:
   description: >-
     This is a Weles server.   You can find out more about Weles at
     [http://tbd.tbd](http://tbd.tbd).
-  version: 0.0.0
+  version: v1
   title: Weles
   termsOfService: 'http://tbd.tbd/terms/'
   contact:
@@ -22,6 +22,8 @@ tags:
     description: Info and management of Weles jobs.
   - name: artifacts
     description: Info about all artifacts used by Weles jobs.
+  - name: general
+    description: Info about Weles (e.g. version)
 schemes:
   - http
 paths:
@@ -269,6 +271,33 @@ paths:
           $ref: '#/responses/NotFound'
         '500':
           $ref: '#/responses/InternalServer'
+  /version:
+    get:
+      tags:
+        - general
+      summary: Show current version of Weles internals
+      description: Version and state of API (e.g. v1 obsolete, v2 stable,
+                   v3 devel) and server version.
+      operationId: Version
+      produces:
+        - application/json
+      responses:
+        '200':
+          description: OK
+          schema:
+            $ref: '#/definitions/Version'
+          headers:
+            Weles-Server-Version:
+              type: string
+              description: Version of Weles server.
+            Weles-API-Version:
+              type: string
+              description: Version of Weles API.
+            Weles-API-State:
+              type: string
+              description: State of Weles API.
+        '500':
+          $ref: '#/responses/InternalServer'
 responses:
   BadRequest:
     description: Bad Request
@@ -552,6 +581,24 @@ definitions:
         $ref: '#/definitions/ArtifactSortBy'
       SortOrder:
         $ref: '#/definitions/SortOrder'
+  Version:
+    description: |
+      defines version of Weles API (and its state) and server.
+    type: object
+    properties:
+      Server:
+        description: Version of Weles server.
+        type: string
+      API:
+        description: Version of Weles API.
+        type: string
+      State:
+        description: State of Weles API.
+        type: string
+        enum:
+          - devel
+          - stable
+          - deprecated
 externalDocs:
   description: TBD
   url: 'http://TBD.tbd'
diff --git a/version.go b/version.go
new file mode 100644 (file)
index 0000000..a73fa17
--- /dev/null
@@ -0,0 +1,125 @@
+// Code generated by go-swagger; DO NOT EDIT.
+
+// Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+//
+
+package weles
+
+// This file was generated by the swagger tool.
+// Editing this file might prove futile when you re-run the swagger generate command
+
+import (
+       "encoding/json"
+
+       strfmt "github.com/go-openapi/strfmt"
+
+       "github.com/go-openapi/errors"
+       "github.com/go-openapi/swag"
+       "github.com/go-openapi/validate"
+)
+
+// Version defines version of Weles API (and its state) and server.
+//
+// swagger:model Version
+type Version struct {
+
+       // Version of Weles API.
+       API string `json:"API,omitempty"`
+
+       // Version of Weles server.
+       Server string `json:"Server,omitempty"`
+
+       // State of Weles API.
+       // Enum: [devel stable deprecated]
+       State string `json:"State,omitempty"`
+}
+
+// Validate validates this version
+func (m *Version) Validate(formats strfmt.Registry) error {
+       var res []error
+
+       if err := m.validateState(formats); err != nil {
+               res = append(res, err)
+       }
+
+       if len(res) > 0 {
+               return errors.CompositeValidationError(res...)
+       }
+       return nil
+}
+
+var versionTypeStatePropEnum []interface{}
+
+func init() {
+       var res []string
+       if err := json.Unmarshal([]byte(`["devel","stable","deprecated"]`), &res); err != nil {
+               panic(err)
+       }
+       for _, v := range res {
+               versionTypeStatePropEnum = append(versionTypeStatePropEnum, v)
+       }
+}
+
+const (
+
+       // VersionStateDevel captures enum value "devel"
+       VersionStateDevel string = "devel"
+
+       // VersionStateStable captures enum value "stable"
+       VersionStateStable string = "stable"
+
+       // VersionStateDeprecated captures enum value "deprecated"
+       VersionStateDeprecated string = "deprecated"
+)
+
+// prop value enum
+func (m *Version) validateStateEnum(path, location string, value string) error {
+       if err := validate.Enum(path, location, value, versionTypeStatePropEnum); err != nil {
+               return err
+       }
+       return nil
+}
+
+func (m *Version) validateState(formats strfmt.Registry) error {
+
+       if swag.IsZero(m.State) { // not required
+               return nil
+       }
+
+       // value enum
+       if err := m.validateStateEnum("State", "body", m.State); err != nil {
+               return err
+       }
+
+       return nil
+}
+
+// MarshalBinary interface implementation
+func (m *Version) MarshalBinary() ([]byte, error) {
+       if m == nil {
+               return nil, nil
+       }
+       return swag.WriteJSON(m)
+}
+
+// UnmarshalBinary interface implementation
+func (m *Version) UnmarshalBinary(b []byte) error {
+       var res Version
+       if err := swag.ReadJSON(b, &res); err != nil {
+               return err
+       }
+       *m = res
+       return nil
+}
index 43d1c08..028a4cb 100644 (file)
--- a/weles.go
+++ b/weles.go
@@ -16,3 +16,6 @@
 
 // Package weles represents the base of the Weles system.
 package weles
+
+// SrvVersion indicates version of Weles server.
+const SrvVersion string = "0.1.0"