Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pig_冷冷
Pig
提交
68c11aaf
Pig
项目概览
pig_冷冷
/
Pig
上一次同步 10 个月
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Pig
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
68c11aaf
编写于
12月 15, 2022
作者:
L
lbw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
⬆
Upgrading dependencies. close #I66E7R up nacos 2.2.0
上级
d79f5ec7
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
767 addition
and
255 deletion
+767
-255
pig-register/pom.xml
pig-register/pom.xml
+7
-1
pig-register/src/main/java/com/alibaba/nacos/console/controller/HealthController.java
...om/alibaba/nacos/console/controller/HealthController.java
+5
-5
pig-register/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java
...alibaba/nacos/console/controller/NamespaceController.java
+27
-60
pig-register/src/main/java/com/alibaba/nacos/console/controller/v2/NamespaceControllerV2.java
...ba/nacos/console/controller/v2/NamespaceControllerV2.java
+148
-0
pig-register/src/main/java/com/alibaba/nacos/console/exception/ConsoleExceptionHandler.java
...baba/nacos/console/exception/ConsoleExceptionHandler.java
+2
-1
pig-register/src/main/java/com/alibaba/nacos/console/exception/NacosApiExceptionHandler.java
...aba/nacos/console/exception/NacosApiExceptionHandler.java
+134
-0
pig-register/src/main/java/com/alibaba/nacos/console/model/form/NamespaceForm.java
...a/com/alibaba/nacos/console/model/form/NamespaceForm.java
+115
-0
pig-register/src/main/java/com/alibaba/nacos/console/service/NamespaceOperationService.java
...baba/nacos/console/service/NamespaceOperationService.java
+148
-0
pig-register/src/main/resources/application.yml
pig-register/src/main/resources/application.yml
+1
-0
pig-register/src/main/resources/nacos-version.txt
pig-register/src/main/resources/nacos-version.txt
+1
-1
pig-register/src/main/resources/static/css/main.css
pig-register/src/main/resources/static/css/main.css
+31
-40
pig-register/src/main/resources/static/index.html
pig-register/src/main/resources/static/index.html
+2
-2
pig-register/src/main/resources/static/js/main.js
pig-register/src/main/resources/static/js/main.js
+146
-145
未找到文件。
pig-register/pom.xml
浏览文件 @
68c11aaf
...
...
@@ -27,7 +27,7 @@
<description>
nacos 注册配置中心
</description>
<properties>
<nacos.version>
2.
1.1
</nacos.version>
<nacos.version>
2.
2.0.PIGOEM
</nacos.version>
</properties>
<dependencies>
...
...
@@ -59,6 +59,12 @@
<version>
${nacos.version}
</version>
</dependency>
<dependency>
<groupId>
io.springboot.nacos
</groupId>
<artifactId>
nacos-prometheus
</artifactId>
<version>
${nacos.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-security
</artifactId>
...
...
pig-register/src/main/java/com/alibaba/nacos/console/controller/HealthController.java
浏览文件 @
68c11aaf
...
...
@@ -16,7 +16,7 @@
package
com.alibaba.nacos.console.controller
;
import
com.alibaba.nacos.config.server.service.repository.PersistService
;
import
com.alibaba.nacos.config.server.service.repository.
ConfigInfo
PersistService
;
import
com.alibaba.nacos.naming.controllers.OperatorController
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -40,13 +40,13 @@ public class HealthController {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
HealthController
.
class
);
private
final
PersistService
p
ersistService
;
private
final
ConfigInfoPersistService
configInfoP
ersistService
;
private
final
OperatorController
apiCommands
;
@Autowired
public
HealthController
(
PersistService
p
ersistService
,
OperatorController
apiCommands
)
{
this
.
persistService
=
p
ersistService
;
public
HealthController
(
ConfigInfoPersistService
configInfoP
ersistService
,
OperatorController
apiCommands
)
{
this
.
configInfoPersistService
=
configInfoP
ersistService
;
this
.
apiCommands
=
apiCommands
;
}
...
...
@@ -90,7 +90,7 @@ public class HealthController {
private
boolean
isConfigReadiness
()
{
// check db
try
{
p
ersistService
.
configInfoCount
(
""
);
configInfoP
ersistService
.
configInfoCount
(
""
);
return
true
;
}
catch
(
Exception
e
)
{
...
...
pig-register/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java
浏览文件 @
68c11aaf
...
...
@@ -16,21 +16,26 @@
package
com.alibaba.nacos.console.controller
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
com.alibaba.nacos.auth.annotation.Secured
;
import
com.alibaba.nacos.common.model.RestResult
;
import
com.alibaba.nacos.common.model.RestResultUtils
;
import
com.alibaba.nacos.common.utils.StringUtils
;
import
com.alibaba.nacos.config.server.model.TenantInfo
;
import
com.alibaba.nacos.config.server.service.repository.PersistService
;
import
com.alibaba.nacos.console.enums.NamespaceTypeEnum
;
import
com.alibaba.nacos.config.server.service.repository.CommonPersistService
;
import
com.alibaba.nacos.console.model.Namespace
;
import
com.alibaba.nacos.console.model.NamespaceAllInfo
;
import
com.alibaba.nacos.console.service.NamespaceOperationService
;
import
com.alibaba.nacos.plugin.auth.constant.ActionTypes
;
import
com.alibaba.nacos.plugin.auth.impl.constant.AuthConstants
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.regex.Pattern
;
...
...
@@ -45,45 +50,22 @@ import java.util.regex.Pattern;
public
class
NamespaceController
{
@Autowired
private
PersistService
persistService
;
private
CommonPersistService
commonPersistService
;
@Autowired
private
NamespaceOperationService
namespaceOperationService
;
private
final
Pattern
namespaceIdCheckPattern
=
Pattern
.
compile
(
"^[\\w-]+"
);
private
static
final
int
NAMESPACE_ID_MAX_LENGTH
=
128
;
private
static
final
String
DEFAULT_NAMESPACE
=
"public"
;
private
static
final
int
DEFAULT_QUOTA
=
200
;
private
static
final
String
DEFAULT_CREATE_SOURCE
=
"nacos"
;
private
static
final
String
DEFAULT_NAMESPACE_SHOW_NAME
=
"Public"
;
private
static
final
String
DEFAULT_NAMESPACE_DESCRIPTION
=
"Public Namespace"
;
private
static
final
String
DEFAULT_TENANT
=
""
;
private
static
final
String
DEFAULT_KP
=
"1"
;
/**
* Get namespace list.
* @return namespace list
*/
@GetMapping
public
RestResult
<
List
<
Namespace
>>
getNamespaces
()
{
// TODO 获取用kp
List
<
TenantInfo
>
tenantInfos
=
persistService
.
findTenantByKp
(
DEFAULT_KP
);
Namespace
namespace0
=
new
Namespace
(
""
,
DEFAULT_NAMESPACE
,
DEFAULT_QUOTA
,
persistService
.
configInfoCount
(
DEFAULT_TENANT
),
NamespaceTypeEnum
.
GLOBAL
.
getType
());
List
<
Namespace
>
namespaces
=
new
ArrayList
<>();
namespaces
.
add
(
namespace0
);
for
(
TenantInfo
tenantInfo
:
tenantInfos
)
{
int
configCount
=
persistService
.
configInfoCount
(
tenantInfo
.
getTenantId
());
Namespace
namespaceTmp
=
new
Namespace
(
tenantInfo
.
getTenantId
(),
tenantInfo
.
getTenantName
(),
tenantInfo
.
getTenantDesc
(),
DEFAULT_QUOTA
,
configCount
,
NamespaceTypeEnum
.
CUSTOM
.
getType
());
namespaces
.
add
(
namespaceTmp
);
}
return
RestResultUtils
.
success
(
namespaces
);
return
RestResultUtils
.
success
(
namespaceOperationService
.
getNamespaceList
());
}
/**
...
...
@@ -92,19 +74,8 @@ public class NamespaceController {
* @return namespace all info
*/
@GetMapping
(
params
=
"show=all"
)
public
NamespaceAllInfo
getNamespace
(
@RequestParam
(
"namespaceId"
)
String
namespaceId
)
{
// TODO 获取用kp
if
(
StringUtils
.
isBlank
(
namespaceId
))
{
return
new
NamespaceAllInfo
(
namespaceId
,
DEFAULT_NAMESPACE_SHOW_NAME
,
DEFAULT_QUOTA
,
persistService
.
configInfoCount
(
DEFAULT_TENANT
),
NamespaceTypeEnum
.
GLOBAL
.
getType
(),
DEFAULT_NAMESPACE_DESCRIPTION
);
}
else
{
TenantInfo
tenantInfo
=
persistService
.
findTenantByKp
(
DEFAULT_KP
,
namespaceId
);
int
configCount
=
persistService
.
configInfoCount
(
namespaceId
);
return
new
NamespaceAllInfo
(
namespaceId
,
tenantInfo
.
getTenantName
(),
DEFAULT_QUOTA
,
configCount
,
NamespaceTypeEnum
.
CUSTOM
.
getType
(),
tenantInfo
.
getTenantDesc
());
}
public
NamespaceAllInfo
getNamespace
(
@RequestParam
(
"namespaceId"
)
String
namespaceId
)
throws
NacosException
{
return
namespaceOperationService
.
getNamespace
(
namespaceId
);
}
/**
...
...
@@ -118,7 +89,6 @@ public class NamespaceController {
public
Boolean
createNamespace
(
@RequestParam
(
"customNamespaceId"
)
String
namespaceId
,
@RequestParam
(
"namespaceName"
)
String
namespaceName
,
@RequestParam
(
value
=
"namespaceDesc"
,
required
=
false
)
String
namespaceDesc
)
{
// TODO 获取用kp
if
(
StringUtils
.
isBlank
(
namespaceId
))
{
namespaceId
=
UUID
.
randomUUID
().
toString
();
}
...
...
@@ -130,13 +100,13 @@ public class NamespaceController {
if
(
namespaceId
.
length
()
>
NAMESPACE_ID_MAX_LENGTH
)
{
return
false
;
}
if
(
persistService
.
tenantInfoCountByTenantId
(
namespaceId
)
>
0
)
{
return
false
;
}
}
persistService
.
insertTenantInfoAtomic
(
DEFAULT_KP
,
namespaceId
,
namespaceName
,
namespaceDesc
,
DEFAULT_CREATE_SOURCE
,
System
.
currentTimeMillis
());
return
true
;
try
{
return
namespaceOperationService
.
createNamespace
(
namespaceId
,
namespaceName
,
namespaceDesc
);
}
catch
(
NacosException
e
)
{
return
false
;
}
}
/**
...
...
@@ -149,7 +119,7 @@ public class NamespaceController {
if
(
StringUtils
.
isBlank
(
namespaceId
))
{
return
false
;
}
return
(
p
ersistService
.
tenantInfoCountByTenantId
(
namespaceId
)
>
0
);
return
(
commonP
ersistService
.
tenantInfoCountByTenantId
(
namespaceId
)
>
0
);
}
/**
...
...
@@ -164,9 +134,7 @@ public class NamespaceController {
public
Boolean
editNamespace
(
@RequestParam
(
"namespace"
)
String
namespace
,
@RequestParam
(
"namespaceShowName"
)
String
namespaceShowName
,
@RequestParam
(
value
=
"namespaceDesc"
,
required
=
false
)
String
namespaceDesc
)
{
// TODO 获取用kp
persistService
.
updateTenantNameAtomic
(
DEFAULT_KP
,
namespace
,
namespaceShowName
,
namespaceDesc
);
return
true
;
return
namespaceOperationService
.
editNamespace
(
namespace
,
namespaceShowName
,
namespaceDesc
);
}
/**
...
...
@@ -176,9 +144,8 @@ public class NamespaceController {
*/
@DeleteMapping
@Secured
(
resource
=
AuthConstants
.
CONSOLE_RESOURCE_NAME_PREFIX
+
"namespaces"
,
action
=
ActionTypes
.
WRITE
)
public
Boolean
deleteConfig
(
@RequestParam
(
"namespaceId"
)
String
namespaceId
)
{
persistService
.
removeTenantInfoAtomic
(
DEFAULT_KP
,
namespaceId
);
return
true
;
public
Boolean
deleteNamespace
(
@RequestParam
(
"namespaceId"
)
String
namespaceId
)
{
return
namespaceOperationService
.
removeNamespace
(
namespaceId
);
}
}
pig-register/src/main/java/com/alibaba/nacos/console/controller/v2/NamespaceControllerV2.java
0 → 100644
浏览文件 @
68c11aaf
/*
* Copyright 1999-2022 Alibaba Group Holding 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
com.alibaba.nacos.console.controller.v2
;
import
com.alibaba.nacos.api.annotation.NacosApi
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
com.alibaba.nacos.api.exception.api.NacosApiException
;
import
com.alibaba.nacos.api.model.v2.ErrorCode
;
import
com.alibaba.nacos.api.model.v2.Result
;
import
com.alibaba.nacos.auth.annotation.Secured
;
import
com.alibaba.nacos.common.utils.StringUtils
;
import
com.alibaba.nacos.console.model.Namespace
;
import
com.alibaba.nacos.console.model.NamespaceAllInfo
;
import
com.alibaba.nacos.console.model.form.NamespaceForm
;
import
com.alibaba.nacos.console.service.NamespaceOperationService
;
import
com.alibaba.nacos.plugin.auth.constant.ActionTypes
;
import
com.alibaba.nacos.plugin.auth.constant.SignType
;
import
com.alibaba.nacos.plugin.auth.impl.constant.AuthConstants
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.regex.Pattern
;
/**
* NamespaceControllerV2.
*
* @author dongyafei
* @date 2022/8/16
*/
@NacosApi
@RestController
@RequestMapping
(
path
=
"/v2/console/namespace"
)
public
class
NamespaceControllerV2
{
private
final
NamespaceOperationService
namespaceOperationService
;
public
NamespaceControllerV2
(
NamespaceOperationService
namespaceOperationService
)
{
this
.
namespaceOperationService
=
namespaceOperationService
;
}
private
final
Pattern
namespaceIdCheckPattern
=
Pattern
.
compile
(
"^[\\w-]+"
);
private
static
final
int
NAMESPACE_ID_MAX_LENGTH
=
128
;
/**
* Get namespace list.
* @return namespace list
*/
@GetMapping
(
"/list"
)
public
Result
<
List
<
Namespace
>>
getNamespaceList
()
{
return
Result
.
success
(
namespaceOperationService
.
getNamespaceList
());
}
/**
* get namespace all info by namespace id.
* @param namespaceId namespaceId
* @return namespace all info
*/
@GetMapping
()
@Secured
(
resource
=
AuthConstants
.
CONSOLE_RESOURCE_NAME_PREFIX
+
"namespaces"
,
action
=
ActionTypes
.
READ
,
signType
=
SignType
.
CONSOLE
)
public
Result
<
NamespaceAllInfo
>
getNamespace
(
@RequestParam
(
"namespaceId"
)
String
namespaceId
)
throws
NacosException
{
return
Result
.
success
(
namespaceOperationService
.
getNamespace
(
namespaceId
));
}
/**
* create namespace.
* @param namespaceForm namespaceForm.
* @return whether create ok
*/
@PostMapping
@Secured
(
resource
=
AuthConstants
.
CONSOLE_RESOURCE_NAME_PREFIX
+
"namespaces"
,
action
=
ActionTypes
.
WRITE
,
signType
=
SignType
.
CONSOLE
)
public
Result
<
Boolean
>
createNamespace
(
NamespaceForm
namespaceForm
)
throws
NacosException
{
namespaceForm
.
validate
();
String
namespaceId
=
namespaceForm
.
getNamespaceId
();
String
namespaceName
=
namespaceForm
.
getNamespaceName
();
String
namespaceDesc
=
namespaceForm
.
getNamespaceDesc
();
if
(
StringUtils
.
isBlank
(
namespaceId
))
{
namespaceId
=
UUID
.
randomUUID
().
toString
();
}
else
{
namespaceId
=
namespaceId
.
trim
();
if
(!
namespaceIdCheckPattern
.
matcher
(
namespaceId
).
matches
())
{
throw
new
NacosApiException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
ErrorCode
.
ILLEGAL_NAMESPACE
,
"namespaceId ["
+
namespaceId
+
"] mismatch the pattern"
);
}
if
(
namespaceId
.
length
()
>
NAMESPACE_ID_MAX_LENGTH
)
{
throw
new
NacosApiException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
ErrorCode
.
ILLEGAL_NAMESPACE
,
"too long namespaceId, over "
+
NAMESPACE_ID_MAX_LENGTH
);
}
}
return
Result
.
success
(
namespaceOperationService
.
createNamespace
(
namespaceId
,
namespaceName
,
namespaceDesc
));
}
/**
* edit namespace.
* @param namespaceForm namespace params
* @return whether edit ok
*/
@PutMapping
@Secured
(
resource
=
AuthConstants
.
CONSOLE_RESOURCE_NAME_PREFIX
+
"namespaces"
,
action
=
ActionTypes
.
WRITE
,
signType
=
SignType
.
CONSOLE
)
public
Result
<
Boolean
>
editNamespace
(
NamespaceForm
namespaceForm
)
throws
NacosException
{
namespaceForm
.
validate
();
return
Result
.
success
(
namespaceOperationService
.
editNamespace
(
namespaceForm
.
getNamespaceId
(),
namespaceForm
.
getNamespaceName
(),
namespaceForm
.
getNamespaceDesc
()));
}
/**
* delete namespace by id.
* @param namespaceId namespace ID
* @return whether delete ok
*/
@DeleteMapping
@Secured
(
resource
=
AuthConstants
.
CONSOLE_RESOURCE_NAME_PREFIX
+
"namespaces"
,
action
=
ActionTypes
.
WRITE
,
signType
=
SignType
.
CONSOLE
)
public
Result
<
Boolean
>
deleteNamespace
(
@RequestParam
(
"namespaceId"
)
String
namespaceId
)
{
return
Result
.
success
(
namespaceOperationService
.
removeNamespace
(
namespaceId
));
}
}
pig-register/src/main/java/com/alibaba/nacos/console/exception/ConsoleExceptionHandler.java
浏览文件 @
68c11aaf
...
...
@@ -16,10 +16,10 @@
package
com.alibaba.nacos.console.exception
;
import
com.alibaba.nacos.plugin.auth.exception.AccessException
;
import
com.alibaba.nacos.common.model.RestResultUtils
;
import
com.alibaba.nacos.common.utils.ExceptionUtil
;
import
com.alibaba.nacos.core.utils.Commons
;
import
com.alibaba.nacos.plugin.auth.exception.AccessException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -42,6 +42,7 @@ public class ConsoleExceptionHandler {
@ExceptionHandler
(
AccessException
.
class
)
private
ResponseEntity
<
String
>
handleAccessException
(
AccessException
e
)
{
LOGGER
.
error
(
"got exception. {}"
,
e
.
getErrMsg
());
return
ResponseEntity
.
status
(
HttpStatus
.
FORBIDDEN
).
body
(
e
.
getErrMsg
());
}
...
...
pig-register/src/main/java/com/alibaba/nacos/console/exception/NacosApiExceptionHandler.java
0 → 100644
浏览文件 @
68c11aaf
/*
* Copyright 1999-2022 Alibaba Group Holding 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
com.alibaba.nacos.console.exception
;
import
com.alibaba.nacos.api.annotation.NacosApi
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
com.alibaba.nacos.api.exception.api.NacosApiException
;
import
com.alibaba.nacos.api.model.v2.ErrorCode
;
import
com.alibaba.nacos.api.model.v2.Result
;
import
com.alibaba.nacos.common.utils.ExceptionUtil
;
import
com.alibaba.nacos.plugin.auth.exception.AccessException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageConversionException
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.web.HttpMediaTypeException
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
javax.servlet.ServletException
;
import
java.io.IOException
;
/**
* Exception Handler for Nacos API.
*
* @author dongyafei
* @date 2022/7/22
*/
@Order
(-
1
)
@ControllerAdvice
(
annotations
=
{
NacosApi
.
class
})
@ResponseBody
public
class
NacosApiExceptionHandler
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
NacosApiExceptionHandler
.
class
);
@ExceptionHandler
(
NacosApiException
.
class
)
public
ResponseEntity
<
Result
<
String
>>
handleNacosApiException
(
NacosApiException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getErrAbstract
(),
e
.
getErrMsg
());
return
ResponseEntity
.
status
(
e
.
getErrCode
())
.
body
(
new
Result
<>(
e
.
getDetailErrCode
(),
e
.
getErrAbstract
(),
e
.
getErrMsg
()));
}
@ExceptionHandler
(
NacosException
.
class
)
public
ResponseEntity
<
Result
<
String
>>
handleNacosException
(
NacosException
e
)
{
LOGGER
.
error
(
"got exception. {}"
,
e
.
getErrMsg
());
return
ResponseEntity
.
status
(
e
.
getErrCode
()).
body
(
Result
.
failure
(
ErrorCode
.
SERVER_ERROR
,
e
.
getErrMsg
()));
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
HttpMessageNotReadableException
.
class
)
public
Result
<
String
>
handleHttpMessageNotReadableException
(
HttpMessageNotReadableException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
PARAMETER_MISSING
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
HttpMessageConversionException
.
class
)
public
Result
<
String
>
handleHttpMessageConversionException
(
HttpMessageConversionException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
PARAMETER_VALIDATE_ERROR
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
NumberFormatException
.
class
)
public
Result
<
String
>
handleNumberFormatException
(
NumberFormatException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
PARAMETER_VALIDATE_ERROR
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
IllegalArgumentException
.
class
)
public
Result
<
String
>
handleIllegalArgumentException
(
IllegalArgumentException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
PARAMETER_VALIDATE_ERROR
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
MissingServletRequestParameterException
.
class
)
public
Result
<
String
>
handleMissingServletRequestParameterException
(
MissingServletRequestParameterException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
PARAMETER_MISSING
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
@ExceptionHandler
(
HttpMediaTypeException
.
class
)
public
Result
<
String
>
handleHttpMediaTypeException
(
HttpMediaTypeException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
MEDIA_TYPE_ERROR
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
FORBIDDEN
)
@ExceptionHandler
(
AccessException
.
class
)
public
Result
<
String
>
handleAccessException
(
AccessException
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
ACCESS_DENIED
,
e
.
getErrMsg
());
}
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
value
=
{
DataAccessException
.
class
,
ServletException
.
class
,
IOException
.
class
})
public
Result
<
String
>
handleDataAccessException
(
Exception
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
ErrorCode
.
DATA_ACCESS_ERROR
,
e
.
getMessage
());
}
@ResponseStatus
(
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
Exception
.
class
)
public
Result
<
String
>
handleOtherException
(
Exception
e
)
{
LOGGER
.
error
(
"got exception. {} {}"
,
e
.
getMessage
(),
ExceptionUtil
.
getAllExceptionMsg
(
e
));
return
Result
.
failure
(
e
.
getMessage
());
}
}
pig-register/src/main/java/com/alibaba/nacos/console/model/form/NamespaceForm.java
0 → 100644
浏览文件 @
68c11aaf
/*
* Copyright 1999-2022 Alibaba Group Holding 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
com.alibaba.nacos.console.model.form
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
com.alibaba.nacos.api.exception.api.NacosApiException
;
import
com.alibaba.nacos.api.model.v2.ErrorCode
;
import
org.springframework.http.HttpStatus
;
import
java.io.Serializable
;
import
java.util.Objects
;
/**
* NamespaceForm.
*
* @author dongyafei
* @date 2022/8/16
*/
public
class
NamespaceForm
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1078976569495343487L
;
private
String
namespaceId
;
private
String
namespaceName
;
private
String
namespaceDesc
;
public
NamespaceForm
()
{
}
public
NamespaceForm
(
String
namespaceId
,
String
namespaceName
,
String
namespaceDesc
)
{
this
.
namespaceId
=
namespaceId
;
this
.
namespaceName
=
namespaceName
;
this
.
namespaceDesc
=
namespaceDesc
;
}
public
String
getNamespaceId
()
{
return
namespaceId
;
}
public
void
setNamespaceId
(
String
namespaceId
)
{
this
.
namespaceId
=
namespaceId
;
}
public
String
getNamespaceName
()
{
return
namespaceName
;
}
public
void
setNamespaceName
(
String
namespaceName
)
{
this
.
namespaceName
=
namespaceName
;
}
public
String
getNamespaceDesc
()
{
return
namespaceDesc
;
}
public
void
setNamespaceDesc
(
String
namespaceDesc
)
{
this
.
namespaceDesc
=
namespaceDesc
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
NamespaceForm
that
=
(
NamespaceForm
)
o
;
return
Objects
.
equals
(
namespaceId
,
that
.
namespaceId
)
&&
Objects
.
equals
(
namespaceName
,
that
.
namespaceName
)
&&
Objects
.
equals
(
namespaceDesc
,
that
.
namespaceDesc
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
namespaceId
,
namespaceName
,
namespaceDesc
);
}
@Override
public
String
toString
()
{
return
"NamespaceVo{"
+
"namespaceId='"
+
namespaceId
+
'\''
+
", namespaceName='"
+
namespaceName
+
'\''
+
", namespaceDesc='"
+
namespaceDesc
+
'\''
+
'}'
;
}
/**
* check required param.
* @throws NacosException NacosException
*/
public
void
validate
()
throws
NacosException
{
if
(
null
==
namespaceId
)
{
throw
new
NacosApiException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
ErrorCode
.
PARAMETER_MISSING
,
"required parameter 'namespaceId' is missing"
);
}
if
(
null
==
namespaceName
)
{
throw
new
NacosApiException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
ErrorCode
.
PARAMETER_MISSING
,
"required parameter 'namespaceName' is missing"
);
}
}
}
pig-register/src/main/java/com/alibaba/nacos/console/service/NamespaceOperationService.java
0 → 100644
浏览文件 @
68c11aaf
/*
* Copyright 1999-2022 Alibaba Group Holding 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
com.alibaba.nacos.console.service
;
import
com.alibaba.nacos.api.exception.NacosException
;
import
com.alibaba.nacos.api.exception.api.NacosApiException
;
import
com.alibaba.nacos.api.model.v2.ErrorCode
;
import
com.alibaba.nacos.common.utils.StringUtils
;
import
com.alibaba.nacos.config.server.model.TenantInfo
;
import
com.alibaba.nacos.config.server.service.repository.CommonPersistService
;
import
com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService
;
import
com.alibaba.nacos.console.enums.NamespaceTypeEnum
;
import
com.alibaba.nacos.console.model.Namespace
;
import
com.alibaba.nacos.console.model.NamespaceAllInfo
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* NamespaceOperationService.
*
* @author dongyafei
* @date 2022/8/16
*/
@Service
public
class
NamespaceOperationService
{
private
final
ConfigInfoPersistService
configInfoPersistService
;
private
final
CommonPersistService
commonPersistService
;
private
static
final
String
DEFAULT_NAMESPACE
=
"public"
;
private
static
final
String
DEFAULT_NAMESPACE_SHOW_NAME
=
"Public"
;
private
static
final
String
DEFAULT_NAMESPACE_DESCRIPTION
=
"Public Namespace"
;
private
static
final
int
DEFAULT_QUOTA
=
200
;
private
static
final
String
DEFAULT_CREATE_SOURCE
=
"nacos"
;
private
static
final
String
DEFAULT_TENANT
=
""
;
private
static
final
String
DEFAULT_KP
=
"1"
;
public
NamespaceOperationService
(
ConfigInfoPersistService
configInfoPersistService
,
CommonPersistService
commonPersistService
)
{
this
.
configInfoPersistService
=
configInfoPersistService
;
this
.
commonPersistService
=
commonPersistService
;
}
public
List
<
Namespace
>
getNamespaceList
()
{
// TODO 获取用kp
List
<
TenantInfo
>
tenantInfos
=
commonPersistService
.
findTenantByKp
(
DEFAULT_KP
);
Namespace
namespace0
=
new
Namespace
(
""
,
DEFAULT_NAMESPACE
,
DEFAULT_QUOTA
,
configInfoPersistService
.
configInfoCount
(
DEFAULT_TENANT
),
NamespaceTypeEnum
.
GLOBAL
.
getType
());
List
<
Namespace
>
namespaceList
=
new
ArrayList
<>();
namespaceList
.
add
(
namespace0
);
for
(
TenantInfo
tenantInfo
:
tenantInfos
)
{
int
configCount
=
configInfoPersistService
.
configInfoCount
(
tenantInfo
.
getTenantId
());
Namespace
namespaceTmp
=
new
Namespace
(
tenantInfo
.
getTenantId
(),
tenantInfo
.
getTenantName
(),
tenantInfo
.
getTenantDesc
(),
DEFAULT_QUOTA
,
configCount
,
NamespaceTypeEnum
.
CUSTOM
.
getType
());
namespaceList
.
add
(
namespaceTmp
);
}
return
namespaceList
;
}
/**
* query namespace by namespace id.
* @param namespaceId namespace Id.
* @return NamespaceAllInfo.
*/
public
NamespaceAllInfo
getNamespace
(
String
namespaceId
)
throws
NacosException
{
// TODO 获取用kp
if
(
StringUtils
.
isBlank
(
namespaceId
))
{
return
new
NamespaceAllInfo
(
namespaceId
,
DEFAULT_NAMESPACE_SHOW_NAME
,
DEFAULT_QUOTA
,
configInfoPersistService
.
configInfoCount
(
DEFAULT_TENANT
),
NamespaceTypeEnum
.
GLOBAL
.
getType
(),
DEFAULT_NAMESPACE_DESCRIPTION
);
}
else
{
TenantInfo
tenantInfo
=
commonPersistService
.
findTenantByKp
(
DEFAULT_KP
,
namespaceId
);
if
(
null
==
tenantInfo
)
{
throw
new
NacosApiException
(
HttpStatus
.
NOT_FOUND
.
value
(),
ErrorCode
.
NAMESPACE_NOT_EXIST
,
"namespaceId [ "
+
namespaceId
+
" ] not exist"
);
}
int
configCount
=
configInfoPersistService
.
configInfoCount
(
namespaceId
);
return
new
NamespaceAllInfo
(
namespaceId
,
tenantInfo
.
getTenantName
(),
DEFAULT_QUOTA
,
configCount
,
NamespaceTypeEnum
.
CUSTOM
.
getType
(),
tenantInfo
.
getTenantDesc
());
}
}
/**
* create namespace.
* @param namespaceId namespace ID
* @param namespaceName namespace Name
* @param namespaceDesc namespace Desc
* @return whether create ok
*/
public
Boolean
createNamespace
(
String
namespaceId
,
String
namespaceName
,
String
namespaceDesc
)
throws
NacosException
{
// TODO 获取用kp
if
(
commonPersistService
.
tenantInfoCountByTenantId
(
namespaceId
)
>
0
)
{
throw
new
NacosApiException
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
(),
ErrorCode
.
NAMESPACE_ALREADY_EXIST
,
"namespaceId ["
+
namespaceId
+
"] already exist"
);
}
commonPersistService
.
insertTenantInfoAtomic
(
DEFAULT_KP
,
namespaceId
,
namespaceName
,
namespaceDesc
,
DEFAULT_CREATE_SOURCE
,
System
.
currentTimeMillis
());
return
true
;
}
/**
* edit namespace.
*/
public
Boolean
editNamespace
(
String
namespaceId
,
String
namespaceName
,
String
namespaceDesc
)
{
// TODO 获取用kp
commonPersistService
.
updateTenantNameAtomic
(
DEFAULT_KP
,
namespaceId
,
namespaceName
,
namespaceDesc
);
return
true
;
}
/**
* remove namespace.
*/
public
Boolean
removeNamespace
(
String
namespaceId
)
{
commonPersistService
.
removeTenantInfoAtomic
(
DEFAULT_KP
,
namespaceId
);
return
true
;
}
}
pig-register/src/main/resources/application.yml
浏览文件 @
68c11aaf
...
...
@@ -10,6 +10,7 @@ db:
url
:
0
:
jdbc:mysql://${MYSQL_HOST:pig-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pig_config}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
nacos
:
core
:
auth
:
...
...
pig-register/src/main/resources/nacos-version.txt
浏览文件 @
68c11aaf
version=2.
1.1
version=2.
2.0
pig-register/src/main/resources/static/css/main.css
浏览文件 @
68c11aaf
此差异已折叠。
点击以展开。
pig-register/src/main/resources/static/index.html
浏览文件 @
68c11aaf
...
...
@@ -35,7 +35,7 @@
<link
rel=
"stylesheet"
type=
"text/css"
href=
"console-ui/public/css/icon.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"console-ui/public/css/font-awesome.css"
>
<!-- 第三方css结束 -->
<link
href=
"./css/main.css?
1cbbea1b0db3eec7912c
"
rel=
"stylesheet"
></head>
<link
href=
"./css/main.css?
c18229e4d79449526734
"
rel=
"stylesheet"
></head>
<body>
<div
id=
"root"
style=
"overflow:hidden"
></div>
...
...
@@ -56,6 +56,6 @@
<script
src=
"console-ui/public/js/merge.js"
></script>
<script
src=
"console-ui/public/js/loader.js"
></script>
<!-- 第三方js结束 -->
<script
type=
"text/javascript"
src=
"./js/main.js?
1cbbea1b0db3eec7912c
"
></script></body>
<script
type=
"text/javascript"
src=
"./js/main.js?
c18229e4d79449526734
"
></script></body>
</html>
pig-register/src/main/resources/static/js/main.js
浏览文件 @
68c11aaf
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录