Skip to content

Commit

Permalink
Upgrade to OpenSearch 2.0.0-alpha1
Browse files Browse the repository at this point in the history
Signed-off-by: cliu123 <lc12251109@gmail.com>
  • Loading branch information
cliu123 committed Apr 3, 2022
1 parent b73650b commit c28ff0d
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public void postIndex(ShardId shardId, Index index, IndexResult result) {
if(previousContent == null) {
//no previous content
if(!result.isCreated()) {
log.warn("No previous content and not created (its an update but do not find orig source) for {}/{}/{}/{}", index.startTime(), shardId, index.type(), index.id());
log.warn("No previous content and not created (its an update but do not find orig source) for {}/{}/{}", index.startTime(), shardId, index.id());
}
assert result.isCreated():"No previous content and not created";
} else {
if(result.isCreated()) {
log.warn("Previous content and created for {}/{}/{}/{}", index.startTime(), shardId, index.type(), index.id());
log.warn("Previous content and created for {}/{}/{}", index.startTime(), shardId, index.id());
}
assert !result.isCreated():"Previous content and created";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public void binaryFieldRead(final FieldInfo fieldInfo, byte[] fieldValue) {
}
}

public void stringFieldRead(final FieldInfo fieldInfo, final byte[] fieldValue) {
public void stringFieldRead(final FieldInfo fieldInfo, final String fieldValue) {
try {
if(!recordField(fieldInfo.name, true)) {
return;
}
fieldRead0(fieldInfo.name, new String(fieldValue, StandardCharsets.UTF_8));
fieldRead0(fieldInfo.name, fieldValue);
} catch (Exception e) {
log.error("Unexpected error reading string field '{}' in index '{}'", fieldInfo.name, index.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ public void checkIntegrity() throws IOException {
public void close() throws IOException {
in.close();
}

@Override
public long ramBytesUsed() {
return in.ramBytesUsed();
}
}

@Override
Expand Down Expand Up @@ -521,7 +516,7 @@ public int hashCode() {
}

@Override
public void stringField(final FieldInfo fieldInfo, final byte[] value) throws IOException {
public void stringField(final FieldInfo fieldInfo, final String value) throws IOException {
fieldReadCallback.stringFieldRead(fieldInfo, value);
delegate.stringField(fieldInfo, value);
}
Expand Down Expand Up @@ -610,7 +605,7 @@ public int hashCode() {
}

@Override
public void stringField(final FieldInfo fieldInfo, final byte[] value) throws IOException {
public void stringField(final FieldInfo fieldInfo, final String value) throws IOException {
delegate.stringField(fieldInfo, value);
}

Expand Down Expand Up @@ -681,7 +676,7 @@ public int hashCode() {
}

@Override
public void stringField(final FieldInfo fieldInfo, final byte[] value) throws IOException {
public void stringField(final FieldInfo fieldInfo, final String value) throws IOException {
final Optional<MaskedField> mf = maskedFieldsMap.getMaskedField(fieldInfo.name);

if(mf.isPresent()) {
Expand Down Expand Up @@ -868,11 +863,6 @@ private SortedDocValues wrapSortedDocValues(final String field, final SortedDocV
if (mf != null) {
return new SortedDocValues() {

@Override
public BytesRef binaryValue() throws IOException {
return mf.mask(sortedDocValues.binaryValue());
}

@Override
public int lookupTerm(BytesRef key) throws IOException {
return sortedDocValues.lookupTerm(key);
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/org/opensearch/security/TracingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,10 @@ public void testAdvancedMapping() throws Exception {
setup(Settings.EMPTY, new DynamicSecurityConfig(), Settings.EMPTY, true, ClusterConfiguration.DEFAULT);

try (Client tc = getClient()) {
tc.admin().indices().create(new CreateIndexRequest("myindex1")
.mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")
.mapping("mytype2", FileHelper.loadFile("mapping2.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")
.mapping("mytype3", FileHelper.loadFile("mapping3.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")
.mapping("mytype4", FileHelper.loadFile("mapping4.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex1")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")).actionGet();
}

RestHelper rh = nonSslRestHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,10 @@ public void testAdvancedMapping() throws Exception {
rh.executePutRequest("_opendistro/_security/api/audit/config", AuditTestUtils.createAuditPayload(settings), encodeBasicHeader("admin", "admin"));

try (Client tc = getClient()) {
tc.admin().indices().create(new CreateIndexRequest("myindex1")
.mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")
.mapping("mytype2", FileHelper.loadFile("mapping2.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")
.mapping("mytype3", FileHelper.loadFile("mapping3.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")
.mapping("mytype4", FileHelper.loadFile("mapping4.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex1")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex3")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex4")).actionGet();
}

System.out.println("############ write into mapping 1");
Expand Down Expand Up @@ -391,10 +387,8 @@ public void testImmutableIndex() throws Exception {
rh.executePutRequest("_opendistro/_security/api/audit/config", AuditTestUtils.createAuditPayload(Settings.EMPTY), encodeBasicHeader("admin", "admin"));

try (Client tc = getClient()) {
tc.admin().indices().create(new CreateIndexRequest("myindex1")
.mapping("mytype1", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")
.mapping("mytype2", FileHelper.loadFile("mapping1.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex1")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("myindex2")).actionGet();
}

System.out.println("############ immutable 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CustomFieldMaskedComplexMappingTest extends AbstractDlsFlsTest{
protected void populateData(Client tc) {

try {
tc.admin().indices().create(new CreateIndexRequest("logs").mapping("_doc", FileHelper.loadFile("dlsfls/masked_field_mapping.json"), XContentType.JSON)).actionGet();
tc.admin().indices().create(new CreateIndexRequest("logs")).actionGet();


byte[] data = FileHelper.loadFile("dlsfls/logs_bulk_data.json").getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ protected void populateData(Client tc) {
"";

tc.admin().indices().create(new CreateIndexRequest("deals")
.settings(Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build())
.mapping("mytype", mapping, XContentType.JSON)).actionGet();
.settings(Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build())).actionGet();

//tc.index(new IndexRequest("deals").id("3").setRefreshPolicy(RefreshPolicy.IMMEDIATE)
// .source("{\"amount\": 7,\"owner\": \"a\", \"my_nested_object\" : {\"name\": \"spock\"}}", XContentType.JSON)).actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void testDlsWithMinDocCountZeroAggregations() throws Exception {
setup();

try (Client client = getClient()) {
client.admin().indices().create(new CreateIndexRequest("logs").mapping("_doc", ImmutableMap.of("properties", ImmutableMap.of("termX", ImmutableMap.of("type", "keyword"))))).actionGet();
client.admin().indices().create(new CreateIndexRequest("logs")).actionGet();

for (int i = 0; i < 3; i++) {
client.index(new IndexRequest("logs").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("amount", i, "termX", "A", "timestamp", "2022-01-06T09:05:00Z")).actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ public class FlsExistsFieldsTest extends AbstractDlsFlsTest {

protected void populateData(Client tc) {

tc.admin().indices().create(new CreateIndexRequest("data").mapping("doc",
"@timestamp", "type=date",
"host", "type=text,norms=false",
"response", "type=text,norms=false",
"non-existing", "type=text,norms=false"
))
tc.admin().indices().create(new CreateIndexRequest("data"))
.actionGet();

for (int i = 0; i < 1; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class FlsFieldsTest extends AbstractDlsFlsTest{

protected void populateData(Client tc) {

tc.admin().indices().create(new CreateIndexRequest("deals")
.mapping("deals", "timestamp","type=date","@timestamp","type=date")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("deals")).actionGet();

try {
String doc = FileHelper.loadFile("dlsfls/doc1.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class FlsFieldsWcTest extends AbstractDlsFlsTest{

protected void populateData(Client tc) {

tc.admin().indices().create(new CreateIndexRequest("deals")
.mapping("deals", "timestamp","type=date","@timestamp","type=date")).actionGet();
tc.admin().indices().create(new CreateIndexRequest("deals")).actionGet();

try {
String doc = FileHelper.loadFile("dlsfls/doc1.json");
Expand Down

0 comments on commit c28ff0d

Please sign in to comment.