Search in sources :

Example 1 with ConfigTextResolver

use of com.ctrip.framework.apollo.portal.component.txtresolver.ConfigTextResolver in project apollo by ctripcorp.

the class ItemService method updateConfigItemByText.

/**
 * parse config text and update config items
 *
 * @return parse result
 */
public void updateConfigItemByText(NamespaceTextModel model) {
    String appId = model.getAppId();
    Env env = model.getEnv();
    String clusterName = model.getClusterName();
    String namespaceName = model.getNamespaceName();
    NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
    if (namespace == null) {
        throw new BadRequestException("namespace:" + namespaceName + " not exist in env:" + env + ", cluster:" + clusterName);
    }
    long namespaceId = namespace.getId();
    String configText = model.getConfigText();
    ConfigTextResolver resolver = model.getFormat() == ConfigFileFormat.Properties ? propertyResolver : fileTextResolver;
    ItemChangeSets changeSets = resolver.resolve(namespaceId, configText, itemAPI.findItems(appId, env, clusterName, namespaceName));
    if (changeSets.isEmpty()) {
        return;
    }
    String operator = model.getOperator();
    if (StringUtils.isBlank(operator)) {
        operator = userInfoHolder.getUser().getUserId();
    }
    changeSets.setDataChangeLastModifiedBy(operator);
    updateItems(appId, env, clusterName, namespaceName, changeSets);
    Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE_BY_TEXT, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
    Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
}
Also used : ConfigTextResolver(com.ctrip.framework.apollo.portal.component.txtresolver.ConfigTextResolver) NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Env(com.ctrip.framework.apollo.portal.environment.Env)

Aggregations

ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)1 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)1 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 ConfigTextResolver (com.ctrip.framework.apollo.portal.component.txtresolver.ConfigTextResolver)1 Env (com.ctrip.framework.apollo.portal.environment.Env)1