Skip to content

Commit 6ba4782

Browse files
authored
feat: add scheduler features api for manager (#3488)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent 92b26fa commit 6ba4782

File tree

10 files changed

+210
-13
lines changed

10 files changed

+210
-13
lines changed

api/manager/docs.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,41 @@ const docTemplate = `{
22922292
}
22932293
}
22942294
},
2295+
"/scheduler-features": {
2296+
"get": {
2297+
"description": "Get Scheduler Features",
2298+
"consumes": [
2299+
"application/json"
2300+
],
2301+
"produces": [
2302+
"application/json"
2303+
],
2304+
"tags": [
2305+
"Scheduler Feature"
2306+
],
2307+
"summary": "Get Scheudler Features",
2308+
"responses": {
2309+
"200": {
2310+
"description": "OK",
2311+
"schema": {
2312+
"type": "array",
2313+
"items": {
2314+
"type": "string"
2315+
}
2316+
}
2317+
},
2318+
"400": {
2319+
"description": "Bad Request"
2320+
},
2321+
"404": {
2322+
"description": "Not Found"
2323+
},
2324+
"500": {
2325+
"description": "Internal Server Error"
2326+
}
2327+
}
2328+
}
2329+
},
22952330
"/schedulers": {
22962331
"get": {
22972332
"description": "Get Schedulers",

api/manager/swagger.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,6 +2286,41 @@
22862286
}
22872287
}
22882288
},
2289+
"/scheduler-features": {
2290+
"get": {
2291+
"description": "Get Scheduler Features",
2292+
"consumes": [
2293+
"application/json"
2294+
],
2295+
"produces": [
2296+
"application/json"
2297+
],
2298+
"tags": [
2299+
"Scheduler Feature"
2300+
],
2301+
"summary": "Get Scheudler Features",
2302+
"responses": {
2303+
"200": {
2304+
"description": "OK",
2305+
"schema": {
2306+
"type": "array",
2307+
"items": {
2308+
"type": "string"
2309+
}
2310+
}
2311+
},
2312+
"400": {
2313+
"description": "Bad Request"
2314+
},
2315+
"404": {
2316+
"description": "Not Found"
2317+
},
2318+
"500": {
2319+
"description": "Internal Server Error"
2320+
}
2321+
}
2322+
}
2323+
},
22892324
"/schedulers": {
22902325
"get": {
22912326
"description": "Get Schedulers",

api/manager/swagger.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,29 @@ paths:
25822582
summary: Add Scheduler to schedulerCluster
25832583
tags:
25842584
- SchedulerCluster
2585+
/scheduler-features:
2586+
get:
2587+
consumes:
2588+
- application/json
2589+
description: Get Scheduler Features
2590+
produces:
2591+
- application/json
2592+
responses:
2593+
"200":
2594+
description: OK
2595+
schema:
2596+
items:
2597+
type: string
2598+
type: array
2599+
"400":
2600+
description: Bad Request
2601+
"404":
2602+
description: Not Found
2603+
"500":
2604+
description: Internal Server Error
2605+
summary: Get Scheudler Features
2606+
tags:
2607+
- Scheduler Feature
25852608
/schedulers:
25862609
get:
25872610
consumes:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 The Dragonfly Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package handlers
18+
19+
import (
20+
"net/http"
21+
22+
"github.com/gin-gonic/gin"
23+
24+
// nolint
25+
_ "d7y.io/dragonfly/v2/manager/models"
26+
)
27+
28+
// @Summary Get Scheudler Features
29+
// @Description Get Scheduler Features
30+
// @Tags Scheduler Feature
31+
// @Accept json
32+
// @Produce json
33+
// @Success 200 {array} string
34+
// @Failure 400
35+
// @Failure 404
36+
// @Failure 500
37+
// @Router /scheduler-features [get]
38+
func (h *Handlers) GetSchedulerFeatures(ctx *gin.Context) {
39+
features := h.service.GetSchedulerFeatures(ctx.Request.Context())
40+
ctx.JSON(http.StatusOK, features)
41+
}

manager/router/router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ func Init(cfg *config.Config, logDir string, service service.Service, database *
159159
s.GET(":id", h.GetScheduler)
160160
s.GET("", h.GetSchedulers)
161161

162+
// Scheduler Feature.
163+
sf := apiv1.Group("/scheduler-features", jwt.MiddlewareFunc(), rbac)
164+
sf.GET("", h.GetSchedulerFeatures)
165+
162166
// Seed Peer Cluster.
163167
spc := apiv1.Group("/seed-peer-clusters", jwt.MiddlewareFunc(), rbac)
164168
spc.POST("", h.CreateSeedPeerCluster)

manager/service/mocks/service_mock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 The Dragonfly Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package service
18+
19+
import (
20+
"context"
21+
22+
"d7y.io/dragonfly/v2/manager/types"
23+
)
24+
25+
func (s *service) GetSchedulerFeatures(ctx context.Context) []string {
26+
return types.DefaultSchedulerFeatures
27+
}

manager/service/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type Service interface {
101101
UpdateScheduler(context.Context, uint, types.UpdateSchedulerRequest) (*models.Scheduler, error)
102102
GetScheduler(context.Context, uint) (*models.Scheduler, error)
103103
GetSchedulers(context.Context, types.GetSchedulersQuery) ([]models.Scheduler, int64, error)
104+
GetSchedulerFeatures(context.Context) []string
104105

105106
CreateBucket(context.Context, types.CreateBucketRequest) error
106107
DestroyBucket(context.Context, string) error

manager/types/scheduler.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616

1717
package types
1818

19-
const (
20-
// SchedulerFeatureSchedule is the schedule feature of scheduler.
21-
SchedulerFeatureSchedule = "schedule"
22-
23-
// SchedulerFeaturePreheat is the preheat feature of scheduler.
24-
SchedulerFeaturePreheat = "preheat"
25-
)
26-
27-
var (
28-
// DefaultSchedulerFeatures is the default features of scheduler.
29-
DefaultSchedulerFeatures = []string{SchedulerFeatureSchedule, SchedulerFeaturePreheat}
30-
)
31-
3219
type SchedulerParams struct {
3320
ID uint `uri:"id" binding:"required"`
3421
}

manager/types/scheduler_feature.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2024 The Dragonfly Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package types
18+
19+
const (
20+
// SchedulerFeatureSchedule is the schedule feature of scheduler.
21+
SchedulerFeatureSchedule = "schedule"
22+
23+
// SchedulerFeaturePreheat is the preheat feature of scheduler.
24+
SchedulerFeaturePreheat = "preheat"
25+
)
26+
27+
var (
28+
// DefaultSchedulerFeatures is the default features of scheduler.
29+
DefaultSchedulerFeatures = []string{SchedulerFeatureSchedule, SchedulerFeaturePreheat}
30+
)

0 commit comments

Comments
 (0)