Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backup InProgress error #569

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions controllers/solrbackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,12 @@ func reconcileSolrCollectionBackup(ctx context.Context, backup *solrv1beta1.Solr
return true, nil
} else if !collectionBackupStatus.InProgress {
// Start the backup by calling solr
var started bool
started, err = util.StartBackupForCollection(ctx, solrCloud, backupRepository, backup, collection, logger)
err = util.StartBackupForCollection(ctx, solrCloud, backupRepository, backup, collection, logger)
if err != nil {
return true, err
return false, err
}
collectionBackupStatus.InProgress = started
if started && collectionBackupStatus.StartTime == nil {
collectionBackupStatus.InProgress = true
if collectionBackupStatus.StartTime == nil {
collectionBackupStatus.StartTime = &now
}
collectionBackupStatus.BackupName = util.FullCollectionBackupName(collection, backup.Name)
Expand Down
22 changes: 15 additions & 7 deletions controllers/util/backup_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/go-logr/logr"
"github.com/robfig/cron/v3"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -91,22 +93,28 @@ func GenerateQueryParamsForBackup(backupRepository *solr.SolrBackupRepository, b
return queryParams
}

func StartBackupForCollection(ctx context.Context, cloud *solr.SolrCloud, backupRepository *solr.SolrBackupRepository, backup *solr.SolrBackup, collection string, logger logr.Logger) (success bool, err error) {
func StartBackupForCollection(ctx context.Context, cloud *solr.SolrCloud, backupRepository *solr.SolrBackupRepository, backup *solr.SolrBackup, collection string, logger logr.Logger) (err error) {
queryParams := GenerateQueryParamsForBackup(backupRepository, backup, collection)
resp := &solr_api.SolrAsyncResponse{}

logger.Info("Calling to start collection backup", "solrCloud", cloud.Name, "collection", collection)
err = solr_api.CallCollectionsApi(ctx, cloud, queryParams, resp)

if err == nil {
if resp.ResponseHeader.Status == 0 {
success = true
}
} else {
if err == nil && resp.ResponseHeader.Status != 0 {
err = &errors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: int32(resp.Error.Code),
Details: &metav1.StatusDetails{
Causes: []metav1.StatusCause{{Message: resp.Error.Message}},
},
Message: "Error occurred while trying to start backup",
}}
}
if err != nil {
logger.Error(err, "Error starting collection backup", "solrCloud", cloud.Name, "collection", collection)
}

return success, err
return err
}

func CheckBackupForCollection(ctx context.Context, cloud *solr.SolrCloud, collection string, backupName string, logger logr.Logger) (finished bool, success bool, asyncStatus string, err error) {
Expand Down
18 changes: 16 additions & 2 deletions controllers/util/solr_api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"encoding/json"
"fmt"
solr "github.com/apache/solr-operator/api/v1beta1"
"io/ioutil"
"io"
"k8s.io/apimachinery/pkg/api/errors"
"net/http"
"net/url"
Expand Down Expand Up @@ -55,6 +55,9 @@ type SolrAsyncResponse struct {

// +optional
Status SolrAsyncStatus `json:"status,omitempty"`

// +optional
Error SolrAsyncError `json:"error,omitempty"`
}

type SolrResponseHeader struct {
Expand All @@ -72,6 +75,17 @@ type SolrAsyncStatus struct {
Message string `json:"msg,omitempty"`
}

type SolrAsyncError struct {
// +optional
Metadata []string `json:"metadata,omitempty"`

// +optional
Message string `json:"msg,omitempty"`

// +optional
Code int `json:"code,omitempty"`
}

type SolrAsyncStatusResponse struct {
ResponseHeader SolrResponseHeader `json:"responseHeader"`

Expand Down Expand Up @@ -154,7 +168,7 @@ func CallCollectionsApi(ctx context.Context, cloud *solr.SolrCloud, urlParams ur
defer resp.Body.Close()

if err == nil && resp.StatusCode != 200 {
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
err = errors.NewServiceUnavailable(fmt.Sprintf("Recieved bad response code of %d from solr with response: %s", resp.StatusCode, string(b)))
}

Expand Down