Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
ac2808e1
Commit
ac2808e1
authored
May 06, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #175 from lepdou/namespace
Namespace
parents
a950569f
9fb54c68
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
732 additions
and
214 deletions
+732
-214
AppNamespaceController.java
...pollo/adminservice/controller/AppNamespaceController.java
+13
-0
AppNamespaceRepository.java
...m/ctrip/apollo/biz/repository/AppNamespaceRepository.java
+4
-0
AppNamespaceService.java
...ava/com/ctrip/apollo/biz/service/AppNamespaceService.java
+7
-0
AllTests.java
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
+2
-0
AppNamespaceRepositoryTest.java
...rip/apollo/biz/repository/AppNamespaceRepositoryTest.java
+33
-0
AdminServiceTransactionTest.java
...ctrip/apollo/biz/service/AdminServiceTransactionTest.java
+4
-4
data.sql
apollo-biz/src/test/resources/data.sql
+8
-0
AppNamespaceDTO.java
.../main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
+34
-0
PortalSettings.java
...src/main/java/com/ctrip/apollo/portal/PortalSettings.java
+4
-0
AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+16
-0
ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+0
-10
NamespaceController.java
...m/ctrip/apollo/portal/controller/NamespaceController.java
+50
-0
ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+0
-87
NamespaceService.java
...ava/com/ctrip/apollo/portal/service/NamespaceService.java
+140
-0
app.html
apollo-portal/src/main/resources/static/app.html
+17
-17
config.html
apollo-portal/src/main/resources/static/config.html
+39
-41
sync.html
apollo-portal/src/main/resources/static/config/sync.html
+2
-2
index.html
apollo-portal/src/main/resources/static/index.html
+2
-2
namespace.html
apollo-portal/src/main/resources/static/namespace.html
+124
-0
CreateAppController.js
...esources/static/scripts/controller/CreateAppController.js
+1
-1
LinkNamespaceController.js
...rces/static/scripts/controller/LinkNamespaceController.js
+90
-0
SyncConfigController.js
...ces/static/scripts/controller/app/SyncConfigController.js
+1
-2
NamespaceService.js
...ain/resources/static/scripts/services/NamespaceService.js
+44
-0
common-style.css
...-portal/src/main/resources/static/styles/common-style.css
+6
-0
AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+1
-1
ConfigServiceTest.java
.../test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
+0
-47
NamespaceServiceTest.java
...st/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
+90
-0
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
View file @
ac2808e1
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
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.RequestMapping
;
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.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
java.util.List
;
@RestController
public
class
AppNamespaceController
{
...
...
@@ -18,4 +24,11 @@ public class AppNamespaceController {
@PathVariable
(
"appnamespace"
)
String
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
View file @
ac2808e1
...
...
@@ -4,10 +4,14 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
java.util.List
;
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>{
AppNamespace
findByAppIdAndName
(
String
appId
,
String
namespaceName
);
AppNamespace
findByName
(
String
namespaceName
);
List
<
AppNamespace
>
findByNameNot
(
String
namespaceName
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
View file @
ac2808e1
...
...
@@ -2,9 +2,12 @@ package com.ctrip.apollo.biz.service;
import
com.google.common.base.Preconditions
;
import
java.util.List
;
import
java.util.Objects
;
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.transaction.annotation.Transactional
;
...
...
@@ -50,4 +53,8 @@ public class AppNamespaceService {
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNs
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
public
List
<
AppNamespace
>
findPublicAppNamespaces
(){
return
appNamespaceRepository
.
findByNameNot
(
ConfigConsts
.
NAMESPACE_DEFAULT
);
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
View file @
ac2808e1
package
com
.
ctrip
.
apollo
.
biz
;
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.service.AdminServiceTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTransactionTest
;
...
...
@@ -14,6 +15,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AppRepositoryTest
.
class
,
AppNamespaceRepositoryTest
.
class
,
AdminServiceTest
.
class
,
ConfigServiceTest
.
class
,
PrivilegeServiceTest
.
class
,
...
...
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppNamespaceRepositoryTest.java
0 → 100644
View file @
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
View file @
ac2808e1
...
...
@@ -50,7 +50,7 @@ public class AdminServiceTransactionTest {
System
.
out
.
println
(
app
.
getAppId
());
}
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
...
...
@@ -58,7 +58,7 @@ public class AdminServiceTransactionTest {
@Before
public
void
setUpTestDataWithinTransaction
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
...
...
@@ -82,7 +82,7 @@ public class AdminServiceTransactionTest {
@After
public
void
tearDownWithinTransaction
()
{
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
Assert
.
assertEquals
(
1
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
8
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
1
,
clusterRepository
.
count
());
}
...
...
@@ -90,7 +90,7 @@ public class AdminServiceTransactionTest {
@AfterTransaction
public
void
verifyFinalDatabaseState
()
{
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
Assert
.
assertEquals
(
0
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
7
,
appNamespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
namespaceRepository
.
count
());
Assert
.
assertEquals
(
0
,
clusterRepository
.
count
());
}
...
...
apollo-biz/src/test/resources/data.sql
0 → 100644
View file @
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
View file @
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
View file @
ac2808e1
...
...
@@ -28,4 +28,8 @@ public class PortalSettings {
public
List
<
Env
>
getEnvs
()
{
return
envs
;
}
public
Env
getFirstEnv
(){
return
envs
.
get
(
0
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
View file @
ac2808e1
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.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
...
...
@@ -61,6 +62,21 @@ public class AdminServiceAPI {
+
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s"
,
appId
,
clusterName
,
namespaceName
),
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
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
ac2808e1
...
...
@@ -31,16 +31,6 @@ public class ConfigController {
@Autowired
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
=
{
"application/json"
})
public
void
modifyItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/NamespaceController.java
0 → 100644
View file @
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
View file @
ac2808e1
...
...
@@ -50,90 +50,6 @@ public class ConfigService {
@Autowired
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
...
...
@@ -160,10 +76,8 @@ public class ConfigService {
namespaceName
);
throw
new
ServiceException
(
e
.
getMessage
());
}
}
/**
* createRelease config items
*/
...
...
@@ -190,7 +104,6 @@ public class ConfigService {
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
()),
e
);
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/NamespaceService.java
0 → 100644
View file @
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
View file @
ac2808e1
...
...
@@ -3,16 +3,16 @@
<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
rel=
"stylesheet"
type=
"text/css"
href=
"
../
styles/common-style.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"
media=
'all'
href=
"vendor/angular/loading-bar.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"styles/common-style.css"
>
<title>
新建项目
</title>
</head>
<body>
<div
ng-include=
"'common/nav.html'"
></div>
<div
ng-include=
"'
views/
common/nav.html'"
></div>
<div
class=
"container-fluid apollo-container"
>
...
...
@@ -64,25 +64,25 @@
</div>
</div>
<div
ng-include=
"'common/footer.html'"
></div>
<div
ng-include=
"'
views/
common/footer.html'"
></div>
<!--angular-->
<script
src=
"
../
vendor/angular/angular.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-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"
../
vendor/angular/loading-bar.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-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=
"vendor/jquery.js"
type=
"text/javascript"
></script>
<!-- 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/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/AppUtils.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/AppUtils.js"
></script>
<script
type=
"application/javascript"
src=
"
../
scripts/controller/CreateAppController.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/controller/CreateAppController.js"
></script>
</body>
</html>
apollo-portal/src/main/resources/static/
views/app
.html
→
apollo-portal/src/main/resources/static/
config
.html
View file @
ac2808e1
...
...
@@ -4,15 +4,15 @@
<head>
<meta
charset=
"UTF-8"
>
<title>
apollo
</title>
<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
rel=
"stylesheet"
type=
"text/css"
href=
"
../
styles/common-style.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"
media=
'all'
href=
"vendor/angular/loading-bar.min.css"
>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"styles/common-style.css"
>
</head>
<body>
<div
ng-include=
"'common/nav.html'"
></div>
<div
ng-include=
"'
views/
common/nav.html'"
></div>
<div
class=
"container-fluid apollo-container"
>
<div
class=
"app"
ng-controller=
"AppConfigController as appConfig"
>
...
...
@@ -28,7 +28,7 @@
<!--app info-->
<section
class=
"panel"
>
<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"
>
<a
href=
"javascript:;"
class=
"icon-chevron-down"
></a>
</span>
...
...
@@ -68,14 +68,13 @@
<a
class=
"list-group-item"
data-toggle=
"modal"
data-target=
"#createEnvModal"
ng-show=
"missEnvs.length > 0"
>
<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"
>
<p
class=
"
apps-description
"
>
添加环境
</p>
<p
class=
"
btn-title
"
>
添加环境
</p>
</div>
</div>
</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="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<!--<div class="col-md-7 hidden-xs">-->
...
...
@@ -84,15 +83,14 @@
<!--</div>-->
<!--</a>-->
<!--<a class="list-group-item" target="_blank" href="/views/app.html?#/appid={{app.appId}}">-->
<!--<div class="row">-->
<!--<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<!--<div class="col-md-7 hidden-xs">-->
<!--<p class="apps-description">添加Namespace</p>-->
<!--</div>-->
<!--</div>-->
<!--</a>-->
<a
class=
"list-group-item"
target=
"_blank"
href=
"namespace.html?#/appid={{pageContext.appId}}"
>
<div
class=
"row"
>
<div
class=
"col-md-2"
><img
src=
"img/plus.png"
class=
"i-20"
></div>
<div
class=
"col-md-7 hidden-xs"
>
<p
class=
"btn-title"
>
添加Namespace
</p>
</div>
</div>
</a>
</section>
</div>
...
...
@@ -128,7 +126,7 @@
<!--class="btn btn-default btn-sm J_tableview_btn">授权-->
<!--</button>-->
<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"
>
同步
</a>
</div>
...
...
@@ -236,7 +234,7 @@
<div
class=
"row"
>
<div
class=
"col-md-11 col-md-offset-1 list"
style=
""
>
<div
class=
"media"
>
<img
src=
"
../
img/history.png"
/>
<img
src=
"img/history.png"
/>
<div
class=
"row"
>
<div
class=
"col-md-10"
><h5
class=
"media-heading"
>
2016-02-23
...
...
@@ -254,7 +252,7 @@
<hr>
</div>
<div
class=
"media"
>
<img
src=
"
../
img/history.png"
/>
<img
src=
"img/history.png"
/>
<div
class=
"row"
>
<div
class=
"col-md-10"
><h5
class=
"media-heading"
>
2016-02-23
...
...
@@ -316,7 +314,7 @@
<h4
class=
"modal-title"
>
Commit changes
</h4>
</div>
<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>
</div>
<div
class=
"modal-footer"
>
...
...
@@ -342,7 +340,7 @@
<input
type=
"text"
class=
"form-control"
placeholder=
"input release title"
ng-model=
"releaseTitle"
required=
"required"
>
<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
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
</button>
...
...
@@ -387,41 +385,41 @@
</div>
<div
ng-include=
"'common/footer.html'"
></div>
<div
ng-include=
"'
views/
common/footer.html'"
></div>
<!-- jquery.js -->
<script
src=
"
../
vendor/jquery.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/jquery.js"
type=
"text/javascript"
></script>
<!--lodash.js-->
<script
src=
"
../
vendor/lodash.min.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/lodash.min.js"
type=
"text/javascript"
></script>
<!--nicescroll-->
<script
src=
"
../
vendor/jquery.nicescroll.min.js"
></script>
<script
src=
"vendor/jquery.nicescroll.min.js"
></script>
<!--angular-->
<script
src=
"
../
vendor/angular/angular.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-toastr-1.4.1.tpls.min.js"
></script>
<script
src=
"
../
vendor/angular/loading-bar.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-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>
<!-- bootstrap.js -->
<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.min.js"
type=
"text/javascript"
></script>
<script
src=
"vendor/bootstrap/js/bootstrap-treeview.min.js"
type=
"text/javascript"
></script>
<!--biz script-->
<script
type=
"application/javascript"
src=
"
../
scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"scripts/app.js"
></script>
<!--service-->
<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/AppUtils.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/AppUtils.js"
></script>
<!--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>
</html>
apollo-portal/src/main/resources/static/
views
/sync.html
→
apollo-portal/src/main/resources/static/
config
/sync.html
View file @
ac2808e1
...
...
@@ -12,7 +12,7 @@
<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"
>
<section
class=
"panel col-md-offset-1 col-md-10"
>
...
...
@@ -175,7 +175,7 @@
</section>
</div>
<div
ng-include=
"'common/footer.html'"
></div>
<div
ng-include=
"'
../views/
common/footer.html'"
></div>
<!--angular-->
<script
src=
"../vendor/angular/angular.min.js"
></script>
...
...
apollo-portal/src/main/resources/static/index.html
View file @
ac2808e1
...
...
@@ -25,7 +25,7 @@
<div
class=
"col-xs-12"
><h1>
Apollo
</h1>
<p>
携程统一配置中心
<br>
<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>
<form
class=
""
role=
"search"
>
...
...
@@ -42,7 +42,7 @@
<div
class=
"container-fluid apollo-container"
>
<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 "
>
<div
class=
"row"
>
<div
class=
"col-md-3"
><h4
class=
"apps-name"
>
{{app.appId}}
</h4></div>
...
...
apollo-portal/src/main/resources/static/namespace.html
0 → 100644
View file @
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
View file @
ac2808e1
...
...
@@ -5,7 +5,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
AppService
.
create
(
'ALL'
,
$scope
.
app
).
then
(
function
(
result
)
{
toastr
.
success
(
'添加成功!'
);
setInterval
(
function
()
{
$window
.
location
.
href
=
'/views/
app
.html?#appid='
+
result
.
appId
;
$window
.
location
.
href
=
'/views/
config
.html?#appid='
+
result
.
appId
;
},
1000
);
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
'添加失败!'
);
...
...
apollo-portal/src/main/resources/static/scripts/controller/LinkNamespaceController.js
0 → 100644
View file @
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
View file @
ac2808e1
...
...
@@ -3,7 +3,6 @@ sync_item_module.controller("SyncItemController",
function
(
$scope
,
$location
,
$window
,
toastr
,
AppService
,
AppUtil
,
ConfigService
)
{
var
params
=
AppUtil
.
parseParams
(
$location
.
$$url
);
var
currentUser
=
'test_user'
;
$scope
.
pageContext
=
{
appId
:
params
.
appid
,
env
:
params
.
env
,
...
...
@@ -115,7 +114,7 @@ sync_item_module.controller("SyncItemController",
};
$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
)
{
...
...
apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js
0 → 100644
View file @
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
View file @
ac2808e1
...
...
@@ -259,3 +259,9 @@ table th {
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
View file @
ac2808e1
...
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
AppServiceTest
.
class
AppServiceTest
.
class
,
NamespaceServiceTest
.
class
})
public
class
AllTests
{
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/ConfigServiceTest.java
View file @
ac2808e1
...
...
@@ -4,12 +4,10 @@ import com.ctrip.apollo.core.ConfigConsts;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
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.ItemDiffs
;
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.service.ConfigService
;
import
com.ctrip.apollo.portal.service.txtresolver.PropertyResolver
;
...
...
@@ -48,51 +46,6 @@ public class ConfigServiceTest {
}
@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
public
void
testUpdateConfigByText
()
{
String
appId
=
"6666"
;
String
clusterName
=
"default"
;
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/NamespaceServiceTest.java
0 → 100644
View file @
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
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment