in amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/CatalogController.java [407:489]
private CatalogMeta constructCatalogMeta(CatalogRegisterInfo info, CatalogMeta oldCatalogMeta) {
CatalogMeta catalogMeta = new CatalogMeta();
catalogMeta.setCatalogName(info.getName());
catalogMeta.setCatalogType(info.getType());
catalogMeta.setCatalogProperties(
PropertiesUtil.unionCatalogProperties(info.getTableProperties(), info.getProperties()));
// fill catalog impl when catalog type is glue
if (CatalogMetaProperties.CATALOG_TYPE_GLUE.equals(info.getType())) {
catalogMeta.putToCatalogProperties(
CatalogProperties.CATALOG_IMPL, GlueCatalog.class.getName());
}
catalogMeta.putToCatalogProperties(
CatalogMetaProperties.TABLE_PROPERTIES_PREFIX + TableProperties.SELF_OPTIMIZING_GROUP,
info.getOptimizerGroup());
String tableFormats;
try {
// validate table format
tableFormats =
info.getTableFormatList().stream()
.map(item -> TableFormat.valueOf(item).name())
.collect(Collectors.joining(","));
} catch (Exception e) {
throw new RuntimeException(
"Invalid table format list, " + String.join(",", info.getTableFormatList()));
}
catalogMeta.getCatalogProperties().put(CatalogMetaProperties.TABLE_FORMATS, tableFormats);
String storageType =
info.getStorageConfig()
.getOrDefault(STORAGE_CONFIGS_KEY_TYPE, STORAGE_CONFIGS_VALUE_TYPE_HADOOP);
fillAuthConfigs2CatalogMeta(catalogMeta, info.getAuthConfig(), oldCatalogMeta, storageType);
// change fileId to base64Code
Map<String, String> metaStorageConfig = new HashMap<>();
metaStorageConfig.put(STORAGE_CONFIGS_KEY_TYPE, storageType);
if (storageType.equals(STORAGE_CONFIGS_VALUE_TYPE_HADOOP)) {
List<String> metaKeyList =
Arrays.asList(
STORAGE_CONFIGS_KEY_HDFS_SITE,
STORAGE_CONFIGS_KEY_CORE_SITE,
STORAGE_CONFIGS_KEY_HIVE_SITE);
// when update catalog, fileId won't be post when file doesn't been changed!
int idx;
boolean fillUseOld = oldCatalogMeta != null;
for (idx = 0; idx < metaKeyList.size(); idx++) {
String fileId = info.getStorageConfig().get(metaKeyList.get(idx));
if (!StringUtils.isEmpty(fileId)) {
String fileSite = platformFileInfoService.getFileContentB64ById(Integer.valueOf(fileId));
metaStorageConfig.put(
metaKeyList.get(idx), StringUtils.isEmpty(fileSite) ? EMPTY_XML_BASE64 : fileSite);
} else {
if (fillUseOld) {
String fileSite = oldCatalogMeta.getStorageConfigs().get(metaKeyList.get(idx));
metaStorageConfig.put(
metaKeyList.get(idx), StringUtils.isEmpty(fileSite) ? EMPTY_XML_BASE64 : fileSite);
} else {
metaStorageConfig.put(metaKeyList.get(idx), EMPTY_XML_BASE64);
}
}
}
} else if (storageType.equals(STORAGE_CONFIGS_VALUE_TYPE_S3)) {
CatalogUtil.copyProperty(
info.getStorageConfig(),
catalogMeta.getCatalogProperties(),
STORAGE_CONFIGS_KEY_REGION,
AwsClientProperties.CLIENT_REGION);
CatalogUtil.copyProperty(
info.getStorageConfig(),
catalogMeta.getCatalogProperties(),
STORAGE_CONFIGS_KEY_S3_ENDPOINT,
S3FileIOProperties.ENDPOINT);
} else if (storageType.equals(STORAGE_CONFIGS_VALUE_TYPE_OSS)) {
CatalogUtil.copyProperty(
info.getStorageConfig(),
catalogMeta.getCatalogProperties(),
STORAGE_CONFIGS_KEY_OSS_ENDPOINT,
AliyunProperties.OSS_ENDPOINT);
} else {
throw new RuntimeException("Invalid storage type " + storageType);
}
catalogMeta.setStorageConfigs(metaStorageConfig);
return catalogMeta;
}