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
daaffa93
Commit
daaffa93
authored
Apr 08, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JPA lifecycle annotation & Integrate env in portal
parent
f4a79c28
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
98 additions
and
55 deletions
+98
-55
App.java
...lo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
+1
-1
BaseEntity.java
...src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
+20
-1
AllTests.java
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
+7
-1
AppRepositoryTest.java
...va/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
+47
-2
application.properties
apollo-biz/src/test/resources/application.properties
+2
-1
import.sql
apollo-biz/src/test/resources/import.sql
+0
-31
AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+20
-12
application.yml
apollo-portal/src/main/resources/application.yml
+1
-6
No files found.
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
View file @
daaffa93
...
@@ -14,7 +14,7 @@ public class App extends BaseEntity {
...
@@ -14,7 +14,7 @@ public class App extends BaseEntity {
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
name
;
private
String
name
;
@Column
(
nullable
=
false
,
unique
=
true
)
@Column
(
nullable
=
false
)
private
String
appId
;
private
String
appId
;
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
View file @
daaffa93
...
@@ -8,6 +8,9 @@ import javax.persistence.Id;
...
@@ -8,6 +8,9 @@ import javax.persistence.Id;
import
javax.persistence.Inheritance
;
import
javax.persistence.Inheritance
;
import
javax.persistence.InheritanceType
;
import
javax.persistence.InheritanceType
;
import
javax.persistence.MappedSuperclass
;
import
javax.persistence.MappedSuperclass
;
import
javax.persistence.PrePersist
;
import
javax.persistence.PreRemove
;
import
javax.persistence.PreUpdate
;
@MappedSuperclass
@MappedSuperclass
@Inheritance
(
strategy
=
InheritanceType
.
TABLE_PER_CLASS
)
@Inheritance
(
strategy
=
InheritanceType
.
TABLE_PER_CLASS
)
...
@@ -17,7 +20,8 @@ public abstract class BaseEntity {
...
@@ -17,7 +20,8 @@ public abstract class BaseEntity {
@GeneratedValue
@GeneratedValue
private
long
id
;
private
long
id
;
private
boolean
isDeleted
;
@Column
(
name
=
"IsDeleted"
)
protected
boolean
isDeleted
;
@Column
(
name
=
"DataChange_CreatedBy"
)
@Column
(
name
=
"DataChange_CreatedBy"
)
private
String
dataChangeCreatedBy
;
private
String
dataChangeCreatedBy
;
...
@@ -78,4 +82,19 @@ public abstract class BaseEntity {
...
@@ -78,4 +82,19 @@ public abstract class BaseEntity {
public
void
setId
(
long
id
)
{
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
this
.
id
=
id
;
}
}
@PrePersist
private
void
prePersist
()
{
if
(
this
.
dataChangeCreatedTime
==
null
)
dataChangeCreatedTime
=
new
Date
();
}
@PreUpdate
private
void
preUpdate
()
{
this
.
dataChangeLastModifiedTime
=
new
Date
();
}
@PreRemove
private
void
preRemove
()
{
this
.
dataChangeLastModifiedTime
=
new
Date
();
}
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
View file @
daaffa93
package
com
.
ctrip
.
apollo
.
biz
;
package
com
.
ctrip
.
apollo
.
biz
;
import
com.ctrip.apollo.biz.repository.AppRepositoryTest
;
import
com.ctrip.apollo.biz.service.AdminServiceTest
;
import
com.ctrip.apollo.biz.service.ConfigServiceTest
;
import
com.ctrip.apollo.biz.service.ConfigServiceTest
;
import
com.ctrip.apollo.biz.service.PrivilegeServiceTest
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite
;
...
@@ -8,7 +11,10 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -8,7 +11,10 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigServiceTest
.
class
})
AppRepositoryTest
.
class
,
AdminServiceTest
.
class
,
ConfigServiceTest
.
class
,
PrivilegeServiceTest
.
class
})
public
class
AllTests
{
public
class
AllTests
{
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
View file @
daaffa93
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -8,6 +9,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
...
@@ -8,6 +9,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
com.ctrip.apollo.biz.SpringTestConfiguration
;
import
com.ctrip.apollo.biz.SpringTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SpringTestConfiguration
.
class
)
@SpringApplicationConfiguration
(
classes
=
SpringTestConfiguration
.
class
)
...
@@ -16,9 +18,52 @@ public class AppRepositoryTest {
...
@@ -16,9 +18,52 @@ public class AppRepositoryTest {
@Autowired
@Autowired
private
AppRepository
appRepository
;
private
AppRepository
appRepository
;
@Before
public
void
before
()
{
appRepository
.
deleteAll
();
}
@Test
@Test
public
void
testListExists
()
{
public
void
testCreate
()
{
Assert
.
assertTrue
(
appRepository
.
count
()
>
0
);
String
appId
=
"someAppId"
;
String
appName
=
"someAppName"
;
String
ownerName
=
"someOwnerName"
;
String
ownerEmail
=
"someOwnerName@ctrip.com"
;
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
appName
);
app
.
setOwnerName
(
ownerName
);
app
.
setOwnerEmail
(
ownerEmail
);
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
appRepository
.
save
(
app
);
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
}
}
@Test
public
void
testRemove
()
{
String
appId
=
"someAppId"
;
String
appName
=
"someAppName"
;
String
ownerName
=
"someOwnerName"
;
String
ownerEmail
=
"someOwnerName@ctrip.com"
;
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
appName
);
app
.
setOwnerName
(
ownerName
);
app
.
setOwnerEmail
(
ownerEmail
);
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
appRepository
.
save
(
app
);
Assert
.
assertEquals
(
1
,
appRepository
.
count
());
appRepository
.
delete
(
app
.
getId
());
Assert
.
assertEquals
(
0
,
appRepository
.
count
());
}
}
}
apollo-biz/src/test/resources/application.properties
View file @
daaffa93
spring.datasource.url
=
jdbc:h2:mem:~/
fxapolloconfigdb;mode=mysql
spring.datasource.url
=
jdbc:h2:mem:~/
apolloconfigdb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE
spring.jpa.hibernate.naming_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.naming_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.show_sql
=
true
spring.h2.console.enabled
=
true
spring.h2.console.enabled
=
true
spring.h2.console.settings.web-allow-others
=
true
spring.h2.console.settings.web-allow-others
=
true
apollo-biz/src/test/resources/import.sql
deleted
100644 → 0
View file @
f4a79c28
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'100003171'
,
'apollo-config-service'
,
'刘一鸣'
,
'liuym@ctrip.com'
);
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'100003172'
,
'apollo-admin-service'
,
'宋顺'
,
'song_s@ctrip.com'
);
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'100003173'
,
'apollo-portal'
,
'张乐'
,
'zhanglea@ctrip.com'
);
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'fxhermesproducer'
,
'fx-hermes-producer'
,
'梁锦华'
,
'jhliang@ctrip.com'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'cluster1'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'cluster2'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'cluster3'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'fxhermesproducer'
,
'default'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'application'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'application'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'application'
);
INSERT
INTO
AppNamespace
(
AppID
,
Name
)
VALUES
(
'fxhermesproducer'
,
'application'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
1
,
'100003171'
,
'default'
,
'application'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
2
,
'fxhermesproducer'
,
'default'
,
'application'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
3
,
'100003172'
,
'default'
,
'application'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
4
,
'100003173'
,
'default'
,
'application'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
5
,
'100003171'
,
'default'
,
'application'
);
INSERT
INTO
Item
(
NamespaceId
,
`Key`
,
Value
,
Comment
)
VALUES
(
1
,
'k1'
,
'v1'
,
'comment1'
);
INSERT
INTO
Item
(
NamespaceId
,
`Key`
,
Value
,
Comment
)
VALUES
(
1
,
'k2'
,
'v2'
,
'comment2'
);
INSERT
INTO
Item
(
NamespaceId
,
`Key`
,
Value
,
Comment
)
VALUES
(
2
,
'k3'
,
'v3'
,
'comment3'
);
INSERT
INTO
Item
(
NamespaceId
,
`Key`
,
Value
,
Comment
)
VALUES
(
5
,
'k3'
,
'v4'
,
'comment4'
);
INSERT
INTO
RELEASE
(
Name
,
Comment
,
AppId
,
ClusterName
,
NamespaceName
,
Configurations
)
VALUES
(
'REV1'
,
'First Release'
,
'100003171'
,
'default'
,
'application'
,
'{"k1":"v1"}'
);
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
View file @
daaffa93
package
com
.
ctrip
.
apollo
.
portal
.
service
;
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.Apollo
;
import
java.util.List
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
@Service
@Service
public
class
AppService
{
public
class
AppService
{
...
@@ -13,18 +16,23 @@ public class AppService {
...
@@ -13,18 +16,23 @@ public class AppService {
@Autowired
@Autowired
private
ClusterService
clusterService
;
private
ClusterService
clusterService
;
public
ClusterNavTree
buildClusterNavTree
(
String
appId
){
@Autowired
ClusterNavTree
tree
=
new
ClusterNavTree
()
;
private
PortalSettings
portalSettings
;
ClusterNavTree
.
Node
localNode
=
new
ClusterNavTree
.
Node
(
Apollo
.
Env
.
LOCAL
);
public
ClusterNavTree
buildClusterNavTree
(
String
appId
)
{
localNode
.
setClusters
(
clusterService
.
findClusters
(
Apollo
.
Env
.
LOCAL
,
appId
));
ClusterNavTree
tree
=
new
ClusterNavTree
();
tree
.
addNode
(
localNode
);
// ClusterNavTree.Node uatNode = new ClusterNavTree.Node(Apollo.Env.UAT);
List
<
Env
>
envs
=
portalSettings
.
getEnvs
();
// List<ClusterDTO> uatClusters = new LinkedList<>();
for
(
Env
env
:
envs
)
{
// uatClusters.add(defaultCluster);
ClusterNavTree
.
Node
clusterNode
=
new
ClusterNavTree
.
Node
(
env
);
// uatNode.setClusters(uatClusters);
clusterNode
.
setClusters
(
clusterService
.
findClusters
(
env
,
appId
));
// tree.addNode(uatNode);
tree
.
addNode
(
clusterNode
);
}
// ClusterNavTree.Node uatNode = new ClusterNavTree.Node(Apollo.Env.UAT);
// List<ClusterDTO> uatClusters = new LinkedList<>();
// uatClusters.add(defaultCluster);
// uatNode.setClusters(uatClusters);
// tree.addNode(uatNode);
return
tree
;
return
tree
;
}
}
...
...
apollo-portal/src/main/resources/application.yml
View file @
daaffa93
...
@@ -4,11 +4,6 @@ server:
...
@@ -4,11 +4,6 @@ server:
spring
:
spring
:
application
:
application
:
name
:
apollo-portal
name
:
apollo-portal
datasource
:
url
:
jdbc:h2:mem:~/fxapolloportaldb
jpa
:
hibernate
:
naming_strategy
:
org.hibernate.cfg.EJB3NamingStrategy
logging
:
logging
:
level
:
level
:
...
@@ -20,4 +15,4 @@ ctrip:
...
@@ -20,4 +15,4 @@ ctrip:
apollo
:
apollo
:
portal
:
portal
:
env
:
local,dev
,fws,uat
env
:
local,dev
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