me.snowdrop.istio.api.internal.IstioSpecRegistry Maven / Gradle / Ivy
package me.snowdrop.istio.api.internal;
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import me.snowdrop.istio.api.IstioSpec;
/**
* @author Christophe Laprun
*/
public class IstioSpecRegistry {
private static final String ISTIO_PACKAGE_PREFIX = "me.snowdrop.istio.";
private static final String ISTIO_API_PACKAGE_PREFIX = ISTIO_PACKAGE_PREFIX + "api.";
private static final String ISTIO_MIXER_TEMPLATE_PACKAGE_PREFIX = ISTIO_PACKAGE_PREFIX + "mixer.template.";
private static final String ISTIO_ADAPTER_PACKAGE_PREFIX = ISTIO_PACKAGE_PREFIX + "adapter.";
private static final Map crdInfos = new HashMap<>();
static {
Properties crdFile = new Properties();
try (final InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("istio-crd.properties")) {
crdFile.load(inputStream);
} catch (Exception e) {
throw new RuntimeException("Couldn't load Istio CRD information from classpath", e);
}
crdInfos.putAll(crdFile.entrySet().stream().collect(
Collectors.toMap(
e -> String.valueOf(e.getKey()).toLowerCase(),
e -> getCRDInfoFrom(e))
));
}
private static CRDInfo getCRDInfoFrom(Map.Entry