scala.collection.immutable.Map Java Examples

The following examples show how to use scala.collection.immutable.Map. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveOldCheckpointsWhenBaseDirContainsRegularFiles() {
  TaskName taskName = new TaskName("Partition 0");
  ContainerStorageManager containerStorageManager = mock(ContainerStorageManager.class);
  Map<String, SystemStream> changelogSystemStreams = mock(Map.class);
  SystemAdmins systemAdmins = mock(SystemAdmins.class);
  File loggedStoreBaseDir = mock(File.class);
  Partition changelogPartition = new Partition(0);
  TaskMode taskMode = TaskMode.Active;
  StorageManagerUtil storageManagerUtil = mock(StorageManagerUtil.class);

  File mockStoreDir = mock(File.class);
  String mockStoreDirName = "notDirectory";

  when(loggedStoreBaseDir.listFiles()).thenReturn(new File[] {mockStoreDir});
  when(mockStoreDir.getName()).thenReturn(mockStoreDirName);
  when(storageManagerUtil.getTaskStoreDir(eq(loggedStoreBaseDir), eq(mockStoreDirName), eq(taskName), eq(taskMode))).thenReturn(mockStoreDir);
  // null here can happen if listFiles is called on a non-directory
  when(mockStoreDir.listFiles(any(FileFilter.class))).thenReturn(null);

  TransactionalStateTaskStorageManager tsm = new TransactionalStateTaskStorageManager(taskName, containerStorageManager,
      changelogSystemStreams, systemAdmins, loggedStoreBaseDir, changelogPartition, taskMode, storageManagerUtil);

  tsm.removeOldCheckpoints(CheckpointId.create());
}
 
Example #2
Source File: FinagleContextInteropTest.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override public Scope newScope(TraceContext currentSpan) {
  Map<Buf, MarshalledContext.Cell> saved = broadcast().env();
  Map<Buf, MarshalledContext.Cell> update;
  if (currentSpan != null) { // replace the existing trace context with this one
    update = broadcast().env().updated(
      TRACE_ID_KEY.marshalId(),
      broadcast().Real().apply(TRACE_ID_KEY, new Some(toTraceId(currentSpan)))
    );
  } else { // remove the existing trace context from scope
    update = broadcast().env().filterKeys(
      new AbstractFunction1<Buf, Object>() {
        @Override public Object apply(Buf v1) {
          return !v1.equals(TRACE_ID_KEY.marshalId());
        }
      });
  }
  broadcastLocal.set(new Some(update));
  return () -> broadcastLocal.set(new Some(saved));
}
 
Example #3
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlushOrder() {
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  StorageEngine mockStore = mock(StorageEngine.class);
  java.util.Map<String, StorageEngine> taskStores = ImmutableMap.of("mockStore", mockStore);
  when(csm.getAllStores(any())).thenReturn(taskStores);

  TransactionalStateTaskStorageManager tsm = spy(buildTSM(csm, mock(Partition.class), new StorageManagerUtil()));
  // stub actual method call
  doReturn(mock(Map.class)).when(tsm).getNewestChangelogSSPOffsets(any(), any(), any(), any());

  // invoke flush
  tsm.flush();

  // ensure that stores are flushed before we get newest changelog offsets
  InOrder inOrder = inOrder(mockStore, tsm);
  inOrder.verify(mockStore).flush();
  inOrder.verify(tsm).getNewestChangelogSSPOffsets(any(), any(), any(), any());
}
 
Example #4
Source File: InfoExtractorTest.java    From dr-elephant with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadInfoSparkNoConfig() {
  Map<String,String> properties = new HashMap<String,String>();

  AppResult result = new AppResult();

  HadoopApplicationData data = new SparkApplicationData("application_5678",
      properties,
      new ApplicationInfoImpl("", "", new Vector<ApplicationAttemptInfoImpl>(0,1,0)),
      new Vector<JobData>(0,1,0),
      new Vector<StageData>(0,1,0),
      new Vector<ExecutorSummary>(0,1,0));

  // test to make sure loadInfo does not throw exception if properties are not defined
  InfoExtractor.loadInfo(result, data);

  assertTrue(result.jobDefId.isEmpty());
  assertTrue(result.jobExecId.isEmpty());
  assertTrue(result.flowDefId.isEmpty());
  assertTrue(result.flowExecId.isEmpty());
}
 
