Implement Health Check Api.
Signed-off-by: naman.gupta <naman.gupta@samsung.com>
Change-Id: Id091fa42eb6df5995f9d5d3995a075a59bb827f9
rw.WriteHeader(200)
}
+
+// A1ControllerGetHealthcheckInternalServerErrorCode is the HTTP code returned for type A1ControllerGetHealthcheckInternalServerError
+const A1ControllerGetHealthcheckInternalServerErrorCode int = 500
+
+/*A1ControllerGetHealthcheckInternalServerError Internal error to signal A1 is not healthy. Client should attempt to retry later.
+
+swagger:response a1ControllerGetHealthcheckInternalServerError
+*/
+type A1ControllerGetHealthcheckInternalServerError struct {
+}
+
+// NewA1ControllerGetHealthcheckInternalServerError creates A1ControllerGetHealthcheckInternalServerError with default headers values
+func NewA1ControllerGetHealthcheckInternalServerError() *A1ControllerGetHealthcheckInternalServerError {
+
+ return &A1ControllerGetHealthcheckInternalServerError{}
+}
+
+// WriteResponse to the client
+func (o *A1ControllerGetHealthcheckInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
+
+ rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
+
+ rw.WriteHeader(500)
+}
}
api := operations.NewA1API(swaggerSpec)
+
+ api.A1MediatorA1ControllerGetHealthcheckHandler = a1_mediator.A1ControllerGetHealthcheckHandlerFunc(func(param a1_mediator.A1ControllerGetHealthcheckParams) middleware.Responder {
+ a1.Logger.Debug("handler for get Health Check of A1")
+ resp := r.rh.GetA1Health()
+ if resp == false {
+ return a1_mediator.NewA1ControllerGetHealthcheckInternalServerError()
+ }
+ return a1_mediator.NewA1ControllerGetHealthcheckOK()
+ })
+
api.A1MediatorA1ControllerGetAllPolicyTypesHandler = a1_mediator.A1ControllerGetAllPolicyTypesHandlerFunc(func(param a1_mediator.A1ControllerGetAllPolicyTypesParams) middleware.Responder {
a1.Logger.Debug("handler for get all policy type")
return a1_mediator.NewA1ControllerGetAllPolicyTypesOK().WithPayload(r.rh.GetAllPolicyType())
}
}
+func (rh *Resthook) GetA1Health() bool {
+ data, _ := rh.db.GetAll(a1MediatorNs)
+ if data != nil {
+ a1.Logger.Debug("Database connected and A1 is healthy")
+ return true
+ }
+ return false
+}
+
func (rh *Resthook) GetAllPolicyType() []models.PolicyTypeID {
var policyTypeIDs []models.PolicyTypeID
os.Exit(code)
}
+func TestHealth(t *testing.T) {
+ resp := rh.GetA1Health()
+ if resp == true {
+ a1.Logger.Debug("A1 is healthy ")
+ assert.Equal(t, true, resp)
+ } else {
+ a1.Logger.Debug("A1 is unhealthy")
+ assert.Equal(t, false, resp)
+ }
+}
+
func TestGetAllPolicyType(t *testing.T) {
resp := rh.GetAllPolicyType()
assert.Equal(t, 2, len(resp))