/** * Generate header. * * @param logEventPack the log event pack * @return the log header */ private RecordHeader generateHeader(LogEventPack logEventPack) { RecordHeader logHeader = null; if (header != null) { logHeader = new RecordHeader(); for (LogHeaderStructureDto field : header) { switch (field) { case KEYHASH: logHeader.setEndpointKeyHash(logEventPack.getEndpointKey()); break; case TIMESTAMP: logHeader.setTimestamp(System.currentTimeMillis()); break; case TOKEN: logHeader.setApplicationToken(applicationToken); break; case VERSION: logHeader.setHeaderVersion(LOG_HEADER_VERSION); break; case LSVERSION: logHeader.setLogSchemaVersion(logEventPack.getLogSchema().getVersion()); break; default: if (LOG.isWarnEnabled()) { LOG.warn("Current header field [{}] doesn't support", field); } break; } } } return logHeader; }
@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); }