Search in sources :

Example 6 with EurekaHttpResponse

use of com.netflix.discovery.shared.transport.EurekaHttpResponse in project eureka by Netflix.

the class Jersey2ReplicationClient method sendHeartBeat.

/**
     * Compared to regular heartbeat, in the replication channel the server may return a more up to date
     * instance copy.
     */
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {
    String urlPath = "apps/" + appName + '/' + id;
    Response response = null;
    try {
        WebTarget webResource = jerseyClient.target(serviceUrl).path(urlPath).queryParam("status", info.getStatus().toString()).queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString());
        if (overriddenStatus != null) {
            webResource = webResource.queryParam("overriddenstatus", overriddenStatus.name());
        }
        Builder requestBuilder = webResource.request();
        addExtraHeaders(requestBuilder);
        // Jersey2 refuses to handle PUT with no body
        response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).put(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE));
        InstanceInfo infoFromPeer = null;
        if (response.getStatus() == Status.CONFLICT.getStatusCode() && response.hasEntity()) {
            infoFromPeer = response.readEntity(InstanceInfo.class);
        }
        return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : EurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse) EurekaHttpResponse.anEurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse) ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 7 with EurekaHttpResponse

use of com.netflix.discovery.shared.transport.EurekaHttpResponse in project eureka by Netflix.

the class Jersey2ReplicationClient method statusUpdate.

@Override
public EurekaHttpResponse<Void> statusUpdate(String asgName, ASGStatus newStatus) {
    Response response = null;
    try {
        String urlPath = "asg/" + asgName + "/status";
        response = jerseyClient.target(serviceUrl).path(urlPath).queryParam("value", newStatus.name()).request().header(PeerEurekaNode.HEADER_REPLICATION, "true").put(Entity.text(""));
        return EurekaHttpResponse.status(response.getStatus());
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : EurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse) EurekaHttpResponse.anEurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse) ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response)

Example 8 with EurekaHttpResponse

use of com.netflix.discovery.shared.transport.EurekaHttpResponse in project eureka by Netflix.

the class AbstractJersey2EurekaHttpClient method register.

@Override
public EurekaHttpResponse<Void> register(InstanceInfo info) {
    String urlPath = "apps/" + info.getAppName();
    Response response = null;
    try {
        Builder resourceBuilder = jerseyClient.target(serviceUrl).path(urlPath).request();
        addExtraProperties(resourceBuilder);
        addExtraHeaders(resourceBuilder);
        response = resourceBuilder.accept(MediaType.APPLICATION_JSON).acceptEncoding("gzip").post(Entity.json(info));
        return anEurekaHttpResponse(response.getStatus()).headers(headersOf(response)).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey2 HTTP POST {}/{} with instance {}; statusCode={}", serviceUrl, urlPath, info.getId(), response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : EurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse) EurekaHttpResponse.anEurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse) Response(javax.ws.rs.core.Response) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(javax.ws.rs.client.Invocation.Builder)

Example 9 with EurekaHttpResponse

use of com.netflix.discovery.shared.transport.EurekaHttpResponse in project eureka by Netflix.

the class AbstractJersey2EurekaHttpClient method getApplicationsInternal.

private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath, String[] regions) {
    Response response = null;
    try {
        WebTarget webTarget = jerseyClient.target(serviceUrl).path(urlPath);
        if (regions != null && regions.length > 0) {
            webTarget = webTarget.queryParam("regions", StringUtil.join(regions));
        }
        Builder requestBuilder = webTarget.request();
        addExtraProperties(requestBuilder);
        addExtraHeaders(requestBuilder);
        response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get();
        Applications applications = null;
        if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
            applications = response.readEntity(Applications.class);
        }
        return anEurekaHttpResponse(response.getStatus(), applications).headers(headersOf(response)).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey2 HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : EurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse) EurekaHttpResponse.anEurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse) Response(javax.ws.rs.core.Response) Applications(com.netflix.discovery.shared.Applications) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget)

Example 10 with EurekaHttpResponse

use of com.netflix.discovery.shared.transport.EurekaHttpResponse in project eureka by Netflix.

the class AbstractJersey2EurekaHttpClient method statusUpdate.

@Override
public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus, InstanceInfo info) {
    String urlPath = "apps/" + appName + '/' + id + "/status";
    Response response = null;
    try {
        Builder requestBuilder = jerseyClient.target(serviceUrl).path(urlPath).queryParam("value", newStatus.name()).queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).request();
        addExtraProperties(requestBuilder);
        addExtraHeaders(requestBuilder);
        // Jersey2 refuses to handle PUT with no body
        response = requestBuilder.put(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE));
        return anEurekaHttpResponse(response.getStatus()).headers(headersOf(response)).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey2 HTTP PUT {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : EurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse) EurekaHttpResponse.anEurekaHttpResponse(com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse) Response(javax.ws.rs.core.Response) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(javax.ws.rs.client.Invocation.Builder)

Aggregations

EurekaHttpResponse (com.netflix.discovery.shared.transport.EurekaHttpResponse)11 EurekaHttpResponse.anEurekaHttpResponse (com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse)11 Response (javax.ws.rs.core.Response)11 Builder (javax.ws.rs.client.Invocation.Builder)9 EurekaHttpResponseBuilder (com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder)8 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)3 WebTarget (javax.ws.rs.client.WebTarget)3 Application (com.netflix.discovery.shared.Application)1 Applications (com.netflix.discovery.shared.Applications)1