From 78663b353ba46d9c55112f8161610fc4b2610624 Mon Sep 17 00:00:00 2001 From: Alba Hita Catala Date: Tue, 30 Jul 2024 13:46:28 +0200 Subject: [PATCH] ARO-9390: Add asynchronous methods Asynchronous methods require a StatusAccepted as a response. This commit adds 2 new async methods (add and update) that will be used on v2 of cluster_mgmt. Signed-off-by: Alba Hita Catala --- pkg/concepts/method.go | 14 ++++++++++++++ pkg/concepts/parameter.go | 2 +- pkg/generators/golang/json_generator.go | 4 ++-- pkg/http/binding_calculator.go | 8 ++++++-- pkg/language/checks.go | 4 ++-- pkg/nomenclator/names.go | 8 +++++--- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pkg/concepts/method.go b/pkg/concepts/method.go index e68b373..589c34b 100644 --- a/pkg/concepts/method.go +++ b/pkg/concepts/method.go @@ -81,6 +81,11 @@ func (m *Method) IsAdd() bool { return m.name.Equals(nomenclator.Add) } +// IsAsyncAdd return true if this is an asynchronous add method. +func (m *Method) IsAsyncAdd() bool { + return m.name.Equals(nomenclator.AsyncAdd) +} + // IsDelete returns true if this is a delete method. func (m *Method) IsDelete() bool { return m.name.Equals(nomenclator.Delete) @@ -111,11 +116,18 @@ func (m *Method) IsUpdate() bool { return m.name.Equals(nomenclator.Update) } +// IsAsyncUpdate returns true if this is an asynchronous update method. +func (m *Method) IsAsyncUpdate() bool { + return m.name.Equals(nomenclator.AsyncUpdate) +} + // IsAction determined if this method is an action instead of a regular REST method. func (m *Method) IsAction() bool { switch { case m.IsAdd(): return false + case m.IsAsyncAdd(): + return false case m.IsDelete(): return false case m.IsGet(): @@ -128,6 +140,8 @@ func (m *Method) IsAction() bool { return false case m.IsUpdate(): return false + case m.IsAsyncUpdate(): + return false default: return true } diff --git a/pkg/concepts/parameter.go b/pkg/concepts/parameter.go index 58aa82a..492c031 100644 --- a/pkg/concepts/parameter.go +++ b/pkg/concepts/parameter.go @@ -89,7 +89,7 @@ func (p *Parameter) IsBody() bool { if p.owner == nil { return false } - isRest := p.owner.IsAdd() || p.owner.IsGet() || p.owner.IsSearch() || p.owner.IsUpdate() + isRest := p.owner.IsAdd() || p.owner.IsAsyncAdd() || p.owner.IsGet() || p.owner.IsSearch() || p.owner.IsUpdate() || p.owner.IsAsyncUpdate() if isRest && p.name.Equals(nomenclator.Body) { return true } diff --git a/pkg/generators/golang/json_generator.go b/pkg/generators/golang/json_generator.go index 018db16..156462c 100644 --- a/pkg/generators/golang/json_generator.go +++ b/pkg/generators/golang/json_generator.go @@ -836,7 +836,7 @@ func (g *JSONSupportGenerator) generateResourceSupport(resource *concepts.Resour func (g *JSONSupportGenerator) generateMethodSource(method *concepts.Method) { switch { - case method.IsAdd(): + case method.IsAdd() || method.IsAsyncAdd(): g.generateAddMethodSource(method) case method.IsDelete(): g.generateDeleteMethodSource(method) @@ -848,7 +848,7 @@ func (g *JSONSupportGenerator) generateMethodSource(method *concepts.Method) { g.generatePostMethodSource(method) case method.IsSearch(): g.generateSearchMethodSource(method) - case method.IsUpdate(): + case method.IsUpdate() || method.IsAsyncUpdate(): g.generateUpdateMethodSource(method) case method.IsAction(): g.generateActionMethodSource(method) diff --git a/pkg/http/binding_calculator.go b/pkg/http/binding_calculator.go index 73cbaac..200e19a 100644 --- a/pkg/http/binding_calculator.go +++ b/pkg/http/binding_calculator.go @@ -146,7 +146,7 @@ func (c *BindingCalculator) ResponseBodyParameters(method *concepts.Method) []*c func (c *BindingCalculator) Method(method *concepts.Method) string { name := method.Name() switch { - case name.Equals(nomenclator.Add): + case name.Equals(nomenclator.Add) || name.Equals(nomenclator.AsyncAdd): return http.MethodPost case name.Equals(nomenclator.Delete): return http.MethodDelete @@ -156,7 +156,7 @@ func (c *BindingCalculator) Method(method *concepts.Method) string { return http.MethodGet case name.Equals(nomenclator.Post): return http.MethodPost - case name.Equals(nomenclator.Update): + case name.Equals(nomenclator.Update) || name.Equals(nomenclator.AsyncUpdate): return http.MethodPatch default: return http.MethodPost @@ -173,6 +173,10 @@ func (c *BindingCalculator) DefaultStatus(method *concepts.Method) string { status = http.StatusCreated case name.Equals(nomenclator.Add): status = http.StatusCreated + case name.Equals(nomenclator.AsyncAdd): + status = http.StatusAccepted + case name.Equals(nomenclator.AsyncUpdate): + status = http.StatusAccepted case name.Equals(nomenclator.Update): status = http.StatusOK case name.Equals(nomenclator.Delete): diff --git a/pkg/language/checks.go b/pkg/language/checks.go index 31fc7f9..768dee0 100644 --- a/pkg/language/checks.go +++ b/pkg/language/checks.go @@ -60,7 +60,7 @@ func (r *Reader) checkResource(resource *concepts.Resource) { func (r *Reader) checkMethod(method *concepts.Method) { // Run specific checks according tot he type of method: switch { - case method.IsAdd(): + case method.IsAdd() || method.IsAsyncAdd(): r.checkAdd(method) case method.IsDelete(): r.checkDelete(method) @@ -72,7 +72,7 @@ func (r *Reader) checkMethod(method *concepts.Method) { r.checkPost(method) case method.IsSearch(): r.checkSearch(method) - case method.IsUpdate(): + case method.IsUpdate() || method.IsAsyncUpdate(): r.checkUpdate(method) case method.IsAction(): r.checkAction(method) diff --git a/pkg/nomenclator/names.go b/pkg/nomenclator/names.go index b6dfc65..ce433a5 100644 --- a/pkg/nomenclator/names.go +++ b/pkg/nomenclator/names.go @@ -22,9 +22,11 @@ import ( var ( // A: - Adapt = names.ParseUsingCase("Adapt") - Adapter = names.ParseUsingCase("Adapter") - Add = names.ParseUsingCase("Add") + Adapt = names.ParseUsingCase("Adapt") + Adapter = names.ParseUsingCase("Adapter") + Add = names.ParseUsingCase("Add") + AsyncAdd = names.ParseUsingCase("AsyncAdd") + AsyncUpdate = names.ParseUsingCase("AsyncUpdate") // B: Body = names.ParseUsingCase("Body")