Commit 13241ea0 by Yiming Liu

Update pom to support actuator

parent 44375b3b
package com.ctrip.apollo.adminservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
import com.ctrip.apollo.biz.service.AppService;
@Component
public class AdminServiceHealthIndicator implements HealthIndicator {
@Autowired
private AppService appService;
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
private int check() {
PageRequest pageable = new PageRequest(0, 1);
appService.findAll(pageable);
return 0;
}
}
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency> <dependency>
......
package com.ctrip.apollo.biz.service; package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.App; import com.ctrip.apollo.biz.entity.App;
...@@ -27,8 +28,12 @@ public class AdminService { ...@@ -27,8 +28,12 @@ public class AdminService {
@Autowired @Autowired
private ClusterRepository clusterRepository; private ClusterRepository clusterRepository;
@Autowired
private CounterService counter;
public App createNewApp(String appId, String appName, String ownerName, String ownerEmail, public App createNewApp(String appId, String appName, String ownerName, String ownerEmail,
String namespace) { String namespace) {
counter.increment("admin.createNewApp.start");
App app = new App(); App app = new App();
app.setAppId(appId); app.setAppId(appId);
app.setName(appName); app.setName(appName);
...@@ -51,7 +56,7 @@ public class AdminService { ...@@ -51,7 +56,7 @@ public class AdminService {
ns.setClusterName(cluster.getName()); ns.setClusterName(cluster.getName());
ns.setNamespaceName(namespace); ns.setNamespaceName(namespace);
namespaceRepository.save(ns); namespaceRepository.save(ns);
counter.increment("admin.createNewApp.success");
return app; return app;
} }
} }
package com.ctrip.apollo.configservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
import com.ctrip.apollo.biz.service.AppService;
@Component
public class ConfigServiceHealthIndicator implements HealthIndicator {
@Autowired
private AppService appService;
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
private int check() {
PageRequest pageable = new PageRequest(0, 1);
appService.findAll(pageable);
return 0;
}
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <parent>
<groupId>com.ctrip.apollo</groupId> <groupId>com.ctrip.apollo</groupId>
<artifactId>apollo</artifactId> <artifactId>apollo</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>apollo-portal</artifactId> <artifactId>apollo-portal</artifactId>
<name>Apollo Portal</name> <name>Apollo Portal</name>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.ctrip.apollo</groupId> <groupId>com.ctrip.apollo</groupId>
<artifactId>apollo-core</artifactId> <artifactId>apollo-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> </dependencies>
<groupId>org.springframework.boot</groupId> <build>
<artifactId>spring-boot-devtools</artifactId> <plugins>
<optional>true</optional> <plugin>
</dependency> <groupId>org.springframework.boot</groupId>
<dependency> <artifactId>spring-boot-maven-plugin</artifactId>
<groupId>org.springframework.boot</groupId> </plugin>
<artifactId>spring-boot-starter-data-jpa</artifactId> </plugins>
</dependency> </build>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> </project>
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