Search in sources :

Example 11 with ContainerPlacementRequestMessage

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

the class TestContainerPlacementMetadataStore method testReadWriteContainerPlacementResponseMessages.

@Test
public void testReadWriteContainerPlacementResponseMessages() {
    ContainerPlacementResponseMessage messageWrittenToMetastore = new ContainerPlacementResponseMessage(UUID.randomUUID(), "app-attempt-001", Integer.toString(new Random().nextInt(5)), "ANY_HOST", ContainerPlacementMessage.StatusCode.BAD_REQUEST, "Request ignored redundant", System.currentTimeMillis());
    containerPlacementMetadataStore.writeContainerPlacementResponseMessage(messageWrittenToMetastore);
    Optional<ContainerPlacementResponseMessage> messageReadFromMetastore = containerPlacementMetadataStore.readContainerPlacementResponseMessage(messageWrittenToMetastore.getUuid());
    Assert.assertTrue(messageReadFromMetastore.isPresent());
    Assert.assertEquals(messageWrittenToMetastore, messageReadFromMetastore.get());
    // Request store must not contain anything
    Optional<ContainerPlacementRequestMessage> readNull = containerPlacementMetadataStore.readContainerPlacementRequestMessage(messageWrittenToMetastore.getUuid());
    Assert.assertTrue(!readNull.isPresent());
    // No request messages should exist
    Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementRequestMessage(messageWrittenToMetastore.getUuid()).isPresent());
    Assert.assertTrue(containerPlacementMetadataStore.getContainerPlacementStore().all().size() == 1);
}
Also used : Random(java.util.Random) ContainerPlacementResponseMessage(org.apache.samza.container.placement.ContainerPlacementResponseMessage) ContainerPlacementRequestMessage(org.apache.samza.container.placement.ContainerPlacementRequestMessage) Test(org.junit.Test)

Example 12 with ContainerPlacementRequestMessage

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

the class TestContainerPlacementMetadataStore method testReadWriteContainerPlacementRequestMessages.

@Test
public void testReadWriteContainerPlacementRequestMessages() {
    Long timestamp = System.currentTimeMillis();
    UUID uuid = containerPlacementMetadataStore.writeContainerPlacementRequestMessage("app-attempt-001", "4", "ANY_HOST", null, timestamp);
    Optional<ContainerPlacementRequestMessage> messageReadFromMetastore = containerPlacementMetadataStore.readContainerPlacementRequestMessage(uuid);
    Assert.assertTrue(messageReadFromMetastore.isPresent());
    assertContainerPlacementRequestMessage(uuid, "app-attempt-001", "4", "ANY_HOST", null, timestamp, messageReadFromMetastore.get());
    // Check for non existent key
    Optional<ContainerPlacementRequestMessage> readNull = containerPlacementMetadataStore.readContainerPlacementRequestMessage(UUID.randomUUID());
    Assert.assertTrue(!readNull.isPresent());
    // No response messages should exist
    Assert.assertTrue(!containerPlacementMetadataStore.readContainerPlacementResponseMessage(uuid).isPresent());
    Assert.assertEquals(1, containerPlacementMetadataStore.readAllContainerPlacementRequestMessages().size());
}
Also used : UUID(java.util.UUID) ContainerPlacementRequestMessage(org.apache.samza.container.placement.ContainerPlacementRequestMessage) Test(org.junit.Test)

Example 13 with ContainerPlacementRequestMessage

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

the class TestContainerPlacementObjectMapper method testIncomingContainerMessageSerDe.

@Test
public void testIncomingContainerMessageSerDe() throws IOException {
    testContainerPlacementRequestMessage(new ContainerPlacementRequestMessage(UUID.randomUUID(), "app-attempt-001", "4", "ANY_HOST", System.currentTimeMillis()));
    testContainerPlacementRequestMessage(new ContainerPlacementRequestMessage(UUID.randomUUID(), "app-attempt-001", "4", "ANY_HOST", Duration.ofSeconds(10), System.currentTimeMillis()));
}
Also used : ContainerPlacementRequestMessage(org.apache.samza.container.placement.ContainerPlacementRequestMessage) Test(org.junit.Test)

Example 14 with ContainerPlacementRequestMessage

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

the class ContainerPlacementMetadataStore method readContainerPlacementRequestMessage.

/**
 * Reads a {@link ContainerPlacementRequestMessage} from the underlying metastore
 * @param uuid uuid of the request
 * @return ContainerPlacementRequestMessage if present
 */
public Optional<ContainerPlacementRequestMessage> readContainerPlacementRequestMessage(UUID uuid) {
    Preconditions.checkState(!stopped, "Underlying metadata store not available");
    Preconditions.checkNotNull(uuid, "uuid cannot be null");
    byte[] messageBytes = containerPlacementMessageStore.get(toContainerPlacementMessageKey(uuid, ContainerPlacementRequestMessage.class));
    if (ArrayUtils.isNotEmpty(messageBytes)) {
        try {
            ContainerPlacementRequestMessage requestMessage = (ContainerPlacementRequestMessage) objectMapper.readValue(messageBytes, ContainerPlacementMessage.class);
            return Optional.of(requestMessage);
        } catch (IOException e) {
            throw new SamzaException(String.format("Error reading the ContainerPlacementResponseMessage for uuid: %s", uuid), e);
        }
    }
    return Optional.empty();
}
Also used : ContainerPlacementMessage(org.apache.samza.container.placement.ContainerPlacementMessage) IOException(java.io.IOException) SamzaException(org.apache.samza.SamzaException) ContainerPlacementRequestMessage(org.apache.samza.container.placement.ContainerPlacementRequestMessage)

Aggregations

ContainerPlacementRequestMessage (org.apache.samza.container.placement.ContainerPlacementRequestMessage)14 Test (org.junit.Test)8 ContainerPlacementMetadata (org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadata)6 ContainerPlacementResponseMessage (org.apache.samza.container.placement.ContainerPlacementResponseMessage)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 IOException (java.io.IOException)3 SamzaException (org.apache.samza.SamzaException)3 ContainerPlacementMessage (org.apache.samza.container.placement.ContainerPlacementMessage)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 UUID (java.util.UUID)2 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)2 MapConfig (org.apache.samza.config.MapConfig)2 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1