Example #5
Source File: SubStringCounterDataSource.java    From net.jgp.labs.spark with Apache License 2.0 6 votes vote down vote up
@Override
public BaseRelation createRelation(SQLContext arg0, Map<String,
    String> arg1) {
  log.debug("-> createRelation()");

  java.util.Map<String, String> javaMap = scala.collection.JavaConverters
      .mapAsJavaMapConverter(arg1).asJava();

  SubStringCounterRelation br = new SubStringCounterRelation();
  br.setSqlContext(arg0);

  for (java.util.Map.Entry<String, String> entry : javaMap.entrySet()) {
    String key = entry.getKey();
    String value = entry.getValue();
    log.debug("[{}] --> [{}]", key, value);
    if (key.compareTo(K.PATH) == 0) {
      br.setFilename(value);
    } else if (key.startsWith(K.COUNT)) {
      br.addCriteria(value);
    }
  }

  return br;
}
 
Example #6
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
private java.util.Map<String, scala.collection.immutable.Set<TSentryPrivilege>> getRoleToPrivileges(final List<String> roles) {
    final java.util.Map<String, scala.collection.immutable.Set<TSentryPrivilege>> rolePrivilegesMap = new HashMap<>();
    execute(new Command<Void>() {
        @Override
        public Void run(SentryGenericServiceClient client) throws Exception {
            for (String role : roles) {
                final Set<TSentryPrivilege> rolePrivileges = client.listPrivilegesByRoleName(
                    requestorName, role, COMPONENT_NAME, instanceName);
                final scala.collection.immutable.Set<TSentryPrivilege> rolePrivilegesScala =
                    scala.collection.JavaConverters.asScalaSetConverter(rolePrivileges).asScala().toSet();
                rolePrivilegesMap.put(role, rolePrivilegesScala);
            }
            return null;
        }
    });

    return rolePrivilegesMap;
}
 
Example #7
Source File: SentryKafkaAuthorizer.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(java.util.Map<String, ?> configs) {
  final Object sentryKafkaSiteUrlConfig = configs.get(KafkaAuthConf.SENTRY_KAFKA_SITE_URL);
  if (sentryKafkaSiteUrlConfig != null) {
    this.sentry_site = sentryKafkaSiteUrlConfig.toString();
  }
  final Object kafkaSuperUsersConfig = configs.get(KafkaAuthConf.KAFKA_SUPER_USERS);
  if (kafkaSuperUsersConfig != null) {
    getSuperUsers(kafkaSuperUsersConfig.toString());
  }
  final Object kafkaServiceInstanceName = configs.get(KafkaAuthConf.KAFKA_SERVICE_INSTANCE_NAME);
  if (kafkaServiceInstanceName != null) {
    this.kafkaServiceInstanceName = kafkaServiceInstanceName.toString();
  }
  final Object kafkaServiceUserName = configs.get(KafkaAuthConf.KAFKA_SERVICE_USER_NAME);
  if (kafkaServiceUserName != null) {
    this.requestorName = kafkaServiceUserName.toString();
  }
  LOG.info("Configuring Sentry KafkaAuthorizer: " + sentry_site);
  final KafkaAuthBindingSingleton instance = KafkaAuthBindingSingleton.getInstance();
  instance.configure(this.kafkaServiceInstanceName, this.requestorName, sentry_site);
  this.binding = instance.getAuthBinding();
}
 
Example #8
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testCheckpointFailsIfErrorCreatingCheckpoint() {
  ContainerStorageManager csm = mock(ContainerStorageManager.class);

  StorageEngine mockLPStore = mock(StorageEngine.class);
  StoreProperties lpStoreProps = mock(StoreProperties.class);
  when(mockLPStore.getStoreProperties()).thenReturn(lpStoreProps);
  when(lpStoreProps.isPersistedToDisk()).thenReturn(true);
  when(lpStoreProps.isLoggedStore()).thenReturn(true);
  when(mockLPStore.checkpoint(any())).thenThrow(new IllegalStateException());
  java.util.Map<String, StorageEngine> taskStores =
      ImmutableMap.of("loggedPersistentStore", mockLPStore);
  when(csm.getAllStores(any())).thenReturn(taskStores);

  TransactionalStateTaskStorageManager tsm = spy(buildTSM(csm, mock(Partition.class), new StorageManagerUtil()));

  Map<SystemStreamPartition, Option<String>> offsets = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(mock(SystemStreamPartition.class), Option.apply("1")));

  // invoke checkpoint
  tsm.checkpoint(CheckpointId.create(), offsets);
  verify(tsm, never()).writeChangelogOffsetFiles(any(), any(), any());
  fail("Should have thrown an exception if error creating store checkpoint");
}
 
