up v2.1.0
This commit is contained in:
1 parent
e840b53978
commit
97d3a38ed8
7 files changed
+110
-25
No files matched your search
@@ -1,3 +1,8 @@
|
||||
### v2.1.0
|
||||
* fix panic type casting in shapshot
|
||||
* create empty default config now
|
||||
* add method `/module/get_by_name` to fetch module object by name
|
||||
|
||||
### v2.0.3
|
||||
* fix data race when applyCommandOnLeader in websocket handler
|
||||
* update dependencies
|
||||
|
||||
+12
-6
@@ -29,17 +29,23 @@ type config struct {
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /config/get_active_config_by_module_name [POST]
|
||||
func (c *config) GetActiveConfigByModuleName(request domain.GetByModuleNameRequest) (*entity.Config, error) {
|
||||
var response *entity.Config
|
||||
var (
|
||||
module *entity.Module
|
||||
config *entity.Config
|
||||
)
|
||||
c.rstore.VisitReadonlyState(func(state state.ReadonlyState) {
|
||||
module := state.Modules().GetByName(request.ModuleName)
|
||||
module = state.Modules().GetByName(request.ModuleName)
|
||||
if module != nil {
|
||||
response = state.Configs().GetActiveByModuleId(module.Id)
|
||||
config = state.Configs().GetActiveByModuleId(module.Id)
|
||||
}
|
||||
})
|
||||
if response == nil {
|
||||
return nil, status.Error(codes.NotFound, utils.ValidationError)
|
||||
if module == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "module with name '%s' not found", request.ModuleName)
|
||||
}
|
||||
return response, nil
|
||||
if config == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "active config for module '%s' not found", request.ModuleName)
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// CreateUpdateConfig godoc
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-config-service/cluster"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/service"
|
||||
"isp-config-service/store"
|
||||
"isp-config-service/store/state"
|
||||
@@ -61,6 +63,28 @@ func (*module) DeleteModules(identities []string) (*domain.DeleteResponse, error
|
||||
return &deleteResponse, err
|
||||
}
|
||||
|
||||
// GetModuleByName godoc
|
||||
// @Summary Метод получения модуля по имени
|
||||
// @Description Модуль
|
||||
// @Tags Модули
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.GetByModuleNameRequest true "название модуля"
|
||||
// @Success 200 {object} entity.Module
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError "модуль с указанным названием не найден"
|
||||
// @Router /module/get_by_name [POST]
|
||||
func (c *module) GetModuleByName(req domain.GetByModuleNameRequest) (*entity.Module, error) {
|
||||
var module *entity.Module
|
||||
c.rstore.VisitReadonlyState(func(readonlyState state.ReadonlyState) {
|
||||
module = readonlyState.Modules().GetByName(req.ModuleName)
|
||||
})
|
||||
if module == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "module with name '%s' not found", req.ModuleName)
|
||||
}
|
||||
return module, nil
|
||||
}
|
||||
|
||||
func NewModule(rstore *store.Store) *module {
|
||||
return &module{
|
||||
rstore: rstore,
|
||||
|
||||
+58
-12
@@ -223,6 +223,21 @@ definitions:
|
||||
version:
|
||||
type: string
|
||||
type: object
|
||||
entity.Module:
|
||||
properties:
|
||||
createdAt:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
lastConnectedAt:
|
||||
type: string
|
||||
lastDisconnectedAt:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
required:
|
||||
- name
|
||||
type: object
|
||||
jsonschema.Definitions:
|
||||
additionalProperties: {}
|
||||
type: object
|
||||
@@ -236,7 +251,7 @@ definitions:
|
||||
type: string
|
||||
additionalItems:
|
||||
description: section 5.9
|
||||
type: integer
|
||||
type: string
|
||||
additionalProperties:
|
||||
description: section 5.18
|
||||
type: string
|
||||
@@ -281,7 +296,7 @@ definitions:
|
||||
type: string
|
||||
items:
|
||||
description: section 5.9
|
||||
type: integer
|
||||
type: string
|
||||
maxItems:
|
||||
description: section 5.10
|
||||
type: integer
|
||||
@@ -296,7 +311,7 @@ definitions:
|
||||
type: integer
|
||||
media:
|
||||
description: RFC draft-wright-json-schema-hyperschema-00, section 4
|
||||
type: integer
|
||||
type: string
|
||||
minItems:
|
||||
description: section 5.11
|
||||
type: integer
|
||||
@@ -314,7 +329,7 @@ definitions:
|
||||
type: integer
|
||||
not:
|
||||
description: section 5.25
|
||||
type: integer
|
||||
type: string
|
||||
oneOf:
|
||||
description: section 5.24
|
||||
items:
|
||||
@@ -354,7 +369,7 @@ definitions:
|
||||
type: string
|
||||
additionalItems:
|
||||
description: section 5.9
|
||||
type: integer
|
||||
type: string
|
||||
additionalProperties:
|
||||
description: section 5.18
|
||||
type: string
|
||||
@@ -400,7 +415,7 @@ definitions:
|
||||
type: string
|
||||
items:
|
||||
description: section 5.9
|
||||
type: integer
|
||||
type: string
|
||||
maxItems:
|
||||
description: section 5.10
|
||||
type: integer
|
||||
@@ -415,7 +430,7 @@ definitions:
|
||||
type: integer
|
||||
media:
|
||||
description: RFC draft-wright-json-schema-hyperschema-00, section 4
|
||||
type: integer
|
||||
type: string
|
||||
minItems:
|
||||
description: section 5.11
|
||||
type: integer
|
||||
@@ -433,7 +448,7 @@ definitions:
|
||||
type: integer
|
||||
not:
|
||||
description: section 5.25
|
||||
type: integer
|
||||
type: string
|
||||
oneOf:
|
||||
description: section 5.24
|
||||
items:
|
||||
@@ -473,7 +488,7 @@ definitions:
|
||||
type: string
|
||||
additionalItems:
|
||||
description: section 5.9
|
||||
type: integer
|
||||
type: string
|
||||
additionalProperties:
|
||||
description: section 5.18
|
||||
type: string
|
||||
@@ -518,7 +533,7 @@ definitions:
|
||||
type: string
|
||||
items:
|
||||
description: section 5.9
|
||||
type: integer
|
||||
type: string
|
||||
maxItems:
|
||||
description: section 5.10
|
||||
type: integer
|
||||
@@ -533,7 +548,7 @@ definitions:
|
||||
type: integer
|
||||
media:
|
||||
description: RFC draft-wright-json-schema-hyperschema-00, section 4
|
||||
type: integer
|
||||
type: string
|
||||
minItems:
|
||||
description: section 5.11
|
||||
type: integer
|
||||
@@ -551,7 +566,7 @@ definitions:
|
||||
type: integer
|
||||
not:
|
||||
description: section 5.25
|
||||
type: integer
|
||||
type: string
|
||||
oneOf:
|
||||
description: section 5.24
|
||||
items:
|
||||
@@ -915,6 +930,37 @@ paths:
|
||||
summary: Метод удаления объектов модулей по идентификаторам
|
||||
tags:
|
||||
- Модули
|
||||
/module/get_by_name:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Модуль
|
||||
parameters:
|
||||
- description: название модуля
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.GetByModuleNameRequest'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/entity.Module'
|
||||
"404":
|
||||
description: модуль с указанным названием не найден
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/structure.GrpcError'
|
||||
summary: Метод получения модуля по имени
|
||||
tags:
|
||||
- Модули
|
||||
/module/get_modules_info:
|
||||
post:
|
||||
consumes:
|
||||
|
||||
+6
-5
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
type Handlers struct {
|
||||
// ===== MODULE =====
|
||||
DeleteModules func(identities []string) (*domain.DeleteResponse, error) `method:"delete_module" group:"module" inner:"true"`
|
||||
GetModulesInfo func() ([]domain.ModuleInfo, error) `method:"get_modules_info" group:"module" inner:"true"`
|
||||
|
||||
DeleteModules func(identities []string) (*domain.DeleteResponse, error) `method:"delete_module" group:"module" inner:"true"`
|
||||
GetModulesInfo func() ([]domain.ModuleInfo, error) `method:"get_modules_info" group:"module" inner:"true"`
|
||||
GetModuleByName func(req domain.GetByModuleNameRequest) (*entity.Module, error) `method:"get_by_name" group:"module" inner:"true"`
|
||||
// ===== CONFIG =====
|
||||
GetActiveConfigByModuleName func(request domain.GetByModuleNameRequest) (*entity.Config, error) `method:"get_active_config_by_module_name" group:"config" inner:"true"`
|
||||
CreateUpdateConfig func(config domain.CreateUpdateConfigRequest) (*domain.ConfigModuleInfo, error) `method:"create_update_config" group:"config" inner:"true"`
|
||||
@@ -34,8 +34,9 @@ type Handlers struct {
|
||||
|
||||
func GetHandlers() *Handlers {
|
||||
return &Handlers{
|
||||
DeleteModules: controller.Module.DeleteModules,
|
||||
GetModulesInfo: controller.Module.GetModulesAggregatedInfo,
|
||||
DeleteModules: controller.Module.DeleteModules,
|
||||
GetModulesInfo: controller.Module.GetModulesAggregatedInfo,
|
||||
GetModuleByName: controller.Module.GetModuleByName,
|
||||
|
||||
GetActiveConfigByModuleName: controller.Config.GetActiveConfigByModuleName,
|
||||
CreateUpdateConfig: controller.Config.CreateUpdateConfig,
|
||||
|
||||
+4
-1
@@ -95,7 +95,10 @@ func (h *SocketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []by
|
||||
h.store.VisitReadonlyState(func(readState state.ReadonlyState) {
|
||||
configs = readState.Configs().GetByModuleIds([]string{module.Id})
|
||||
})
|
||||
if len(configs) == 0 && len(configSchema.DefaultConfig) > 0 {
|
||||
if len(configs) == 0 { //create empty default config
|
||||
if configSchema.DefaultConfig == nil {
|
||||
configSchema.DefaultConfig = make(map[string]interface{})
|
||||
}
|
||||
config := entity.Config{
|
||||
Id: state.GenerateId(),
|
||||
Name: module.Name,
|
||||
|
||||
Reference in new issue
Block a user