Search in sources :

Example 6 with ReplicationListResponse

use of com.netflix.eureka.cluster.protocol.ReplicationListResponse in project eureka by Netflix.

the class ReplicationTaskProcessor method process.

@Override
public ProcessingResult process(List<ReplicationTask> tasks) {
    ReplicationList list = createReplicationListOf(tasks);
    try {
        EurekaHttpResponse<ReplicationListResponse> response = replicationClient.submitBatchUpdates(list);
        int statusCode = response.getStatusCode();
        if (!isSuccess(statusCode)) {
            if (statusCode == 503) {
                logger.warn("Server busy (503) HTTP status code received from the peer {}; rescheduling tasks after delay", peerId);
                return ProcessingResult.Congestion;
            } else {
                // Unexpected error returned from the server. This should ideally never happen.
                logger.error("Batch update failure with HTTP status code {}; discarding {} replication tasks", statusCode, tasks.size());
                return ProcessingResult.PermanentError;
            }
        } else {
            handleBatchResponse(tasks, response.getEntity().getResponseList());
        }
    } catch (Throwable e) {
        if (isNetworkConnectException(e)) {
            logNetworkErrorSample(null, e);
            return ProcessingResult.TransientError;
        } else {
            logger.error("Not re-trying this exception because it does not seem to be a network exception", e);
            return ProcessingResult.PermanentError;
        }
    }
    return ProcessingResult.Success;
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList)

Example 7 with ReplicationListResponse

use of com.netflix.eureka.cluster.protocol.ReplicationListResponse in project eureka by Netflix.

the class TestableHttpReplicationClient method submitBatchUpdates.

@Override
public EurekaHttpResponse<ReplicationListResponse> submitBatchUpdates(ReplicationList replicationList) {
    if (networkFailureCounter.get() < networkFailuresRepeatCount) {
        networkFailureCounter.incrementAndGet();
        throw new RuntimeException(new IOException("simulated network failure"));
    }
    if (processingDelayMs > 0) {
        try {
            Thread.sleep(processingDelayMs);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    List<ReplicationInstanceResponse> responseList = new ArrayList<>();
    responseList.add(new ReplicationInstanceResponse(batchStatusCode, instanceInfoFromPeer));
    ReplicationListResponse replicationListResponse = new ReplicationListResponse(responseList);
    handledRequests.add(new HandledRequest(RequestType.Batch, replicationList));
    int statusCode = networkStatusCodes[callCounter.getAndIncrement()];
    return anEurekaHttpResponse(statusCode, replicationListResponse).type(MediaType.APPLICATION_JSON_TYPE).build();
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)7 ReplicationInstanceResponse (com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)4 ReplicationList (com.netflix.eureka.cluster.protocol.ReplicationList)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 CodecWrapper (com.netflix.discovery.converters.wrappers.CodecWrapper)1 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)1 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)1 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)1 EurekaHttpResponse (com.netflix.discovery.shared.transport.EurekaHttpResponse)1 EurekaHttpResponse.anEurekaHttpResponse (com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse)1 ReplicationInstance (com.netflix.eureka.cluster.protocol.ReplicationInstance)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 IOException (java.io.IOException)1 Response (javax.ws.rs.core.Response)1