Skip to content

Commit

Permalink
Created EngineExtension with default implementation from EnginePlugin (
Browse files Browse the repository at this point in the history
…opensearch-project#393)

* Added EngineExtension Interface
Signed-off-by: varuntumbe <[email protected]>

* deleting the depreciated method
Signed-off-by: varuntumbe <[email protected]>

* spotlessApply has been done
Signed-off-by: varuntumbe <[email protected]>
  • Loading branch information
varuntumbe authored and kokibas committed Mar 17, 2023
1 parent 51f70d9 commit df89a69
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/main/java/org/opensearch/sdk/EngineExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.sdk;

import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecServiceFactory;
import org.opensearch.index.engine.EngineFactory;
import org.opensearch.index.seqno.RetentionLeases;
import org.opensearch.index.translog.TranslogDeletionPolicy;
import org.opensearch.index.translog.TranslogDeletionPolicyFactory;

import java.util.Optional;
import java.util.function.Supplier;

/**
* A Extension that provides alternative engine implementations.
*
*/
public interface EngineExtension {

/**
* When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings to determine
* whether or not to provide an engine factory for the given index. A Extension that is not overriding the default engine should return
* {@link Optional#empty()}. If multiple Extensions return an engine factory for a given index the index will not be created and an
* {@link IllegalStateException} will be thrown during index creation.
*
* @return an optional engine factory
*/
default Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
return Optional.empty();
}

/**
* EXPERT:
* When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings
* to determine if a custom {@link CodecServiceFactory} should be provided for the given index. A Extension that is not overriding
* the {@link CodecServiceFactory} through the Extension can ignore this method and the default Codec specified in the
* {@link IndexSettings} will be used.
*/
default Optional<CodecServiceFactory> getCustomCodecServiceFactory(IndexSettings indexSettings) {
return Optional.empty();
}

/**
* When an index is created this method is invoked for each engine Extension. Engine Extensions that need to provide a
* custom {@link TranslogDeletionPolicy} can override this method to return a function that takes the {@link IndexSettings}
* and a {@link Supplier} for {@link RetentionLeases} and returns a custom {@link TranslogDeletionPolicy}.
*
* Only one of the installed Engine Extensions can override this otherwise {@link IllegalStateException} will be thrown.
*
* @return a function that returns an instance of {@link TranslogDeletionPolicy}
*/
default Optional<TranslogDeletionPolicyFactory> getCustomTranslogDeletionPolicyFactory() {
return Optional.empty();
}
}

0 comments on commit df89a69

Please sign in to comment.