Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Optimize governance api. * Print the version info when SC startup. * Restore support for v3 api. * Fix the CI failure. * Fix the CI failure.
- Loading branch information
1 parent
d81050f
commit d4585af
Showing
19 changed files
with
618 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//Copyright 2017 Huawei Technologies Co., Ltd | ||
// | ||
//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 chain | ||
|
||
import ( | ||
"github.com/ServiceComb/service-center/pkg/util" | ||
) | ||
|
||
type Result struct { | ||
OK bool | ||
Err error | ||
Args []interface{} | ||
} | ||
|
||
type CallbackFunc func(r Result) | ||
|
||
type Callback struct { | ||
Func CallbackFunc | ||
} | ||
|
||
func (cb *Callback) Invoke(r Result) { | ||
go func() { | ||
defer util.RecoverAndReport() | ||
cb.Func(r) | ||
}() | ||
} | ||
|
||
func (cb *Callback) Fail(err error, args ...interface{}) { | ||
cb.Invoke(Result{ | ||
OK: false, | ||
Err: err, | ||
Args: args, | ||
}) | ||
} | ||
|
||
func (cb *Callback) Success(args ...interface{}) { | ||
cb.Invoke(Result{ | ||
OK: true, | ||
Args: args, | ||
}) | ||
} | ||
|
||
func NewCallback(f CallbackFunc) Callback { | ||
return Callback{ | ||
Func: f, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//Copyright 2017 Huawei Technologies Co., Ltd | ||
// | ||
//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 chain | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ServiceComb/service-center/pkg/util" | ||
"sync" | ||
) | ||
|
||
var handlersMap map[string][]Handler | ||
|
||
type Chain struct { | ||
name string | ||
handlers []Handler | ||
currentIndex int | ||
mux sync.Mutex | ||
} | ||
|
||
func (c *Chain) Init(chainName string, hs []Handler) { | ||
c.name = chainName | ||
c.currentIndex = -1 | ||
if len(hs) > 0 { | ||
c.handlers = make([]Handler, 0, len(hs)) | ||
copy(c.handlers, hs) | ||
} | ||
} | ||
|
||
func (c *Chain) Name() string { | ||
return c.name | ||
} | ||
|
||
func (c *Chain) doNext(i *Invocation) { | ||
defer util.RecoverAndReport() | ||
|
||
if c.currentIndex >= len(c.handlers) { | ||
i.Fail(fmt.Errorf("Over end of chain '%s'", c.name)) | ||
return | ||
} | ||
c.currentIndex += 1 | ||
c.handlers[c.currentIndex].Handle(i) | ||
} | ||
|
||
func (c *Chain) next(i *Invocation) { | ||
go c.doNext(i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//Copyright 2017 Huawei Technologies Co., Ltd | ||
// | ||
//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 chain | ||
|
||
type Handler interface { | ||
Handle(i *Invocation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//Copyright 2017 Huawei Technologies Co., Ltd | ||
// | ||
//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 chain | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
const DEFAULT_MAP_SIZE = 10 | ||
|
||
type Invocation struct { | ||
Callback | ||
handlerContext map[string]interface{} | ||
context map[string]interface{} | ||
chain *Chain | ||
} | ||
|
||
func (i *Invocation) Init(ch *Chain) { | ||
i.handlerContext = make(map[string]interface{}, DEFAULT_MAP_SIZE) | ||
i.context = make(map[string]interface{}, DEFAULT_MAP_SIZE) | ||
i.chain = ch | ||
} | ||
|
||
func (i *Invocation) HandlerContext() map[string]interface{} { | ||
return i.handlerContext | ||
} | ||
|
||
func (i *Invocation) Context() map[string]interface{} { | ||
return i.context | ||
} | ||
|
||
func (i *Invocation) WithHandlerContext(key string, val interface{}) *Invocation { | ||
i.handlerContext[key] = val | ||
return i | ||
} | ||
|
||
func (i *Invocation) WithContext(key string, val interface{}) *Invocation { | ||
i.context[key] = val | ||
return i | ||
} | ||
|
||
func (i *Invocation) Next(f CallbackFunc) { | ||
i.Func = f | ||
if i.chain == nil { | ||
i.Fail(errors.New("Can not find any chain for this invocation")) | ||
return | ||
} | ||
i.chain.next(i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//Copyright 2017 Huawei Technologies Co., Ltd | ||
// | ||
//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 v3 | ||
|
||
import ( | ||
"github.com/ServiceComb/service-center/pkg/rest" | ||
"github.com/ServiceComb/service-center/server/rest/controller/v4" | ||
) | ||
|
||
// GovernService 治理相关接口服务 | ||
type GovernService struct { | ||
v4.GovernService | ||
} | ||
|
||
// URLPatterns 路由 | ||
func (governService *GovernService) URLPatterns() []rest.Route { | ||
return []rest.Route{ | ||
{rest.HTTP_METHOD_GET, "/registry/v3/govern/service/:serviceId", governService.GetServiceDetail}, | ||
{rest.HTTP_METHOD_GET, "/registry/v3/govern/relation", governService.GetGraph}, | ||
{rest.HTTP_METHOD_GET, "/registry/v3/govern/services", governService.GetAllServicesInfo}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//Copyright 2017 Huawei Technologies Co., Ltd | ||
// | ||
//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 v3 | ||
|
||
import ( | ||
"github.com/ServiceComb/service-center/pkg/rest" | ||
"github.com/ServiceComb/service-center/server/rest/controller/v4" | ||
) | ||
|
||
type MicroServiceInstanceService struct { | ||
v4.MicroServiceInstanceService | ||
} | ||
|
||
func (this *MicroServiceInstanceService) URLPatterns() []rest.Route { | ||
return []rest.Route{ | ||
{rest.HTTP_METHOD_GET, "/registry/v3/instances", this.FindInstances}, | ||
{rest.HTTP_METHOD_GET, "/registry/v3/microservices/:serviceId/instances", this.GetInstances}, | ||
{rest.HTTP_METHOD_GET, "/registry/v3/microservices/:serviceId/instances/:instanceId", this.GetOneInstance}, | ||
{rest.HTTP_METHOD_POST, "/registry/v3/microservices/:serviceId/instances", this.RegisterInstance}, | ||
{rest.HTTP_METHOD_DELETE, "/registry/v3/microservices/:serviceId/instances/:instanceId", this.UnregisterInstance}, | ||
{rest.HTTP_METHOD_PUT, "/registry/v3/microservices/:serviceId/instances/:instanceId/properties", this.UpdateMetadata}, | ||
{rest.HTTP_METHOD_PUT, "/registry/v3/microservices/:serviceId/instances/:instanceId/status", this.UpdateStatus}, | ||
{rest.HTTP_METHOD_PUT, "/registry/v3/microservices/:serviceId/instances/:instanceId/heartbeat", this.Heartbeat}, | ||
{rest.HTTP_METHOD_PUT, "/registry/v3/heartbeats", this.HeartbeatSet}, | ||
} | ||
} |
Oops, something went wrong.