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;
}
}
...@@ -16,28 +16,9 @@ ...@@ -16,28 +16,9 @@
<artifactId>apollo-core</artifactId> <artifactId>apollo-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
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