1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 15:29:42 +02:00

feat(edgestacks): add support for transactions EE-5326 (#8908)

This commit is contained in:
andres-portainer 2023-05-05 20:39:22 -03:00 committed by GitHub
parent 59f543f442
commit e82c88317e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 254 additions and 104 deletions

View file

@ -7,8 +7,10 @@ import (
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
httperrors "github.com/portainer/portainer/api/http/errors"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/pkg/featureflags"
)
func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
@ -23,7 +25,15 @@ func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request)
return httperror.InternalServerError("Unable to retrieve user details from authentication token", err)
}
edgeStack, err := handler.createSwarmStack(method, dryrun, tokenData.ID, r)
var edgeStack *portainer.EdgeStack
if featureflags.IsEnabled(portainer.FeatureNoTx) {
edgeStack, err = handler.createSwarmStack(handler.DataStore, method, dryrun, tokenData.ID, r)
} else {
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
edgeStack, err = handler.createSwarmStack(tx, method, dryrun, tokenData.ID, r)
return err
})
}
if err != nil {
switch {
case httperrors.IsInvalidPayloadError(err):
@ -36,15 +46,15 @@ func (handler *Handler) edgeStackCreate(w http.ResponseWriter, r *http.Request)
return response.JSON(w, edgeStack)
}
func (handler *Handler) createSwarmStack(method string, dryrun bool, userID portainer.UserID, r *http.Request) (*portainer.EdgeStack, error) {
func (handler *Handler) createSwarmStack(tx dataservices.DataStoreTx, method string, dryrun bool, userID portainer.UserID, r *http.Request) (*portainer.EdgeStack, error) {
switch method {
case "string":
return handler.createEdgeStackFromFileContent(r, dryrun)
return handler.createEdgeStackFromFileContent(r, tx, dryrun)
case "repository":
return handler.createEdgeStackFromGitRepository(r, dryrun, userID)
return handler.createEdgeStackFromGitRepository(r, tx, dryrun, userID)
case "file":
return handler.createEdgeStackFromFileUpload(r, dryrun)
return handler.createEdgeStackFromFileUpload(r, tx, dryrun)
}
return nil, httperrors.NewInvalidPayloadError("Invalid value for query parameter: method. Value must be one of: string, repository or file")
}