org.opensearch.migrations.replay.TransformationLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trafficReplayer Show documentation
Show all versions of trafficReplayer Show documentation
Everything opensearch migrations
package org.opensearch.migrations.replay;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opensearch.migrations.transform.IJsonTransformer;
import org.opensearch.migrations.transform.IJsonTransformerProvider;
import org.opensearch.migrations.transform.JsonCompositeTransformer;
import org.opensearch.migrations.transform.JsonKeysForHttpMessage;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TransformationLoader {
public static final String WRONG_JSON_STRUCTURE_MESSAGE =
"Must specify the top-level configuration list with a sequence of "
+ "maps that have only one key each, where the key is the name of the transformer to be configured.";
public static final Pattern CLASS_NAME_PATTERN = Pattern.compile("^[^{}]*$");
private final List providers;
ObjectMapper objMapper = new ObjectMapper();
public TransformationLoader() {
ServiceLoader transformerProviders = ServiceLoader.load(
IJsonTransformerProvider.class
);
var inProgressProviders = new ArrayList();
for (var provider : transformerProviders) {
log.info("Adding IJsonTransfomerProvider: " + provider);
inProgressProviders.add(provider);
}
providers = Collections.unmodifiableList(inProgressProviders);
log.atInfo()
.setMessage(
() -> "IJsonTransformerProviders loaded: "
+ providers.stream().map(p -> p.getClass().toString()).collect(Collectors.joining("; "))
)
.log();
}
List