Example #9
Source File: TestAclsCrud.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAclsForNonExistentRole() {
  sentryKafkaAuthorizer = new SentryKafkaAuthorizer();
  java.util.Map<String, String> configs = new HashMap<>();
  configs.put(KafkaAuthConf.SENTRY_KAFKA_SITE_URL, "file://" + sentrySitePath.getAbsolutePath());
  sentryKafkaAuthorizer.configure(configs);

  final String role1 = "role1";
  Set<Acl> acls = new HashSet<>();
  final Acl acl = new Acl(new KafkaPrincipal("role", role1),
      Allow$.MODULE$,
      "127.0.0.1",
      Operation$.MODULE$.fromString("READ"));
  acls.add(acl);
  scala.collection.immutable.Set<Acl> aclsScala = scala.collection.JavaConversions.asScalaSet(acls).toSet();
  Resource resource = new Resource(ResourceType$.MODULE$.fromString("TOPIC"), "test-topic");
  try {
    sentryKafkaAuthorizer.addAcls(aclsScala, resource);
  } catch (Exception ex) {
    assertCausedMessage(ex, "Can not add Acl for non-existent Role: role1");
  }
}
 
Example #10
Source File: PoolConfiguration.java    From AsyncDao with MIT License 5 votes vote down vote up
private Map<String, String> buildSslConfig() {
    Map<String, String> sslConfig = Map$.MODULE$.empty();
    if (!StringUtil.isNullOrEmpty(sslMode)) {
        sslConfig = sslConfig.$plus(Tuple2.apply("sslmode", sslMode));
    }
    if (!StringUtil.isNullOrEmpty(sslRootCert)) {
        sslConfig = sslConfig.$plus(Tuple2.apply("sslrootcert", sslRootCert));
    }
    return sslConfig;
}
 
Example #11
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteChangelogOffsetFilesWithEmptyChangelogTopic() throws IOException {
  String storeName = "mockStore";
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  StorageEngine mockStore = mock(StorageEngine.class);
  java.util.Map<String, StorageEngine> taskStores = ImmutableMap.of(storeName, mockStore);
  when(csm.getAllStores(any())).thenReturn(taskStores);

  Partition changelogPartition = new Partition(0);
  SystemStream changelogSS = new SystemStream("system", "changelog");
  SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSS, changelogPartition);
  StorageManagerUtil mockSMU = mock(StorageManagerUtil.class);
  File mockCurrentStoreDir = mock(File.class);
  when(mockSMU.getTaskStoreDir(any(), eq(storeName), any(), any())).thenReturn(mockCurrentStoreDir);
  TransactionalStateTaskStorageManager tsm = spy(buildTSM(csm, changelogPartition, mockSMU));

  String changelogNewestOffset = null;
  Map<SystemStreamPartition, Option<String>> offsets = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(changelogSSP, Option.apply(changelogNewestOffset)));

  Path checkpointPath = Files.createTempDirectory("store-checkpoint-test").toAbsolutePath();

  Map<String, Path> checkpointPaths = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(storeName, checkpointPath));
  Map<String, SystemStream> storeChangelogs = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(storeName, changelogSS));

  // invoke method
  tsm.writeChangelogOffsetFiles(checkpointPaths, storeChangelogs, offsets);

  // verify that the offset files were not written to the checkpoint dir
  assertFalse(Files.exists(new File(checkpointPath.toFile(), StorageManagerUtil.OFFSET_FILE_NAME_LEGACY).toPath()));
  assertFalse(Files.exists(new File(checkpointPath.toFile(), StorageManagerUtil.OFFSET_FILE_NAME_NEW).toPath()));
  java.util.Map<SystemStreamPartition, String> fileOffsets = new StorageManagerUtil()
      .readOffsetFile(checkpointPath.toFile(), ImmutableSet.of(changelogSSP), false);
  assertEquals(0, fileOffsets.size());

  // verify that delete was called on current store dir offset file
  verify(mockSMU, times(1)).deleteOffsetFile(eq(mockCurrentStoreDir));
}
 
