Search in sources :

Example 6 with SystemAdmin

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

the class TestKafkaSystemAdminJava method testValidateChangelogStreamDelegatesToCreateStream_specialCharsInTopicName.

@Test
public void testValidateChangelogStreamDelegatesToCreateStream_specialCharsInTopicName() {
    final String STREAM = "test.Change_Log.Validate";
    Properties coordProps = new Properties();
    Map<String, ChangelogInfo> changeLogMap = new HashMap<>();
    changeLogMap.put(STREAM, new ChangelogInfo(3, new Properties()));
    KafkaSystemAdmin systemAdmin = createSystemAdmin(coordProps, 3, Util.javaMapAsScalaMap(changeLogMap));
    SystemAdmin admin = Mockito.spy(systemAdmin);
    StreamSpec spec = new StreamSpec("testId", STREAM, "testSystem", 12);
    admin.createChangelogStream(spec.getPhysicalName(), spec.getPartitionCount());
    admin.validateStream(spec);
    // Should not throw
    admin.validateChangelogStream(STREAM, spec.getPartitionCount());
    Mockito.verify(admin).createStream(Mockito.any());
    Mockito.verify(admin, Mockito.times(3)).validateStream(Mockito.any());
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) HashMap(java.util.HashMap) SystemAdmin(org.apache.samza.system.SystemAdmin) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with SystemAdmin

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

the class TestKafkaSystemAdminJava method testCreateChangelogStreamDelegatesToCreateStream_specialCharsInTopicName.

@Test
public void testCreateChangelogStreamDelegatesToCreateStream_specialCharsInTopicName() {
    final String STREAM = "test.Change_Log.Stream";
    final int PARTITIONS = 12;
    final int REP_FACTOR = 3;
    Properties coordProps = new Properties();
    Properties changeLogProps = new Properties();
    changeLogProps.setProperty("cleanup.policy", "compact");
    changeLogProps.setProperty("segment.bytes", "139");
    Map<String, ChangelogInfo> changeLogMap = new HashMap<>();
    changeLogMap.put(STREAM, new ChangelogInfo(REP_FACTOR, changeLogProps));
    SystemAdmin admin = Mockito.spy(createSystemAdmin(coordProps, 3, Util.javaMapAsScalaMap(changeLogMap)));
    StreamSpec spec = new StreamSpec(KafkaSystemAdmin.CHANGELOG_STREAMID(), STREAM, SYSTEM(), PARTITIONS);
    admin.createChangelogStream(STREAM, PARTITIONS);
    admin.validateStream(spec);
    ArgumentCaptor<StreamSpec> specCaptor = ArgumentCaptor.forClass(StreamSpec.class);
    Mockito.verify(admin).createStream(specCaptor.capture());
    StreamSpec internalSpec = specCaptor.getValue();
    // KafkaStreamSpec is used to carry replication factor
    assertTrue(internalSpec instanceof KafkaStreamSpec);
    assertEquals(KafkaSystemAdmin.CHANGELOG_STREAMID(), internalSpec.getId());
    assertEquals(SYSTEM(), internalSpec.getSystemName());
    assertEquals(STREAM, internalSpec.getPhysicalName());
    assertEquals(REP_FACTOR, ((KafkaStreamSpec) internalSpec).getReplicationFactor());
    assertEquals(PARTITIONS, internalSpec.getPartitionCount());
    assertEquals(changeLogProps, ((KafkaStreamSpec) internalSpec).getProperties());
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) HashMap(java.util.HashMap) SystemAdmin(org.apache.samza.system.SystemAdmin) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with SystemAdmin

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

the class TestKafkaSystemAdminJava method testCreateChangelogStreamDelegatesToCreateStream.

@Test
public void testCreateChangelogStreamDelegatesToCreateStream() {
    final String STREAM = "testChangeLogStream";
    final int PARTITIONS = 12;
    final int REP_FACTOR = 3;
    Properties coordProps = new Properties();
    Properties changeLogProps = new Properties();
    changeLogProps.setProperty("cleanup.policy", "compact");
    changeLogProps.setProperty("segment.bytes", "139");
    Map<String, ChangelogInfo> changeLogMap = new HashMap<>();
    changeLogMap.put(STREAM, new ChangelogInfo(REP_FACTOR, changeLogProps));
    SystemAdmin admin = Mockito.spy(createSystemAdmin(coordProps, 3, Util.javaMapAsScalaMap(changeLogMap)));
    StreamSpec spec = new StreamSpec(KafkaSystemAdmin.CHANGELOG_STREAMID(), STREAM, SYSTEM(), PARTITIONS);
    admin.createChangelogStream(STREAM, PARTITIONS);
    admin.validateStream(spec);
    ArgumentCaptor<StreamSpec> specCaptor = ArgumentCaptor.forClass(StreamSpec.class);
    Mockito.verify(admin).createStream(specCaptor.capture());
    StreamSpec internalSpec = specCaptor.getValue();
    // KafkaStreamSpec is used to carry replication factor
    assertTrue(internalSpec instanceof KafkaStreamSpec);
    assertEquals(KafkaSystemAdmin.CHANGELOG_STREAMID(), internalSpec.getId());
    assertEquals(SYSTEM(), internalSpec.getSystemName());
    assertEquals(STREAM, internalSpec.getPhysicalName());
    assertEquals(REP_FACTOR, ((KafkaStreamSpec) internalSpec).getReplicationFactor());
    assertEquals(PARTITIONS, internalSpec.getPartitionCount());
    assertEquals(changeLogProps, ((KafkaStreamSpec) internalSpec).getProperties());
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) HashMap(java.util.HashMap) SystemAdmin(org.apache.samza.system.SystemAdmin) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with SystemAdmin

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

