Search in sources :

Example 1 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestContainerHeartbeatMonitor method testFailedToFetchNewAMCoordinatorUrl.

@Test
public void testFailedToFetchNewAMCoordinatorUrl() throws InterruptedException {
    this.containerHeartbeatMonitor = spy(buildContainerHeartbeatMonitor(true));
    CoordinatorStreamValueSerde serde = new CoordinatorStreamValueSerde(SetConfig.TYPE);
    ContainerHeartbeatMonitor.ContainerHeartbeatMetrics metrics = this.containerHeartbeatMonitor.getMetrics();
    when(this.containerHeartbeatClient.requestHeartbeat()).thenReturn(FAILURE_RESPONSE);
    when(this.coordinatorStreamStore.get(CoordinationConstants.YARN_COORDINATOR_URL)).thenReturn(serde.toBytes(COORDINATOR_URL));
    this.containerHeartbeatMonitor.start();
    // wait for the executor to finish the heartbeat check task
    boolean fixedRateTaskCompleted = this.schedulerFixedRateExecutionLatch.await(2, TimeUnit.SECONDS);
    assertTrue("Did not complete heartbeat check", fixedRateTaskCompleted);
    assertEquals("Heartbeat expired count should be 1", 1, metrics.getHeartbeatExpiredCount().getCount());
    assertEquals("Heartbeat established failure count should be 1", 1, metrics.getHeartbeatEstablishedFailureCount().getCount());
    // shutdown task should have been submitted
    verify(this.scheduler).schedule(any(Runnable.class), eq((long) ContainerHeartbeatMonitor.SHUTDOWN_TIMOUT_MS), eq(TimeUnit.MILLISECONDS));
    verify(this.onExpired).run();
    this.containerHeartbeatMonitor.stop();
    verify(this.scheduler).shutdown();
}
Also used : CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Test(org.junit.Test)

Example 2 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class ZkJobCoordinator method loadMetadataResources.

/**
 * Stores the configuration of the job in the coordinator stream.
 */
@VisibleForTesting
void loadMetadataResources(JobModel jobModel) {
    try {
        MetadataResourceUtil metadataResourceUtil = createMetadataResourceUtil(jobModel, config);
        metadataResourceUtil.createResources();
        if (coordinatorStreamStore != null) {
            // TODO: SAMZA-2273 - publish configs async
            CoordinatorStreamValueSerde jsonSerde = new CoordinatorStreamValueSerde(SetConfig.TYPE);
            NamespaceAwareCoordinatorStreamStore configStore = new NamespaceAwareCoordinatorStreamStore(coordinatorStreamStore, SetConfig.TYPE);
            for (Map.Entry<String, String> entry : config.entrySet()) {
                byte[] serializedValue = jsonSerde.toBytes(entry.getValue());
                configStore.put(entry.getKey(), serializedValue);
            }
            configStore.flush();
            if (new JobConfig(config).getStartpointEnabled()) {
                // fan out the startpoints
                StartpointManager startpointManager = createStartpointManager();
                startpointManager.start();
                try {
                    startpointManager.fanOut(JobModelUtil.getTaskToSystemStreamPartitions(jobModel));
                } finally {
                    startpointManager.stop();
                }
            }
        } else {
            LOG.warn("No metadata store registered to this job coordinator. Config not written to the metadata store and no Startpoints fan out.");
        }
    } catch (IOException ex) {
        throw new SamzaException(String.format("IO exception while loading metadata resources."), ex);
    }
}
Also used : NamespaceAwareCoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore) StartpointManager(org.apache.samza.startpoint.StartpointManager) IOException(java.io.IOException) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Map(java.util.Map) HashMap(java.util.HashMap) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestJobCoordinatorMetadataManager method testReadJobCoordinatorMetadataFailed.

@Test
public void testReadJobCoordinatorMetadataFailed() {
    JobCoordinatorMetadata jobCoordinatorMetadata = new JobCoordinatorMetadata(NEW_EPOCH_ID, NEW_CONFIG_ID, NEW_JOB_MODEL_ID);
    Serde<String> mockSerde = spy(new CoordinatorStreamValueSerde(SetJobCoordinatorMetadataMessage.TYPE));
    doThrow(new RuntimeException("Failed to read coordinator stream")).when(mockSerde).fromBytes(any());
    jobCoordinatorMetadataManager = spy(new JobCoordinatorMetadataManager(metadataStore, ClusterType.YARN, new MetricsRegistryMap(), mockSerde));
    jobCoordinatorMetadataManager.writeJobCoordinatorMetadata(jobCoordinatorMetadata);
    JobCoordinatorMetadata actualMetadata = jobCoordinatorMetadataManager.readJobCoordinatorMetadata();
    assertNull("Read failed should return null", actualMetadata);
    assertEquals("Metadata read failed count should be 1", 1, jobCoordinatorMetadataManager.getMetrics().getMetadataReadFailedCount().getValue().intValue());
}
Also used : JobCoordinatorMetadata(org.apache.samza.job.JobCoordinatorMetadata) Matchers.anyString(org.mockito.Matchers.anyString) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Test(org.junit.Test)

