Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit d8f48be

Browse files
author
smothiki
committed
feat(doctor): add doctor client code and doctor api call
1 parent 5270df6 commit d8f48be

10 files changed

Lines changed: 331 additions & 7 deletions

File tree

api/swagger-spec/swagger.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ paths:
5252
description: unexpected error
5353
schema:
5454
$ref: "#/definitions/error"
55+
/v3/doctor/{uuid}:
56+
parameters:
57+
- $ref: "#/parameters/UUID"
58+
post:
59+
operationId: publishDoctorInfo
60+
summary: "publish doctor info to Workflow Manager API"
61+
parameters:
62+
- name: body
63+
in: body
64+
schema:
65+
$ref: "#/definitions/doctorInfo"
66+
responses:
67+
200:
68+
description: publish doctorInfo response
69+
default:
70+
description: unexpected error
71+
schema:
72+
$ref: "#/definitions/error"
5573
/v3/versions/{train}/{component}:
5674
get:
5775
operationId: getComponentByName
@@ -255,6 +273,12 @@ parameters:
255273
in: path
256274
description: The release version of the deis component, eg., 2.0.0-beta2
257275
required: true
276+
UUID:
277+
name: uuid
278+
type: string
279+
in: path
280+
description: A universal Id to represent a sepcific request or report
281+
required: true
258282
definitions:
259283
cluster:
260284
type: object
@@ -275,6 +299,13 @@ definitions:
275299
type: array
276300
items:
277301
$ref: "#/definitions/componentVersion"
302+
doctorInfo:
303+
type: object
304+
required:
305+
- cluster
306+
properties:
307+
cluster:
308+
$ref: "#/definitions/cluster"
278309
componentVersion:
279310
type: object
280311
properties:

boot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func main() {
5454
defer close(ch)
5555

5656
// Get a new router, with handler functions
57-
r := handlers.RegisterRoutes(mux.NewRouter(), secretInterface, rcInterface, availableVersion)
57+
r := handlers.RegisterRoutes(mux.NewRouter(), secretInterface, rcInterface, availableVersion, apiClient)
5858
// Bind to a port and pass our router in
5959
hostStr := fmt.Sprintf(":%s", config.Spec.Port)
6060
log.Printf("Serving on %s", hostStr)

data/data.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,23 @@ func getRCItems(rcLister rc.Lister) ([]api.ReplicationController, error) {
151151
return rcs.Items, nil
152152
}
153153

154+
// GetDoctorInfo collects doctor info and return DoctorInfo struct
155+
func GetDoctorInfo(
156+
c InstalledData,
157+
i ClusterID,
158+
v AvailableComponentVersion,
159+
secretGetterCreator KubeSecretGetterCreator,
160+
) (models.DoctorInfo, error) {
161+
cluster, err := GetCluster(c, i, v, secretGetterCreator)
162+
if err != nil {
163+
return nil, err
164+
}
165+
doctor := models.DoctorInfo{
166+
cluster: &cluster,
167+
}
168+
return doctor, nil
169+
}
170+
154171
// newestVersion is a temporary static implementation of a real "return newest version" function
155172
func newestVersion(v1 string, v2 string) string {
156173
return v1

handlers/handlers.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import (
77

88
"github.com/arschles/kubeapp/api/rc"
99
"github.com/deis/workflow-manager/data"
10+
"github.com/deis/workflow-manager/pkg/swagger/client/operations"
1011
"github.com/gorilla/mux"
12+
"github.com/satori/go.uuid"
1113
)
1214

1315
const (
1416
componentsRoute = "/components" // resource value for components route
1517
idRoute = "/id" // resource value for ID route
18+
doctorRoute = "/doctor"
1619
)
1720

1821
// RegisterRoutes attaches handler functions to routes
@@ -21,6 +24,7 @@ func RegisterRoutes(
2124
secretGetterCreator data.KubeSecretGetterCreator,
2225
rcLister rc.Lister,
2326
availableVersions data.AvailableVersions,
27+
apiClient *apiclient.WorkflowManager,
2428
) *mux.Router {
2529

2630
clusterID := data.NewClusterIDFromPersistentStorage(secretGetterCreator)
@@ -31,6 +35,13 @@ func RegisterRoutes(
3135
secretGetterCreator,
3236
))
3337
r.Handle(idRoute, IDHandler(clusterID))
38+
r.Handle(doctorRoute, DoctorHandler(
39+
data.NewInstalledDeisData(rcLister),
40+
clusterID,
41+
data.NewLatestReleasedComponent(secretGetterCreator, rcLister, availableVersions),
42+
secretGetterCreator,
43+
apiclient,
44+
))
3445
return r
3546
}
3647

@@ -53,6 +64,28 @@ func ComponentsHandler(
5364
})
5465
}
5566

