聊聊eureka instance的overriddenstatus

本文主要研究一下eureka instance的overriddenstatus

overriddenstatus

eureka-client-1.8.8-sources.jar!/com/netflix/appinfo/InstanceInfo.java

        /**
         * Sets the status overridden by some other external process.This is
         * mostly used in putting an instance out of service to block traffic to
         * it.
         *
         * @param status the overridden {@link InstanceStatus} of the instance.
         * @return @return the {@link InstanceInfo} builder.
         */
        public Builder setOverriddenStatus(InstanceStatus status) {
            result.overriddenstatus = status;
            return this;
        }

通过注释可以看到,这个overriddenstatus的意思就是用于外部的一些操作,在netflix里头就是用于red/black部署的时候,先把指定服务设置为OUT_OF_SERVICE来故意关闭请求流量。

1_r6qGvK49cv_9A8b4OCAZZw.png

InstanceStatus枚举定义如下:

    public enum InstanceStatus {
        UP, // Ready to receive traffic
        DOWN, // Do not send traffic- healthcheck callback failed
        STARTING, // Just about starting- initializations to be done - do not
        // send traffic
        OUT_OF_SERVICE, // Intentionally shutdown for traffic
        UNKNOWN;

        public static InstanceStatus toEnum(String s) {
            if (s != null) {
                try {
                    return InstanceStatus.valueOf(s.toUpperCase());
                } catch (IllegalArgumentException e) {
                    // ignore and fall through to unknown
                    logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN);
                }
            }
            return UNKNOWN;
        }
    }

操作

设置OUT_OF_SERVICE

curl -i -X PUT http://localhost:8761/eureka/apps/client1/127.0.0.1:client1:8081/status?value=OUT_OF_SERVICE
HTTP/1.1 200
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 May 2018 06:52:29 GMT

删除OUT_OF_SERVICE

curl -i -X DELETE http://localhost:8761/eureka/apps/client1/127.0.0.1:client1:8081/status
HTTP/1.1 200
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 May 2018 06:54:30 GM

小结

eureka instance的overriddenstatus对于部署来说非常好用,比如red/black升级,将部分原服务先设置为OUT_OF_SERVICE,停止接收请求,即变为black,之后新部署的服务启动起来,即为red。如果新服务正常,就可以关闭旧服务了,假设新服务出现问题,则立马删除掉新服务,将原有服务的overriddenstatus删除掉,恢复UP,恢复接收流量。

doc

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,798评论 19 139
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,164评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,487评论 0 23
  • Eric纪阅读 1,157评论 0 0
  • 1.一位旅行者走在拉萨的市中心,看着宏伟的布达拉宫,走在以前他坐在电脑前查询西藏自治区旅游网站熟悉而陌生的街道上...
    昂贵的青春阅读 2,990评论 0 0