Search in sources :

Example 1 with ContainerPlacementMessage

use of org.apache.samza.container.placement.ContainerPlacementMessage in project samza by apache.

the class TestContainerPlacementObjectMapper method testContainerPlacementRequestMessage.

private void testContainerPlacementRequestMessage(ContainerPlacementRequestMessage requestMessage) throws IOException {
    ObjectMapper objectMapper = ContainerPlacementMessageObjectMapper.getObjectMapper();
    ContainerPlacementMessage message = objectMapper.readValue(objectMapper.writeValueAsString(requestMessage), ContainerPlacementMessage.class);
    assertTrue(message instanceof ContainerPlacementRequestMessage);
    ContainerPlacementRequestMessage deserializedRequest = (ContainerPlacementRequestMessage) message;
    assertEquals(requestMessage, deserializedRequest);
}
Also used : ContainerPlacementMessage(org.apache.samza.container.placement.ContainerPlacementMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ContainerPlacementRequestMessage(org.apache.samza.container.placement.ContainerPlacementRequestMessage)

Example 2 with ContainerPlacementMessage

use of org.apache.samza.container.placement.ContainerPlacementMessage in project samza by apache.

the class TestContainerPlacementObjectMapper method testContainerPlacementResponseMessage.

private void testContainerPlacementResponseMessage(ContainerPlacementResponseMessage responseMessage) throws IOException {
    ObjectMapper objectMapper = ContainerPlacementMessageObjectMapper.getObjectMapper();
    ContainerPlacementMessage message = objectMapper.readValue(objectMapper.writeValueAsString(responseMessage), ContainerPlacementMessage.class);
    assertTrue(message instanceof ContainerPlacementResponseMessage);
    ContainerPlacementResponseMessage deserializedResponse = (ContainerPlacementResponseMessage) message;
    assertEquals(responseMessage, deserializedResponse);
}
Also used : ContainerPlacementMessage(org.apache.samza.container.placement.ContainerPlacementMessage) ContainerPlacementResponseMessage(org.apache.samza.container.placement.ContainerPlacementResponseMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ContainerPlacementMessage

use of org.apache.samza.container.placement.ContainerPlacementMessage in project samza by apache.

the class ContainerPlacementMetadataStore method readAllContainerPlacementRequestMessages.

@VisibleForTesting
List<ContainerPlacementRequestMessage> readAllContainerPlacementRequestMessages() {
    Preconditions.checkState(!stopped, "Underlying metadata store not available");
    List<ContainerPlacementRequestMessage> newActions = new ArrayList<>();
    Map<String, byte[]> messageBytes = containerPlacementMessageStore.all();
    for (byte[] action : messageBytes.values()) {
        try {
            ContainerPlacementMessage message = objectMapper.readValue(action, ContainerPlacementMessage.class);
            if (message instanceof ContainerPlacementRequestMessage) {
                newActions.add((ContainerPlacementRequestMessage) message);
            }
        } catch (IOException e) {
            throw new SamzaException(e);
        }
    }
    // Sort the actions in order of timestamp
    newActions.sort(Comparator.comparingLong(ContainerPlacementRequestMessage::getTimestamp));
    return newActions;
}
Also used : ContainerPlacementMessage(org.apache.samza.container.placement.ContainerPlacementMessage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException) ContainerPlacementRequestMessage(org.apache.samza.container.placement.ContainerPlacementRequestMessage) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ContainerPlacementMessage (org.apache.samza.container.placement.ContainerPlacementMessage)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ContainerPlacementRequestMessage (org.apache.samza.container.placement.ContainerPlacementRequestMessage)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 SamzaException (org.apache.samza.SamzaException)1 ContainerPlacementResponseMessage (org.apache.samza.container.placement.ContainerPlacementResponseMessage)1