bool ConfigValidator::validate()

in aios/apps/facility/build_service/build_service/admin/ConfigValidator.cpp [187:318]


bool ConfigValidator::validate(const string& configPath, bool firstTime)
{
    ResourceReaderPtr resourceReader = ResourceReaderManager::getResourceReader(configPath);
    GraphConfig graphConfig;
    bool globalBuildV2Mode = false;
    if (resourceReader->getGraphConfig(graphConfig)) {
        auto targetGraph = graphConfig.getGraphName();
        globalBuildV2Mode = (targetGraph == "BatchBuildV2/FullBatchBuild.graph" ||
                             targetGraph == "BuildIndexV2.graph" || targetGraph == "BuildIndexV2.npc_mode.graph");
    }
    BuildServiceConfig buildServiceConfig;
    if (!resourceReader->getConfigWithJsonPath((BUILD_APP_FILE_NAME.c_str()), "", buildServiceConfig)) {
        string errorMsg = "read " + string((BUILD_APP_FILE_NAME.c_str())) + " from " + configPath + "failed";
        REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
        return false;
    }
    if (!buildServiceConfig.validate()) {
        string errorMsg = "validate " + string((BUILD_APP_FILE_NAME.c_str())) + " from " + configPath + "failed";
        REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
        return false;
    }

    vector<string> dataTables;
    if (_buildId.has_datatable()) {
        dataTables.push_back(_buildId.datatable());
    } else {
        if (!resourceReader->getAllDataTables(dataTables)) {
            string errorMsg = "read data table config[" + configPath + "] failed!";
            REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
            return false;
        }
    }
    vector<string> allTableNames;
    for (size_t i = 0; i < dataTables.size(); ++i) {
        bool buildV2Mode = globalBuildV2Mode;
        if (!buildV2Mode) {
            config::ControlConfig controlConfig;
            if (!resourceReader->getDataTableConfigWithJsonPath(dataTables[i], "control_config", controlConfig)) {
                string errorMsg = "get control config failed!";
                REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
                return false;
            }
            buildV2Mode = (controlConfig.useIndexV2() ||
                           controlConfig.getDataLinkMode() == ControlConfig::DataLinkMode::NPC_MODE);
        }
        string dataTableFilePath = ResourceReader::getDataTableRelativePath(dataTables[i]);
        do {
            DataDescriptions dataDescriptions;
            if (!resourceReader->getConfigWithJsonPath(dataTableFilePath, "data_descriptions",
                                                       dataDescriptions.toVector())) {
                string errorMsg = "read " + dataTableFilePath + " from " + configPath + " failed";
                REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
                return false;
            }
            if (!dataDescriptions.validate()) {
                string errorMsg = "validate " + dataTableFilePath + " from " + configPath + " failed";
                REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
                return false;
            }
        } while (0);

        VALIDATE(ProcessorRuleConfig, dataTableFilePath.c_str(), "processor_rule_config");
        VALIDATE(ProcessorConfig, dataTableFilePath.c_str(), "processor_config");
        VALIDATE_CONTAINER(DocProcessorChainConfigVec, dataTableFilePath.c_str(), "processor_chain_config");
        vector<string> clusterNames;
        if (!resourceReader->getAllClusters(dataTables[i], clusterNames)) {
            string errorMsg = "read cluster config[" + configPath + "] failed!";
            REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
            return false;
        }

        for (const auto& clusterName : clusterNames) {
            if (!validateSchema(resourceReader, clusterName, buildV2Mode)) {
                string errorMsg = "validate schema for cluster [" + clusterName + "] failed";
                REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
                return false;
            }
            if (buildV2Mode) {
                BuilderClusterConfig clusterConfig;
                if (!clusterConfig.init(clusterName, *resourceReader)) {
                    REPORT_ERROR(SERVICE_ERROR_CONFIG, string("get cluster config failed"));
                    return false;
                }
            }
            string tableName;
            if (!resourceReader->getClusterConfigWithJsonPath(clusterName, "cluster_config.table_name", tableName)) {
                REPORT_ERROR(SERVICE_ERROR_CONFIG, string("get tableName in cluster config failed"));
                return false;
            }
            allTableNames.push_back(tableName);
            string clusterConfig = ResourceReader::getClusterConfRelativePath(clusterName);
            BuildRuleConfig buildRuleConfig;
            if (!getValidateConfig<BuildRuleConfig>(*(resourceReader.get()), clusterConfig.c_str(),
                                                    "cluster_config.builder_rule_config", buildRuleConfig)) {
                return false;
            }
            SwiftConfig swiftConfig;
            if (!getValidateConfig<SwiftConfig>(*(resourceReader.get()), clusterConfig.c_str(), "swift_config",
                                                swiftConfig)) {
                return false;
            }
            if (!validateHashMode(resourceReader, clusterConfig.c_str())) {
                return false;
            }

            if (!validateBuilderClusterConfig(configPath, clusterName)) {
                return false;
            }
            if (!validateOfflineIndexPartitionOptions(configPath, clusterName)) {
                return false;
            }
            if (!validateSwiftMemoryPreferMode(swiftConfig, buildRuleConfig, buildV2Mode)) {
                return false;
            }
            if (!validateSwiftConfig(swiftConfig, buildServiceConfig, buildV2Mode)) {
                return false;
            }
        }
    }
    if (!validateAppPlanMaker(configPath)) {
        return false;
    }
    if (firstTime) {
        vector<string> patchShemas = resourceReader->getSchemaPatchFileNames(allTableNames);
        if (!patchShemas.empty()) {
            string errorMsg = "first time start build should not take schema patch file in" + configPath;
            REPORT_ERROR(SERVICE_ERROR_CONFIG, errorMsg);
            return false;
        }
    }
    return true;
}