Search in sources :

Example 6 with ReplicationList

use of com.netflix.eureka.cluster.protocol.ReplicationList 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 (maybeReadTimeOut(e)) {
            logger.error("It seems to be a socket read timeout exception, it will retry later. if it continues to happen and some eureka node occupied all the cpu time, you should set property 'eureka.server.peer-node-read-timeout-ms' to a bigger value", e);
            // read timeout exception is more Congestion then TransientError, return Congestion for longer delay
            return ProcessingResult.Congestion;
        } else 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 ReplicationList

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

the class PeerReplicationResourceTest method testCancelBatching.

@Test
public void testCancelBatching() throws Exception {
    when(instanceResource.cancelLease(anyString())).thenReturn(Response.ok().build());
    ReplicationList replicationList = new ReplicationList(newReplicationInstanceOf(Action.Cancel, instanceInfo));
    Response response = peerReplicationResource.batchReplication(replicationList);
    assertStatusOkReply(response);
    verify(instanceResource, times(1)).cancelLease("true");
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) Test(org.junit.Test)

Example 8 with ReplicationList

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

the class PeerReplicationResourceTest method testDeleteStatusOverride.

@Test
public void testDeleteStatusOverride() throws Exception {
    when(instanceResource.deleteStatusUpdate(anyString(), anyString(), anyString())).thenReturn(Response.ok().build());
    ReplicationInstance replicationInstance = newReplicationInstanceOf(Action.DeleteStatusOverride, instanceInfo);
    Response response = peerReplicationResource.batchReplication(new ReplicationList(replicationInstance));
    assertStatusOkReply(response);
    verify(instanceResource, times(1)).deleteStatusUpdate("true", replicationInstance.getStatus(), Long.toString(replicationInstance.getLastDirtyTimestamp()));
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) Test(org.junit.Test)

Example 9 with ReplicationList

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

the class PeerReplicationResourceTest method testHeartbeat.

@Test
public void testHeartbeat() throws Exception {
    when(instanceResource.renewLease(anyString(), anyString(), anyString(), anyString())).thenReturn(Response.ok().build());
    ReplicationInstance replicationInstance = newReplicationInstanceOf(Action.Heartbeat, instanceInfo);
    Response response = peerReplicationResource.batchReplication(new ReplicationList(replicationInstance));
    assertStatusOkReply(response);
    verify(instanceResource, times(1)).renewLease("true", replicationInstance.getOverriddenStatus(), instanceInfo.getStatus().name(), Long.toString(replicationInstance.getLastDirtyTimestamp()));
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) Test(org.junit.Test)

Example 10 with ReplicationList

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

the class PeerReplicationResourceTest method testConflictResponseReturnsTheInstanceInfoInTheResponseEntity.

@Test
public void testConflictResponseReturnsTheInstanceInfoInTheResponseEntity() throws Exception {
    when(instanceResource.renewLease(anyString(), anyString(), anyString(), anyString())).thenReturn(Response.status(Status.CONFLICT).entity(instanceInfo).build());
    ReplicationInstance replicationInstance = newReplicationInstanceOf(Action.Heartbeat, instanceInfo);
    Response response = peerReplicationResource.batchReplication(new ReplicationList(replicationInstance));
    assertStatusIsConflict(response);
    assertResponseEntityExist(response);
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) Response(javax.ws.rs.core.Response) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) Test(org.junit.Test)

Aggregations

ReplicationList (com.netflix.eureka.cluster.protocol.ReplicationList)10 ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)8 Test (org.junit.Test)8 ReplicationInstance (com.netflix.eureka.cluster.protocol.ReplicationInstance)7 ReplicationInstanceResponse (com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)7 Response (javax.ws.rs.core.Response)6 InstanceInfo (com.netflix.appinfo.InstanceInfo)2 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 HandledRequest (com.netflix.eureka.cluster.TestableHttpReplicationClient.HandledRequest)1 ArrayList (java.util.ArrayList)1