Example #12
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteChangelogOffsetFiles() throws IOException {
  String storeName = "mockStore";
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  StorageEngine mockStore = mock(StorageEngine.class);
  java.util.Map<String, StorageEngine> taskStores = ImmutableMap.of(storeName, mockStore);
  when(csm.getAllStores(any())).thenReturn(taskStores);

  Partition changelogPartition = new Partition(0);
  SystemStream changelogSS = new SystemStream("system", "changelog");
  SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSS, changelogPartition);
  StorageManagerUtil smu = spy(new StorageManagerUtil());
  File mockCurrentStoreDir = mock(File.class);
  doReturn(mockCurrentStoreDir).when(smu).getTaskStoreDir(any(), eq(storeName), any(), any());
  doNothing().when(smu).writeOffsetFile(eq(mockCurrentStoreDir), any(), anyBoolean());
  TransactionalStateTaskStorageManager tsm = spy(buildTSM(csm, changelogPartition, smu));

  String changelogNewestOffset = "1";
  Map<SystemStreamPartition, Option<String>> offsets = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(changelogSSP, Option.apply(changelogNewestOffset)));

  Path checkpointPath = Files.createTempDirectory("store-checkpoint-test").toAbsolutePath();

  Map<String, Path> checkpointPaths = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(storeName, checkpointPath));
  Map<String, SystemStream> storeChangelogs = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(storeName, changelogSS));

  // invoke method
  tsm.writeChangelogOffsetFiles(checkpointPaths, storeChangelogs, offsets);

  // verify that offset file was written to the checkpoint dir
  java.util.Map<SystemStreamPartition, String> fileOffsets = new StorageManagerUtil()
      .readOffsetFile(checkpointPath.toFile(), ImmutableSet.of(changelogSSP), false);
  assertEquals(1, fileOffsets.size());
  assertEquals(changelogNewestOffset, fileOffsets.get(changelogSSP));

  // verify that offset file write was called on the current dir
  verify(smu, times(1)).writeOffsetFile(eq(mockCurrentStoreDir), any(), anyBoolean());
}
 
Example #13
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test(expected = SamzaException.class)
public void testCheckpointFailsIfErrorWritingOffsetFiles() {
  ContainerStorageManager csm = mock(ContainerStorageManager.class);

  StorageEngine mockLPStore = mock(StorageEngine.class);
  StoreProperties lpStoreProps = mock(StoreProperties.class);
  when(mockLPStore.getStoreProperties()).thenReturn(lpStoreProps);
  when(lpStoreProps.isPersistedToDisk()).thenReturn(true);
  when(lpStoreProps.isLoggedStore()).thenReturn(true);
  Path mockPath = mock(Path.class);
  when(mockLPStore.checkpoint(any())).thenReturn(Optional.of(mockPath));
  java.util.Map<String, StorageEngine> taskStores =
      ImmutableMap.of("loggedPersistentStore", mockLPStore);
  when(csm.getAllStores(any())).thenReturn(taskStores);

  TransactionalStateTaskStorageManager tsm = spy(buildTSM(csm, mock(Partition.class), new StorageManagerUtil()));
  doThrow(new SamzaException("Error writing offset file"))
      .when(tsm).writeChangelogOffsetFiles(any(), any(), any());

  Map<SystemStreamPartition, Option<String>> offsets = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(mock(SystemStreamPartition.class), Option.apply("1")));

  // invoke checkpoint
  tsm.checkpoint(CheckpointId.create(), offsets);

  fail("Should have thrown an exception if error writing offset file.");
}
 
Example #14
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfErrorGettingMetadata() {
  // empty topic == null newest offset
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  TransactionalStateTaskStorageManager 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);

  Map<String, SystemStream> storeChangelogs =
      ScalaJavaUtil.toScalaMap(ImmutableMap.of(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)).thenThrow(new SamzaException("Error getting metadata"));
  when(systemAdmin.getSSPMetadata(eq(ImmutableSet.of(changelogSSP)))).thenReturn(null);

  // invoke the method
  Map<SystemStreamPartition, Option<String>> offsets =
      tsm.getNewestChangelogSSPOffsets(
          taskName, storeChangelogs, changelogPartition, systemAdmins);

  // verify results
  fail("Should have thrown an exception if admin had an error getting metadata");
}
 
