Merge pull request #1 from integration-system/common_configs

migrate invoke from convert to config
This commit is contained in:
Yan authored and GitHub committed 2019-10-28 15:58:21 +03:00
commit 887f166f30
12 files changed
+187 -101

No files matched your search

+1 -1
View File
@@ -1 +1 @@
1.2.3
1.2.4
+2
View File
@@ -1,3 +1,5 @@
## v1.2.4
* migrate invoke to config service
## v1.2.3
* read configuration from `stdin` till `EOF`
## v1.2.2
Generated
+92 -46
View File
@@ -50,19 +50,26 @@
[[projects]]
branch = "master"
digest = "1:abd0cd78d6d27a98080f2b2a7fd39bb2f3d3eef6aa20c720093129f04fb41d78"
name = "github.com/integration-system/gowsdl"
packages = ["soap"]
digest = "1:c4f3970d1f30f5e9bc1751b62b7ea6127256e59fd63a3d36e166fe1121250c57"
name = "github.com/integration-system/go-cmp"
packages = [
"cmp",
"cmp/internal/diff",
"cmp/internal/function",
"cmp/internal/value",
]
pruneopts = "UT"
revision = "368713356c71961354e09ab9b734740ebdd94784"
revision = "ac5582987a2f25e8743e0ebb7259312adda05c23"
[[projects]]
branch = "master"
digest = "1:95c2d64f7a0ec98156d5b970f7cef94d418025ec4b4324d81318743db2a158fc"
digest = "1:2c5074a55f97c23cd89581a5d66fa82c26ee1fa01bffad0d3f540e8d28b131e5"
name = "github.com/integration-system/isp-lib"
packages = [
"backend",
"config/schema",
"http",
"proto/stubs",
"streaming",
"structure",
"utils",
]
@@ -99,18 +106,6 @@
revision = "03217c3e97663914aec3faafde50d081f197a0a2"
version = "1.1.8"
[[projects]]
digest = "1:acfc228fb5fbfb82645c121e3224bd546ed68aef6dfc87f63e2d8de099a3822b"
name = "github.com/klauspost/compress"
packages = [
"flate",
"gzip",
"zlib",
]
pruneopts = "UT"
revision = "a41f1a10bd3b167958ff6df80b800fe2969dd3ca"
version = "v1.9.0"
[[projects]]
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
name = "github.com/konsorten/go-windows-terminal-sequences"
@@ -159,6 +154,14 @@
revision = "e6d60cf7ba1f42d86d54cdf5508611c4aafb3970"
version = "v0.0.1"
[[projects]]
digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b"
name = "github.com/pkg/errors"
packages = ["."]
pruneopts = "UT"
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
version = "v0.8.1"
[[projects]]
digest = "1:b36a0ede02c4c2aef7df7f91cbbb7bb88a98b5d253509d4f997dda526e50c88c"
name = "github.com/russross/blackfriday"
@@ -215,26 +218,6 @@
revision = "bfe2e925cfb6d44b40ad3a779165ea7e8aff9212"
version = "v1.22.0"
[[projects]]
digest = "1:c468422f334a6b46a19448ad59aaffdfc0a36b08fdcc1c749a0b29b6453d7e59"
name = "github.com/valyala/bytebufferpool"
packages = ["."]
pruneopts = "UT"
revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
version = "v1.0.0"
[[projects]]
branch = "master"
digest = "1:77f7e2f75e4c44ede24f47aca6c514f24f06c6a0ee3c47c8d7ce2b77b49ac482"
name = "github.com/valyala/fasthttp"
packages = [
".",
"fasthttputil",
"stackless",
]
pruneopts = "UT"
revision = "9bc6da12192c610a272a9289b9574eb5d8cfdfe1"
[[projects]]
branch = "master"
digest = "1:87fe9bca786484cef53d52adeec7d1c52bc2bfbee75734eddeb75fc5c7023871"
@@ -261,19 +244,52 @@
[[projects]]
branch = "master"
digest = "1:76ee51c3f468493aff39dbacc401e8831fbb765104cbf613b89bef01cf4bad70"
digest = "1:c124e945335a9c62ede3a565f3198c5ae9a5ecc39fddd85871138362d128fb74"
name = "golang.org/x/net"
packages = ["context"]
packages = [
"context",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"trace",
]
pruneopts = "UT"
revision = "ec77196f6094c3492a8b61f2c11cf937f78992ae"
revision = "fe3aa8a4527195a6057b3fad46619d7d090e99b5"
[[projects]]
branch = "master"
digest = "1:56068728488986584e5a2f3576cb84d52bad7ec7fbe63a14b0d3b26bfdb41b8b"
digest = "1:89c4223950671f7afdc98761c6a601b83594865490c71b434194b6cacf208e6a"
name = "golang.org/x/sys"
packages = ["unix"]
pruneopts = "UT"
revision = "6c3a3bfe00aeca2b8685f04a482824367e7d2135"
revision = "f8518d3b3627146e88bd43ca73045e1b8d8eb6c6"
[[projects]]
digest = "1:8d8faad6b12a3a4c819a3f9618cb6ee1fa1cfc33253abeeea8b55336721e3405"
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/language",
"internal/language/compact",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable",
]
pruneopts = "UT"
revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"
version = "v0.3.2"
[[projects]]
branch = "master"
@@ -287,16 +303,42 @@
revision = "548a555dbc03994223efbaba0090152849259498"
[[projects]]
digest = "1:42de3e9a8a8d7d0c7dc0e832f03786c3993c6d97b0e4a18268fb0142cd65e247"
digest = "1:6cd77d0b616d2dcebd363dfecba593f27b0151fc82cdb5fbfb96c5a7cfbc95b5"
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"binarylog/grpc_binarylog_v1",
"codes",
"connectivity",
"credentials",
"credentials/internal",
"encoding",
"encoding/proto",
"grpclog",
"internal",
"internal/backoff",
"internal/balancerload",
"internal/binarylog",
"internal/channelz",
"internal/envconfig",
"internal/grpcrand",
"internal/grpcsync",
"internal/syscall",
"internal/transport",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"serviceconfig",
"stats",
"status",
"tap",
]
pruneopts = "UT"
revision = "f6d0f9ee430895e87ef1ceb5ac8f39725bafceef"
@@ -316,15 +358,19 @@
input-imports = [
"github.com/codegangsta/cli",
"github.com/integration-system/bellows",
"github.com/integration-system/isp-lib/backend",
"github.com/integration-system/isp-lib/config/schema",
"github.com/integration-system/isp-lib/http",
"github.com/integration-system/isp-lib/structure",
"github.com/olekukonko/tablewriter",
"github.com/pkg/errors",
"github.com/tidwall/gjson",
"github.com/tidwall/pretty",
"github.com/tidwall/sjson",
"github.com/valyala/fasthttp",
"github.com/xeipuuv/gojsonschema",
"google.golang.org/grpc",
"google.golang.org/grpc/codes",
"google.golang.org/grpc/metadata",
"google.golang.org/grpc/status",
"gopkg.in/yaml.v2",
]
solver-name = "gps-cdcl"
+1 -1
View File
@@ -19,7 +19,7 @@ yum install ispctl
gateHost: 127.0.0.1:0000
instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```
* `gateHost` - адрес любого isp-convert-service в кластере
* `gateHost` - адрес любого isp-config-service в кластере
* `instanceUuid` - UUID - идентификатор экземпляра приложений
## Использование
+4 -4
View File
@@ -1,8 +1,8 @@
package cfg
const (
getAvailableConfigs = "/api/config/module/get_modules_info"
getConfigByModuleName = "/api/config/config/get_config_by_instance_uuid_and_module_name"
createUpdateConfig = "/api/config/config/create_update_config"
getSchemaByModuleId = "/api/config/schema/get_by_module_id"
getAvailableConfigs = "config/module/get_modules_info"
getConfigByModuleName = "config/config/get_config_by_instance_uuid_and_module_name"
createUpdateConfig = "config/config/create_update_config"
getSchemaByModuleId = "config/schema/get_by_module_id"
)
+56 -23
View File
@@ -1,65 +1,98 @@
package cfg
import (
"github.com/integration-system/isp-lib/http"
"github.com/integration-system/isp-lib/backend"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
const (
instanceIdHeader = "x-instance-identity"
scheme = "http://"
callerId = 1
)
func NewConfigClient(client http.RestClient) *configClient {
func NewConfigClient() *configClient {
return &configClient{
client: client,
headers: make(map[string]string),
cli: &backend.InternalGrpcClient{},
headers: make(map[string][]string),
}
}
type configClient struct {
client http.RestClient
headers map[string]string
cli *backend.InternalGrpcClient
headers metadata.MD
gateHost string
address string
instanceUuid string
}
func (c *configClient) ReceiveConfig(gateHost, instanceUuid string) {
func (c *configClient) ReceiveConfig(address, instanceUuid string) error {
var err error
c.cli, err = backend.NewGrpcClient(address, grpc.WithInsecure())
if err != nil {
return err
}
c.address = address
c.instanceUuid = instanceUuid
c.headers[instanceIdHeader] = instanceUuid
c.gateHost = scheme + gateHost
c.headers[instanceIdHeader] = []string{instanceUuid}
return nil
}
func (c *configClient) GetAvailableConfigs() ([]ModuleInfo, error) {
response := make([]ModuleInfo, 0)
if err := c.client.Invoke("POST", c.gateHost+getAvailableConfigs, c.headers, nil, &response); err != nil {
return nil, err
err := c.cli.Invoke(getAvailableConfigs, callerId, nil, &response, backend.WithMetadata(c.headers))
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
}
return response, nil
}
func (c *configClient) GetConfigByModuleName(name string) (*Config, error) {
request := &getModuleByUuidAndNameRequest{Name: name, Uuid: c.instanceUuid}
response := new(Config)
if err := c.client.Invoke("POST", c.gateHost+getConfigByModuleName, c.headers, request, response); err != nil {
return nil, err
err := c.cli.Invoke(getConfigByModuleName, callerId, request, response, backend.WithMetadata(c.headers))
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
}
return response, nil
}
func (c *configClient) CreateUpdateConfig(request Config) (*Config, error) {
response := new(Config)
if err := c.client.Invoke("POST", c.gateHost+createUpdateConfig, c.headers, &request, response); err != nil {
return nil, err
err := c.cli.Invoke(createUpdateConfig, callerId, &request, response, backend.WithMetadata(c.headers))
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
}
return response, nil
}
func (c *configClient) GetSchemaByModuleId(moduleId int32) (*ConfigSchema, error) {
request := &getSchemaByModuleIdRequest{ModuleId: moduleId}
response := new(ConfigSchema)
if err := c.client.Invoke("POST", c.gateHost+getSchemaByModuleId, c.headers, &request, response); err != nil {
return nil, err
err := c.cli.Invoke(getSchemaByModuleId, callerId, &request, response, backend.WithMetadata(c.headers))
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
}
}
func (c *configClient) errorHandler(err error) error {
errStatus, ok := status.FromError(err)
if !ok {
return err
}
switch errStatus.Code() {
case codes.Unavailable:
return errors.Errorf("config service didn't connection on %s", c.address)
default:
return err
}
return response, nil
}
+1 -1
View File
@@ -2,8 +2,8 @@ package command
import (
"encoding/json"
"errors"
"fmt"
"github.com/pkg/errors"
"isp-ctl/cfg"
"isp-ctl/service"
"strings"
+2 -3
View File
@@ -2,9 +2,8 @@ package command
import (
"encoding/json"
"errors"
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
"isp-ctl/bash"
"isp-ctl/flag"
@@ -54,7 +53,7 @@ func (g getCommand) action(ctx *cli.Context) {
func (g getCommand) checkObject(jsonObject []byte, depth string) {
jsonString := gjson.Get(string(jsonObject), depth)
if jsonString.Raw == "" {
printError(errors.New(fmt.Sprintf("Path '%s' not found\n", depth)))
printError(errors.Errorf("Path '%s' not found\n", depth))
} else {
var data interface{}
if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil {
+3 -4
View File
@@ -1,9 +1,8 @@
package command
import (
"errors"
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"html/template"
"isp-ctl/bash"
"isp-ctl/flag"
@@ -45,8 +44,8 @@ func (s schemaCommand) action(ctx *cli.Context) {
case flag.OutPrintHtmlValue:
s.printHtml(schema)
default:
printError(errors.New(fmt.Sprintf(
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)))
printError(errors.Errorf(
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
}
}
}
+1 -1
View File
@@ -2,8 +2,8 @@ package command
import (
"encoding/json"
"errors"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
"io/ioutil"
"isp-ctl/bash"
+1 -2
View File
@@ -58,6 +58,5 @@ func CheckGlobal(c *cli.Context) error {
}
}
}
service.Config.ReceiveConfiguration(host, uuid)
return nil
return service.Config.ReceiveConfiguration(host, uuid)
}
+23 -15
View File
@@ -2,39 +2,47 @@ package service
import (
"encoding/json"
"errors"
"fmt"
"github.com/integration-system/isp-lib/config/schema"
"github.com/integration-system/isp-lib/http"
"github.com/valyala/fasthttp"
"github.com/pkg/errors"
"github.com/xeipuuv/gojsonschema"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"isp-ctl/cfg"
)
var (
configClient = cfg.NewConfigClient(http.NewJsonRestClient())
Config configService
configClient = cfg.NewConfigClient()
Config = &configService{}
)
type configService struct {
UnsafeEnable bool
}
func (configService) ReceiveConfiguration(host, uuid string) {
configClient.ReceiveConfig(host, uuid)
func (c *configService) ReceiveConfiguration(host, uuid string) error {
return configClient.ReceiveConfig(host, uuid)
}
func (configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
return configClient.GetAvailableConfigs()
func (c *configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
if moduleInfo, err := configClient.GetAvailableConfigs(); err != nil {
return nil, err
} else {
return moduleInfo, nil
}
}
func (configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) {
func (c *configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) {
if moduleName == "" {
return nil, nil, errors.New("need module name")
}
if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil {
if errorResponse, ok := err.(http.ErrorResponse); ok && errorResponse.StatusCode == fasthttp.StatusNotFound {
return nil, nil, errors.New(fmt.Sprintf("module '%s' not found", moduleName))
if errorStatus, ok := status.FromError(err); ok {
switch errorStatus.Code() {
case codes.NotFound:
return nil, nil, errors.Errorf("module '%s' not found", moduleName)
}
}
return nil, nil, err
} else if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
@@ -44,7 +52,7 @@ func (configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cf
}
}
func (configService) GetSchemaByModuleId(moduleId int32) (schema.Schema, error) {
func (c *configService) GetSchemaByModuleId(moduleId int32) (schema.Schema, error) {
if configSchema, err := configClient.GetSchemaByModuleId(moduleId); err != nil {
return nil, err
} else {
@@ -53,7 +61,7 @@ func (configService) GetSchemaByModuleId(moduleId int32) (schema.Schema, error)
}
}
func (c configService) CreateUpdateConfig(stringToChange string, configuration *cfg.Config) (map[string]interface{}, error) {
func (c *configService) CreateUpdateConfig(stringToChange string, configuration *cfg.Config) (map[string]interface{}, error) {
newData := make(map[string]interface{})
if stringToChange != "" {
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
@@ -75,7 +83,7 @@ func (c configService) CreateUpdateConfig(stringToChange string, configuration *
}
}
func (c configService) checkSchema(moduleId int32, object map[string]interface{}) (bool, error) {
func (c *configService) checkSchema(moduleId int32, object map[string]interface{}) (bool, error) {
if c.UnsafeEnable {
return true, nil
}