Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
supermeng committed Nov 29, 2017
1 parent eb1f145 commit ee840a1
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 1,233 deletions.
40 changes: 1 addition & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,49 +115,11 @@ PATCH /api/engine/config
# BadRequest: PodGroupSpec JSON格式错误,或者缺少必需的参数
PATCH /api/engine/maintenance&on=false
# 删除PodGroup部署
# 维护模式设置
# 参数:
# on: 是否打开维护模式
# 返回:
# OK: EngineConfig JSON 数据
PATCH /api/podgroups?name={string}&cmd=replica&num_instances={int}&restart_policy={string}
# 更改PodGroup运行时的Instance数量以及重启策略
# 参数:
# name: PodGroup名称
# num_instances: 需要的实例数量
# restart_policy(optional): 重启策略,值包括:never, always, onfail
# 返回:
# Accepted: 任务被接受
# 错误信息:
# BadRequest: 缺少必需的参数
# NotAllowed: 集群缺少相关资源可被调度
# NotFound: 没有找到对应名称的PodGroup
PATCH /api/podgroups?name={string}&cmd=spec
# 更改PodGroup运行时的具体Spec配置信息
# 参数:
# name: PodGroup名称
# Body: 新的PodSpec
# 返回:
# Accepted: 任务被接受
# 错误信息:
# BadRequest: 缺少必需的参数
# NotAllowed: 集群缺少相关资源可被调度
# NotFound: 没有找到对应名称的PodGroup
PATCH /api/podgroups?name={string}&cmd=operation&optype={start/stop/restart}[&instance={int}]
# 更改PodGroup运行时的具体Spec配置信息
# 参数:
# name: PodGroup名称
# optype: 操作类型 停止或重启
# instance: 操作的pg instance,不传时为整个pod group
# 返回:
# Accepted: 任务被接受
# 错误信息:
# BadRequest: 缺少必需的参数
# NotAllowed: 集群缺少相关资源可被调度
# NotFound: 没有找到对应名称的PodGroup
```

### PodGroup Api
Expand Down
2 changes: 2 additions & 0 deletions apiserver/cntstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"golang.org/x/net/context"
)

// cnt means container

type RestfulCntStatusHstry struct {
server.BaseResource
}
Expand Down
4 changes: 2 additions & 2 deletions apiserver/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func (m *ReadOnlySwitch) ServeHTTP(ctx context.Context, w http.ResponseWriter, r

if e.ReadOnly() && strings.ToUpper(r.Method) != "GET" &&
!strings.HasPrefix(r.URL.Path, "/api/engine/") {
log.Warnf("Do ReadOnly Request!, %q %q, duration=%v",
log.Warnf("Do ReadOnly Request Permitted!, %q %q, duration=%v",
r.Method, r.URL.Path, time.Since(start))
w.WriteHeader(403)
w.Write([]byte("Read Only Permitted.\n"))
w.Write([]byte("Do ReadOnly Permitted.\n"))
return ctx
}
return next(ctx, w, r)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/podgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (rpg RestfulPodGroups) Patch(ctx context.Context, r *http.Request) (int, in
instance := form.ParamInt(r, "instance", 0)
opTypeOptions := []string{"start", "stop", "restart"}
opType := form.ParamStringOptions(r, "optype", opTypeOptions, "noop")
err = orcEngine.ChageState(pgName, opType, instance)
err = orcEngine.ChangeState(pgName, opType, instance)
}

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
EtcdResourcesKey = "/lain/config/resources"
EtcdGuardSwitchKey = "/lain/config/guardswitch"

EtcdReadOnlyKey = "/lain/deployd/engine/config"
EtcdConfigKey = "/lain/deployd/engine/config"
)

var (
Expand All @@ -37,7 +37,7 @@ func watchResource(store storage.Store) {
}

func WatchEngineConfig(engine *OrcEngine) {
watcher(engine.store, EtcdReadOnlyKey, engine.config)
watcher(engine.store, EtcdConfigKey, engine.config)
}

func watcher(store storage.Store, key string, v interface{}) {
Expand Down Expand Up @@ -85,7 +85,7 @@ func GuardGotoWork(store storage.Store) bool {
}

func ConfigEngine(engine *OrcEngine) bool {
if err := engine.store.Set(EtcdReadOnlyKey, engine.config, true); err != nil {
if err := engine.store.Set(EtcdConfigKey, engine.config, true); err != nil {
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (engine *OrcEngine) DriftNode(fromNode, toNode string, pgName string, pgIns
// so far we just wait for the dependsCtrl to react to the events
}

func (engine *OrcEngine) ChageState(pgName, op string, instance int) error {
func (engine *OrcEngine) ChangeState(pgName, op string, instance int) error {
engine.RLock()
defer engine.RUnlock()
if pgCtrl, ok := engine.pgCtrls[pgName]; ok {
Expand Down
2 changes: 1 addition & 1 deletion engine/engine_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ type orcOperChangeState struct {
}

func (op orcOperChangeState) Do(engine *OrcEngine) {
op.pgCtrl.ChageState(op.op, op.instance)
op.pgCtrl.ChangeState(op.op, op.instance)
}
2 changes: 2 additions & 0 deletions engine/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func HandleDockerEvent(engine *OrcEngine, event *adoc.Event) {
}
}

// cnt means container

const (
KCntStatus = "/lain/deployd/histroy"
FmtKCntStatusLstPos = "/lain/deployd/histroy/%s/%d/lastpos"
Expand Down
6 changes: 3 additions & 3 deletions engine/podgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ func (pgCtrl *podGroupController) Refresh(force bool) {
pgCtrl.opsChan <- pgOperLogOperation{"PodGroup refreshing finished"}
}

func (pgCtrl *podGroupController) ChageState(op string, instance int) {
func (pgCtrl *podGroupController) ChangeState(op string, instance int) {
pgCtrl.RLock()
spec := pgCtrl.spec.Clone()
pgCtrl.RUnlock()
if instance == 0 {
for i := 0; i < spec.NumInstances; i += 1 {
pgCtrl.opsChan <- pgOperChageState{op, i + 1}
pgCtrl.opsChan <- pgOperChangeState{op, i + 1}
}
} else if instance > 0 && instance <= spec.NumInstances {
pgCtrl.opsChan <- pgOperChageState{op, instance}
pgCtrl.opsChan <- pgOperChangeState{op, instance}
}
pgCtrl.opsChan <- pgOperSnapshotGroup{true}
pgCtrl.opsChan <- pgOperSaveStore{true}
Expand Down
4 changes: 2 additions & 2 deletions engine/podgroup_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,12 @@ func (op pgOperSendState) Do(pgCtrl *podGroupController, c cluster.Cluster, stor
return false
}

type pgOperChageState struct {
type pgOperChangeState struct {
op string
instance int
}

func (op pgOperChageState) Do(pgCtrl *podGroupController, c cluster.Cluster, store storage.Store, ev *RuntimeEagleView) bool {
func (op pgOperChangeState) Do(pgCtrl *podGroupController, c cluster.Cluster, store storage.Store, ev *RuntimeEagleView) bool {
start := time.Now()
defer func() {
pgCtrl.RLock()
Expand Down
Loading

0 comments on commit ee840a1

Please sign in to comment.