Example #15
Source File: ExcludeAnnotationsConvertorTest.java    From minnal with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReadFieldsAndHandleThem() throws NoSuchFieldException, SecurityException {
	doNothing().when(convertor).handleExcludedAnnotations(eq(DummyModel.class), any(Field.class), any(Option.class));
	convertor.read(DummyModel.class, mock(Map.class));
	verify(convertor).handleExcludedAnnotations(eq(DummyModel.class), eq(DummyModel.class.getDeclaredField("field1")), any(Option.class));
	verify(convertor).handleExcludedAnnotations(eq(DummyModel.class), eq(DummyModel.class.getDeclaredField("field2")), any(Option.class));
	verify(convertor).handleExcludedAnnotations(eq(DummyModel.class), eq(DummyModel.class.getDeclaredField("field3")), any(Option.class));
}
 
Example #16
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfNullMetadata() {
  // empty topic == null newest offset
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  TransactionalStateTaskStorageManager 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);

  Map<String, SystemStream> storeChangelogs =
      ScalaJavaUtil.toScalaMap(ImmutableMap.of(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
  Map<SystemStreamPartition, Option<String>> offsets =
      tsm.getNewestChangelogSSPOffsets(
          taskName, storeChangelogs, changelogPartition, systemAdmins);

  // verify results
  fail("Should have thrown an exception if admin didn't return any metadata");
}
 
Example #17
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNewestOffsetsReturnsNoneForEmptyTopic() {
  // empty topic == null newest offset
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  TransactionalStateTaskStorageManager 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);

  Map<String, SystemStream> storeChangelogs =
      ScalaJavaUtil.toScalaMap(ImmutableMap.of(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
  Map<SystemStreamPartition, Option<String>> offsets =
      tsm.getNewestChangelogSSPOffsets(
          taskName, storeChangelogs, changelogPartition, systemAdmins);

  // verify results
  assertEquals(1, offsets.size());
  assertEquals(Option.empty(), offsets.apply(changelogSSP));
}
 
Example #18
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * This should never happen with CheckpointingTaskStorageManager. #getNewestChangelogSSPOffset must
 * return a key for every changelog SSP. If the SSP is empty, the value should be none. If it could
 * not fetch metadata, it should throw an exception instead of skipping the SSP.
 * If this contract is accidentally broken, ensure that we fail the commit
 */
@Test(expected = SamzaException.class)
public void testWriteChangelogOffsetFilesWithNoChangelogOffset() throws IOException {
  String storeName = "mockStore";
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  StorageEngine mockStore = mock(StorageEngine.class);
  java.util.Map<String, StorageEngine> taskStores = ImmutableMap.of(storeName, mockStore);
  when(csm.getAllStores(any())).thenReturn(taskStores);

  Partition changelogPartition = new Partition(0);
  SystemStream changelogSS = new SystemStream("system", "changelog");
  SystemStreamPartition changelogSSP = new SystemStreamPartition(changelogSS, changelogPartition);
  TransactionalStateTaskStorageManager tsm = spy(buildTSM(csm, changelogPartition, new StorageManagerUtil()));

  // no mapping present for changelog newest offset
  Map<SystemStreamPartition, Option<String>> offsets = ScalaJavaUtil.toScalaMap(ImmutableMap.of());

  Path checkpointPath = Files.createTempDirectory("store-checkpoint-test").toAbsolutePath();
  Map<String, Path> checkpointPaths = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(storeName, checkpointPath));
  Map<String, SystemStream> storeChangelogs = ScalaJavaUtil.toScalaMap(
      ImmutableMap.of(storeName, changelogSS));

  // invoke method
  tsm.writeChangelogOffsetFiles(checkpointPaths, storeChangelogs, offsets);

  fail("Should have thrown an exception if no changelog offset found for checkpointed store");
}
 
Example #19
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
private TransactionalStateTaskStorageManager buildTSM(ContainerStorageManager csm, Partition changelogPartition,
    StorageManagerUtil smu) {
  TaskName taskName = new TaskName("Partition 0");
  Map<String, SystemStream> changelogSystemStreams = mock(Map.class);
  SystemAdmins systemAdmins = mock(SystemAdmins.class);
  File loggedStoreBaseDir = mock(File.class);
  TaskMode taskMode = TaskMode.Active;

  return new TransactionalStateTaskStorageManager(
      taskName, csm, changelogSystemStreams, systemAdmins,
      loggedStoreBaseDir, changelogPartition, taskMode, smu);
}
 
Example #20
Source File: ExcludeAnnotationsConvertor.java    From minnal with Apache License 2.0 5 votes vote down vote up
@Override
public Option<Model> read(Class<?> cls, Map<String, String> typeMap) {
	Option<Model> model = super.read(cls, typeMap);
	for (Field field : cls.getDeclaredFields()) {
		handleExcludedAnnotations(cls, field, model);
	}
	return model;
}
 
Example #21
Source File: TestTransactionalStateTaskStorageManager.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test(expected = SamzaException.class)
public void testGetNewestOffsetsThrowsIfNullSSPMetadata() {
  // empty topic == null newest offset
  ContainerStorageManager csm = mock(ContainerStorageManager.class);
  TransactionalStateTaskStorageManager 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);

  Map<String, SystemStream> storeChangelogs =
      ScalaJavaUtil.toScalaMap(ImmutableMap.of(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
  Map<SystemStreamPartition, Option<String>> offsets =
      tsm.getNewestChangelogSSPOffsets(
          taskName, storeChangelogs, changelogPartition, systemAdmins);

  // verify results
  fail("Should have thrown an exception if admin returned null metadata for changelog SSP");
}
 
Example #22
Source File: TestAclsCrud.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddRole() {
  sentryKafkaAuthorizer = new SentryKafkaAuthorizer();
  java.util.Map<String, String> configs = new HashMap<>();
  configs.put(KafkaAuthConf.SENTRY_KAFKA_SITE_URL, "file://" + sentrySitePath.getAbsolutePath());
  sentryKafkaAuthorizer.configure(configs);

  final String role1 = "role1";
  try {
    sentryKafkaAuthorizer.addRole(role1);
  } catch (Exception ex) {
    Assert.fail("Failed to create role.");
  }
}
 
Example #23
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
public Map<Resource, scala.collection.immutable.Set<Acl>> getAcls(KafkaPrincipal principal) {
    if (principal.getPrincipalType().toLowerCase().equals("group")) {
        List<String> roles = getRolesforGroup(principal.getName());
        return getAclsForRoles(roles);
    } else {
        LOG.info("Did not recognize Principal type: " + principal.getPrincipalType() + ". Returning Acls for all principals.");
        return getAcls();
    }
}
 
Example #24
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private java.util.Map<Resource, scala.collection.immutable.Set<Acl>> rolePrivilegesToResourceAcls(java.util.Map<String, scala.collection.immutable.Set<TSentryPrivilege>> rolePrivilegesMap) {
    final java.util.Map<Resource, scala.collection.immutable.Set<Acl>> resourceAclsMap = new HashMap<>();
    for (String role : rolePrivilegesMap.keySet()) {
        scala.collection.immutable.Set<TSentryPrivilege> privileges = rolePrivilegesMap.get(role);
        final Iterator<TSentryPrivilege> iterator = privileges.iterator();
        while (iterator.hasNext()) {
            TSentryPrivilege privilege = iterator.next();
            final List<TAuthorizable> authorizables = privilege.getAuthorizables();
            String host = null;
            String operation = privilege.getAction();
            for (TAuthorizable tAuthorizable : authorizables) {
                if (tAuthorizable.getType().equals(KafkaAuthorizable.AuthorizableType.HOST.name())) {
                    host = tAuthorizable.getName();
                } else {
                    Resource resource = new Resource(ResourceType$.MODULE$.fromString(tAuthorizable.getType()), tAuthorizable.getName());
                    if (operation.equals("*")) {
                        operation = "All";
                    }
                    Acl acl = new Acl(new KafkaPrincipal("role", role), Allow$.MODULE$, host, Operation$.MODULE$.fromString(operation));
                    Set<Acl> newAclsJava = new HashSet<Acl>();
                    newAclsJava.add(acl);
                    addExistingAclsForResource(resourceAclsMap, resource, newAclsJava);
                    final scala.collection.mutable.Set<Acl> aclScala = JavaConversions.asScalaSet(newAclsJava);
                    resourceAclsMap.put(resource, aclScala.<Acl>toSet());
                }
            }
        }
    }

    return resourceAclsMap;
}
 
Example #25
Source File: KafkaAuthBinding.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
private void addExistingAclsForResource(java.util.Map<Resource, scala.collection.immutable.Set<Acl>> resourceAclsMap, Resource resource, java.util.Set<Acl> newAclsJava) {
    final scala.collection.immutable.Set<Acl> existingAcls = resourceAclsMap.get(resource);
    if (existingAcls != null) {
        final Iterator<Acl> aclsIter = existingAcls.iterator();
        while (aclsIter.hasNext()) {
            Acl curAcl = aclsIter.next();
            newAclsJava.add(curAcl);
        }
    }
}
 
Example #26
Source File: ColumnarBatchRow.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
    public <K, V> java.util.Map<K, V> getJavaMap(int i) {
/*        Function1<Object,Object> function = CatalystTypeConverters.createToScalaConverter(structType.fields()[i].dataType());
        ((scala.collection.Map)function.apply(row.getMap(i))).
        return row.getMap(i);
        */
        throw new UnsupportedOperationException("dsfd");
    }
 
Example #27
Source File: ScalaFeelEngine.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public boolean evaluateSimpleUnaryTests(String expression,
                                        String inputVariable,
                                        VariableContext variableContext) {
  Map inputVariableMap = new Map.Map1(UnaryTests$.MODULE$.inputVariable(), inputVariable);

  StaticVariableProvider inputVariableContext = new StaticVariableProvider(inputVariableMap);

  ContextVariableWrapper contextVariableWrapper = new ContextVariableWrapper(variableContext);

  CustomContext context = new CustomContext() {
    public VariableProvider variableProvider() {
      return new CompositeVariableProvider(toScalaList(inputVariableContext, contextVariableWrapper));
    }
  };

  Either either = feelEngine.evalUnaryTests(expression, context);

  if (either instanceof Right) {
    Right right = (Right) either;
    Object value = right.value();

    return BoxesRunTime.unboxToBoolean(value);

  } else {
    Left left = (Left) either;
    Failure failure = (Failure) left.value();
    String message = failure.message();

    throw LOGGER.evaluationException(message);

  }
}
 
Example #28
Source File: TaskStorageManagerFactory.java    From samza with Apache License 2.0 5 votes vote down vote up
public static TaskStorageManager create(TaskName taskName, ContainerStorageManager containerStorageManager,
    Map<String, SystemStream> storeChangelogs, SystemAdmins systemAdmins,
    File loggedStoreBaseDir, Partition changelogPartition,
    Config config, TaskMode taskMode) {
  if (new TaskConfig(config).getTransactionalStateCheckpointEnabled()) {
    return new TransactionalStateTaskStorageManager(taskName, containerStorageManager, storeChangelogs, systemAdmins,
        loggedStoreBaseDir, changelogPartition, taskMode, new StorageManagerUtil());
  } else {
    return new NonTransactionalStateTaskStorageManager(taskName, containerStorageManager, storeChangelogs, systemAdmins,
        loggedStoreBaseDir, changelogPartition);
  }
}
 
Example #29
Source File: IngraphTransformationRepairSemaphoreNeighbor.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<IngraphSemaphoreNeighborMatch> matches) throws IOException {
	final Transaction transaction = driver.newTransaction();
	for (final IngraphSemaphoreNeighborMatch match : matches) {
		final Long route2 = match.getRoute2();
		final Long semaphore = match.getSemaphore();
		transaction.add(ENTRY, new Map.Map2<>("route2", route2, "semaphore", semaphore));
	}
}
 
Example #30
Source File: IngraphTransformationRepairRouteSensor.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<IngraphRouteSensorMatch> matches) throws IOException {
	final Transaction transaction = driver.newTransaction();
	for (final IngraphRouteSensorMatch match : matches) {
		final Long route = match.getRoute();
		final Long sensor = match.getSensor();

		transaction.add("_e4", new Map.Map2("route", route, "sensor", sensor));
	}
}