diff --git a/cmd/builder/server/server.go b/cmd/builder/server/server.go index bfe3655a5..4685af780 100644 --- a/cmd/builder/server/server.go +++ b/cmd/builder/server/server.go @@ -41,7 +41,6 @@ import ( "github.com/goodrain/rainbond/pkg/builder/discover" "github.com/goodrain/rainbond/pkg/builder/exector" "github.com/goodrain/rainbond/pkg/api/handler" - "github.com/goodrain/rainbond/pkg/db" "github.com/goodrain/rainbond/pkg/db/config" "github.com/goodrain/rainbond/pkg/event" "os" @@ -63,10 +62,6 @@ func Run(s *option.Builder) error { EtcdEndPoints: s.Config.EtcdEndPoints, EtcdTimeout: s.Config.EtcdTimeout, } - if err := db.CreateManager(dbconfig); err != nil { - return err - } - defer db.CloseManager() if err := event.NewManager(event.EventConfig{EventLogServers: s.Config.EventLogServers}); err != nil { return err } @@ -75,14 +70,6 @@ func Run(s *option.Builder) error { if err != nil { return err } - if err := handler.CreateServiceManger(api_option.Config{ - DBType: dbconfig.DBType, - DBConnectionInfo: dbconfig.MysqlConnectionInfo, - EtcdEndpoint: dbconfig.EtcdEndPoints, - }); err != nil { - logrus.Errorf("create servie manager error, %v", err) - return err - } if err := exec.Start(); err != nil { return err } diff --git a/pkg/builder/apiHandler/service_action.go b/pkg/builder/apiHandler/service_action.go index 184604c98..9b5a2379e 100644 --- a/pkg/builder/apiHandler/service_action.go +++ b/pkg/builder/apiHandler/service_action.go @@ -19,14 +19,54 @@ package apiHandler import ( - "github.com/goodrain/rainbond/pkg/api/handler" + "github.com/pquerna/ffjson/ffjson" + "os" + "strings" + "net/http" + "fmt" + "bytes" + "strconv" "github.com/goodrain/rainbond/pkg/worker/discover/model" ) //UpgradeService 滚动升级 -func UpgradeService(upgradeTask *model.RollingUpgradeTaskBody) error { - if err := handler.GetServiceManager().ServiceUpgrade(upgradeTask); err != nil { +func UpgradeService(tenantName, serviceAlias string ,ru *model.RollingUpgradeTaskBody) error { + url := fmt.Sprintf("http://127.0.0.1:8888/v2/tenants/%s/services/%s/upgrade", tenantName, serviceAlias) + version, err := strconv.Atoi(ru.CurrentDeployVersion) + if err != nil { return err } - return nil + raw := struct { + DeployVersion int `json:"deploy_version"` + EventID string `json:"event_id"` + }{ + DeployVersion:version, + EventID:ru.EventID, + } + rawBody, err := ffjson.Marshal(raw) + if err != nil { + return err + } + return publicRequest("post", url,rawBody) +} + +func publicRequest(method, url string, body...[]byte) error { + client := &http.Client{} + var rawBody *bytes.Buffer + if len(body) != 0 { + rawBody = bytes.NewBuffer(body[0]) + }else { + rawBody = nil + } + request, _ := http.NewRequest(strings.ToUpper(method), url, rawBody) + token := os.Getenv("TOKEN") + if token != "" { + request.Header.Set("Authorization", "Token "+token) + } + response, _ := client.Do(request) + if response.StatusCode == 200 { + //body, _ := ioutil.ReadAll(response.Body) + return nil + } + return fmt.Errorf("send upgrade mission error") } \ No newline at end of file diff --git a/pkg/builder/exector/build_from_image_run.go b/pkg/builder/exector/build_from_image_run.go index 64c587d3a..26fda9ae5 100644 --- a/pkg/builder/exector/build_from_image_run.go +++ b/pkg/builder/exector/build_from_image_run.go @@ -96,7 +96,7 @@ func (i *ImageBuildItem) Run(timeout time.Duration) error { logrus.Errorf("storage version info error, ignor it: %s", err.Error()) } i.Logger.Info("应用同步完成,开始启动应用", map[string]string{"step": "build-exector"}) - if err := apiHandler.UpgradeService(i.CreateUpgradeTaskBody()); err != nil { + if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil { i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"}) logrus.Errorf("rolling update service error, %s", err.Error()) } diff --git a/pkg/builder/exector/build_from_sourcecode_run.go b/pkg/builder/exector/build_from_sourcecode_run.go index 5a4edeaa6..9fc06b90e 100644 --- a/pkg/builder/exector/build_from_sourcecode_run.go +++ b/pkg/builder/exector/build_from_sourcecode_run.go @@ -132,7 +132,7 @@ func (i *SourceCodeBuildItem) Run(timeout time.Duration) error { } i.Logger.Info("应用同步完成,开始启动应用", map[string]string{"step": "build-exector"}) - if err := apiHandler.UpgradeService(i.CreateUpgradeTaskBody()); err != nil { + if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil { i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"}) logrus.Errorf("rolling update service error, %s", err.Error()) } @@ -196,7 +196,7 @@ func (i *SourceCodeBuildItem) buildImage() error { } i.Logger.Info("应用同步完成,开始启动应用", map[string]string{"step": "build-exector"}) - if err := apiHandler.UpgradeService(i.CreateUpgradeTaskBody()); err != nil { + if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil { i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"}) logrus.Errorf("rolling update service error, %s", err.Error()) } diff --git a/pkg/builder/exector/exector.go b/pkg/builder/exector/exector.go index d153c47ce..fb1b2cea6 100644 --- a/pkg/builder/exector/exector.go +++ b/pkg/builder/exector/exector.go @@ -69,8 +69,6 @@ func NewManager(conf config.Config) (Manager, error) { type exectorManager struct { DockerClient *client.Client EtcdCli *clientv3.Client - - } //TaskType: