Search in sources :

Example 21 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class ConfigsImportService method importNamespace.

private void importNamespace(final String appId, final Env env, final String clusterName, final String namespaceName, final String configText, final String format, boolean ignoreConflictNamespace, String operator) {
    NamespaceDTO namespaceDTO;
    try {
        namespaceDTO = namespaceService.loadNamespaceBaseInfo(appId, env, clusterName, namespaceName);
    } catch (Exception e) {
        // not existed
        namespaceDTO = null;
    }
    if (namespaceDTO == null) {
        namespaceDTO = new NamespaceDTO();
        namespaceDTO.setAppId(appId);
        namespaceDTO.setClusterName(clusterName);
        namespaceDTO.setNamespaceName(namespaceName);
        namespaceDTO.setDataChangeCreatedBy(operator);
        namespaceDTO.setDataChangeLastModifiedBy(operator);
        namespaceDTO = namespaceService.createNamespace(env, namespaceDTO);
        roleInitializationService.initNamespaceRoles(appId, namespaceName, operator);
        roleInitializationService.initNamespaceEnvRoles(appId, namespaceName, operator);
    }
    List<ItemDTO> itemDTOS = itemService.findItems(appId, env, clusterName, namespaceName);
    // skip import if target namespace has existed items
    if (!CollectionUtils.isEmpty(itemDTOS) && ignoreConflictNamespace) {
        return;
    }
    importItems(appId, env, clusterName, namespaceName, configText, namespaceDTO, operator);
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) ServerException(java.rmi.ServerException) IOException(java.io.IOException) ServiceException(com.ctrip.framework.apollo.common.exception.ServiceException)

Example 22 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceBranchService method createBranch.

@Transactional
public NamespaceDTO createBranch(String appId, Env env, String parentClusterName, String namespaceName, String operator) {
    NamespaceDTO createdBranch = namespaceBranchAPI.createBranch(appId, env, parentClusterName, namespaceName, operator);
    Tracer.logEvent(TracerEventType.CREATE_GRAY_RELEASE, String.format("%s+%s+%s+%s", appId, env, parentClusterName, namespaceName));
    return createdBranch;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceService method findNamespaceBOs.

/**
 * load cluster all namespace info with items
 */
public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) {
    List<NamespaceDTO> namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName);
    if (namespaces == null || namespaces.size() == 0) {
        throw new BadRequestException("namespaces not exist");
    }
    List<NamespaceBO> namespaceBOs = new LinkedList<>();
    for (NamespaceDTO namespace : namespaces) {
        NamespaceBO namespaceBO;
        try {
            namespaceBO = transformNamespace2BO(env, namespace);
            namespaceBOs.add(namespaceBO);
        } catch (Exception e) {
            LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", appId, env, clusterName, namespace.getNamespaceName(), e);
            throw e;
        }
    }
    return namespaceBOs;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO) NamespaceBO(com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) LinkedList(java.util.LinkedList) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException)

Example 24 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO in project apollo by ctripcorp.

the class NamespaceService method createNamespace.

public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
    if (StringUtils.isEmpty(namespace.getDataChangeCreatedBy())) {
        namespace.setDataChangeCreatedBy(userInfoHolder.getUser().getUserId());
    }
    if (StringUtils.isEmpty(namespace.getDataChangeLastModifiedBy())) {
        namespace.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
    }
    NamespaceDTO createdNamespace = namespaceAPI.createNamespace(env, namespace);
    Tracer.logEvent(TracerEventType.CREATE_NAMESPACE, String.format("%s+%s+%s+%s", namespace.getAppId(), env, namespace.getClusterName(), namespace.getNamespaceName()));
    return createdNamespace;
}
Also used : NamespaceDTO(com.ctrip.framework.apollo.common.dto.NamespaceDTO)

Example 25 with NamespaceDTO

use of com.ctrip.framework.apollo.common.dto.NamespaceDTO 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

NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)36 Test (org.junit.Test)13 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)12 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)10 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)8 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)7 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)7 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)4 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)4 Sql (org.springframework.test.context.jdbc.Sql)4 Item (com.ctrip.framework.apollo.biz.entity.Item)3 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)3 OpenNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO)3 NamespaceBO (com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO)3 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)3 Env (com.ctrip.framework.apollo.portal.environment.Env)3 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RestTemplate (org.springframework.web.client.RestTemplate)3