Search in sources :

Example 1 with SystemAdmins

use of org.apache.samza.system.SystemAdmins in project samza by apache.

the class TestTransactionalStateTaskBackupManager method testGetNewestOffsetsThrowsIfNullSSPMetadata.

@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfNullSSPMetadata() {
    // empty topic == null newest offset
    ContainerStorageManager csm = mock(ContainerStorageManager.class);
    KafkaTransactionalStateTaskBackupManager tsm = buildTSM(csm, mock(Partition.class), new StorageManagerUtil());
    TaskName taskName = mock(TaskName.class);
    String changelogSystemName = "systemName";
    String storeName = "storeName";
    String changelogStreamName = "changelogName";
    String newestChangelogSSPOffset = null;
    SystemStream changelogSystemStream = new SystemStream(changelogSystemName, changelogStreamName);
    Partition changelogPartition = new Partition(0);
    SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSystemStream, changelogPartition);
    java.util.Map<String, SystemStream> storeChangelogs = new HashMap<>();
    storeChangelogs.put(storeName, changelogSystemStream);
    SystemAdmins systemAdmins = mock(SystemAdmins.class);
    SystemAdmin systemAdmin = mock(SystemAdmin.class);
    SystemStreamPartitionMetadata metadata = mock(SystemStreamPartitionMetadata.class);
    when(metadata.getNewestOffset()).thenReturn(newestChangelogSSPOffset);
    when(systemAdmins.getSystemAdmin(changelogSystemName)).thenReturn(systemAdmin);
    java.util.Map metadataMap = new HashMap() {

        {
            put(changelogSSP, null);
        }
    };
    when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(metadataMap);
    // invoke the method
    java.util.Map<String, String> offsets = tsm.getNewestChangelogSSPOffsets(taskName, storeChangelogs, changelogPartition, systemAdmins);
    // verify results
    fail("Should have thrown an exception if admin returned null metadata for changelog SSP");
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) HashMap(java.util.HashMap) SystemStream(org.apache.samza.system.SystemStream) SystemStreamPartitionMetadata(org.apache.samza.system.SystemStreamMetadata.SystemStreamPartitionMetadata) TaskName(org.apache.samza.container.TaskName) SystemAdmin(org.apache.samza.system.SystemAdmin) SystemAdmins(org.apache.samza.system.SystemAdmins) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 2 with SystemAdmins

use of org.apache.samza.system.SystemAdmins in project samza by apache.

the class TestTransactionalStateTaskBackupManager method testGetNewestOffsetsThrowsIfNullMetadata.

@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfNullMetadata() {
    // empty topic == null newest offset
    ContainerStorageManager csm = mock(ContainerStorageManager.class);
    KafkaTransactionalStateTaskBackupManager tsm = buildTSM(csm, mock(Partition.class), new StorageManagerUtil());
    TaskName taskName = mock(TaskName.class);
    String changelogSystemName = "systemName";
    String storeName = "storeName";
    String changelogStreamName = "changelogName";
    String newestChangelogSSPOffset = null;
    SystemStream changelogSystemStream = new SystemStream(changelogSystemName, changelogStreamName);
    Partition changelogPartition = new Partition(0);
    SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSystemStream, changelogPartition);
    java.util.Map<String, SystemStream> storeChangelogs = new HashMap<>();
    storeChangelogs.put(storeName, changelogSystemStream);
    SystemAdmins systemAdmins = mock(SystemAdmins.class);
    SystemAdmin systemAdmin = mock(SystemAdmin.class);
    SystemStreamPartitionMetadata metadata = mock(SystemStreamPartitionMetadata.class);
    when(metadata.getNewestOffset()).thenReturn(newestChangelogSSPOffset);
    when(systemAdmins.getSystemAdmin(changelogSystemName)).thenReturn(systemAdmin);
    when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(null);
    // invoke the method
    java.util.Map<String, String> offsets = tsm.getNewestChangelogSSPOffsets(taskName, storeChangelogs, changelogPartition, systemAdmins);
    // verify results
    fail("Should have thrown an exception if admin didn't return any metadata");
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) HashMap(java.util.HashMap) SystemStream(org.apache.samza.system.SystemStream) SystemStreamPartitionMetadata(org.apache.samza.system.SystemStreamMetadata.SystemStreamPartitionMetadata) TaskName(org.apache.samza.container.TaskName) SystemAdmin(org.apache.samza.system.SystemAdmin) SystemAdmins(org.apache.samza.system.SystemAdmins) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 3 with SystemAdmins

use of org.apache.samza.system.SystemAdmins in project samza by apache.

the class TestTransactionalStateTaskBackupManager method buildTSM.

private KafkaTransactionalStateTaskBackupManager buildTSM(ContainerStorageManager csm, Partition changelogPartition, StorageManagerUtil smu) {
    TaskName taskName = new TaskName("Partition 0");
    java.util.Map<String, SystemStream> changelogSystemStreams = mock(java.util.Map.class);
    SystemAdmins systemAdmins = mock(SystemAdmins.class);
    return new KafkaTransactionalStateTaskBackupManager(taskName, changelogSystemStreams, systemAdmins, changelogPartition);
}
Also used : TaskName(org.apache.samza.container.TaskName) SystemStream(org.apache.samza.system.SystemStream) SystemAdmins(org.apache.samza.system.SystemAdmins)

