Skip to content

Commit

Permalink
[remodeling]: Rename scheduler to supervisor & plugin to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx7xxxx committed Feb 5, 2021
1 parent d3b4836 commit 0e122a8
Show file tree
Hide file tree
Showing 58 changed files with 710 additions and 712 deletions.
6 changes: 3 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/megaease/easegateway/pkg/option"
"github.com/megaease/easegateway/pkg/pidfile"
"github.com/megaease/easegateway/pkg/profile"
"github.com/megaease/easegateway/pkg/scheduler"
"github.com/megaease/easegateway/pkg/supervisor"
"github.com/megaease/easegateway/pkg/version"

// For register stuff.
Expand Down Expand Up @@ -66,8 +66,8 @@ func main() {
logger.Errorf("new cluster failed: %v", err)
os.Exit(1)
}
sdl := scheduler.MustNew(opt, cls)
scheduler.InitGlobalScheduler(sdl)
sdl := supervisor.MustNew(opt, cls)
supervisor.InitGlobalSupervisor(sdl)
api := egapi.MustNewServer(opt, cls)

if graceupdate.CallOriProcessTerm(sdl.FirstDone()) {
Expand Down
16 changes: 8 additions & 8 deletions pkg/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/megaease/easegateway/pkg/scheduler"
"github.com/megaease/easegateway/pkg/supervisor"

yaml "gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -48,7 +48,7 @@ func (s *Server) _plusOneVersion() int64 {
return version
}

