Skip to content

Commit 1bc5838

Browse files
committed
Created metadata lib and added AliasMetadataModel and MappingMetadataModel
Signed-off-by: Manik Garg <gargmanik1317@gmail.com>
1 parent 696951d commit 1bc5838

14 files changed

Lines changed: 994 additions & 194 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
- Added public getter method in `SourceFieldMapper` to return excluded field ([#20205](https://github.com/opensearch-project/OpenSearch/pull/20205))
1010
- Relax jar hell check when extended plugins share transitive dependencies ([#20103](https://github.com/opensearch-project/OpenSearch/pull/20103))
1111
- Added public getter method in `SourceFieldMapper` to return included field ([#20290](https://github.com/opensearch-project/OpenSearch/pull/20290))
12+
- Created new metadata lib and added AliasMetadataModel and MappingMetadataModel classes ([#20328](https://github.com/opensearch-project/OpenSearch/pull/20328))
1213

1314
### Changed
1415
- Handle custom metadata files in subdirectory-store ([#20157](https://github.com/opensearch-project/OpenSearch/pull/20157))

libs/metadata/build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apply plugin: 'opensearch.publish'
2+
3+
base {
4+
archivesName = 'opensearch-metadata'
5+
}
6+
7+
dependencies {
8+
api project(':libs:opensearch-common')
9+
api project(':libs:opensearch-core')
10+
11+
testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
12+
testImplementation "junit:junit:${versions.junit}"
13+
testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}"
14+
15+
testImplementation(project(":test:framework")) {
16+
exclude group: 'org.opensearch', module: 'opensearch-metadata'
17+
}
18+
}
19+
20+
thirdPartyAudit.enabled = false
21+
22+
tasks.withType(de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis) {
23+
enabled = false
24+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.metadata.compress;
10+
11+
import org.opensearch.common.annotation.ExperimentalApi;
12+
import org.opensearch.core.common.io.stream.StreamInput;
13+
import org.opensearch.core.common.io.stream.StreamOutput;
14+
import org.opensearch.core.common.io.stream.Writeable;
15+
16+
import java.io.IOException;
17+
import java.util.Arrays;
18+
19+
/**
20+
* Generic data holder class for compressed data.
21+
* This class stores compressed bytes and their checksum.
22+
* <p>
23+
* Can be used for any type of compressed content (XContent, raw bytes, etc.)
24+
*/
25+
@ExperimentalApi
26+
public final class CompressedData implements Writeable {
27+
28+
private final byte[] compressedBytes;
29+
private final int checksum;
30+
31+
/**
32+
* Creates a new CompressedData object.
33+
*
34+
* @param compressedBytes the compressed bytes
35+
* @param checksum the checksum of the uncompressed content
36+
*/
37+
public CompressedData(byte[] compressedBytes, int checksum) {
38+
this.compressedBytes = compressedBytes;
39+
this.checksum = checksum;
40+
}
41+
42+
/**
43+
* Creates a new CompressedData object from a stream.
44+
*
45+
* @param in the stream input
46+
* @throws IOException if an I/O error occurs
47+
*/
48+
public CompressedData(StreamInput in) throws IOException {
49+
this.checksum = in.readInt();
50+
this.compressedBytes = in.readByteArray();
51+
}
52+
53+
/**
54+
* Returns the compressed bytes.
55+
*
56+
* @return the compressed bytes
57+
*/
58+
public byte[] compressedBytes() {
59+
return compressedBytes;
60+
}
61+
62+
/**
63+
* Returns the checksum of the uncompressed content.
64+
*
65+
* @return the checksum value
66+
*/
67+
public int checksum() {
68+
return checksum;
69+
}
70+
71+
@Override
72+
public void writeTo(StreamOutput out) throws IOException {
73+
out.writeInt(checksum);
74+
out.writeByteArray(compressedBytes);
75+
}
76+
77+
@Override
78+
public boolean equals(Object o) {
79+
if (this == o) return true;
80+
if (o == null || getClass() != o.getClass()) return false;
81+
82+
CompressedData that = (CompressedData) o;
83+
return checksum == that.checksum && Arrays.equals(compressedBytes, that.compressedBytes);
84+
}
85+
86+
@Override
87+
public int hashCode() {
88+
return checksum;
89+
}
90+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/** Compression package. */
10+
package org.opensearch.metadata.compress;

0 commit comments

Comments
 (0)