Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
ac2808e1
apollo
项目概览
wrr-cat
/
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,发现更多精彩内容 >>
提交
ac2808e1
编写于
5月 06, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #175 from lepdou/namespace
Namespace
上级
a950569f
9fb54c68
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
732 addition
and
214 deletion
+732
-214
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
...pollo/adminservice/controller/AppNamespaceController.java
+13
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppNamespaceRepository.java
...m/ctrip/apollo/biz/repository/AppNamespaceRepository.java
+4
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
...ava/com/ctrip/apollo/biz/service/AppNamespaceService.java
+7
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
+2
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppNamespaceRepositoryTest.java
...rip/apollo/biz/repository/AppNamespaceRepositoryTest.java
+33
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTransactionTest.java
...ctrip/apollo/biz/service/AdminServiceTransactionTest.java
+4
-4
apollo-biz/src/test/resources/data.sql
apollo-biz/src/test/resources/data.sql
+8
-0
apollo-core/src/main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
.../main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
+34
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/PortalSettings.java
...src/main/java/com/ctrip/apollo/portal/PortalSettings.java
+4
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+16
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+0
-10
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/NamespaceController.java
...m/ctrip/apollo/portal/controller/NamespaceController.java
+50
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+0
-87
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/NamespaceService.java
...ava/com/ctrip/apollo/portal/service/NamespaceService.java
+140
-0
apollo-portal/src/main/resources/static/app.html
apollo-portal/src/main/resources/static/app.html
+17
-17
apollo-portal/src/main/resources/static/config.html
apollo-portal/src/main/resources/static/config.html
+39
-41
apollo-portal/src/main/resources/static/config/sync.html
apollo-portal/src/main/resources/static/config/sync.html
+2
-2
apollo-portal/src/main/resources/static/index.html
apollo-portal/src/main/resources/static/index.html
+2
-2
apollo-portal/src/main/resources/static/namespace.html
apollo-portal/src/main/resources/static/namespace.html
+124
-0
apollo-portal/src/main/resources/static/scripts/controller/CreateAppController.js
...esources/static/scripts/controller/CreateAppController.js
+1
-1
apollo-portal/src/main/resources/static/scripts/controller/LinkNamespaceController.js
...rces/static/scripts/controller/LinkNamespaceController.js
+90
-0
apollo-portal/src/main/resources/static/scripts/controller/app/SyncConfigController.js
...ces/static/scripts/controller/app/SyncConfigController.js
+1
-2
apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js
...ain/resources/static/scripts/services/NamespaceService.js
+44
-0
apollo-portal/src/main/resources/static/styles/common-style.css
...-portal/src/main/resources/static/styles/common-style.css
+6
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+1
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
.../test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
+0
-47
apollo-portal/src/test/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
...st/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
+90
-0
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
浏览文件 @
ac2808e1
package
com.ctrip.apollo.adminservice.controller
;
package
com.ctrip.apollo.adminservice.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.biz.service.AppNamespaceService
;
import
com.ctrip.apollo.biz.service.AppNamespaceService
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
java.util.List
;
@RestController
@RestController
public
class
AppNamespaceController
{
public
class
AppNamespaceController
{
...
@@ -18,4 +24,11 @@ public class AppNamespaceController {
...
@@ -18,4 +24,11 @@ public class AppNamespaceController {
@PathVariable
(
"appnamespace"
)
String
appnamespace
)
{
@PathVariable
(
"appnamespace"
)
String
appnamespace
)
{
return
appNamespaceService
.
isAppNamespaceNameUnique
(
appId
,
appnamespace
);
return
appNamespaceService
.
isAppNamespaceNameUnique
(
appId
,
appnamespace
);
}
}
@RequestMapping
(
"/appnamespaces/public"
)
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(){
List
<
AppNamespace
>
appNamespaces
=
appNamespaceService
.
findPublicAppNamespaces
();
return
BeanUtils
.
batchTransform
(
AppNamespaceDTO
.
class
,
appNamespaces
);
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppNamespaceRepository.java
浏览文件 @
ac2808e1
...
@@ -4,10 +4,14 @@ import org.springframework.data.repository.PagingAndSortingRepository;
...
@@ -4,10 +4,14 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
java.util.List
;
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>{
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>{
AppNamespace
findByAppIdAndName
(
String
appId
,
String
namespaceName
);
AppNamespace
findByAppIdAndName
(
String
appId
,
String
namespaceName
);
AppNamespace
findByName
(
String
namespaceName
);
AppNamespace
findByName
(
String
namespaceName
);
List
<
AppNamespace
>
findByNameNot
(
String
namespaceName
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
浏览文件 @
ac2808e1
...
@@ -2,9 +2,12 @@ package com.ctrip.apollo.biz.service;
...
@@ -2,9 +2,12 @@ package com.ctrip.apollo.biz.service;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Preconditions
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -50,4 +53,8 @@ public class AppNamespaceService {
...
@@ -50,4 +53,8 @@ public class AppNamespaceService {
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNs
.
getId
(),
Audit
.
OP
.
INSERT
,
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNs
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
createBy
);
}
}
public
List
<
AppNamespace
>
findPublicAppNamespaces
(){
return
appNamespaceRepository
.
findByNameNot
(
ConfigConsts
.
NAMESPACE_DEFAULT
);
}
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
浏览文件 @
ac2808e1
package
com.ctrip.apollo.biz
;
package
com.ctrip.apollo.biz
;
import
com.ctrip.apollo.biz.message.DatabaseMessageSenderTest
;
import
com.ctrip.apollo.biz.message.DatabaseMessageSenderTest
;
import
com.ctrip.apollo.biz.repository.AppNamespaceRepositoryTest
;
import
com.ctrip.apollo.biz.repository.AppRepositoryTest
;
import
com.ctrip.apollo.biz.repository.AppRepositoryTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTransactionTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTransactionTest
;
...
@@ -14,6 +15,7 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -14,6 +15,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
AppRepositoryTest
.
class
,
AppRepositoryTest
.
class
,
AppNamespaceRepositoryTest
.
class
,
AdminServiceTest
.
class
,
AdminServiceTest
.
class
,
ConfigServiceTest
.
class
,
ConfigServiceTest
.
class
,
PrivilegeServiceTest
.
class
,
PrivilegeServiceTest
.
class
,
...
...
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppNamespaceRepositoryTest.java
0 → 100644
浏览文件 @
ac2808e1
package
com.ctrip.apollo.biz.repository
;
import
com.ctrip.apollo.biz.BizTestConfiguration
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
@Transactional
@Rollback
public
class
AppNamespaceRepositoryTest
{
@Autowired
private
AppNamespaceRepository
repository
;
@Test
public
void
testFindAllPublicAppNamespaces
(){
List
<
AppNamespace
>
appNamespaceList
=
repository
.
findByNameNot
(
ConfigConsts
.
NAMESPACE_DEFAULT
);
Assert
.
assertEquals
(
4
,
appNamespaceList
.
size
());
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTransactionTest.java
浏览文件 @
ac2808e1
...
@@ -50,7 +50,7 @@ public class AdminServiceTransactionTest {
...
@@ -50,7 +50,7 @@ public class AdminServiceTransactionTest {
System
.
out
.
println
(
app
.
getAppId
());
System
.
out
.
println
(
app
.
getAppId
());
}
}
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
...
@@ -58,7 +58,7 @@ public class AdminServiceTransactionTest {
...
@@ -58,7 +58,7 @@ public class AdminServiceTransactionTest {
@Before
@Before
public
void
setUpTestDataWithinTransaction
()
{
public
void
setUpTestDataWithinTransaction
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
...
@@ -82,7 +82,7 @@ public class AdminServiceTransactionTest {
...
@@ -82,7 +82,7 @@ public class AdminServiceTransactionTest {
@After
@After
public
void
tearDownWithinTransaction
()
{
public
void
tearDownWithinTransaction
()
{
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
Assert
.
assertEquals
(
1
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
8
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
1
,
clusterRepository
.
count
());
}
}
...
@@ -90,7 +90,7 @@ public class AdminServiceTransactionTest {
...
@@ -90,7 +90,7 @@ public class AdminServiceTransactionTest {
@AfterTransaction
@AfterTransaction
public
void
verifyFinalDatabaseState
()
{
public
void
verifyFinalDatabaseState
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
}
...
...
apollo-biz/src/test/resources/data.sql
0 → 100644
浏览文件 @
ac2808e1
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'application'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'fx.apollo.config'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'application'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'fx.apollo.admin'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'application'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'fx.apollo.portal'
);
INSERT
INTO
AppNamespace
(
AppID
,
Name
)
VALUES
(
'fxhermesproducer'
,
'fx.hermes.producer'
);
apollo-core/src/main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
0 → 100644
浏览文件 @
ac2808e1
package
com.ctrip.apollo.core.dto
;
public
class
AppNamespaceDTO
{
private
String
name
;
private
String
appId
;
private
String
comment
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
String
getComment
()
{
return
comment
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/PortalSettings.java
浏览文件 @
ac2808e1
...
@@ -28,4 +28,8 @@ public class PortalSettings {
...
@@ -28,4 +28,8 @@ public class PortalSettings {
public
List
<
Env
>
getEnvs
()
{
public
List
<
Env
>
getEnvs
()
{
return
envs
;
return
envs
;
}
}
public
Env
getFirstEnv
(){
return
envs
.
get
(
0
);
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
ac2808e1
package
com.ctrip.apollo.portal.api
;
package
com.ctrip.apollo.portal.api
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
...
@@ -61,6 +62,21 @@ public class AdminServiceAPI {
...
@@ -61,6 +62,21 @@ public class AdminServiceAPI {
+
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s"
,
appId
,
clusterName
,
namespaceName
),
+
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s"
,
appId
,
clusterName
,
namespaceName
),
NamespaceDTO
.
class
);
NamespaceDTO
.
class
);
}
}
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(
Env
env
){
AppNamespaceDTO
[]
appNamespaceDTOs
=
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)+
"appnamespaces/public"
,
AppNamespaceDTO
[].
class
);
return
Arrays
.
asList
(
appNamespaceDTOs
);
}
public
NamespaceDTO
save
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
.
postForEntity
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"/apps/%s/clusters/%s/namespaces"
,
namespace
.
getAppId
(),
namespace
.
getClusterName
()),
namespace
,
NamespaceDTO
.
class
)
.
getBody
();
}
}
}
@Service
@Service
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
浏览文件 @
ac2808e1
...
@@ -31,16 +31,6 @@ public class ConfigController {
...
@@ -31,16 +31,6 @@ public class ConfigController {
@Autowired
@Autowired
private
ConfigService
configService
;
private
ConfigService
configService
;
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
throw
new
BadRequestException
(
"app id and cluster name can not be empty"
);
}
return
configService
.
findNampspaces
(
appId
,
Env
.
valueOf
(
env
),
clusterName
);
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
"application/json"
})
"application/json"
})
public
void
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
void
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/NamespaceController.java
0 → 100644
浏览文件 @
ac2808e1
package
com.ctrip.apollo.portal.controller
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.service.NamespaceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
public
class
NamespaceController
{
@Autowired
private
NamespaceService
namespaceService
;
@RequestMapping
(
"/appnamespaces/public"
)
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(){
return
namespaceService
.
findPublicAppNamespaces
();
}
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
save
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
){
if
(
StringUtils
.
isContainEmpty
(
env
,
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
())){
throw
new
BadRequestException
(
"request payload contains empty"
);
}
return
namespaceService
.
save
(
Env
.
valueOf
(
env
),
namespace
);
}
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceVO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
))
{
throw
new
BadRequestException
(
"app id and cluster name can not be empty"
);
}
return
namespaceService
.
findNampspaces
(
appId
,
Env
.
valueOf
(
env
),
clusterName
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
浏览文件 @
ac2808e1
...
@@ -50,90 +50,6 @@ public class ConfigService {
...
@@ -50,90 +50,6 @@ public class ConfigService {
@Autowired
@Autowired
private
ConfigTextResolver
resolver
;
private
ConfigTextResolver
resolver
;
private
Gson
gson
=
new
Gson
();
/**
* load cluster all namespace info with items
*/
public
List
<
NamespaceVO
>
findNampspaces
(
String
appId
,
Env
env
,
String
clusterName
)
{
List
<
NamespaceDTO
>
namespaces
=
namespaceAPI
.
findNamespaceByCluster
(
appId
,
env
,
clusterName
);
if
(
namespaces
==
null
||
namespaces
.
size
()
==
0
)
{
return
Collections
.
emptyList
();
}
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
for
(
NamespaceDTO
namespace
:
namespaces
)
{
NamespaceVO
namespaceVO
=
null
;
try
{
namespaceVO
=
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
);
namespaceVOs
.
add
(
namespaceVO
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
throw
e
;
}
}
return
namespaceVOs
;
}
@SuppressWarnings
(
"unchecked"
)
private
NamespaceVO
parseNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
NamespaceDTO
namespace
)
{
NamespaceVO
namespaceVO
=
new
NamespaceVO
();
namespaceVO
.
setNamespace
(
namespace
);
List
<
NamespaceVO
.
ItemVO
>
itemVos
=
new
LinkedList
<>();
namespaceVO
.
setItems
(
itemVos
);
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest Release
ReleaseDTO
release
=
null
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
try
{
release
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
releaseItems
=
gson
.
fromJson
(
release
.
getConfigurations
(),
Map
.
class
);
}
catch
(
HttpClientErrorException
e
)
{
if
(
e
.
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
)
{
logger
.
warn
(
ExceptionUtils
.
toString
(
e
));
}
else
{
throw
e
;
}
}
//not Release config items
List
<
ItemDTO
>
items
=
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
int
modifiedItemCnt
=
0
;
for
(
ItemDTO
itemDTO
:
items
)
{
NamespaceVO
.
ItemVO
itemVO
=
parseItemVO
(
itemDTO
,
releaseItems
);
if
(
itemVO
.
isModified
())
{
modifiedItemCnt
++;
}
itemVos
.
add
(
itemVO
);
}
namespaceVO
.
setItemModifiedCnt
(
modifiedItemCnt
);
return
namespaceVO
;
}
private
NamespaceVO
.
ItemVO
parseItemVO
(
ItemDTO
itemDTO
,
Map
<
String
,
String
>
releaseItems
)
{
String
key
=
itemDTO
.
getKey
();
NamespaceVO
.
ItemVO
itemVO
=
new
NamespaceVO
.
ItemVO
();
itemVO
.
setItem
(
itemDTO
);
String
newValue
=
itemDTO
.
getValue
();
String
oldValue
=
releaseItems
.
get
(
key
);
if
(!
StringUtils
.
isEmpty
(
key
)
&&
(
oldValue
==
null
||
!
newValue
.
equals
(
oldValue
)))
{
itemVO
.
setModified
(
true
);
itemVO
.
setOldValue
(
oldValue
==
null
?
""
:
oldValue
);
itemVO
.
setNewValue
(
newValue
);
}
return
itemVO
;
}
/**
/**
* parse config text and update config items
* parse config text and update config items
...
@@ -160,10 +76,8 @@ public class ConfigService {
...
@@ -160,10 +76,8 @@ public class ConfigService {
namespaceName
);
namespaceName
);
throw
new
ServiceException
(
e
.
getMessage
());
throw
new
ServiceException
(
e
.
getMessage
());
}
}
}
}
/**
/**
* createRelease config items
* createRelease config items
*/
*/
...
@@ -190,7 +104,6 @@ public class ConfigService {
...
@@ -190,7 +104,6 @@ public class ConfigService {
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
()),
e
);
namespaceIdentifer
.
getClusterName
()),
e
);
}
}
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/NamespaceService.java
0 → 100644
浏览文件 @
ac2808e1
package
com.ctrip.apollo.portal.service
;
import
com.google.gson.Gson
;
import
com.ctrip.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
NamespaceService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
NamespaceService
.
class
);
@Autowired
private
AdminServiceAPI
.
ItemAPI
itemAPI
;
@Autowired
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Autowired
private
PortalSettings
portalSettings
;
private
Gson
gson
=
new
Gson
();
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(){
return
namespaceAPI
.
findPublicAppNamespaces
(
portalSettings
.
getFirstEnv
());
}
public
NamespaceDTO
save
(
Env
env
,
NamespaceDTO
namespace
){
return
namespaceAPI
.
save
(
env
,
namespace
);
}
/**
* load cluster all namespace info with items
*/
public
List
<
NamespaceVO
>
findNampspaces
(
String
appId
,
Env
env
,
String
clusterName
)
{
List
<
NamespaceDTO
>
namespaces
=
namespaceAPI
.
findNamespaceByCluster
(
appId
,
env
,
clusterName
);
if
(
namespaces
==
null
||
namespaces
.
size
()
==
0
)
{
return
Collections
.
emptyList
();
}
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
for
(
NamespaceDTO
namespace
:
namespaces
)
{
NamespaceVO
namespaceVO
=
null
;
try
{
namespaceVO
=
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
);
namespaceVOs
.
add
(
namespaceVO
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
throw
e
;
}
}
return
namespaceVOs
;
}
@SuppressWarnings
(
"unchecked"
)
private
NamespaceVO
parseNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
NamespaceDTO
namespace
)
{
NamespaceVO
namespaceVO
=
new
NamespaceVO
();
namespaceVO
.
setNamespace
(
namespace
);
List
<
NamespaceVO
.
ItemVO
>
itemVos
=
new
LinkedList
<>();
namespaceVO
.
setItems
(
itemVos
);
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest Release
ReleaseDTO
release
=
null
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
try
{
release
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
releaseItems
=
gson
.
fromJson
(
release
.
getConfigurations
(),
Map
.
class
);
}
catch
(
HttpClientErrorException
e
)
{
if
(
e
.
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
)
{
logger
.
warn
(
ExceptionUtils
.
toString
(
e
));
}
else
{
throw
e
;
}
}
//not Release config items
List
<
ItemDTO
>
items
=
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
int
modifiedItemCnt
=
0
;
for
(
ItemDTO
itemDTO
:
items
)
{
NamespaceVO
.
ItemVO
itemVO
=
parseItemVO
(
itemDTO
,
releaseItems
);
if
(
itemVO
.
isModified
())
{
modifiedItemCnt
++;
}
itemVos
.
add
(
itemVO
);
}
namespaceVO
.
setItemModifiedCnt
(
modifiedItemCnt
);
return
namespaceVO
;
}
private
NamespaceVO
.
ItemVO
parseItemVO
(
ItemDTO
itemDTO
,
Map
<
String
,
String
>
releaseItems
)
{
String
key
=
itemDTO
.
getKey
();
NamespaceVO
.
ItemVO
itemVO
=
new
NamespaceVO
.
ItemVO
();
itemVO
.
setItem
(
itemDTO
);
String
newValue
=
itemDTO
.
getValue
();
String
oldValue
=
releaseItems
.
get
(
key
);
if
(!
StringUtils
.
isEmpty
(
key
)
&&
(
oldValue
==
null
||
!
newValue
.
equals
(
oldValue
)))
{
itemVO
.
setModified
(
true
);
itemVO
.
setOldValue
(
oldValue
==
null
?
""
:
oldValue
);
itemVO
.
setNewValue
(
newValue
);
}
return
itemVO
;
}
}
apollo-portal/src/main/resources/static/
views/create-
app.html
→
apollo-portal/src/main/resources/static/app.html
浏览文件 @
ac2808e1
...
@@ -3,16 +3,16 @@
...
@@ -3,16 +3,16 @@
<head>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<!-- styles -->
<!-- styles -->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../
vendor/bootstrap/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"vendor/bootstrap/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../
vendor/angular/angular-toastr-1.4.1.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"vendor/angular/angular-toastr-1.4.1.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
media=
'all'
href=
"
../
vendor/angular/loading-bar.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
media=
'all'
href=
"vendor/angular/loading-bar.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../
styles/common-style.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"styles/common-style.css"
>
<title>
新建项目
</title>
<title>
新建项目
</title>
</head>
</head>
<body>
<body>
<div
ng-include=
"'common/nav.html'"
></div>
<div
ng-include=
"'
views/
common/nav.html'"
></div>
<div
class=
"container-fluid apollo-container"
>
<div
class=
"container-fluid apollo-container"
>
...
@@ -64,25 +64,25 @@
...
@@ -64,25 +64,25 @@
</div>
</div>
</div>
</div>
<div
ng-include=
"'common/footer.html'"
></div>
<div
ng-include=
"'
views/
common/footer.html'"
></div>
<!--angular-->
<!--angular-->
<script
src=
"
../
vendor/angular/angular.min.js"
></script>
<script
src=
"vendor/angular/angular.min.js"
></script>
<script
src=
"
../
vendor/angular/angular-route.min.js"
></script>
<script
src=
"vendor/angular/angular-route.min.js"
></script>
<script
src=
"
../
vendor/angular/angular-resource.min.js"
></script>
<script
src=
"vendor/angular/angular-resource.min.js"
></script>
<script
src=
"
../
vendor/angular/angular-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"vendor/angular/angular-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"
../
vendor/angular/loading-bar.min.js"
></script>
<script
src=
"vendor/angular/loading-bar.min.js"
></script>
<!-- jquery.js -->
<!-- jquery.js -->
<script
src=
"
../
vendor/jquery.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/jquery.js"
type=
"text/javascript"
></script>
<!-- bootstrap.js -->
<!-- bootstrap.js -->
<script
src=
"
../
vendor/bootstrap/js/bootstrap.min.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/bootstrap/js/bootstrap.min.js"
type=
"text/javascript"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/AppUtils.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/AppUtils.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/controller/CreateAppController.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/controller/CreateAppController.js"
></script>
</body>
</body>
</html>
</html>
apollo-portal/src/main/resources/static/
views/app
.html
→
apollo-portal/src/main/resources/static/
config
.html
浏览文件 @
ac2808e1
...
@@ -4,15 +4,15 @@
...
@@ -4,15 +4,15 @@
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
apollo
</title>
<title>
apollo
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../
vendor/bootstrap/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"vendor/bootstrap/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../
vendor/angular/angular-toastr-1.4.1.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"vendor/angular/angular-toastr-1.4.1.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
media=
'all'
href=
"
../
vendor/angular/loading-bar.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
media=
'all'
href=
"vendor/angular/loading-bar.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"
../
styles/common-style.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"styles/common-style.css"
>
</head>
</head>
<body>
<body>
<div
ng-include=
"'common/nav.html'"
></div>
<div
ng-include=
"'
views/
common/nav.html'"
></div>
<div
class=
"container-fluid apollo-container"
>
<div
class=
"container-fluid apollo-container"
>
<div
class=
"app"
ng-controller=
"AppConfigController as appConfig"
>
<div
class=
"app"
ng-controller=
"AppConfigController as appConfig"
>
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
<!--app info-->
<!--app info-->
<section
class=
"panel"
>
<section
class=
"panel"
>
<header
class=
"panel-heading"
>
<header
class=
"panel-heading"
>
<img
src=
"
../
img/info.png"
class=
"i-25-20"
/>
应用信息
<img
src=
"img/info.png"
class=
"i-25-20"
/>
应用信息
<span
class=
"tools pull-right"
>
<span
class=
"tools pull-right"
>
<a
href=
"javascript:;"
class=
"icon-chevron-down"
></a>
<a
href=
"javascript:;"
class=
"icon-chevron-down"
></a>
</span>
</span>
...
@@ -68,14 +68,13 @@
...
@@ -68,14 +68,13 @@
<a
class=
"list-group-item"
data-toggle=
"modal"
data-target=
"#createEnvModal"
<a
class=
"list-group-item"
data-toggle=
"modal"
data-target=
"#createEnvModal"
ng-show=
"missEnvs.length > 0"
>
ng-show=
"missEnvs.length > 0"
>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-2"
><img
src=
"
../
img/plus.png"
class=
"i-20"
></div>
<div
class=
"col-md-2"
><img
src=
"img/plus.png"
class=
"i-20"
></div>
<div
class=
"col-md-7 hidden-xs"
>
<div
class=
"col-md-7 hidden-xs"
>
<p
class=
"
apps-description
"
>
添加环境
</p>
<p
class=
"
btn-title
"
>
添加环境
</p>
</div>
</div>
</div>
</div>
</a>
</a>
<!--<a class="list-group-item" target="_blank" href="/views/
app
.html?#/appid={{app.appId}}">-->
<!--<a class="list-group-item" target="_blank" href="/views/
config
.html?#/appid={{app.appId}}">-->
<!--<div class="row">-->
<!--<div class="row">-->
<!--<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<!--<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<!--<div class="col-md-7 hidden-xs">-->
<!--<div class="col-md-7 hidden-xs">-->
...
@@ -84,15 +83,14 @@
...
@@ -84,15 +83,14 @@
<!--</div>-->
<!--</div>-->
<!--</a>-->
<!--</a>-->
<!--<a class="list-group-item" target="_blank" href="/views/app.html?#/appid={{app.appId}}">-->
<a
class=
"list-group-item"
target=
"_blank"
href=
"namespace.html?#/appid={{pageContext.appId}}"
>
<!--<div class="row">-->
<div
class=
"row"
>
<!--<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<div
class=
"col-md-2"
><img
src=
"img/plus.png"
class=
"i-20"
></div>
<!--<div class="col-md-7 hidden-xs">-->
<div
class=
"col-md-7 hidden-xs"
>
<!--<p class="apps-description">添加Namespace</p>-->
<p
class=
"btn-title"
>
添加Namespace
</p>
<!--</div>-->
</div>
</div>
<!--</div>-->
</a>
<!--</a>-->
</section>
</section>
</div>
</div>
...
@@ -128,7 +126,7 @@
...
@@ -128,7 +126,7 @@
<!--class="btn btn-default btn-sm J_tableview_btn">授权-->
<!--class="btn btn-default btn-sm J_tableview_btn">授权-->
<!--</button>-->
<!--</button>-->
<a
type=
"button"
target=
"_blank"
<a
type=
"button"
target=
"_blank"
href=
"sync.html?#/appid={{pageContext.appId}}&env={{pageContext.env}}&clusterName={{pageContext.clusterName}}&namespaceName={{namespace.namespace.namespaceName}}"
href=
"
config/
sync.html?#/appid={{pageContext.appId}}&env={{pageContext.env}}&clusterName={{pageContext.clusterName}}&namespaceName={{namespace.namespace.namespaceName}}"
class=
"btn btn-default btn-sm J_tableview_btn"
>
同步
class=
"btn btn-default btn-sm J_tableview_btn"
>
同步
</a>
</a>
</div>
</div>
...
@@ -236,7 +234,7 @@
...
@@ -236,7 +234,7 @@
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-11 col-md-offset-1 list"
style=
""
>
<div
class=
"col-md-11 col-md-offset-1 list"
style=
""
>
<div
class=
"media"
>
<div
class=
"media"
>
<img
src=
"
../
img/history.png"
/>
<img
src=
"img/history.png"
/>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-10"
><h5
class=
"media-heading"
>
2016-02-23
<div
class=
"col-md-10"
><h5
class=
"media-heading"
>
2016-02-23
...
@@ -254,7 +252,7 @@
...
@@ -254,7 +252,7 @@
<hr>
<hr>
</div>
</div>
<div
class=
"media"
>
<div
class=
"media"
>
<img
src=
"
../
img/history.png"
/>
<img
src=
"img/history.png"
/>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-10"
><h5
class=
"media-heading"
>
2016-02-23
<div
class=
"col-md-10"
><h5
class=
"media-heading"
>
2016-02-23
...
@@ -316,7 +314,7 @@
...
@@ -316,7 +314,7 @@
<h4
class=
"modal-title"
>
Commit changes
</h4>
<h4
class=
"modal-title"
>
Commit changes
</h4>
</div>
</div>
<div
class=
"modal-body"
>
<div
class=
"modal-body"
>
<textarea
rows=
"4"
class=
"form-control"
style=
"width:570px;"
placeholder=
"
input change log.
..."
<textarea
rows=
"4"
class=
"form-control"
style=
"width:570px;"
placeholder=
"
Add an optional extended description
..."
ng-model=
"commitComment"
></textarea>
ng-model=
"commitComment"
></textarea>
</div>
</div>
<div
class=
"modal-footer"
>
<div
class=
"modal-footer"
>
...
@@ -342,7 +340,7 @@
...
@@ -342,7 +340,7 @@
<input
type=
"text"
class=
"form-control"
placeholder=
"input release title"
<input
type=
"text"
class=
"form-control"
placeholder=
"input release title"
ng-model=
"releaseTitle"
required=
"required"
>
ng-model=
"releaseTitle"
required=
"required"
>
<textarea
rows=
"4"
class=
"form-control"
style=
"margin-top: 15px;"
ng-model=
"releaseComment"
<textarea
rows=
"4"
class=
"form-control"
style=
"margin-top: 15px;"
ng-model=
"releaseComment"
placeholder=
"
input release log.
..."
></textarea>
placeholder=
"
Add an optional extended description
..."
></textarea>
</div>
</div>
<div
class=
"modal-footer"
>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
</button>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
</button>
...
@@ -387,41 +385,41 @@
...
@@ -387,41 +385,41 @@
</div>
</div>
<div
ng-include=
"'common/footer.html'"
></div>
<div
ng-include=
"'
views/
common/footer.html'"
></div>
<!-- jquery.js -->
<!-- jquery.js -->
<script
src=
"
../
vendor/jquery.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/jquery.js"
type=
"text/javascript"
></script>
<!--lodash.js-->
<!--lodash.js-->
<script
src=
"
../
vendor/lodash.min.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/lodash.min.js"
type=
"text/javascript"
></script>
<!--nicescroll-->
<!--nicescroll-->
<script
src=
"
../
vendor/jquery.nicescroll.min.js"
></script>
<script
src=
"vendor/jquery.nicescroll.min.js"
></script>
<!--angular-->
<!--angular-->
<script
src=
"
../
vendor/angular/angular.min.js"
></script>
<script
src=
"vendor/angular/angular.min.js"
></script>
<script
src=
"
../
vendor/angular/angular-ui-router.min.js"
></script>
<script
src=
"vendor/angular/angular-ui-router.min.js"
></script>
<script
src=
"
../
vendor/angular/angular-resource.min.js"
></script>
<script
src=
"vendor/angular/angular-resource.min.js"
></script>
<script
src=
"
../
vendor/angular/angular-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"vendor/angular/angular-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"
../
vendor/angular/loading-bar.min.js"
></script>
<script
src=
"vendor/angular/loading-bar.min.js"
></script>
<!-- bootstrap.js -->
<!-- bootstrap.js -->
<script
src=
"
../
vendor/bootstrap/js/bootstrap.min.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/bootstrap/js/bootstrap.min.js"
type=
"text/javascript"
></script>
<script
src=
"
../
vendor/bootstrap/js/bootstrap-treeview.min.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/bootstrap/js/bootstrap-treeview.min.js"
type=
"text/javascript"
></script>
<!--biz script-->
<!--biz script-->
<script
type=
"application/javascript"
src=
"
../
scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/app.js"
></script>
<!--service-->
<!--service-->
<script
type=
"application/javascript"
src=
"
../
scripts/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/services/ConfigService.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/services/ConfigService.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/AppUtils.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/AppUtils.js"
></script>
<!--controller-->
<!--controller-->
<script
type=
"application/javascript"
src=
"
../
scripts/controller/app/AppConfigController.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/controller/app/AppConfigController.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/PageCommon.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/PageCommon.js"
></script>
</body>
</body>
</html>
</html>
apollo-portal/src/main/resources/static/
views
/sync.html
→
apollo-portal/src/main/resources/static/
config
/sync.html
浏览文件 @
ac2808e1
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
<body>
<body>
<div
ng-include=
"'common/nav.html'"
></div>
<div
ng-include=
"'
../views/
common/nav.html'"
></div>
<div
class=
"container-fluid apollo-container"
ng-controller=
"SyncItemController"
>
<div
class=
"container-fluid apollo-container"
ng-controller=
"SyncItemController"
>
<section
class=
"panel col-md-offset-1 col-md-10"
>
<section
class=
"panel col-md-offset-1 col-md-10"
>
...
@@ -175,7 +175,7 @@
...
@@ -175,7 +175,7 @@
</section>
</section>
</div>
</div>
<div
ng-include=
"'common/footer.html'"
></div>
<div
ng-include=
"'
../views/
common/footer.html'"
></div>
<!--angular-->
<!--angular-->
<script
src=
"../vendor/angular/angular.min.js"
></script>
<script
src=
"../vendor/angular/angular.min.js"
></script>
...
...
apollo-portal/src/main/resources/static/index.html
浏览文件 @
ac2808e1
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<div
class=
"col-xs-12"
><h1>
Apollo
</h1>
<div
class=
"col-xs-12"
><h1>
Apollo
</h1>
<p>
携程统一配置中心
<br>
<p>
携程统一配置中心
<br>
<span
class=
"package-amount"
>
共收录了
<strong>
{{appsCount}}
</strong>
个项目
</span>
<span
class=
"package-amount"
>
共收录了
<strong>
{{appsCount}}
</strong>
个项目
</span>
<a
class=
"btn btn-success"
href=
"
views/create-
app.html"
>
创建项目
</a>
<a
class=
"btn btn-success"
href=
"app.html"
>
创建项目
</a>
</p>
</p>
<form
class=
""
role=
"search"
>
<form
class=
""
role=
"search"
>
...
@@ -42,7 +42,7 @@
...
@@ -42,7 +42,7 @@
<div
class=
"container-fluid apollo-container"
>
<div
class=
"container-fluid apollo-container"
>
<div
class=
"list-group apps"
>
<div
class=
"list-group apps"
>
<a
class=
"package list-group-item"
target=
"_blank"
href=
"
/views/app
.html?#/appid={{app.appId}}"
<a
class=
"package list-group-item"
target=
"_blank"
href=
"
config
.html?#/appid={{app.appId}}"
ng-repeat=
"app in apps "
>
ng-repeat=
"app in apps "
>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-3"
><h4
class=
"apps-name"
>
{{app.appId}}
</h4></div>
<div
class=
"col-md-3"
><h4
class=
"apps-name"
>
{{app.appId}}
</h4></div>
...
...
apollo-portal/src/main/resources/static/namespace.html
0 → 100644
浏览文件 @
ac2808e1
<!doctype html>
<html
ng-app=
"application"
>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<!-- styles -->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"vendor/bootstrap/css/bootstrap.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"vendor/angular/angular-toastr-1.4.1.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
media=
'all'
href=
"vendor/angular/loading-bar.min.css"
>
<link
href=
"http://cdn.bootcss.com/select2/4.0.2-rc.1/css/select2.css"
rel=
"stylesheet"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"styles/common-style.css"
>
<title>
新建Namespace
</title>
</head>
<body>
<div
ng-include=
"'views/common/nav.html'"
></div>
<div
class=
"container-fluid apollo-container"
>
<div
class=
"row"
>
<div
class=
"col-md-8 col-md-offset-2"
>
<div
class=
"panel"
>
<header
class=
"panel-heading"
>
新建Namespace
</header>
<div
class=
"panel-body"
>
<form
class=
"form-horizontal"
ng-controller=
"LinkNamespaceController"
ng-submit=
"saveNamespace()"
>
<div
class=
"form-group"
>
<label
class=
"col-sm-3 control-label"
>
应用ID
</label>
<div
class=
"col-sm-6"
>
{{appId}}
</div>
</div>
<div
class=
"form-horizontal"
>
<div
class=
"form-group"
>
<label
class=
"col-sm-3 control-label"
>
选择集群
</label>
<div
class=
"col-sm-6"
>
<table
class=
"table table-hover"
>
<thead>
<tr>
<td><input
type=
"checkbox"
ng-click=
"toggleEnvsCheckedStatus()"
></td>
</td>
<td>
环境
</td>
<td>
集群
</td>
</tr>
</thead>
<tbody>
<tr
ng-repeat=
"namespaceIdentifer in namespaceIdentifers"
>
<td
width=
"10%"
><input
type=
"checkbox"
ng-checked=
"namespaceIdentifer.checked"
ng-click=
"switchSelect(namespaceIdentifer)"
></td>
<td
width=
"30%"
>
{{namespaceIdentifer.env}}
</td>
<td
width=
"60%"
>
{{namespaceIdentifer.name}}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div
class=
"form-group"
ng-show=
"isRootUser"
>
<label
class=
"col-sm-3 control-label"
><font
style=
"color: red"
>
*
</font>
namespace类型
</label>
<div
class=
"col-sm-4"
>
<label
class=
"radio-inline"
>
<input
type=
"radio"
name=
"x"
ng-checked=
"namespaceType == 1"
ng-click=
"selectNamespaceType(1)"
>
关联
</label>
<label
class=
"radio-inline"
>
<input
type=
"radio"
name=
"x"
ng-checked=
"namespaceType == 2"
ng-click=
"selectNamespaceType(2)"
>
新建
</label>
</div>
</div>
<div
class=
"form-group"
ng-show=
"namespaceType == 2"
>
<label
class=
"col-sm-3 control-label"
><font
style=
"color: red"
>
*
</font>
namespace
</label>
<div
class=
"col-sm-4"
>
<input
type=
"text"
class=
"form-control"
placeholder=
"输入namespace名称"
>
</div>
</div>
<div
class=
"form-group"
ng-show=
"namespaceType == 1"
>
<label
class=
"col-sm-3 control-label"
><font
style=
"color: red"
>
*
</font>
namespace
</label>
<div
class=
"col-sm-4"
>
<select
id=
"namespaces"
>
</select>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<button
type=
"submit"
class=
"btn btn-default"
>
提交
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div
ng-include=
"'views/common/footer.html'"
></div>
<!--angular-->
<script
src=
"vendor/angular/angular.min.js"
></script>
<script
src=
"vendor/angular/angular-resource.min.js"
></script>
<script
src=
"vendor/angular/angular-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"vendor/angular/loading-bar.min.js"
></script>
<!-- jquery.js -->
<script
src=
"vendor/jquery.js"
type=
"text/javascript"
></script>
<script
src=
"http://cdn.bootcss.com/select2/4.0.2-rc.1/js/select2.min.js"
></script>
<!-- bootstrap.js -->
<script
src=
"vendor/bootstrap/js/bootstrap.min.js"
type=
"text/javascript"
></script>
<script
type=
"application/javascript"
src=
"scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/services/NamespaceService.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/AppUtils.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/controller/LinkNamespaceController.js"
></script>
</body>
</html>
apollo-portal/src/main/resources/static/scripts/controller/CreateAppController.js
浏览文件 @
ac2808e1
...
@@ -5,7 +5,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
...
@@ -5,7 +5,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
AppService
.
create
(
'
ALL
'
,
$scope
.
app
).
then
(
function
(
result
)
{
AppService
.
create
(
'
ALL
'
,
$scope
.
app
).
then
(
function
(
result
)
{
toastr
.
success
(
'
添加成功!
'
);
toastr
.
success
(
'
添加成功!
'
);
setInterval
(
function
()
{
setInterval
(
function
()
{
$window
.
location
.
href
=
'
/views/
app
.html?#appid=
'
+
result
.
appId
;
$window
.
location
.
href
=
'
/views/
config
.html?#appid=
'
+
result
.
appId
;
},
1000
);
},
1000
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
'
添加失败!
'
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
'
添加失败!
'
);
...
...
apollo-portal/src/main/resources/static/scripts/controller/LinkNamespaceController.js
0 → 100644
浏览文件 @
ac2808e1
application_module
.
controller
(
"
LinkNamespaceController
"
,
[
'
$scope
'
,
'
$location
'
,
'
$window
'
,
'
toastr
'
,
'
AppService
'
,
'
AppUtil
'
,
'
NamespaceService
'
,
function
(
$scope
,
$location
,
$window
,
toastr
,
AppService
,
AppUtil
,
NamespaceService
)
{
var
params
=
AppUtil
.
parseParams
(
$location
.
$$url
);
$scope
.
appId
=
params
.
appid
;
$scope
.
isRootUser
=
params
.
root
?
true
:
false
;
////// load env //////
AppService
.
load_nav_tree
(
$scope
.
appId
).
then
(
function
(
result
)
{
$scope
.
namespaceIdentifers
=
[];
result
.
nodes
.
forEach
(
function
(
node
)
{
var
env
=
node
.
env
;
node
.
clusters
.
forEach
(
function
(
cluster
)
{
cluster
.
env
=
env
;
cluster
.
checked
=
false
;
$scope
.
namespaceIdentifers
.
push
(
cluster
);
})
});
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
加载环境出错
"
);
});
NamespaceService
.
find_public_namespaces
().
then
(
function
(
result
)
{
var
publicNamespaces
=
[];
result
.
forEach
(
function
(
item
)
{
var
namespace
=
{};
namespace
.
id
=
item
.
name
;
namespace
.
text
=
item
.
name
;
publicNamespaces
.
push
(
namespace
);
});
$
(
'
#namespaces
'
).
select2
({
width
:
'
250px
'
,
data
:
publicNamespaces
});
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
load public namespace error
"
);
});
$scope
.
saveNamespace
=
function
()
{
var
selectedClusters
=
collectSelectedClusters
();
if
(
selectedClusters
.
length
==
0
){
toastr
.
warning
(
"
请选择集群
"
);
return
;
}
var
namespaceName
=
$
(
'
#namespaces
'
).
select2
(
'
data
'
)[
0
].
id
;
selectedClusters
.
forEach
(
function
(
cluster
)
{
NamespaceService
.
save
(
$scope
.
appId
,
cluster
.
env
,
cluster
.
clusterName
,
namespaceName
).
then
(
function
(
result
)
{
toastr
.
success
(
cluster
.
env
+
"
_
"
+
result
.
clusterName
+
"
_
"
+
result
.
namespaceName
+
"
创建成功
"
);
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
cluster
.
env
+
"
_
"
+
cluster
.
clusterName
+
"
_
"
+
namespaceName
+
"
创建失败
"
);
});
})
};
var
envAllSelected
=
false
;
$scope
.
toggleEnvsCheckedStatus
=
function
()
{
envAllSelected
=
!
envAllSelected
;
$scope
.
namespaceIdentifers
.
forEach
(
function
(
namespaceIdentifer
)
{
namespaceIdentifer
.
checked
=
envAllSelected
;
})
};
function
collectSelectedClusters
()
{
var
selectedClusters
=
[];
$scope
.
namespaceIdentifers
.
forEach
(
function
(
namespaceIdentifer
)
{
if
(
namespaceIdentifer
.
checked
){
namespaceIdentifer
.
clusterName
=
namespaceIdentifer
.
name
;
selectedClusters
.
push
(
namespaceIdentifer
);
}
});
return
selectedClusters
;
}
$scope
.
namespaceType
=
1
;
$scope
.
selectNamespaceType
=
function
(
type
)
{
$scope
.
namespaceType
=
type
;
};
$scope
.
switchSelect
=
function
(
o
)
{
o
.
checked
=
!
o
.
checked
;
}
}]);
apollo-portal/src/main/resources/static/scripts/controller/app/SyncConfigController.js
浏览文件 @
ac2808e1
...
@@ -3,7 +3,6 @@ sync_item_module.controller("SyncItemController",
...
@@ -3,7 +3,6 @@ sync_item_module.controller("SyncItemController",
function
(
$scope
,
$location
,
$window
,
toastr
,
AppService
,
AppUtil
,
ConfigService
)
{
function
(
$scope
,
$location
,
$window
,
toastr
,
AppService
,
AppUtil
,
ConfigService
)
{
var
params
=
AppUtil
.
parseParams
(
$location
.
$$url
);
var
params
=
AppUtil
.
parseParams
(
$location
.
$$url
);
var
currentUser
=
'
test_user
'
;
$scope
.
pageContext
=
{
$scope
.
pageContext
=
{
appId
:
params
.
appid
,
appId
:
params
.
appid
,
env
:
params
.
env
,
env
:
params
.
env
,
...
@@ -115,7 +114,7 @@ sync_item_module.controller("SyncItemController",
...
@@ -115,7 +114,7 @@ sync_item_module.controller("SyncItemController",
};
};
$scope
.
backToAppHomePage
=
function
()
{
$scope
.
backToAppHomePage
=
function
()
{
$window
.
location
.
href
=
'
/views/
app
.html?#appid=
'
+
$scope
.
pageContext
.
appId
;
$window
.
location
.
href
=
'
/views/
config
.html?#appid=
'
+
$scope
.
pageContext
.
appId
;
};
};
$scope
.
switchSelect
=
function
(
o
)
{
$scope
.
switchSelect
=
function
(
o
)
{
...
...
apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js
0 → 100644
浏览文件 @
ac2808e1
appService
.
service
(
"
NamespaceService
"
,
[
'
$resource
'
,
'
$q
'
,
function
(
$resource
,
$q
)
{
var
namespace_source
=
$resource
(
""
,
{},
{
find_public_namespaces
:
{
method
:
'
GET
'
,
isArray
:
true
,
url
:
'
/appnamespaces/public
'
},
save
:
{
method
:
'
POST
'
,
url
:
'
/apps/:appId/envs/:env/clusters/:clusterName/namespaces
'
,
isArray
:
false
}
});
return
{
find_public_namespaces
:
function
()
{
var
d
=
$q
.
defer
();
namespace_source
.
find_public_namespaces
({},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
d
.
reject
(
result
);
});
return
d
.
promise
;
},
save
:
function
(
appId
,
env
,
clusterName
,
namespaceName
)
{
var
d
=
$q
.
defer
();
namespace_source
.
save
({
appId
:
appId
,
env
:
env
,
clusterName
:
clusterName
},
{
appId
:
appId
,
clusterName
:
clusterName
,
namespaceName
:
namespaceName
},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
d
.
reject
(
result
);
});
return
d
.
promise
;
}
}
}]);
apollo-portal/src/main/resources/static/styles/common-style.css
浏览文件 @
ac2808e1
...
@@ -259,3 +259,9 @@ table th {
...
@@ -259,3 +259,9 @@ table th {
padding-bottom
:
4px
;
padding-bottom
:
4px
;
}
}
.list-group-item
.btn-title
{
color
:
gray
;
font-family
:
"Apple Color Emoji"
;
font-size
:
16px
;
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
浏览文件 @
ac2808e1
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
AppServiceTest
.
class
AppServiceTest
.
class
,
NamespaceServiceTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
浏览文件 @
ac2808e1
...
@@ -4,12 +4,10 @@ import com.ctrip.apollo.core.ConfigConsts;
...
@@ -4,12 +4,10 @@ import com.ctrip.apollo.core.ConfigConsts;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.ItemDiffs
;
import
com.ctrip.apollo.portal.entity.ItemDiffs
;
import
com.ctrip.apollo.portal.entity.NamespaceIdentifer
;
import
com.ctrip.apollo.portal.entity.NamespaceIdentifer
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
...
@@ -47,51 +45,6 @@ public class ConfigServiceTest {
...
@@ -47,51 +45,6 @@ public class ConfigServiceTest {
public
void
setup
()
{
public
void
setup
()
{
}
}
@Test
public
void
testFindNamespace
()
{
String
appId
=
"6666"
;
String
clusterName
=
"default"
;
String
namespaceName
=
"application"
;
NamespaceDTO
application
=
new
NamespaceDTO
();
application
.
setId
(
1
);
application
.
setClusterName
(
clusterName
);
application
.
setAppId
(
appId
);
application
.
setNamespaceName
(
namespaceName
);
NamespaceDTO
hermas
=
new
NamespaceDTO
();
hermas
.
setId
(
2
);
hermas
.
setClusterName
(
"default"
);
hermas
.
setAppId
(
appId
);
hermas
.
setNamespaceName
(
"hermas"
);
List
<
NamespaceDTO
>
namespaces
=
Arrays
.
asList
(
application
,
hermas
);
ReleaseDTO
someRelease
=
new
ReleaseDTO
();
someRelease
.
setConfigurations
(
"{\"a\":\"123\",\"b\":\"123\"}"
);
ItemDTO
i1
=
new
ItemDTO
(
"a"
,
"123"
,
""
,
1
);
ItemDTO
i2
=
new
ItemDTO
(
"b"
,
"1"
,
""
,
2
);
ItemDTO
i3
=
new
ItemDTO
(
""
,
""
,
"#dddd"
,
3
);
ItemDTO
i4
=
new
ItemDTO
(
"c"
,
"1"
,
""
,
4
);
List
<
ItemDTO
>
someItems
=
Arrays
.
asList
(
i1
,
i2
,
i3
,
i4
);
when
(
namespaceAPI
.
findNamespaceByCluster
(
appId
,
Env
.
DEV
,
clusterName
)).
thenReturn
(
namespaces
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someRelease
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
"hermas"
)).
thenReturn
(
someRelease
);
when
(
itemAPI
.
findItems
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someItems
);
List
<
NamespaceVO
>
namespaceVOs
=
configService
.
findNampspaces
(
appId
,
Env
.
DEV
,
clusterName
);
assertEquals
(
2
,
namespaceVOs
.
size
());
NamespaceVO
namespaceVO
=
namespaceVOs
.
get
(
0
);
assertEquals
(
4
,
namespaceVO
.
getItems
().
size
());
assertEquals
(
"a"
,
namespaceVO
.
getItems
().
get
(
0
).
getItem
().
getKey
());
assertEquals
(
2
,
namespaceVO
.
getItemModifiedCnt
());
assertEquals
(
appId
,
namespaceVO
.
getNamespace
().
getAppId
());
assertEquals
(
clusterName
,
namespaceVO
.
getNamespace
().
getClusterName
());
assertEquals
(
namespaceName
,
namespaceVO
.
getNamespace
().
getNamespaceName
());
}
@Test
@Test
public
void
testUpdateConfigByText
()
{
public
void
testUpdateConfigByText
()
{
String
appId
=
"6666"
;
String
appId
=
"6666"
;
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
0 → 100644
浏览文件 @
ac2808e1
package
com.ctrip.apollo.portal
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.service.NamespaceService
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
java.util.Arrays
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
NamespaceServiceTest
{
@Mock
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Mock
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
@Mock
private
AdminServiceAPI
.
ItemAPI
itemAPI
;
@Mock
private
PropertyResolver
resolver
;
@InjectMocks
private
NamespaceService
namespaceService
;
@Before
public
void
setup
()
{
}
@Test
public
void
testFindNamespace
()
{
String
appId
=
"6666"
;
String
clusterName
=
"default"
;
String
namespaceName
=
"application"
;
NamespaceDTO
application
=
new
NamespaceDTO
();
application
.
setId
(
1
);
application
.
setClusterName
(
clusterName
);
application
.
setAppId
(
appId
);
application
.
setNamespaceName
(
namespaceName
);
NamespaceDTO
hermas
=
new
NamespaceDTO
();
hermas
.
setId
(
2
);
hermas
.
setClusterName
(
"default"
);
hermas
.
setAppId
(
appId
);
hermas
.
setNamespaceName
(
"hermas"
);
List
<
NamespaceDTO
>
namespaces
=
Arrays
.
asList
(
application
,
hermas
);
ReleaseDTO
someRelease
=
new
ReleaseDTO
();
someRelease
.
setConfigurations
(
"{\"a\":\"123\",\"b\":\"123\"}"
);
ItemDTO
i1
=
new
ItemDTO
(
"a"
,
"123"
,
""
,
1
);
ItemDTO
i2
=
new
ItemDTO
(
"b"
,
"1"
,
""
,
2
);
ItemDTO
i3
=
new
ItemDTO
(
""
,
""
,
"#dddd"
,
3
);
ItemDTO
i4
=
new
ItemDTO
(
"c"
,
"1"
,
""
,
4
);
List
<
ItemDTO
>
someItems
=
Arrays
.
asList
(
i1
,
i2
,
i3
,
i4
);
when
(
namespaceAPI
.
findNamespaceByCluster
(
appId
,
Env
.
DEV
,
clusterName
)).
thenReturn
(
namespaces
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someRelease
);
when
(
releaseAPI
.
loadLatestRelease
(
appId
,
Env
.
DEV
,
clusterName
,
"hermas"
)).
thenReturn
(
someRelease
);
when
(
itemAPI
.
findItems
(
appId
,
Env
.
DEV
,
clusterName
,
namespaceName
)).
thenReturn
(
someItems
);
List
<
NamespaceVO
>
namespaceVOs
=
namespaceService
.
findNampspaces
(
appId
,
Env
.
DEV
,
clusterName
);
assertEquals
(
2
,
namespaceVOs
.
size
());
NamespaceVO
namespaceVO
=
namespaceVOs
.
get
(
0
);
assertEquals
(
4
,
namespaceVO
.
getItems
().
size
());
assertEquals
(
"a"
,
namespaceVO
.
getItems
().
get
(
0
).
getItem
().
getKey
());
assertEquals
(
2
,
namespaceVO
.
getItemModifiedCnt
());
assertEquals
(
appId
,
namespaceVO
.
getNamespace
().
getAppId
());
assertEquals
(
clusterName
,
namespaceVO
.
getNamespace
().
getClusterName
());
assertEquals
(
namespaceName
,
namespaceVO
.
getNamespace
().
getNamespaceName
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录