the class SamzaTaskProxy method getJobModel.

/**
   * Retrieves the jobModel from the jobCoordinator.
   * @param jobInstance the job instance (jobId, jobName).
   * @return the JobModel fetched from the coordinator stream.
   */
protected JobModel getJobModel(JobInstance jobInstance) {
    CoordinatorStreamSystemConsumer coordinatorSystemConsumer = null;
    CoordinatorStreamSystemProducer coordinatorSystemProducer = null;
    try {
        CoordinatorStreamSystemFactory coordinatorStreamSystemFactory = new CoordinatorStreamSystemFactory();
        Config coordinatorSystemConfig = getCoordinatorSystemConfig(jobInstance);
        LOG.info("Using config: {} to create coordinatorStream producer and consumer.", coordinatorSystemConfig);
        coordinatorSystemConsumer = coordinatorStreamSystemFactory.getCoordinatorStreamSystemConsumer(coordinatorSystemConfig, METRICS_REGISTRY);
        coordinatorSystemProducer = coordinatorStreamSystemFactory.getCoordinatorStreamSystemProducer(coordinatorSystemConfig, METRICS_REGISTRY);
        LOG.info("Registering coordinator system stream consumer.");
        coordinatorSystemConsumer.register();
        LOG.debug("Starting coordinator system stream consumer.");
        coordinatorSystemConsumer.start();
        LOG.debug("Bootstrapping coordinator system stream consumer.");
        coordinatorSystemConsumer.bootstrap();
        LOG.info("Registering coordinator system stream producer.");
        coordinatorSystemProducer.register(SOURCE);
        Config config = coordinatorSystemConsumer.getConfig();
        LOG.info("Got config from coordinatorSystemConsumer: {}.", config);
        ChangelogPartitionManager changelogManager = new ChangelogPartitionManager(coordinatorSystemProducer, coordinatorSystemConsumer, SOURCE);
        changelogManager.start();
        LocalityManager localityManager = new LocalityManager(coordinatorSystemProducer, coordinatorSystemConsumer);
        localityManager.start();
        String jobCoordinatorSystemName = config.get(JobConfig.JOB_COORDINATOR_SYSTEM());
        /**
       * Select job coordinator system properties from config and instantiate SystemAdmin for it alone.
       * Instantiating SystemAdmin's for other input/output systems defined in config is unnecessary.
       */
        Config systemAdminConfig = config.subset(String.format("systems.%s", jobCoordinatorSystemName), false);
        scala.collection.immutable.Map<String, SystemAdmin> systemAdmins = JobModelManager.getSystemAdmins(systemAdminConfig);
        StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 0, SystemClock.instance());
        Map<TaskName, Integer> changeLogPartitionMapping = changelogManager.readChangeLogPartitionMapping();
        return JobModelManager.readJobModel(config, changeLogPartitionMapping, localityManager, streamMetadataCache, null);
    } finally {
        if (coordinatorSystemConsumer != null) {
            coordinatorSystemConsumer.stop();
        }
        if (coordinatorSystemProducer != null) {
            coordinatorSystemProducer.stop();
        }
    }
}
Also used : StreamMetadataCache(org.apache.samza.system.StreamMetadataCache) JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) StorageConfig(org.apache.samza.config.StorageConfig) Config(org.apache.samza.config.Config) CoordinatorStreamSystemFactory(org.apache.samza.coordinator.stream.CoordinatorStreamSystemFactory) CoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.CoordinatorStreamSystemProducer) CoordinatorStreamSystemConsumer(org.apache.samza.coordinator.stream.CoordinatorStreamSystemConsumer) TaskName(org.apache.samza.container.TaskName) ChangelogPartitionManager(org.apache.samza.storage.ChangelogPartitionManager) SystemAdmin(org.apache.samza.system.SystemAdmin) LocalityManager(org.apache.samza.container.LocalityManager)

Example 10 with SystemAdmin

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

the class TestKafkaSystemAdminJava method testValidateStreamDoesNotExist.

@Test(expected = StreamValidationException.class)
public void testValidateStreamDoesNotExist() {
    SystemAdmin admin = this.basicSystemAdmin;
    StreamSpec spec = new StreamSpec("testId", "testStreamNameExist", "testSystem", 8);
    admin.validateStream(spec);
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemAdmin(org.apache.samza.system.SystemAdmin) Test(org.junit.Test)

Aggregations

SystemAdmin (org.apache.samza.system.SystemAdmin)16 StreamSpec (org.apache.samza.system.StreamSpec)12 HashMap (java.util.HashMap)10 Test (org.junit.Test)10 Properties (java.util.Properties)4 Map (java.util.Map)3 MapConfig (org.apache.samza.config.MapConfig)3 SamzaException (org.apache.samza.SamzaException)2 Config (org.apache.samza.config.Config)2 JobConfig (org.apache.samza.config.JobConfig)2 ApplicationRunner (org.apache.samza.runtime.ApplicationRunner)2 StreamMetadataCache (org.apache.samza.system.StreamMetadataCache)2 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)2 Duration (java.time.Duration)1 Collection (java.util.Collection)1 Set (java.util.Set)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 Partition (org.apache.samza.Partition)1 JavaSystemConfig (org.apache.samza.config.JavaSystemConfig)1