Example 4 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestZkLocalApplicationRunner method getConfigFromCoordinatorStream.

private MapConfig getConfigFromCoordinatorStream(Config config) {
    MetadataStoreFactory metadataStoreFactory = ReflectionUtil.getObj(new JobConfig(config).getMetadataStoreFactory(), MetadataStoreFactory.class);
    MetadataStore metadataStore = metadataStoreFactory.getMetadataStore("set-config", config, new MetricsRegistryMap());
    metadataStore.init();
    Map<String, String> configMap = new HashMap<>();
    CoordinatorStreamValueSerde jsonSerde = new CoordinatorStreamValueSerde("set-config");
    metadataStore.all().forEach((key, value) -> {
        CoordinatorStreamStore.CoordinatorMessageKey coordinatorMessageKey = CoordinatorStreamStore.deserializeCoordinatorMessageKeyFromJson(key);
        String deserializedValue = jsonSerde.fromBytes(value);
        configMap.put(coordinatorMessageKey.getKey(), deserializedValue);
    });
    return new MapConfig(configMap);
}
Also used : MetadataStore(org.apache.samza.metadatastore.MetadataStore) ZkMetadataStore(org.apache.samza.zk.ZkMetadataStore) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) MetadataStoreFactory(org.apache.samza.metadatastore.MetadataStoreFactory) CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) JobConfig(org.apache.samza.config.JobConfig)

Example 5 with CoordinatorStreamValueSerde

use of org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde in project samza by apache.

the class TestContainerHeartbeatMonitor method testReestablishConnectionWithNewAM.

@Test
public void testReestablishConnectionWithNewAM() throws InterruptedException {
    String newCoordinatorUrl = "http://some-host-2.prod.linkedin.com";
    this.containerHeartbeatMonitor = spy(buildContainerHeartbeatMonitor(true));
    CoordinatorStreamValueSerde serde = new CoordinatorStreamValueSerde(SetConfig.TYPE);
    ContainerHeartbeatMonitor.ContainerHeartbeatMetrics metrics = this.containerHeartbeatMonitor.getMetrics();
    when(this.containerHeartbeatClient.requestHeartbeat()).thenReturn(FAILURE_RESPONSE).thenReturn(SUCCESS_RESPONSE);
    when(this.containerHeartbeatMonitor.createContainerHeartbeatClient(newCoordinatorUrl, CONTAINER_EXECUTION_ID)).thenReturn(this.containerHeartbeatClient);
    when(this.coordinatorStreamStore.get(CoordinationConstants.YARN_COORDINATOR_URL)).thenReturn(serde.toBytes(newCoordinatorUrl));
    this.containerHeartbeatMonitor.start();
    // wait for the executor to finish the heartbeat check task
    boolean fixedRateTaskCompleted = this.schedulerFixedRateExecutionLatch.await(2, TimeUnit.SECONDS);
    assertTrue("Did not complete heartbeat check", fixedRateTaskCompleted);
    assertEquals("Heartbeat expired count should be 1", 1, metrics.getHeartbeatExpiredCount().getCount());
    assertEquals("Heartbeat established failure count should be 0", 0, metrics.getHeartbeatEstablishedFailureCount().getCount());
    assertEquals("Heartbeat established with new AM should be 1", 1, metrics.getHeartbeatEstablishedWithNewAmCount().getCount());
    // shutdown task should not have been submitted
    verify(this.scheduler, never()).schedule(any(Runnable.class), anyLong(), any());
    verify(this.onExpired, never()).run();
    this.containerHeartbeatMonitor.stop();
    verify(this.scheduler).shutdown();
}
Also used : CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) Test(org.junit.Test)

Aggregations

CoordinatorStreamValueSerde (org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde)8 Test (org.junit.Test)6 HashMap (java.util.HashMap)2 JobConfig (org.apache.samza.config.JobConfig)2 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 IOException (java.io.IOException)1 Map (java.util.Map)1 SamzaException (org.apache.samza.SamzaException)1 MapConfig (org.apache.samza.config.MapConfig)1 MetadataResourceUtil (org.apache.samza.coordinator.MetadataResourceUtil)1 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)1 NamespaceAwareCoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore)1 MockCoordinatorStreamSystemFactory (org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory)1 JobCoordinatorMetadata (org.apache.samza.job.JobCoordinatorMetadata)1 MetadataStore (org.apache.samza.metadatastore.MetadataStore)1 MetadataStoreFactory (org.apache.samza.metadatastore.MetadataStoreFactory)1 StartpointManager (org.apache.samza.startpoint.StartpointManager)1 ZkMetadataStore (org.apache.samza.zk.ZkMetadataStore)1 Matchers.anyString (org.mockito.Matchers.anyString)1