Compare commits
5 Commits
2.39.0
...
fix/EE-476
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01f9a17cce | ||
|
|
f813fa984c | ||
|
|
099d7b4444 | ||
|
|
8ee0571d0a | ||
|
|
bf8332970a |
@@ -80,12 +80,22 @@ func (service *Service) Create(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJo
|
||||
)
|
||||
}
|
||||
|
||||
// UpdateEdgeJob updates an Edge job by ID
|
||||
// Deprecated: use UpdateEdgeJobFunc instead
|
||||
func (service *Service) UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
||||
identifier := service.connection.ConvertToKey(int(ID))
|
||||
return service.connection.UpdateObject(BucketName, identifier, edgeJob)
|
||||
}
|
||||
|
||||
// UpdateEdgeJobFunc updates an edge job inside a transaction avoiding data races.
|
||||
func (service *Service) UpdateEdgeJobFunc(ID portainer.EdgeJobID, updateFunc func(edgeJob *portainer.EdgeJob)) error {
|
||||
id := service.connection.ConvertToKey(int(ID))
|
||||
edgeJob := &portainer.EdgeJob{}
|
||||
|
||||
return service.connection.UpdateObjectFunc(BucketName, id, edgeJob, func() {
|
||||
updateFunc(edgeJob)
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteEdgeJob deletes an Edge job
|
||||
func (service *Service) DeleteEdgeJob(ID portainer.EdgeJobID) error {
|
||||
identifier := service.connection.ConvertToKey(int(ID))
|
||||
|
||||
@@ -78,6 +78,7 @@ type (
|
||||
EdgeJob(ID portainer.EdgeJobID) (*portainer.EdgeJob, error)
|
||||
Create(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error
|
||||
UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error
|
||||
UpdateEdgeJobFunc(ID portainer.EdgeJobID, updateFunc func(edgeJob *portainer.EdgeJob)) error
|
||||
DeleteEdgeJob(ID portainer.EdgeJobID) error
|
||||
GetNextIdentifier() int
|
||||
BucketName() string
|
||||
|
||||
@@ -49,19 +49,20 @@ func (handler *Handler) edgeJobTasksCollect(w http.ResponseWriter, r *http.Reque
|
||||
return httperror.InternalServerError("Unable to get Endpoints from EdgeGroups", err)
|
||||
}
|
||||
|
||||
if slices.Contains(endpointsFromGroups, endpointID) {
|
||||
edgeJob.GroupLogsCollection[endpointID] = portainer.EdgeJobEndpointMeta{
|
||||
CollectLogs: true,
|
||||
LogsStatus: portainer.EdgeJobLogsStatusPending,
|
||||
err = handler.DataStore.EdgeJob().UpdateEdgeJobFunc(edgeJob.ID, func(edgeJob *portainer.EdgeJob) {
|
||||
if slices.Contains(endpointsFromGroups, endpointID) {
|
||||
edgeJob.GroupLogsCollection[endpointID] = portainer.EdgeJobEndpointMeta{
|
||||
CollectLogs: true,
|
||||
LogsStatus: portainer.EdgeJobLogsStatusPending,
|
||||
}
|
||||
} else {
|
||||
meta := edgeJob.Endpoints[endpointID]
|
||||
meta.CollectLogs = true
|
||||
meta.LogsStatus = portainer.EdgeJobLogsStatusPending
|
||||
edgeJob.Endpoints[endpointID] = meta
|
||||
}
|
||||
} else {
|
||||
meta := edgeJob.Endpoints[endpointID]
|
||||
meta.CollectLogs = true
|
||||
meta.LogsStatus = portainer.EdgeJobLogsStatusPending
|
||||
edgeJob.Endpoints[endpointID] = meta
|
||||
}
|
||||
})
|
||||
|
||||
err = handler.DataStore.EdgeJob().UpdateEdgeJob(edgeJob.ID, edgeJob)
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to persist Edge job changes in the database", err)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/portainer/libhttp/response"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
httperrors "github.com/portainer/portainer/api/http/errors"
|
||||
"github.com/portainer/portainer/api/internal/endpointutils"
|
||||
)
|
||||
|
||||
// @id EndpointDelete
|
||||
@@ -124,6 +125,28 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
||||
}
|
||||
}
|
||||
|
||||
if !endpointutils.IsEdgeEndpoint(endpoint) {
|
||||
return response.Empty(w)
|
||||
}
|
||||
|
||||
edgeJobs, err := handler.DataStore.EdgeJob().EdgeJobs()
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to retrieve edge jobs from the database", err)
|
||||
}
|
||||
|
||||
for idx := range edgeJobs {
|
||||
edgeJob := &edgeJobs[idx]
|
||||
if _, ok := edgeJob.Endpoints[endpoint.ID]; ok {
|
||||
err = handler.DataStore.EdgeJob().UpdateEdgeJobFunc(edgeJob.ID, func(j *portainer.EdgeJob) {
|
||||
delete(j.Endpoints, endpoint.ID)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return httperror.InternalServerError("Unable to update edge job", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response.Empty(w)
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,9 @@ func (s *stubEdgeJobService) Create(ID portainer.EdgeJobID, edgeJob *portainer.E
|
||||
func (s *stubEdgeJobService) UpdateEdgeJob(ID portainer.EdgeJobID, edgeJob *portainer.EdgeJob) error {
|
||||
return nil
|
||||
}
|
||||
func (s *stubEdgeJobService) UpdateEdgeJobFunc(ID portainer.EdgeJobID, updateFunc func(edgeJob *portainer.EdgeJob)) error {
|
||||
return nil
|
||||
}
|
||||
func (s *stubEdgeJobService) DeleteEdgeJob(ID portainer.EdgeJobID) error { return nil }
|
||||
func (s *stubEdgeJobService) GetNextIdentifier() int { return 0 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user