Search in sources :

Example 6 with NamespaceIdentifier

use of com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier in project apollo by ctripcorp.

the class ItemService method syncItems.

public void syncItems(List<NamespaceIdentifier> comparedNamespaces, List<ItemDTO> sourceItems) {
    List<ItemDiffs> itemDiffs = compare(comparedNamespaces, sourceItems);
    for (ItemDiffs itemDiff : itemDiffs) {
        NamespaceIdentifier namespaceIdentifier = itemDiff.getNamespace();
        ItemChangeSets changeSets = itemDiff.getDiffs();
        changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
        String appId = namespaceIdentifier.getAppId();
        Env env = namespaceIdentifier.getEnv();
        String clusterName = namespaceIdentifier.getClusterName();
        String namespaceName = namespaceIdentifier.getNamespaceName();
        itemAPI.updateItemsByChangeSet(appId, env, clusterName, namespaceName, changeSets);
        Tracer.logEvent(TracerEventType.SYNC_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
    }
}
Also used : NamespaceIdentifier(com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) ItemDiffs(com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs) Env(com.ctrip.framework.apollo.portal.environment.Env)

Example 7 with NamespaceIdentifier

use of com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier in project apollo by ctripcorp.

the class ItemService method compare.

public List<ItemDiffs> compare(List<NamespaceIdentifier> comparedNamespaces, List<ItemDTO> sourceItems) {
    List<ItemDiffs> result = new LinkedList<>();
    for (NamespaceIdentifier namespace : comparedNamespaces) {
        ItemDiffs itemDiffs = new ItemDiffs(namespace);
        try {
            itemDiffs.setDiffs(parseChangeSets(namespace, sourceItems));
        } catch (BadRequestException e) {
            itemDiffs.setDiffs(new ItemChangeSets());
            itemDiffs.setExtInfo("该集群下没有名为 " + namespace.getNamespaceName() + " 的namespace");
        }
        result.add(itemDiffs);
    }
    return result;
}
Also used : NamespaceIdentifier(com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier) ItemChangeSets(com.ctrip.framework.apollo.common.dto.ItemChangeSets) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) ItemDiffs(com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs) LinkedList(java.util.LinkedList)

Aggregations

NamespaceIdentifier (com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier)7 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)5 ItemDiffs (com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs)5 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)2 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)2 AbstractUnitTest (com.ctrip.framework.apollo.portal.AbstractUnitTest)2 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)2 Env (com.ctrip.framework.apollo.portal.environment.Env)2 Test (org.junit.Test)2 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 LinkedList (java.util.LinkedList)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1