Skip to content

Commit

Permalink
ARO-9390: Add asynchronous methods
Browse files Browse the repository at this point in the history
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 <ahitacat@redhat.com>
  • Loading branch information
ahitacat committed Jul 30, 2024
1 parent 9a8e01b commit 78663b3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
14 changes: 14 additions & 0 deletions pkg/concepts/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -128,6 +140,8 @@ func (m *Method) IsAction() bool {
return false
case m.IsUpdate():
return false
case m.IsAsyncUpdate():
return false
default:
return true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/concepts/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/generators/golang/json_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions pkg/http/binding_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pkg/language/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions pkg/nomenclator/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 78663b3

Please sign in to comment.