Chore: Move SearchOrgs to org service (#55416)
* Chore: Move SearchOrgs to org service * Fix lint * Fix lint 2
This commit is contained in:
@@ -12,9 +12,9 @@ import (
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
@@ -27,6 +27,7 @@ type gitExportJob struct {
|
||||
dashboardsnapshotsService dashboardsnapshots.Service
|
||||
datasourceService datasources.DataSourceService
|
||||
playlistService playlist.Service
|
||||
orgService org.Service
|
||||
rootDir string
|
||||
|
||||
statusMu sync.Mutex
|
||||
@@ -38,13 +39,15 @@ type gitExportJob struct {
|
||||
|
||||
func startGitExportJob(cfg ExportConfig, sql *sqlstore.SQLStore,
|
||||
dashboardsnapshotsService dashboardsnapshots.Service, rootDir string, orgID int64,
|
||||
broadcaster statusBroadcaster, playlistService playlist.Service, datasourceService datasources.DataSourceService) (Job, error) {
|
||||
broadcaster statusBroadcaster, playlistService playlist.Service, orgService org.Service,
|
||||
datasourceService datasources.DataSourceService) (Job, error) {
|
||||
job := &gitExportJob{
|
||||
logger: log.New("git_export_job"),
|
||||
cfg: cfg,
|
||||
sql: sql,
|
||||
dashboardsnapshotsService: dashboardsnapshotsService,
|
||||
playlistService: playlistService,
|
||||
orgService: orgService,
|
||||
datasourceService: datasourceService,
|
||||
rootDir: rootDir,
|
||||
broadcaster: broadcaster,
|
||||
@@ -142,19 +145,19 @@ func (e *gitExportJob) doExportWithHistory() error {
|
||||
},
|
||||
}
|
||||
|
||||
cmd := &models.SearchOrgsQuery{}
|
||||
err = e.sql.SearchOrgs(e.helper.ctx, cmd)
|
||||
cmd := &org.SearchOrgsQuery{}
|
||||
result, err := e.orgService.Search(e.helper.ctx, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Export each org
|
||||
for _, org := range cmd.Result {
|
||||
if len(cmd.Result) > 1 {
|
||||
e.helper.orgDir = path.Join(e.rootDir, fmt.Sprintf("org_%d", org.Id))
|
||||
for _, org := range result {
|
||||
if len(result) > 1 {
|
||||
e.helper.orgDir = path.Join(e.rootDir, fmt.Sprintf("org_%d", org.ID))
|
||||
e.status.Count["orgs"] += 1
|
||||
}
|
||||
err = e.helper.initOrg(e.sql, org.Id)
|
||||
err = e.helper.initOrg(e.sql, org.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/live"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/playlist"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -153,6 +154,7 @@ type StandardExport struct {
|
||||
sql *sqlstore.SQLStore
|
||||
dashboardsnapshotsService dashboardsnapshots.Service
|
||||
playlistService playlist.Service
|
||||
orgService org.Service
|
||||
datasourceService datasources.DataSourceService
|
||||
|
||||
// updated with mutex
|
||||
@@ -160,7 +162,8 @@ type StandardExport struct {
|
||||
}
|
||||
|
||||
func ProvideService(sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles, gl *live.GrafanaLive, cfg *setting.Cfg,
|
||||
dashboardsnapshotsService dashboardsnapshots.Service, playlistService playlist.Service, datasourceService datasources.DataSourceService) ExportService {
|
||||
dashboardsnapshotsService dashboardsnapshots.Service, playlistService playlist.Service, orgService org.Service,
|
||||
datasourceService datasources.DataSourceService) ExportService {
|
||||
if !features.IsEnabled(featuremgmt.FlagExport) {
|
||||
return &StubExport{}
|
||||
}
|
||||
@@ -171,6 +174,7 @@ func ProvideService(sql *sqlstore.SQLStore, features featuremgmt.FeatureToggles,
|
||||
logger: log.New("export_service"),
|
||||
dashboardsnapshotsService: dashboardsnapshotsService,
|
||||
playlistService: playlistService,
|
||||
orgService: orgService,
|
||||
datasourceService: datasourceService,
|
||||
exportJob: &stoppedJob{},
|
||||
dataDir: cfg.DataPath,
|
||||
@@ -228,7 +232,7 @@ func (ex *StandardExport) HandleRequestExport(c *models.ReqContext) response.Res
|
||||
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Error creating export folder", nil)
|
||||
}
|
||||
job, err = startGitExportJob(cfg, ex.sql, ex.dashboardsnapshotsService, dir, c.OrgID, broadcast, ex.playlistService, ex.datasourceService)
|
||||
job, err = startGitExportJob(cfg, ex.sql, ex.dashboardsnapshotsService, dir, c.OrgID, broadcast, ex.playlistService, ex.orgService, ex.datasourceService)
|
||||
default:
|
||||
return response.Error(http.StatusBadRequest, "Unsupported job format", nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user