예제 #1
0
 public void initLogAppender(LogAppenderDto appender) {
   this.minSchemaVersion = appender.getMinLogSchemaVersion();
   this.maxSchemaVersion = appender.getMaxLogSchemaVersion();
   this.confirmDelivery = appender.isConfirmDelivery();
   byte[] rawConfiguration = appender.getRawConfiguration();
   try {
     AvroByteArrayConverter<T> converter = new AvroByteArrayConverter<>(configurationClass);
     T configuration = converter.fromByteArray(rawConfiguration);
     initFromConfiguration(appender, configuration);
   } catch (IOException e) {
     LOG.error("Unable to parse configuration for appender '" + getName() + "'", e);
   }
 }
  private LogEventPack generateLogEventPack(int count) throws IOException {
    LogEventPack logEventPack = new LogEventPack();
    List<LogEvent> events = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
      LogEvent event = new LogEvent();
      event.setLogData(
          logDataConverter.toByteArray(new LogData(Level.DEBUG, UUID.randomUUID().toString())));
      events.add(event);
    }
    logEventPack.setDateCreated(System.currentTimeMillis());
    logEventPack.setEndpointKey(endpointKeyHash);

    logEventPack.setLogSchemaVersion(2);
    logEventPack.setEvents(events);
    LogSchemaDto logSchemaDto = new LogSchemaDto();
    logSchemaDto.setApplicationId(String.valueOf(RANDOM.nextInt()));
    logSchemaDto.setId(String.valueOf(RANDOM.nextInt()));
    logSchemaDto.setCreatedTime(System.currentTimeMillis());
    logSchemaDto.setSchema(LogData.getClassSchema().toString());

    logEventPack.setLogSchema(new LogSchema(logSchemaDto));
    return logEventPack;
  }
  @Before
  public void beforeTest() throws IOException {
    endpointKeyHash = UUID.randomUUID().toString();
    appToken = String.valueOf(RANDOM.nextInt(Integer.MAX_VALUE));

    appenderDto = new LogAppenderDto();
    appenderDto.setId("Test_id");
    appenderDto.setApplicationToken(appToken);
    appenderDto.setName("Test Name");
    appenderDto.setTenantId(String.valueOf(RANDOM.nextInt()));
    appenderDto.setHeaderStructure(Arrays.asList(LogHeaderStructureDto.values()));
    appenderDto.setApplicationToken(appToken);

    header = new RecordHeader();
    header.setApplicationToken(appToken);
    header.setEndpointKeyHash(endpointKeyHash);
    header.setHeaderVersion(1);
    header.setTimestamp(System.currentTimeMillis());

    logEventPack = new LogEventPack();
    logEventPack.setDateCreated(System.currentTimeMillis());
    logEventPack.setEndpointKey(endpointKeyHash);

    CassandraServer server = new CassandraServer("127.0.0.1", 9142);
    configuration = new CassandraConfig();
    configuration.setCassandraBatchType(CassandraBatchType.UNLOGGED);
    configuration.setKeySpace(KEY_SPACE_NAME);
    configuration.setTableNamePattern("logs_$app_token_$config_hash");
    configuration.setCassandraExecuteRequestType(CassandraExecuteRequestType.ASYNC);
    configuration.setCassandraServers(Arrays.asList(server));
    configuration.setCallbackThreadPoolSize(3);
    configuration.setExecutorThreadPoolSize(3);

    List<ColumnMappingElement> columnMapping = new ArrayList<ColumnMappingElement>();
    columnMapping.add(
        new ColumnMappingElement(
            ColumnMappingElementType.HEADER_FIELD,
            "endpointKeyHash",
            "endpointKeyHash",
            ColumnType.TEXT,
            true,
            false));
    columnMapping.add(
        new ColumnMappingElement(
            ColumnMappingElementType.EVENT_JSON, "", "event_json", ColumnType.TEXT, false, false));
    columnMapping.add(
        new ColumnMappingElement(
            ColumnMappingElementType.UUID, "", "binid", ColumnType.UUID, false, true));

    configuration.setColumnMapping(columnMapping);

    List<ClusteringElement> clusteringMapping = new ArrayList<ClusteringElement>();
    clusteringMapping.add(new ClusteringElement("binid", OrderType.DESC));
    configuration.setClusteringMapping(clusteringMapping);

    AvroByteArrayConverter<CassandraConfig> converter =
        new AvroByteArrayConverter<>(CassandraConfig.class);
    byte[] rawConfiguration = converter.toByteArray(configuration);
    appenderDto.setRawConfiguration(rawConfiguration);

    logAppender = new CassandraLogAppender();
    logAppender.init(appenderDto);
    logAppender.setApplicationToken(appToken);
  }