func (s *Server) _getObject(name string) scheduler.Spec {
func (s *Server) _getObject(name string) supervisor.Spec {
value, err := s.cluster.Get(s.cluster.Layout().ConfigObjectKey(name))
if err != nil {
clusterPanic(err)
Expand All @@ -58,23 +58,23 @@ func (s *Server) _getObject(name string) scheduler.Spec {
return nil
}

spec, err := scheduler.SpecFromYAML(*value)
spec, err := supervisor.SpecFromYAML(*value)
if err != nil {
panic(fmt.Errorf("bad spec(err: %v) from yaml: %s", err, *value))
}

return spec
}

func (s *Server) _listObjects() []scheduler.Spec {
func (s *Server) _listObjects() []supervisor.Spec {
kvs, err := s.cluster.GetPrefix(s.cluster.Layout().ConfigObjectPrefix())
if err != nil {
clusterPanic(err)
}

specs := make([]scheduler.Spec, 0, len(kvs))
specs := make([]supervisor.Spec, 0, len(kvs))
for _, v := range kvs {
spec, err := scheduler.SpecFromYAML(v)
spec, err := supervisor.SpecFromYAML(v)
if err != nil {
panic(fmt.Errorf("bad spec(err: %v) from yaml: %s", err, v))
}
Expand All @@ -84,9 +84,9 @@ func (s *Server) _listObjects() []scheduler.Spec {
return specs
}

func (s *Server) _putObject(spec scheduler.Spec) {
func (s *Server) _putObject(spec supervisor.Spec) {
err := s.cluster.Put(s.cluster.Layout().ConfigObjectKey(spec.GetName()),
scheduler.YAMLFromSpec(spec))
supervisor.YAMLFromSpec(spec))
if err != nil {
clusterPanic(err)
}
Expand Down
52 changes: 26 additions & 26 deletions pkg/api/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,65 @@ const (
// ObjectMetadataPrefix is the object metadata prefix.
ObjectMetadataPrefix = "/metadata/objects"

// PluginMetaPrefix is the plugin of HTTPPipeline metadata prefix.
PluginMetaPrefix = "/metadata/objects/httppipeline/plugins"
// FilterMetaPrefix is the filter of HTTPPipeline metadata prefix.
FilterMetaPrefix = "/metadata/objects/httppipeline/filters"
)

var (
pluginBook = map[string]*httppipeline.PluginRecord{}
pluginKinds []string
filterBook = map[string]*httppipeline.FilterRecord{}
filterKinds []string
)

func (s *Server) setupMetadaAPIs() {
pluginBook = httppipeline.GetPluginBook()
for kind, pr := range pluginBook {
pluginBook[kind] = pr
pluginKinds = append(pluginKinds, kind)
filterBook = httppipeline.GetFilterBook()
for kind, pr := range filterBook {
filterBook[kind] = pr
filterKinds = append(filterKinds, kind)
sort.Strings(pr.Results)
}
sort.Strings(pluginKinds)
sort.Strings(filterKinds)

metadataAPIs := make([]*apiEntry, 0)
metadataAPIs = append(metadataAPIs,
&apiEntry{
Path: PluginMetaPrefix,
Path: FilterMetaPrefix,
Method: "GET",
Handler: s.listPlugins,
Handler: s.listFilters,
},
&apiEntry{
Path: PluginMetaPrefix + "/{kind:string}" + "/description",
Path: FilterMetaPrefix + "/{kind:string}" + "/description",
Method: "GET",
Handler: s.getPluginDescription,
Handler: s.getFilterDescription,
},
&apiEntry{
Path: PluginMetaPrefix + "/{kind:string}" + "/schema",
Path: FilterMetaPrefix + "/{kind:string}" + "/schema",
Method: "GET",
Handler: s.getPluginSchema,
Handler: s.getFilterSchema,
},
&apiEntry{
Path: PluginMetaPrefix + "/{kind:string}" + "/results",
Path: FilterMetaPrefix + "/{kind:string}" + "/results",
Method: "GET",
Handler: s.getPluginResults,
Handler: s.getFilterResults,
},
)

s.apis = append(s.apis, metadataAPIs...)
}

func (s *Server) listPlugins(ctx iris.Context) {
buff, err := yaml.Marshal(pluginKinds)
func (s *Server) listFilters(ctx iris.Context) {
buff, err := yaml.Marshal(filterKinds)
if err != nil {
panic(fmt.Errorf("marshal %#v to yaml failed: %v", pluginKinds, err))
panic(fmt.Errorf("marshal %#v to yaml failed: %v", filterKinds, err))
}

ctx.Header("Content-Type", "text/vnd.yaml")
ctx.Write(buff)
}

func (s *Server) getPluginDescription(ctx iris.Context) {
func (s *Server) getFilterDescription(ctx iris.Context) {
kind := ctx.Params().Get("kind")

pr, exits := pluginBook[kind]
pr, exits := filterBook[kind]
if !exits {
handleAPIError(ctx, iris.StatusNotFound, fmt.Errorf("not found"))
return
Expand All @@ -84,11 +84,11 @@ func (s *Server) getPluginDescription(ctx iris.Context) {
ctx.WriteString(pr.Description)
}

func (s *Server) getPluginSchema(ctx iris.Context) {
func (s *Server) getFilterSchema(ctx iris.Context) {

kind := ctx.Params().Get("kind")

pr, exits := pluginBook[kind]
pr, exits := filterBook[kind]
if !exits {
handleAPIError(ctx, iris.StatusNotFound, fmt.Errorf("not found"))
return
Expand All @@ -103,10 +103,10 @@ func (s *Server) getPluginSchema(ctx iris.Context) {
ctx.Write(buff)
}

func (s *Server) getPluginResults(ctx iris.Context) {
func (s *Server) getFilterResults(ctx iris.Context) {
kind := ctx.Params().Get("kind")

pr, exits := pluginBook[kind]
pr, exits := filterBook[kind]
if !exits {
handleAPIError(ctx, iris.StatusNotFound, fmt.Errorf("not found"))
return
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
_ "github.com/megaease/easegateway/pkg/object/httpproxy"
_ "github.com/megaease/easegateway/pkg/object/httpserver"

"github.com/megaease/easegateway/pkg/scheduler"
"github.com/megaease/easegateway/pkg/supervisor"

"github.com/kataras/iris"
yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -77,13 +77,13 @@ func (s *Server) setupObjectAPIs() {
s.apis = append(s.apis, objAPIs...)
}

func (s *Server) readObjectSpec(ctx iris.Context) (scheduler.Spec, error) {
func (s *Server) readObjectSpec(ctx iris.Context) (supervisor.Spec, error) {
body, err := ioutil.ReadAll(ctx.Request().Body)
if err != nil {
return nil, fmt.Errorf("read body failed: %v", err)
}

spec, err := scheduler.SpecFromYAML(string(body))
spec, err := supervisor.SpecFromYAML(string(body))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func (s *Server) getObject(ctx iris.Context) {

// Reference: https://mailarchive.ietf.org/arch/msg/media-types/e9ZNC0hDXKXeFlAVRWxLCCaG9GI
ctx.Header("Content-Type", "text/vnd.yaml")
ctx.Write([]byte(scheduler.YAMLFromSpec(spec)))
ctx.Write([]byte(supervisor.YAMLFromSpec(spec)))
}

func (s *Server) updateObject(ctx iris.Context) {
Expand Down Expand Up @@ -241,14 +241,14 @@ func (s *Server) listStatusObjects(ctx iris.Context) {
ctx.Write(buff)
}

type specsToSort []scheduler.Spec
type specsToSort []supervisor.Spec

func (s specsToSort) Less(i, j int) bool { return s[i].GetName() < s[j].GetName() }
func (s specsToSort) Len() int { return len(s) }
func (s specsToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

func (s *Server) listObjectKinds(ctx iris.Context) {
kinds := scheduler.ObjectKinds()
kinds := supervisor.ObjectKinds()
buff, err := yaml.Marshal(kinds)
if err != nil {
panic(fmt.Errorf("marshal %#v to yaml failed: %v", kinds, err))
Expand Down
12 changes: 6 additions & 6 deletions pkg/context/httpcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type (

Template() texttemplate.TemplateEngine
SetTemplate(ht *HTTPTemplate)
SaveReqToTemplate(pluginName string) error
SaveRspToTemplate(pluginName string) error
SaveReqToTemplate(filterName string) error
SaveRspToTemplate(filterName string) error
}

// HTTPRequest is all operations for HTTP request.
Expand Down Expand Up @@ -294,11 +294,11 @@ func (ctx *httpContext) SetTemplate(ht *HTTPTemplate) {
}

// SaveHTTPReqToTemplate stores http request related info into HTTP template engine
func (ctx *httpContext) SaveReqToTemplate(pluginName string) error {
return ctx.ht.SaveRequest(pluginName, ctx)
func (ctx *httpContext) SaveReqToTemplate(filterName string) error {
return ctx.ht.SaveRequest(filterName, ctx)
}

// SaveHTTPRspToTemplate stores http response related info into HTTP template engine
func (ctx *httpContext) SaveRspToTemplate(pluginName string) error {
return ctx.ht.SaveResponse(pluginName, ctx)
func (ctx *httpContext) SaveRspToTemplate(filterName string) error {
return ctx.ht.SaveResponse(filterName, ctx)
}
Loading

0 comments on commit 0e122a8

Please sign in to comment.