Skip to content

Commit

Permalink
vpcagent: apihelper: use its own options
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed May 26, 2020
1 parent c05e243 commit 230f004
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
9 changes: 4 additions & 5 deletions pkg/vpcagent/apihelper/apihelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ import (

"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/vpcagent/options"
)

const (
ErrSync = errors.Error("sync error")
)

type APIHelper struct {
opts *options.Options
opts *Options
modelSets IModelSets
modelSetsCh chan IModelSets

mcclientSession *mcclient.ClientSession
}

func NewAPIHelper(opts *options.Options, modelSets IModelSets) (*APIHelper, error) {
func NewAPIHelper(opts *Options, modelSets IModelSets) (*APIHelper, error) {
modelSetsCh := make(chan IModelSets)
helper := &APIHelper{
opts: opts,
Expand All @@ -58,7 +57,7 @@ func (h *APIHelper) Start(ctx context.Context) {

h.run(ctx)

tickDuration := time.Duration(h.opts.APISyncInterval) * time.Second
tickDuration := time.Duration(h.opts.SyncInterval) * time.Second
tick := time.NewTimer(tickDuration)
defer tick.Stop()

Expand Down Expand Up @@ -101,7 +100,7 @@ func (h *APIHelper) doSync(ctx context.Context) (changed bool, err error) {
}

s := h.adminClientSession(ctx)
r, err := SyncModelSets(h.modelSets, s, h.opts.APIListBatchSize)
r, err := SyncModelSets(h.modelSets, s, h.opts.ListBatchSize)
if err != nil {
return false, err
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/vpcagent/apihelper/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package apihelper

import (
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
)

type Options struct {
common_options.CommonOptions

SyncInterval int
ListBatchSize int
}
7 changes: 6 additions & 1 deletion pkg/vpcagent/ovn/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ type Worker struct {

func NewWorker(opts *options.Options) worker.IWorker {
modelSets := agentmodels.NewModelSets()
apih, err := apihelper.NewAPIHelper(opts, modelSets)
apiOpts := &apihelper.Options{
CommonOptions: opts.CommonOptions,
SyncInterval: opts.APISyncInterval,
ListBatchSize: opts.APIListBatchSize,
}
apih, err := apihelper.NewAPIHelper(apiOpts, modelSets)
if err != nil {
return nil
}
Expand Down

0 comments on commit 230f004

Please sign in to comment.