in src/modeling-service/src/main/java/org/apache/kylin/rest/service/MetaStoreService.java [248:332]
public ByteArrayOutputStream getCompressedModelMetadata(String project, List<String> modelList,
boolean exportRecommendations, boolean exportOverProps, boolean exportMultiplePartition) throws Exception {
aclEvaluate.checkProjectWritePermission(project);
NDataModelManager modelManager = modelService.getManager(NDataModelManager.class, project);
NIndexPlanManager indexPlanManager = modelService.getManager(NIndexPlanManager.class, project);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream)) {
ResourceStore oldResourceStore = modelManager.getStore();
KylinConfig newConfig = KylinConfig.createKylinConfig(KylinConfig.getInstanceFromEnv());
ResourceStore newResourceStore = new InMemResourceStore(newConfig);
ResourceStore.setRS(newConfig, newResourceStore);
RawResourceFilter projectFilter = RawResourceFilter.equalFilter("project", project);
for (String modelId : modelList) {
NDataModel dataModelDesc = modelManager.getDataModelDesc(modelId);
if (Objects.isNull(dataModelDesc)) {
throw new KylinException(MODEL_ID_NOT_EXIST, modelId);
}
if (dataModelDesc.isBroken()) {
throw new KylinException(MODEL_EXPORT_ERROR,
String.format(Locale.ROOT, MsgPicker.getMsg().getExportBrokenModel(), modelId));
}
NDataModel modelDesc = modelManager.copyForWrite(dataModelDesc);
IndexPlan copyIndexPlan = indexPlanManager.copy(indexPlanManager.getIndexPlan(modelId));
if (!exportOverProps) {
LinkedHashMap<String, String> overridePropes = Maps.newLinkedHashMap();
if (copyIndexPlan.getOverrideProps().get(BASE_CUBOID_ALWAYS_VALID_KEY) != null) {
overridePropes.put(BASE_CUBOID_ALWAYS_VALID_KEY,
copyIndexPlan.getOverrideProps().get(BASE_CUBOID_ALWAYS_VALID_KEY));
}
if (copyIndexPlan.getOverrideProps().containsKey(RULE_SCHEDULER_DATA_KEY)) {
overridePropes.put(RULE_SCHEDULER_DATA_KEY,
copyIndexPlan.getOverrideProps().get(RULE_SCHEDULER_DATA_KEY));
}
copyIndexPlan.setOverrideProps(overridePropes);
modelDesc.setSegmentConfig(new SegmentConfig());
}
if (!exportMultiplePartition && modelDesc.isMultiPartitionModel()) {
modelDesc.setMultiPartitionDesc(
new MultiPartitionDesc(modelDesc.getMultiPartitionDesc().getColumns()));
}
newResourceStore.putResourceWithoutCheck(modelDesc.getResourcePath(),
ByteSource.wrap(JsonUtil.writeValueAsIndentBytes(modelDesc)), modelDesc.getLastModified(),
modelDesc.getMvcc());
newResourceStore.putResourceWithoutCheck(copyIndexPlan.getResourcePath(),
ByteSource.wrap(JsonUtil.writeValueAsIndentBytes(copyIndexPlan)),
copyIndexPlan.getLastModified(), copyIndexPlan.getMvcc());
// Broken model can't use getAllTables method, will be intercepted in BrokenEntityProxy
Set<String> tables = modelDesc.getAllTables().stream().map(TableRef::getTableDesc)
.map(TableDesc::getResourcePath)
.filter(resPath -> !newResourceStore
.listResourcesRecursively(MetadataType.TABLE_INFO.name(), projectFilter)
.contains(resPath))
.collect(Collectors.toSet());
tables.forEach(resourcePath -> oldResourceStore.copy(resourcePath, newResourceStore));
if (exportRecommendations) {
exportRecommendations(project, modelId, newResourceStore);
}
}
if (CollectionUtils.isEmpty(newResourceStore.listResourcesRecursively(MetadataType.MODEL.name()))) {
throw new KylinException(MODEL_METADATA_FILE_ERROR, MsgPicker.getMsg().getExportAtLeastOneModel());
}
addComputedColumns(project, modelList, newResourceStore);
// add version file
String version = System.getProperty(KE_VERSION) == null ? "unknown" : System.getProperty(KE_VERSION);
StringEntity versionEntity = new StringEntity(VERSION_FILE_META_KEY_TAG, version);
newResourceStore.putResourceWithoutCheck(VERSION_FILE,
ByteSource.wrap(JsonUtil.writeValueAsIndentBytes(versionEntity)), System.currentTimeMillis(), -1);
oldResourceStore.copy(ResourceStore.METASTORE_UUID_TAG, newResourceStore);
writeMetadataToZipOutputStream(zipOutputStream, newResourceStore);
}
return byteArrayOutputStream;
}