Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void run() {
//create necessary checkpoint and changelog streams, if not created
JobModel jobModel = jobModelManager.jobModel();
MetadataResourceUtil metadataResourceUtil =
new MetadataResourceUtil(jobModel, this.metrics, getClass().getClassLoader());
new MetadataResourceUtil(jobModel, this.metrics, getClass().getClassLoader(), config);
metadataResourceUtil.createResources();

// fan out the startpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.annotations.VisibleForTesting;
import org.apache.samza.checkpoint.CheckpointManager;
import org.apache.samza.config.Config;
import org.apache.samza.config.TaskConfig;
import org.apache.samza.job.model.JobModel;
import org.apache.samza.metrics.MetricsRegistry;
Expand All @@ -33,24 +34,20 @@
// TODO: Replace with a metadata admin interface when the {@link MetadataStore} is fully augmented to handle all metadata sources.
public class MetadataResourceUtil {
private final CheckpointManager checkpointManager;
private final Config config;
private final JobModel jobModel; // TODO: Should be loaded by metadata store in the future

/**
* @param jobModel the loaded {@link JobModel}
* @param metricsRegistry the registry for reporting metrics.
*/
public MetadataResourceUtil(JobModel jobModel, MetricsRegistry metricsRegistry, ClassLoader classLoader) {
public MetadataResourceUtil(JobModel jobModel, MetricsRegistry metricsRegistry, ClassLoader classLoader, Config config) {
this.config = config;
this.jobModel = jobModel;
TaskConfig taskConfig = new TaskConfig(jobModel.getConfig());
TaskConfig taskConfig = new TaskConfig(config);
this.checkpointManager = taskConfig.getCheckpointManager(metricsRegistry, classLoader).orElse(null);
}

@VisibleForTesting
MetadataResourceUtil(CheckpointManager checkpointManager, JobModel jobModel) {
this.jobModel = jobModel;
this.checkpointManager = checkpointManager;
}

/**
* Creates and loads the required metadata resources for checkpoints, changelog stream and other
* resources related to the metadata system
Expand All @@ -62,7 +59,13 @@ public void createResources() {
createChangelogStreams();
}

@VisibleForTesting
void createChangelogStreams() {
ChangelogStreamManager.createChangelogStreams(jobModel.getConfig(), jobModel.maxChangeLogStreamPartitions);
ChangelogStreamManager.createChangelogStreams(config, jobModel.maxChangeLogStreamPartitions);
Comment thread
dnishimura marked this conversation as resolved.
}

@VisibleForTesting
CheckpointManager getCheckpointManager() {
return checkpointManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void start() {
try {
jobModel = getJobModel();
// TODO metrics registry has been null here for a while; is it safe?
MetadataResourceUtil metadataResourceUtil = new MetadataResourceUtil(jobModel, null, getClass().getClassLoader());
MetadataResourceUtil metadataResourceUtil = new MetadataResourceUtil(jobModel, null, getClass().getClassLoader(), config);
metadataResourceUtil.createResources();
Comment thread
dnishimura marked this conversation as resolved.
} catch (Exception e) {
LOGGER.error("Exception while trying to getJobModel.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ JobModel readJobModelFromMetadataStore(String zkJobModelVersion) {
@VisibleForTesting
void loadMetadataResources(JobModel jobModel) {
try {
MetadataResourceUtil metadataResourceUtil = createMetadataResourceUtil(jobModel, getClass().getClassLoader());
MetadataResourceUtil metadataResourceUtil = createMetadataResourceUtil(jobModel, getClass().getClassLoader(), config);
metadataResourceUtil.createResources();

if (coordinatorStreamStore != null) {
Expand Down Expand Up @@ -343,8 +343,8 @@ void loadMetadataResources(JobModel jobModel) {
}

@VisibleForTesting
MetadataResourceUtil createMetadataResourceUtil(JobModel jobModel, ClassLoader classLoader) {
return new MetadataResourceUtil(jobModel, metrics.getMetricsRegistry(), classLoader);
MetadataResourceUtil createMetadataResourceUtil(JobModel jobModel, ClassLoader classLoader, Config config) {
return new MetadataResourceUtil(jobModel, metrics.getMetricsRegistry(), classLoader, config);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ProcessJobFactory extends StreamJobFactory with Logging {
changelogStreamManager.writePartitionMapping(taskPartitionMappings)

//create necessary checkpoint and changelog streams
val metadataResourceUtil = new MetadataResourceUtil(jobModel, metricsRegistry, classLoader)
val metadataResourceUtil = new MetadataResourceUtil(jobModel, metricsRegistry, classLoader, config)
metadataResourceUtil.createResources()

// fan out the startpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ThreadJobFactory extends StreamJobFactory with Logging {
changelogStreamManager.writePartitionMapping(taskPartitionMappings)

//create necessary checkpoint and changelog streams
val metadataResourceUtil = new MetadataResourceUtil(jobModel, metricsRegistry, classLoader)
val metadataResourceUtil = new MetadataResourceUtil(jobModel, metricsRegistry, classLoader, config)
metadataResourceUtil.createResources()

// fan out the startpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,60 @@

package org.apache.samza.coordinator;

import com.google.common.collect.ImmutableMap;
import org.apache.samza.checkpoint.CheckpointManager;
import org.apache.samza.checkpoint.CheckpointManagerFactory;
import org.apache.samza.config.Config;
import org.apache.samza.config.MapConfig;
import org.apache.samza.config.TaskConfig;
import org.apache.samza.job.model.JobModel;
import org.apache.samza.metrics.MetricsRegistry;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;


public class TestMetadataResourceUtil {
private CheckpointManager checkpointManager;
private JobModel jobModel;
private JobModel mockJobModel;
private MetricsRegistry mockMetricsRegistry;

@Before
public void setUp() {
checkpointManager = Mockito.mock(CheckpointManager.class);
jobModel = Mockito.mock(JobModel.class);
mockJobModel = Mockito.mock(JobModel.class);
mockMetricsRegistry = Mockito.mock(MetricsRegistry.class);
}

@Test
public void testLoad() {
MetadataResourceUtil metadataResourceUtil = Mockito.spy(new MetadataResourceUtil(checkpointManager, jobModel));
public void testLoadWithCheckpointConfigured() {
MapConfig mapConfig = new MapConfig(ImmutableMap.of(TaskConfig.CHECKPOINT_MANAGER_FACTORY,
TestCheckpointManagerFactory.class.getName()));
MetadataResourceUtil metadataResourceUtil = Mockito.spy(new MetadataResourceUtil(mockJobModel, mockMetricsRegistry, getClass().getClassLoader(), mapConfig));
Mockito.doNothing().when(metadataResourceUtil).createChangelogStreams();

metadataResourceUtil.createResources();
Mockito.verify(checkpointManager).createResources();
Mockito.verify(mockJobModel, Mockito.never()).getConfig(); // Never get config from job model. In standalone, this is empty.
Mockito.verify(metadataResourceUtil.getCheckpointManager()).createResources();
Mockito.verify(metadataResourceUtil).createChangelogStreams();
}


@Test
public void testLoadWithoutCheckpointConfigured() {
MapConfig mapConfig = new MapConfig();
MetadataResourceUtil metadataResourceUtil = Mockito.spy(new MetadataResourceUtil(mockJobModel, mockMetricsRegistry, getClass().getClassLoader(), mapConfig));
Mockito.doNothing().when(metadataResourceUtil).createChangelogStreams();

metadataResourceUtil.createResources();
Mockito.verify(mockJobModel, Mockito.never()).getConfig(); // Never get config from job model. In standalone, this is empty.
Assert.assertNull(metadataResourceUtil.getCheckpointManager());
Mockito.verify(metadataResourceUtil).createChangelogStreams();
}

public static class TestCheckpointManagerFactory implements CheckpointManagerFactory {
@Override
public CheckpointManager getCheckpointManager(Config config, MetricsRegistry registry) {
return Mockito.mock(CheckpointManager.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void testLoadMetadataResources() throws IOException {

MetadataResourceUtil mockMetadataResourceUtil = mock(MetadataResourceUtil.class);
doReturn(mockMetadataResourceUtil).when(zkJobCoordinator)
.createMetadataResourceUtil(any(), eq(getClass().getClassLoader()));
.createMetadataResourceUtil(any(), eq(getClass().getClassLoader()), any(Config.class));

verifyZeroInteractions(mockStartpointManager);

Expand Down