Example 4 with SystemAdmins

use of org.apache.samza.system.SystemAdmins in project samza by apache.

the class TestTransactionalStateTaskBackupManager method testGetNewestOffsetsReturnsNoneForEmptyTopic.

@Test
public void testGetNewestOffsetsReturnsNoneForEmptyTopic() {
    // empty topic == null newest offset
    ContainerStorageManager csm = mock(ContainerStorageManager.class);
    KafkaTransactionalStateTaskBackupManager tsm = buildTSM(csm, mock(Partition.class), new StorageManagerUtil());
    TaskName taskName = mock(TaskName.class);
    String changelogSystemName = "systemName";
    String storeName = "storeName";
    String changelogStreamName = "changelogName";
    String newestChangelogSSPOffset = null;
    SystemStream changelogSystemStream = new SystemStream(changelogSystemName, changelogStreamName);
    Partition changelogPartition = new Partition(0);
    SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSystemStream, changelogPartition);
    java.util.Map<String, SystemStream> storeChangelogs = new HashMap<String, SystemStream>();
    storeChangelogs.put(storeName, changelogSystemStream);
    SystemAdmins systemAdmins = mock(SystemAdmins.class);
    SystemAdmin systemAdmin = mock(SystemAdmin.class);
    SystemStreamPartitionMetadata metadata = mock(SystemStreamPartitionMetadata.class);
    when(metadata.getNewestOffset()).thenReturn(newestChangelogSSPOffset);
    when(systemAdmins.getSystemAdmin(changelogSystemName)).thenReturn(systemAdmin);
    when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(ImmutableMap.of(changelogSSP, metadata));
    // invoke the method
    java.util.Map<String, String> stateCheckpointMarkerMap = tsm.getNewestChangelogSSPOffsets(taskName, storeChangelogs, changelogPartition, systemAdmins);
    // verify results
    assertEquals(1, stateCheckpointMarkerMap.size());
    KafkaStateCheckpointMarker kscm = KafkaStateCheckpointMarker.deserialize(stateCheckpointMarkerMap.get(storeName));
    assertEquals(changelogSSP, kscm.getChangelogSSP());
    assertNull(kscm.getChangelogOffset());
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) HashMap(java.util.HashMap) SystemStream(org.apache.samza.system.SystemStream) SystemStreamPartitionMetadata(org.apache.samza.system.SystemStreamMetadata.SystemStreamPartitionMetadata) TaskName(org.apache.samza.container.TaskName) SystemAdmin(org.apache.samza.system.SystemAdmin) SystemAdmins(org.apache.samza.system.SystemAdmins) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) KafkaStateCheckpointMarker(org.apache.samza.checkpoint.kafka.KafkaStateCheckpointMarker) Test(org.junit.Test)

Example 5 with SystemAdmins

use of org.apache.samza.system.SystemAdmins in project samza by apache.

the class AzureJobCoordinator method start.

@Override
public void start() {
    LOG.info("Starting Azure job coordinator.");
    // The systemAdmins should be started before streamMetadataCache can be used. And it should be stopped when this coordinator is stopped.
    systemAdmins = new SystemAdmins(config);
    systemAdmins.start();
    streamMetadataCache = new StreamMetadataCache(systemAdmins, METADATA_CACHE_TTL_MS, SystemClock.instance());
    table.addProcessorEntity(INITIAL_STATE, processorId, false);
    // Start scheduler for heartbeating
    LOG.info("Starting scheduler for heartbeating.");
    heartbeat.scheduleTask();
    azureLeaderElector.tryBecomeLeader();
    // Start scheduler to check for job model version upgrades
    LOG.info("Starting scheduler to check for job model version upgrades.");
    versionUpgrade.setStateChangeListener(createJMVersionUpgradeListener());
    versionUpgrade.scheduleTask();
    // Start scheduler to check for leader liveness
    LOG.info("Starting scheduler to check for leader liveness.");
    leaderAlive.setStateChangeListener(createLeaderLivenessListener());
    leaderAlive.scheduleTask();
}
Also used : StreamMetadataCache(org.apache.samza.system.StreamMetadataCache) SystemAdmins(org.apache.samza.system.SystemAdmins)

Aggregations

SystemAdmins (org.apache.samza.system.SystemAdmins)47 SystemAdmin (org.apache.samza.system.SystemAdmin)37 SystemStream (org.apache.samza.system.SystemStream)36 Test (org.junit.Test)35 HashMap (java.util.HashMap)34 Partition (org.apache.samza.Partition)31 TaskName (org.apache.samza.container.TaskName)31 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)31 Config (org.apache.samza.config.Config)30 MapConfig (org.apache.samza.config.MapConfig)29 SystemStreamPartitionMetadata (org.apache.samza.system.SystemStreamMetadata.SystemStreamPartitionMetadata)29 Map (java.util.Map)28 TaskConfig (org.apache.samza.config.TaskConfig)28 Set (java.util.Set)27 File (java.io.File)26 KafkaStateCheckpointMarker (org.apache.samza.checkpoint.kafka.KafkaStateCheckpointMarker)26 TaskModel (org.apache.samza.job.model.TaskModel)26 Clock (org.apache.samza.util.Clock)26 Collections (java.util.Collections)25 SSPMetadataCache (org.apache.samza.system.SSPMetadataCache)25