Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
0d541123
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0d541123
编写于
11月 24, 2018
作者:
J
Jason Song
提交者:
GitHub
11月 24, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1704 from nobodyiam/open-api-enhancement
Enhance open api capabilities
上级
5d67ce64
aee5f9b4
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
95 addition
and
1 deletion
+95
-1
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java
.../framework/apollo/openapi/client/ApolloOpenApiClient.java
+11
-0
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/exception/ApolloOpenApiException.java
...ollo/openapi/client/exception/ApolloOpenApiException.java
+7
-0
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/ItemOpenApiService.java
...ork/apollo/openapi/client/service/ItemOpenApiService.java
+29
-0
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenAppNamespaceDTO.java
...rip/framework/apollo/openapi/dto/OpenAppNamespaceDTO.java
+11
-0
apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/service/ItemOpenApiServiceTest.java
...apollo/openapi/client/service/ItemOpenApiServiceTest.java
+28
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java
...ramework/apollo/openapi/v1/controller/ItemController.java
+8
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java
...ork/apollo/openapi/v1/controller/NamespaceController.java
+1
-1
未找到文件。
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java
浏览文件 @
0d541123
...
...
@@ -86,6 +86,17 @@ public class ApolloOpenApiClient {
return
namespaceService
.
getNamespaceLock
(
appId
,
env
,
clusterName
,
namespaceName
);
}
/**
* Get config
*
* @return the item or null if not exists
*
* @since 1.2.0
*/
public
OpenItemDTO
getItem
(
String
appId
,
String
env
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
return
itemService
.
getItem
(
appId
,
env
,
clusterName
,
namespaceName
,
key
);
}
/**
* Add config
* @return the created config
...
...
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/exception/ApolloOpenApiException.java
浏览文件 @
0d541123
...
...
@@ -2,8 +2,15 @@ package com.ctrip.framework.apollo.openapi.client.exception;
public
class
ApolloOpenApiException
extends
RuntimeException
{
private
int
status
;
public
ApolloOpenApiException
(
int
status
,
String
reason
,
String
message
)
{
super
(
String
.
format
(
"Request to apollo open api failed, status code: %d, reason: %s, message: %s"
,
status
,
reason
,
message
));
this
.
status
=
status
;
}
public
int
getStatus
()
{
return
status
;
}
}
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/ItemOpenApiService.java
浏览文件 @
0d541123
package
com.ctrip.framework.apollo.openapi.client.service
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.openapi.client.exception.ApolloOpenApiException
;
import
com.ctrip.framework.apollo.openapi.dto.OpenItemDTO
;
import
com.google.common.base.Strings
;
import
com.google.gson.Gson
;
...
...
@@ -14,6 +15,34 @@ public class ItemOpenApiService extends AbstractOpenApiService {
super
(
client
,
baseUrl
,
gson
);
}
public
OpenItemDTO
getItem
(
String
appId
,
String
env
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
if
(
Strings
.
isNullOrEmpty
(
clusterName
))
{
clusterName
=
ConfigConsts
.
CLUSTER_NAME_DEFAULT
;
}
if
(
Strings
.
isNullOrEmpty
(
namespaceName
))
{
namespaceName
=
ConfigConsts
.
NAMESPACE_APPLICATION
;
}
checkNotEmpty
(
appId
,
"App id"
);
checkNotEmpty
(
env
,
"Env"
);
checkNotEmpty
(
key
,
"Item key"
);
String
path
=
String
.
format
(
"envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s"
,
escapePath
(
env
),
escapePath
(
appId
),
escapePath
(
clusterName
),
escapePath
(
namespaceName
),
escapePath
(
key
));
try
(
CloseableHttpResponse
response
=
get
(
path
))
{
return
gson
.
fromJson
(
EntityUtils
.
toString
(
response
.
getEntity
()),
OpenItemDTO
.
class
);
}
catch
(
Throwable
ex
)
{
// return null if item doesn't exist
if
(
ex
instanceof
ApolloOpenApiException
&&
((
ApolloOpenApiException
)
ex
).
getStatus
()
==
404
)
{
return
null
;
}
throw
new
RuntimeException
(
String
.
format
(
"Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed"
,
key
,
appId
,
clusterName
,
namespaceName
,
env
),
ex
);
}
}
public
OpenItemDTO
createItem
(
String
appId
,
String
env
,
String
clusterName
,
String
namespaceName
,
OpenItemDTO
itemDTO
)
{
if
(
Strings
.
isNullOrEmpty
(
clusterName
))
{
clusterName
=
ConfigConsts
.
CLUSTER_NAME_DEFAULT
;
...
...
apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenAppNamespaceDTO.java
浏览文件 @
0d541123
...
...
@@ -10,6 +10,9 @@ public class OpenAppNamespaceDTO extends BaseDTO {
private
boolean
isPublic
;
// whether to append namespace prefix for public namespace name
private
boolean
appendNamespacePrefix
=
true
;
private
String
comment
;
public
String
getName
()
{
...
...
@@ -44,6 +47,14 @@ public class OpenAppNamespaceDTO extends BaseDTO {
isPublic
=
aPublic
;
}
public
boolean
isAppendNamespacePrefix
()
{
return
appendNamespacePrefix
;
}
public
void
setAppendNamespacePrefix
(
boolean
appendNamespacePrefix
)
{
this
.
appendNamespacePrefix
=
appendNamespacePrefix
;
}
public
String
getComment
()
{
return
comment
;
}
...
...
apollo-openapi/src/test/java/com/ctrip/framework/apollo/openapi/client/service/ItemOpenApiServiceTest.java
浏览文件 @
0d541123
package
com.ctrip.framework.apollo.openapi.client.service
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
com.ctrip.framework.apollo.openapi.dto.OpenItemDTO
;
import
org.apache.http.client.methods.HttpDelete
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.entity.ContentType
;
...
...
@@ -40,6 +42,32 @@ public class ItemOpenApiServiceTest extends AbstractOpenApiServiceTest {
itemOpenApiService
=
new
ItemOpenApiService
(
httpClient
,
someBaseUrl
,
gson
);
}
@Test
public
void
testGetItem
()
throws
Exception
{
String
someKey
=
"someKey"
;
final
ArgumentCaptor
<
HttpGet
>
request
=
ArgumentCaptor
.
forClass
(
HttpGet
.
class
);
itemOpenApiService
.
getItem
(
someAppId
,
someEnv
,
someCluster
,
someNamespace
,
someKey
);
verify
(
httpClient
,
times
(
1
)).
execute
(
request
.
capture
());
HttpGet
get
=
request
.
getValue
();
assertEquals
(
String
.
format
(
"%s/envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s"
,
someBaseUrl
,
someEnv
,
someAppId
,
someCluster
,
someNamespace
,
someKey
),
get
.
getURI
().
toString
());
}
@Test
public
void
testGetNotExistedItem
()
throws
Exception
{
String
someKey
=
"someKey"
;
when
(
statusLine
.
getStatusCode
()).
thenReturn
(
404
);
assertNull
(
itemOpenApiService
.
getItem
(
someAppId
,
someEnv
,
someCluster
,
someNamespace
,
someKey
));
}
@Test
public
void
testCreateItem
()
throws
Exception
{
String
someKey
=
"someKey"
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java
浏览文件 @
0d541123
...
...
@@ -33,6 +33,14 @@ public class ItemController {
@Autowired
private
UserService
userService
;
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key:.+}"
,
method
=
RequestMethod
.
GET
)
public
OpenItemDTO
getItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
String
key
)
{
ItemDTO
itemDTO
=
itemService
.
loadItem
(
Env
.
fromString
(
env
),
appId
,
clusterName
,
namespaceName
,
key
);
return
itemDTO
==
null
?
null
:
OpenApiBeanUtils
.
transformFromItemDTO
(
itemDTO
);
}
@PreAuthorize
(
value
=
"@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName, #env)"
)
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
POST
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java
浏览文件 @
0d541123
...
...
@@ -77,7 +77,7 @@ public class NamespaceController {
}
AppNamespace
appNamespace
=
OpenApiBeanUtils
.
transformToAppNamespace
(
appNamespaceDTO
);
AppNamespace
createdAppNamespace
=
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
AppNamespace
createdAppNamespace
=
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
,
appNamespaceDTO
.
isAppendNamespacePrefix
()
);
publisher
.
publishEvent
(
new
AppNamespaceCreationEvent
(
createdAppNamespace
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录