67+
// DoctorHandler route handler
68+
func DoctorHandler(
69+
c data.InstalledData,
70+
i data.ClusterID,
71+
v data.AvailableComponentVersion,
72+
secretGetterCreator data.KubeSecretGetterCreator,
73+
apiClient *apiclient.WorkflowManager,
74+
) http.Handler {
75+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
76+
doctor, err := data.GetDoctorInfo(c, i, v, secretGetterCreator)
77+
if err != nil {
78+
http.Error(w, err.Error(), http.StatusInternalServerError)
79+
return
80+
}
81+
_, err = apiClient.Operations.PublishDoctorInfo(&operations.PublishDoctorInfoParams{Body: doctor, UUID: uuid.NewV4().String()})
82+
if err != nil {
83+
http.Error(w, err.Error(), http.StatusInternalServerError)
84+
return
85+
}
86+
})
87+
}
88+
5689
// IDHandler route handler
5790
func IDHandler(getter data.ClusterID) http.Handler {
5891
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

pkg/swagger/client/operations/operations_client.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,31 @@ func (a *Client) PublishComponentRelease(params *PublishComponentReleaseParams)
297297
return result.(*PublishComponentReleaseOK), nil
298298
}
299299

300+
/*
301+
PublishDoctorInfo publishes doctor info to workflow manager API
302+
*/
303+
func (a *Client) PublishDoctorInfo(params *PublishDoctorInfoParams) (*PublishDoctorInfoOK, error) {
304+
// TODO: Validate the params before sending
305+
if params == nil {
306+
params = NewPublishDoctorInfoParams()
307+
}
308+
309+
result, err := a.transport.Submit(&client.Operation{
310+
ID: "publishDoctorInfo",
311+
Method: "POST",
312+
PathPattern: "/v3/doctor/{uuid}",
313+
ProducesMediaTypes: []string{"application/json"},
314+
ConsumesMediaTypes: []string{"application/json"},
315+
Schemes: []string{"http"},
316+
Params: params,
317+
Reader: &PublishDoctorInfoReader{formats: a.formats},
318+
})
319+
if err != nil {
320+
return nil, err
321+
}
322+
return result.(*PublishDoctorInfoOK), nil
323+
}
324+
300325
// SetTransport changes the transport on the client
301326
func (a *Client) SetTransport(transport client.Transport) {
302327
a.transport = transport
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package operations
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
import (
7+
"github.com/go-swagger/go-swagger/client"
8+
"github.com/go-swagger/go-swagger/errors"
9+
10+
strfmt "github.com/go-swagger/go-swagger/strfmt"
11+
12+
"github.com/deis/workflow-manager/pkg/swagger/models"
13+
)
14+
15+
// NewPublishDoctorInfoParams creates a new PublishDoctorInfoParams object
16+
// with the default values initialized.
17+
func NewPublishDoctorInfoParams() *PublishDoctorInfoParams {
18+
var ()
19+
return &PublishDoctorInfoParams{}
20+
}
21+
22+
/*PublishDoctorInfoParams contains all the parameters to send to the API endpoint
23+
for the publish doctor info operation typically these are written to a http.Request
24+
*/
25+
type PublishDoctorInfoParams struct {
26+
27+
/*Body*/
28+
Body *models.DoctorInfo
29+
/*UUID
30+
A universal Id to represent a sepcific request or report
31+
32+
*/
33+
UUID string
34+
}
35+
36+
// WithBody adds the body to the publish doctor info params
37+
func (o *PublishDoctorInfoParams) WithBody(body *models.DoctorInfo) *PublishDoctorInfoParams {
38+
o.Body = body
39+
return o
40+
}
41+
42+
// WithUUID adds the uuid to the publish doctor info params
43+
func (o *PublishDoctorInfoParams) WithUUID(uuid string) *PublishDoctorInfoParams {
44+
o.UUID = uuid
45+
return o
46+
}
47+
48+
// WriteToRequest writes these params to a swagger request
49+
func (o *PublishDoctorInfoParams) WriteToRequest(r client.Request, reg strfmt.Registry) error {
50+
51+
var res []error
52+
53+
if o.Body == nil {
54+
o.Body = new(models.DoctorInfo)
55+
}
56+
57+
if err := r.SetBodyParam(o.Body); err != nil {
58+
return err
59+
}
60+
61+
// path param uuid
62+
if err := r.SetPathParam("uuid", o.UUID); err != nil {
63+
return err
64+
}
65+
66+
if len(res) > 0 {
67+
return errors.CompositeValidationError(res...)
68+
}
69+
return nil
70+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package operations
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
import (
7+
"fmt"
8+
"io"
9+
10+
"github.com/go-swagger/go-swagger/client"
11+
"github.com/go-swagger/go-swagger/httpkit"
12+
13+
strfmt "github.com/go-swagger/go-swagger/strfmt"
14+
15+
"github.com/deis/workflow-manager/pkg/swagger/models"
16+
)
17+
18+
// PublishDoctorInfoReader is a Reader for the PublishDoctorInfo structure.
19+
type PublishDoctorInfoReader struct {
20+
formats strfmt.Registry
21+
}
22+
23+
// ReadResponse reads a server response into the recieved o.
24+
func (o *PublishDoctorInfoReader) ReadResponse(response client.Response, consumer httpkit.Consumer) (interface{}, error) {
25+
switch response.Code() {
26+
27+
case 200:
28+
result := NewPublishDoctorInfoOK()
29+
if err := result.readResponse(response, consumer, o.formats); err != nil {
30+
return nil, err
31+
}
32+
return result, nil
33+
34+
default:
35+
result := NewPublishDoctorInfoDefault(response.Code())
36+
if err := result.readResponse(response, consumer, o.formats); err != nil {
37+
return nil, err
38+
}
39+
return nil, result
40+
}
41+
}
42+
43+
// NewPublishDoctorInfoOK creates a PublishDoctorInfoOK with default headers values
44+
func NewPublishDoctorInfoOK() *PublishDoctorInfoOK {
45+
return &PublishDoctorInfoOK{}
46+
}
47+
48+
/*PublishDoctorInfoOK handles this case with default header values.
49+
50+
publish doctorInfo response
51+
*/
52+
type PublishDoctorInfoOK struct {
53+
}
54+
55+
func (o *PublishDoctorInfoOK) Error() string {
56+
return fmt.Sprintf("[POST /v3/doctor/{uuid}][%d] publishDoctorInfoOK ", 200)
57+
}
58+
59+
func (o *PublishDoctorInfoOK) readResponse(response client.Response, consumer httpkit.Consumer, formats strfmt.Registry) error {
60+
61+
return nil
62+
}
63+
64+
// NewPublishDoctorInfoDefault creates a PublishDoctorInfoDefault with default headers values
65+
func NewPublishDoctorInfoDefault(code int) *PublishDoctorInfoDefault {
66+
return &PublishDoctorInfoDefault{
67+
_statusCode: code,
68+
}
69+
}
70+
71+
/*PublishDoctorInfoDefault handles this case with default header values.
72+
73+
unexpected error
74+
*/
75+
type PublishDoctorInfoDefault struct {
76+
_statusCode int
77+
78+
Payload *models.Error
79+
}
80+
81+
// Code gets the status code for the publish doctor info default response
82+
func (o *PublishDoctorInfoDefault) Code() int {
83+
return o._statusCode
84+
}
85+
86+
func (o *PublishDoctorInfoDefault) Error() string {
87+
return fmt.Sprintf("[POST /v3/doctor/{uuid}][%d] publishDoctorInfo default %+v", o._statusCode, o.Payload)
88+
}
89+
90+
func (o *PublishDoctorInfoDefault) readResponse(response client.Response, consumer httpkit.Consumer, formats strfmt.Registry) error {
91+
92+
o.Payload = new(models.Error)
93+
94+
// response payload
95+
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
96+
return err
97+
}
98+
99+
return nil
100+
}

pkg/swagger/models/data.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ package models
44
// Editing this file might prove futile when you re-run the swagger generate command
55

66
import (
7-
strfmt "github.com/go-swagger/go-swagger/strfmt"
8-
"github.com/go-swagger/go-swagger/swag"
9-
107
"github.com/go-swagger/go-swagger/errors"
118
"github.com/go-swagger/go-swagger/httpkit/validate"
9+
strfmt "github.com/go-swagger/go-swagger/strfmt"
10+
"github.com/go-swagger/go-swagger/swag"
1211
)
1312

1413
/*Data data

0 commit comments

Comments
 (0)