Commit daaffa93 by Yiming Liu

Add JPA lifecycle annotation & Integrate env in portal

parent f4a79c28
......@@ -14,7 +14,7 @@ public class App extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false, unique = true)
@Column(nullable = false)
private String appId;
@Column(nullable = false)
......
......@@ -8,6 +8,9 @@ import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
......@@ -17,7 +20,8 @@ public abstract class BaseEntity {
@GeneratedValue
private long id;
private boolean isDeleted;
@Column(name = "IsDeleted")
protected boolean isDeleted;
@Column(name = "DataChange_CreatedBy")
private String dataChangeCreatedBy;
......@@ -78,4 +82,19 @@ public abstract class BaseEntity {
public void setId(long 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();
}
}
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.PrivilegeServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
......@@ -8,7 +11,10 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
ConfigServiceTest.class})
AppRepositoryTest.class,
AdminServiceTest.class,
ConfigServiceTest.class,
PrivilegeServiceTest.class})
public class AllTests {
}
package com.ctrip.apollo.biz.repository;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -8,6 +9,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ctrip.apollo.biz.SpringTestConfiguration;
import com.ctrip.apollo.biz.entity.App;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SpringTestConfiguration.class)
......@@ -16,9 +18,52 @@ public class AppRepositoryTest {
@Autowired
private AppRepository appRepository;
@Before
public void before() {
appRepository.deleteAll();
}
@Test
public void testListExists() {
Assert.assertTrue(appRepository.count() > 0);
public void testCreate() {
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());
}
}
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.properties.hibernate.show_sql=true
spring.h2.console.enabled = true
spring.h2.console.settings.web-allow-others=true
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"}');
package com.ctrip.apollo.portal.service;
import com.ctrip.apollo.Apollo;
import com.ctrip.apollo.portal.entity.ClusterNavTree;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
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
public class AppService {
......@@ -13,18 +16,23 @@ public class AppService {
@Autowired
private ClusterService clusterService;
public ClusterNavTree buildClusterNavTree(String appId){
ClusterNavTree tree = new ClusterNavTree();
@Autowired
private PortalSettings portalSettings;
ClusterNavTree.Node localNode = new ClusterNavTree.Node(Apollo.Env.LOCAL);
localNode.setClusters(clusterService.findClusters(Apollo.Env.LOCAL, appId));
tree.addNode(localNode);
public ClusterNavTree buildClusterNavTree(String appId) {
ClusterNavTree tree = new ClusterNavTree();
// ClusterNavTree.Node uatNode = new ClusterNavTree.Node(Apollo.Env.UAT);
// List<ClusterDTO> uatClusters = new LinkedList<>();
// uatClusters.add(defaultCluster);
// uatNode.setClusters(uatClusters);
// tree.addNode(uatNode);
List<Env> envs = portalSettings.getEnvs();
for (Env env : envs) {
ClusterNavTree.Node clusterNode = new ClusterNavTree.Node(env);
clusterNode.setClusters(clusterService.findClusters(env, appId));
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;
}
......
......@@ -4,11 +4,6 @@ server:
spring:
application:
name: apollo-portal
datasource:
url: jdbc:h2:mem:~/fxapolloportaldb
jpa:
hibernate:
naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
logging:
level:
......@@ -20,4 +15,4 @@ ctrip:
apollo:
portal:
env: local,dev,fws,uat
env: local,dev
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment