Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restTemplate for eureka client failed to change status #3571

Closed
q605450469 opened this issue Jun 20, 2019 · 7 comments
Closed

restTemplate for eureka client failed to change status #3571

q605450469 opened this issue Jun 20, 2019 · 7 comments
Labels
Projects

Comments

@q605450469
Copy link

q605450469 commented Jun 20, 2019

I use Eureka Client with RestTemplate instead of Jersey, and send a post request to change status by use the rest api. but i find it doesn't work. And I find the client code in RestTemplateEurekaHttpClient:

public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info) {
        String urlPath = this.serviceUrl + "apps/" + appName + '/' + id + "?status=" + newStatus.name() + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();
        ResponseEntity<Void> response = this.restTemplate.exchange(urlPath, HttpMethod.PUT, (HttpEntity)null, Void.class, new Object[0]);
        return EurekaHttpResponse.anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
    }

but the server-side code like this InstanceResource:

@PUT
    @Path("status")
    public Response statusUpdate(@QueryParam("value") String newStatus, @HeaderParam("x-netflix-discovery-replication") String isReplication, @QueryParam("lastDirtyTimestamp") String lastDirtyTimestamp) {
        try {
            if (this.registry.getInstanceByAppAndId(this.app.getName(), this.id) == null) {
                logger.warn("Instance not found: {}/{}", this.app.getName(), this.id);
                return Response.status(Status.NOT_FOUND).build();
            } else {
                boolean isSuccess = this.registry.statusUpdate(this.app.getName(), this.id, InstanceStatus.valueOf(newStatus), lastDirtyTimestamp, "true".equals(isReplication));
                if (isSuccess) {
                    logger.info("Status updated: " + this.app.getName() + " - " + this.id + " - " + newStatus);
                    return Response.ok().build();
                } else {
                    logger.warn("Unable to update status: " + this.app.getName() + " - " + this.id + " - " + newStatus);
                    return Response.serverError().build();
                }
            }
        } catch (Throwable var5) {
            logger.error("Error updating instance {} for status {}", this.id, newStatus);
            return Response.serverError().build();
        }
    }

I debug the code and find the request like this:

http://127.0.0.1:8761/eureka/apps/TEST.SERVICE.LOCAL/127.0.0.1:test.service.local:8106?status=OUT_OF_SERVICE&lastDirtyTimestamp=1560997426052

Is this a bug?

@spencergibb
Copy link
Member

Can we step back before analyzing code and tell us what you are trying to do and what goes wrong? Are you using RestTemplateEurekaHttpClient directly? If so you really should be using EurekaClient.

"Doesn't work" isn't an effective bug report.

@q605450469
Copy link
Author

Can we step back before analyzing code and tell us what you are trying to do and what goes wrong? Are you using RestTemplateEurekaHttpClient directly? If so you really should be using EurekaClient.

"Doesn't work" isn't an effective bug report.

Sorry, I may not have made myself clear. I mean I have a springCloud project, and I remove the Jersey dependencies. And I want to change the status of my project in eureka from up to out_of_service. so I sent a post request to change it ,like this:
curl -X POST -H "Content-Type: application/json" -d 'out_of_service' 'http://127.0.0.1:9999/service-registry/instance-status'
in other project, it work, but in this project that removed the Jersey dependencies, it doesn't work.
the status is still up in eureka.
so I analyzing code try to find the answer. And I find the rest API actually invoke other rest API by eureka server provided.
InstanceResource.class in eureka-core.jar:

@PUT
    @Path("status")
    public Response statusUpdate(@QueryParam("value") String newStatus, @HeaderParam("x-netflix-discovery-replication") String isReplication, @QueryParam("lastDirtyTimestamp") String lastDirtyTimestamp) {
        try {
            if (this.registry.getInstanceByAppAndId(this.app.getName(), this.id) == null) {
                logger.warn("Instance not found: {}/{}", this.app.getName(), this.id);
                return Response.status(Status.NOT_FOUND).build();
            } else {
                boolean isSuccess = this.registry.statusUpdate(this.app.getName(), this.id, InstanceStatus.valueOf(newStatus), lastDirtyTimestamp, "true".equals(isReplication));
                if (isSuccess) {
                    logger.info("Status updated: " + this.app.getName() + " - " + this.id + " - " + newStatus);
                    return Response.ok().build();
                } else {
                    logger.warn("Unable to update status: " + this.app.getName() + " - " + this.id + " - " + newStatus);
                    return Response.serverError().build();
                }
            }
        } catch (Throwable var5) {
            logger.error("Error updating instance {} for status {}", this.id, newStatus);
            return Response.serverError().build();
        }
    }

And eureka client use Jersey invoke it by default. if eureka client exclude the Jersey dependencies, it will communicate with eureka server by restTemplate.But I find the request url is wrong when I use restTemlate invoke it.
And the request is build by RestTemplateEurekaHttpClient:

public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info) {
        String urlPath = this.serviceUrl + "apps/" + appName + '/' + id + "?status=" + newStatus.name() + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();
        ResponseEntity<Void> response = this.restTemplate.exchange(urlPath, HttpMethod.PUT, (HttpEntity)null, Void.class, new Object[0]);
        return EurekaHttpResponse.anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
    }

so I want to reconfirm that is it a bug or I am using it the wrong way?

thanks.

@ryanjbaxter
Copy link
Contributor

What version of Spring Cloud?

@q605450469
Copy link
Author

q605450469 commented Jun 20, 2019

spring-cloud:Edgware.SR1
spring-cloud-starter-netflix-eureka-client:1.4.2.RELEASE

@ryanjbaxter
Copy link
Contributor

Please try Edgware.SR6

@q605450469
Copy link
Author

still no good
I look up this class RestTemplateEurekaHttpClient in all version, They all look the same.

@ryanjbaxter ryanjbaxter added this to To do in Hoxton.M1 via automation Jun 21, 2019
@ryanjbaxter ryanjbaxter added this to the 2.2.0.M1 milestone Jun 21, 2019
@spencergibb spencergibb added this to To do in Hoxton.M2 via automation Jul 3, 2019
@spencergibb spencergibb removed this from To do in Hoxton.M1 Jul 3, 2019
@spencergibb spencergibb removed this from the 2.2.0.M1 milestone Jul 3, 2019
@yuwzho
Copy link

yuwzho commented Jul 8, 2019

The eureka REST API gives the url like
PUT /eureka/v2/apps/appID/instanceID/status?value=OUT_OF_SERVICE which works with Postman. While the client make the REST call as
PUT /eureka/v2/apps/appID/instanceID?status=OUT_OF_SERVICE

I am not sure why this API still returns 200 OK without any change in Eureka Server side

@spencergibb spencergibb added this to To do in Hoxton.M3 via automation Aug 16, 2019
@spencergibb spencergibb removed this from To do in Hoxton.M2 Aug 16, 2019
ryanjbaxter added a commit to ryanjbaxter/spring-cloud-netflix that referenced this issue Sep 19, 2019
@ryanjbaxter ryanjbaxter moved this from To do to In progress in Hoxton.M3 Sep 19, 2019
Hoxton.M3 automation moved this from In progress to Done Sep 19, 2019
sabareeshkkanan added a commit to sabareeshkkanan/spring-cloud-netflix that referenced this issue Dec 20, 2019
* Added symbolic link of index.adoc

* Added symbolic link of index.adoc

* set replication client filters in RefreshablePeerEurekaNodes (spring-cloud#3610)

fixes spring-cloudgh-3554

* Update SNAPSHOT to 2.2.0.M2

* Going back to snapshots

* Adding spring cloud circuitbreaker hystrix implementation

* Separated circuitbreaker auto config to its own file

* Initialize remoteRegionAppWhitelist with default value (spring-cloud#3634)

* Moves non-netflix dependencies out of bom into root pom.

fixes spring-cloudgh-3639

* Removes dependency management for okhttp3

* Moves okhttp3 dep mgmt back to bom

* Re-create connection manager on "zuul.host.*" property change (spring-cloud#3407)

* Re-create connection manager on "zuul.host.*" property change 

Fixes spring-cloud#3406

* Wrap connectionManager.shutdown() in try/catch block. Polishing

* Removes okhttp3 again after added back in older branch.

* Updating readme with note about building spring-cloud-netflix-hystrix-contract.  Fixes spring-cloud#3497

* Fromatting

* Upgrades eureka to 1.9.13 and excludes compactmap.

fixes spring-cloudgh-3636

* Update SNAPSHOT to 2.1.3.RELEASE

* Going back to snapshots

* Bumping versions to 2.1.4.BUILD-SNAPSHOT after release

* Add Spring Cloud LoadBalancer starter to Eureka starters. Fixes spring-cloudgh-3646. (spring-cloud#3647)

* Update docs. (spring-cloud#3650)

* ConditionalOnMissingBean on formBodyWrapperFilter, debugFilter… (spring-cloud#3609)

* Bumping versions

* Remove spring.provides.

* removes useless comments

* Fix RestTemplateEurekaHttpClient status update endpoint.  Fixes spring-cloud#3571 (spring-cloud#3657)

* polish

* Updates health check handler to use new StatusAggregator

* Gh 3409 turbine stream test (spring-cloud#3665)

* Add stream-test-support.

* Fix condition.

* Remove outdated workaround.

* Bumping versions

* Optimize code of eureka (spring-cloud#3660)

* Optimize code of eureka

* Merge newest code

* fix checkstyle bug

* Gh 3464 upgrade scc new (spring-cloud#3667)

* Upgrade Spring Cloud Contract version to 2.1.3.RELEASE.

* Gh 3409 turbine stream test (spring-cloud#3665)

* Add stream-test-support.

* Fix condition.

* Remove outdated workaround.

(cherry picked from commit 24f5e0b)

* Updates to use "components" rather than "details"

See spring-projects/spring-boot#17929

* Applying spring-cloud#3407 to the 2.1.x branch

* Added support for reactive service discovery

* Update SNAPSHOT to 2.2.0.M3

* Going back to snapshots

* Update SNAPSHOT to 2.2.0.RC1

* Going back to snapshots

* removing resource class from circle config

* Add property to disable spring cloud circuit breaker for hystrix

* Fix command key configuration.  Use id as command key and class as group key.

* Adding configuration metadata for spring cloud circuitbreaker

* Bumping versions

* Fix some dependencies that show up in the wrong scope

Apparently you can build on the command line but Eclipse is fussy
now and wouldn't compile these projects without explicit
dependencies.

* Also add build helper config for contract tests

* Added maven flatten plugin

* Bumping versions

* Update SNAPSHOT to 2.2.0.RC2

* Going back to snapshots

* Update configuration to use proxyBeanMethods=false.  Fixes spring-cloud#3677

* Create security.md

* Update issue templates

* Bumping versions

* Bumping versions

* Update SNAPSHOT to 2.2.0.RELEASE

* Going back to snapshots

* Bumping versions to 2.2.1.BUILD-SNAPSHOT after release

* Bumping versions

* Fix typo: clas -> class (spring-cloud#3710)

* removes .flattened-pom.xml

* ignores .flattened-pom.xml

* Gh 3718 add zoned loadbalancer instrumentation (spring-cloud#3720)

* Add instrumentation for zoned LoadBalancer.

* Add documentation.

* Fix after review.

* Fix after review.

* Update SNAPSHOT to 2.2.1.RELEASE

* Going back to snapshots

* Bumping versions to 2.2.2.BUILD-SNAPSHOT after release

Co-authored-by: Marcin Grzejszczak <marcin@grzejszczak.pl>
Co-authored-by: Yuxin Bai <LittleBaiBai@users.noreply.github.com>
Co-authored-by: Spencer Gibb <spencer@gibb.tech>
Co-authored-by: Spring Buildmaster <buildmaster@springframework.org>
Co-authored-by: Ryan Baxter <rbaxter@pivotal.io>
Co-authored-by: emilnkrastev <emilnkrastev@gmail.com>
Co-authored-by: Denys Ivano <denys.ivano@gmail.com>
Co-authored-by: Olga Maciaszek-Sharma <olga.maciaszek@gmail.com>
Co-authored-by: Rafał Żukowski <rzukow@gmail.com>
Co-authored-by: OLPMO <OLPMO@users.noreply.github.com>
Co-authored-by: Tim Ysewyn <Tim.Ysewyn@me.com>
Co-authored-by: Dave Syer <david_syer@hotmail.com>
Co-authored-by: Deepika Mohan <deepikadevidm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Hoxton.M3
  
Done
Development

No branches or pull requests

5 participants