forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OBSDATA-440 Adding SegmentMetadataEvent and publishing them via Kafka…
…SegmentMetadataEmitter (#117)
- Loading branch information
1 parent
041215a
commit 7935ac0
Showing
11 changed files
with
563 additions
and
65 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
core/src/main/java/org/apache/druid/java/util/emitter/service/SegmentMetadataEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.java.util.emitter.service; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import org.apache.druid.java.util.emitter.core.Event; | ||
import org.apache.druid.java.util.emitter.core.EventMap; | ||
import org.joda.time.DateTime; | ||
|
||
public class SegmentMetadataEvent implements Event | ||
{ | ||
public static final String FEED = "feed"; | ||
public static final String DATASOURCE = "dataSource"; | ||
public static final String CREATED_TIME = "createdTime"; | ||
public static final String START_TIME = "startTime"; | ||
public static final String END_TIME = "endTime"; | ||
public static final String VERSION = "version"; | ||
public static final String IS_COMPACTED = "isCompacted"; | ||
|
||
private final DateTime createdTime; | ||
private final String dataSource; | ||
private final DateTime startTime; | ||
private final DateTime endTime; | ||
private final String version; | ||
private final boolean isCompacted; | ||
|
||
public SegmentMetadataEvent( | ||
String dataSource, | ||
DateTime createdTime, | ||
DateTime startTime, | ||
DateTime endTime, | ||
String version, | ||
boolean isCompacted | ||
) | ||
{ | ||
this.dataSource = dataSource; | ||
this.createdTime = createdTime; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.version = version; | ||
this.isCompacted = isCompacted; | ||
} | ||
|
||
@Override | ||
public String getFeed() | ||
{ | ||
return "segment_metadata"; | ||
} | ||
|
||
public DateTime getCreatedTime() | ||
{ | ||
return createdTime; | ||
} | ||
|
||
public DateTime getStartTime() | ||
{ | ||
return startTime; | ||
} | ||
|
||
public DateTime getEndTime() | ||
{ | ||
return endTime; | ||
} | ||
|
||
public String getDataSource() | ||
{ | ||
return dataSource; | ||
} | ||
|
||
public String getVersion() | ||
{ | ||
return version; | ||
} | ||
|
||
public boolean isCompacted() | ||
{ | ||
return isCompacted; | ||
} | ||
|
||
@Override | ||
@JsonValue | ||
public EventMap toMap() | ||
{ | ||
|
||
return EventMap.builder() | ||
.put(FEED, getFeed()) | ||
.put(DATASOURCE, dataSource) | ||
.put(CREATED_TIME, createdTime) | ||
.put(START_TIME, startTime) | ||
.put(END_TIME, endTime) | ||
.put(VERSION, version) | ||
.put(IS_COMPACTED, isCompacted) | ||
.build(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
core/src/test/java/org/apache/druid/java/util/emitter/service/SegmentMetadataEventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.java.util.emitter.service; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.apache.druid.java.util.common.DateTimes; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class SegmentMetadataEventTest | ||
{ | ||
@Test | ||
public void testBasicEvent() | ||
{ | ||
SegmentMetadataEvent event = new SegmentMetadataEvent( | ||
"dummy_datasource", | ||
DateTimes.of("2001-01-01T00:00:00.000Z"), | ||
DateTimes.of("2001-01-02T00:00:00.000Z"), | ||
DateTimes.of("2001-01-03T00:00:00.000Z"), | ||
"dummy_version", | ||
true | ||
); | ||
|
||
Assert.assertEquals( | ||
ImmutableMap.<String, Object>builder() | ||
.put(SegmentMetadataEvent.FEED, "segment_metadata") | ||
.put(SegmentMetadataEvent.DATASOURCE, "dummy_datasource") | ||
.put(SegmentMetadataEvent.CREATED_TIME, DateTimes.of("2001-01-01T00:00:00.000Z")) | ||
.put(SegmentMetadataEvent.START_TIME, DateTimes.of("2001-01-02T00:00:00.000Z")) | ||
.put(SegmentMetadataEvent.END_TIME, DateTimes.of("2001-01-03T00:00:00.000Z")) | ||
.put(SegmentMetadataEvent.VERSION, "dummy_version") | ||
.put(SegmentMetadataEvent.IS_COMPACTED, true) | ||
.build(), | ||
event.toMap() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.