I need to stop the Master node during the acceptance test of the Alpha cluster 
mode, It test the slave node can automatically switch to the master status. So 
I need to know Alpha state is Master or Slave, I want to use the custom 
actuator endpoint to implement the Alpha state query interface.

> My question is how can you tell Alpha which kind of Actuator(Spring
> Boot 1.x or Spring Boot 2.x) you want to use.

Configured by profile (e.g -Pspring-boot-1 or -Pspring-boot-2 ) when building 
Alpha Server

张 磊
------------------------------------------------
部门: 亿阳信通IT运维支撑产品线
地址: 北京市海淀区杏石口路99号西山赢府商务中心2410 
邮编: 100093
手机: 18610099300
移邮:zhang_...@boco.com.cn

> 在 2019年1月31日,下午9:03,Willem Jiang <willem.ji...@gmail.com> 写道:
> 
> Hi,
> 
> You don't need to pass all the code here.  You can show your proposal
> by telling us what you want to do with Actuator.
> My question is how can you tell Alpha which kind of Actuator(Spring
> Boot 1.x or Spring Boot 2.x) you want to use.
> 
> Willem Jiang
> 
> Twitter: willemjiang
> Weibo: 姜宁willem
> 
> On Thu, Jan 31, 2019 at 1:40 PM <zhang_...@boco.com.cn> wrote:
>> 
>> 1. I want to extend management based on Actuator in Alpha,But the custom  of 
>> Actuator is not compatible in spring boot 1.x and spring boot 2.x
>> I think it can be solved by adding  alpha-spring-boot-compatibility module, 
>> alpha-spring-boot-compatibility contains alpha-spring-boot-1-starter and 
>> alpha-spring-boot-2-starter.
>> 
>> 
>> Customize Alpha Endpoint in spring boot 1.x
>> package org.apache.servicecomb.pack.alpha.server.actuate.endpoint;
>> 
>> import org.apache.servicecomb.pack.alpha.core.NodeStatus;
>> import org.apache.servicecomb.pack.alpha.core.actuate.endpoint.AlphaStatus;
>> import org.springframework.boot.actuate.endpoint.Endpoint;
>> import org.springframework.boot.context.properties.ConfigurationProperties;
>> import org.springframework.stereotype.Component;
>> 
>> @ConfigurationProperties(prefix = "endpoints.alpha")
>> @Component
>> public class AlphaEndpoint implements Endpoint {
>> 
>>  public static final String END_POINT_ID = "alpha";
>> 
>>  private AlphaStatus alphaStatus = new AlphaStatus();
>> 
>>  @Override
>>  public String getId() {
>>    return END_POINT_ID;
>>  }
>> 
>>  @Override
>>  public boolean isEnabled() {
>>    return true;
>>  }
>> 
>>  @Override
>>  public boolean isSensitive() {
>>    return false;
>>  }
>> 
>>  @Override
>>  public AlphaStatus invoke() {
>>    alphaStatus.setNodeType(NodeStatus.TypeEnum.MASTER);
>>    return alphaStatus;
>>  }
>> 
>> }
>> 
>> 
>> Customize Alpha Endpoint in spring boot 2.x
>> package org.apache.servicecomb.pack.alpha.server.actuate.endpoint;
>> 
>> import org.apache.servicecomb.pack.alpha.core.NodeStatus;
>> import org.apache.servicecomb.pack.alpha.core.actuate.endpoint.AlphaStatus;
>> import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
>> import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
>> import org.springframework.context.annotation.Configuration;
>> 
>> 
>> @Configuration
>> @Endpoint(id = "alpha")
>> public class AlphaEndPoint {
>> 
>>  private AlphaStatus alphaStatus = new AlphaStatus();
>> 
>>  @ReadOperation
>>  public AlphaStatus endpoint() {
>>    alphaStatus.setNodeType(NodeStatus.TypeEnum.MASTER);
>>    return alphaStatus;
>>  }
>> }
>> 
>> 
>> Add dependencies in Alpha server,it version same ${spring.boot.version}
>> <dependency>
>>  <groupId>org.apache.servicecomb.pack</groupId>
>>  <artifactId>alpha-spring-boot-starter</artifactId>
>>  <version>${spring.boot.version}</version>
>> </dependency>
>> 
>> 2. Additional features
>> Same Actuator Endpoint access path with spring boot 1.x and spring boot 2.x
>> Customized ActuatorEndpoint compatible spring boot 2.x actuator in spring 
>> boot 1.x, You can access it via http://127.0.0 
>> <http://127.0.0/>.1/actuator/xxx when using spring boot 1.x
>> 
>> Define ActuatorEndpoint class
>> package org.apache.servicecomb.pack.alpha.server.actuate.endpoint;
>> 
>> import org.springframework.beans.factory.annotation.Autowired;
>> import org.springframework.boot.actuate.endpoint.Endpoint;
>> import org.springframework.stereotype.Component;
>> 
>> import java.util.List;
>> 
>> @Component
>> public class ActuatorEndpoint implements Endpoint<List<Endpoint>> {
>> 
>>  @Autowired
>>  private List<Endpoint> endpoints;
>> 
>>  @Override
>>  public String getId() {
>>    return "actuator";
>>  }
>> 
>>  @Override
>>  public boolean isEnabled() {
>>    return true;
>>  }
>> 
>>  @Override
>>  public boolean isSensitive() {
>>    return false;
>>  }
>> 
>>  @Override
>>  public List<Endpoint> invoke() {
>>    return endpoints;
>>  }
>> }
>> Define ActuatorMvcEndpoint class
>> package org.apache.servicecomb.pack.alpha.server.actuate.endpoint.mvc;
>> 
>> import 
>> org.apache.servicecomb.pack.alpha.server.actuate.endpoint.ActuatorEndpoint;
>> import org.springframework.beans.factory.annotation.Autowired;
>> import org.springframework.boot.actuate.endpoint.Endpoint;
>> import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
>> import org.springframework.stereotype.Component;
>> import org.springframework.web.bind.annotation.*;
>> 
>> import java.util.Optional;
>> import java.util.function.Predicate;
>> import java.util.function.Supplier;
>> 
>> import static java.util.Optional.ofNullable;
>> 
>> @Component
>> public class ActuatorMvcEndpoint extends EndpointMvcAdapter {
>> 
>>  private final ActuatorEndpoint delegate;
>> 
>>  @Autowired
>>  public ActuatorMvcEndpoint(ActuatorEndpoint delegate) {
>>    super(delegate);
>>    this.delegate = delegate;
>>  }
>> 
>>  @RequestMapping(value = "/{endpoint}", method = RequestMethod.GET)
>>  @ResponseBody
>>  public Object endpoint(@PathVariable("endpoint") String id, 
>> @RequestParam(required = false) Boolean enabled,
>>                         @RequestParam(required = false) Boolean sensitive) {
>>    Predicate<Endpoint> isEnabled =
>>            endpoint -> matches(endpoint::isEnabled, ofNullable(enabled));
>> 
>>    Predicate<Endpoint> isSensitive =
>>            endpoint -> matches(endpoint::isSensitive, ofNullable(sensitive));
>> 
>>    Predicate<Endpoint> matchEndPoint =
>>            endpoint -> matches(endpoint::getId, ofNullable(id));
>> 
>>    return this.delegate.invoke().stream()
>>            .filter(matchEndPoint.and(isEnabled.and(isSensitive)))
>>            .findAny().get().invoke();
>>  }
>> 
>>  private <T> boolean matches(Supplier<T> supplier, Optional<T> value) {
>>    return !value.isPresent() || supplier.get().equals(value.get());
>>  }
>> }
>> 
>> 
>> 张 磊
>> ------------------------------------------------
>> 部门: 亿阳信通IT运维支撑产品线
>> 地址: 北京市海淀区杏石口路99号西山赢府商务中心2410
>> 邮编: 100093
>> 手机: 18610099300
>> 移邮:zhang_...@boco.com.cn <mailto:zhang_...@boco.com.cn>
>> 

Reply via email to