X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=a1-go%2Fpkg%2Frestful%2Frestful.go;h=44b34228080caaf0f9c49cc86fee9c3dc2a6e703;hb=be066665846fd9b7840f13a9cd13da62841d47ea;hp=37a7292ea896f731a5dab0f1224c37b13766f385;hpb=f8e5619649c0fb2ddfc466b970e8338a45e55cb8;p=ric-plt%2Fa1.git diff --git a/a1-go/pkg/restful/restful.go b/a1-go/pkg/restful/restful.go index 37a7292..44b3422 100644 --- a/a1-go/pkg/restful/restful.go +++ b/a1-go/pkg/restful/restful.go @@ -21,16 +21,18 @@ package restful import ( - "fmt" "log" "os" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_e_i_data_delivery" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/resthooks" "github.com/go-openapi/loads" "github.com/go-openapi/runtime/middleware" - "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi" - "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations" - "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator" - "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/resthooks" ) func NewRestful() *Restful { @@ -48,10 +50,121 @@ func (r *Restful) setupHandler() *operations.A1API { } 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 { - fmt.Printf("\n---- handler for get all all policy type --- \n") + a1.Logger.Debug("handler for get all policy type") return a1_mediator.NewA1ControllerGetAllPolicyTypesOK().WithPayload(r.rh.GetAllPolicyType()) }) + + api.A1MediatorA1ControllerCreatePolicyTypeHandler = a1_mediator.A1ControllerCreatePolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerCreatePolicyTypeParams) middleware.Responder { + a1.Logger.Debug("handler for Create policy type ") + if err = r.rh.CreatePolicyType(models.PolicyTypeID(params.PolicyTypeID), *params.Body); err == nil { + //Increase prometheus counter + return a1_mediator.NewA1ControllerCreatePolicyTypeCreated() + } + if r.rh.IsTypeAlready(err) || r.rh.IsTypeMismatch(err) { + return a1_mediator.NewA1ControllerCreatePolicyTypeBadRequest() + } + return a1_mediator.NewA1ControllerCreatePolicyTypeServiceUnavailable() + + }) + + api.A1MediatorA1ControllerGetPolicyTypeHandler = a1_mediator.A1ControllerGetPolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyTypeParams) middleware.Responder { + a1.Logger.Debug("handler for get policy type from policytypeID") + return a1_mediator.NewA1ControllerGetPolicyTypeOK().WithPayload(r.rh.GetPolicyType(models.PolicyTypeID(params.PolicyTypeID))) + }) + + api.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler = a1_mediator.A1ControllerCreateOrReplacePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerCreateOrReplacePolicyInstanceParams) middleware.Responder { + a1.Logger.Debug("handler for create policy type instance ") + if err = r.rh.CreatePolicyInstance(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID), params.Body); err == nil { + return a1_mediator.NewA1ControllerCreateOrReplacePolicyInstanceAccepted() + } + if r.rh.IsValidJson(err) { + return a1_mediator.NewA1ControllerCreateOrReplacePolicyInstanceBadRequest() + } + return a1_mediator.NewA1ControllerCreateOrReplacePolicyInstanceServiceUnavailable() + + }) + + api.A1MediatorA1ControllerGetPolicyInstanceHandler = a1_mediator.A1ControllerGetPolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyInstanceParams) middleware.Responder { + a1.Logger.Debug("handler for get policy instance from policytypeID") + if resp, err := r.rh.GetPolicyInstance(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID)); err == nil { + return a1_mediator.NewA1ControllerGetPolicyInstanceOK().WithPayload(resp) + } + if r.rh.IsPolicyInstanceNotFound(err) { + return a1_mediator.NewA1ControllerGetPolicyInstanceNotFound() + } + return a1_mediator.NewA1ControllerGetPolicyInstanceServiceUnavailable() + }) + + api.A1MediatorA1ControllerGetAllInstancesForTypeHandler = a1_mediator.A1ControllerGetAllInstancesForTypeHandlerFunc(func(params a1_mediator.A1ControllerGetAllInstancesForTypeParams) middleware.Responder { + a1.Logger.Debug("handler for get all policy instance") + if resp, err := r.rh.GetAllPolicyInstance(models.PolicyTypeID(params.PolicyTypeID)); err == nil { + if resp != nil { + return a1_mediator.NewA1ControllerGetAllInstancesForTypeOK().WithPayload(resp) + } + } + if r.rh.IsPolicyInstanceNotFound(err) { + return a1_mediator.NewA1ControllerGetPolicyInstanceNotFound() + } + return a1_mediator.NewA1ControllerGetAllInstancesForTypeServiceUnavailable() + + }) + + api.A1MediatorA1ControllerDeletePolicyTypeHandler = a1_mediator.A1ControllerDeletePolicyTypeHandlerFunc(func(params a1_mediator.A1ControllerDeletePolicyTypeParams) middleware.Responder { + a1.Logger.Debug("handler for delete policy type") + if err := r.rh.DeletePolicyType(models.PolicyTypeID(params.PolicyTypeID)); err != nil { + if r.rh.CanPolicyTypeBeDeleted(err) { + return a1_mediator.NewA1ControllerDeletePolicyTypeBadRequest() + } + return a1_mediator.NewA1ControllerDeletePolicyTypeServiceUnavailable() + } + + return a1_mediator.NewA1ControllerDeletePolicyTypeNoContent() + + }) + + api.A1MediatorA1ControllerGetPolicyInstanceStatusHandler = a1_mediator.A1ControllerGetPolicyInstanceStatusHandlerFunc(func(params a1_mediator.A1ControllerGetPolicyInstanceStatusParams) middleware.Responder { + a1.Logger.Debug("handler for get policy instance status") + if resp, err := r.rh.GetPolicyInstanceStatus(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID)); err == nil { + return a1_mediator.NewA1ControllerGetPolicyInstanceStatusOK().WithPayload(resp) + } + if r.rh.IsPolicyInstanceNotFound(err) { + return a1_mediator.NewA1ControllerGetPolicyInstanceStatusNotFound() + } + return a1_mediator.NewA1ControllerGetPolicyInstanceStatusServiceUnavailable() + }) + + api.A1MediatorA1ControllerDeletePolicyInstanceHandler = a1_mediator.A1ControllerDeletePolicyInstanceHandlerFunc(func(params a1_mediator.A1ControllerDeletePolicyInstanceParams) middleware.Responder { + a1.Logger.Debug("handler for delete policy instance") + if err := r.rh.DeletePolicyInstance(models.PolicyTypeID(params.PolicyTypeID), models.PolicyInstanceID(params.PolicyInstanceID)); err != nil { + if r.rh.CanPolicyInstanceBeDeleted(err) { + return a1_mediator.NewA1ControllerDeletePolicyInstanceNotFound() + } + return a1_mediator.NewA1ControllerDeletePolicyInstanceServiceUnavailable() + } + + return a1_mediator.NewA1ControllerDeletePolicyInstanceAccepted() + + }) + + api.A1eiDataDeliveryA1ControllerDataDeliveryHandler = a1_e_i_data_delivery.A1ControllerDataDeliveryHandlerFunc(func(params a1_e_i_data_delivery.A1ControllerDataDeliveryParams) middleware.Responder { + a1.Logger.Debug("handler for EI data delivery") + if err = r.rh.DataDelivery(params.Body); err != nil { + return a1_e_i_data_delivery.NewA1ControllerDataDeliveryNotFound() + } + return a1_e_i_data_delivery.NewA1ControllerDataDeliveryOK() + }) + return api } @@ -60,7 +173,7 @@ func (r *Restful) Run() { server := restapi.NewServer(r.api) defer server.Shutdown() - server.Port = 8080 + server.Port = 10000 server.Host = "0.0.0.0" if err := server.Serve(); err != nil { log.Fatal(err.Error())