use of com.ctrip.framework.apollo.common.dto.ItemChangeSets in project apollo by ctripcorp.
the class NamespaceBranchService method calculateBranchChangeSet.
private ItemChangeSets calculateBranchChangeSet(String appId, Env env, String clusterName, String namespaceName, String branchName, String operator) {
NamespaceBO parentNamespace = namespaceService.loadNamespaceBO(appId, env, clusterName, namespaceName);
if (parentNamespace == null) {
throw new BadRequestException("base namespace not existed");
}
if (parentNamespace.getItemModifiedCnt() > 0) {
throw new BadRequestException("Merge operation failed. Because master has modified items");
}
List<ItemDTO> masterItems = itemService.findItems(appId, env, clusterName, namespaceName);
List<ItemDTO> branchItems = itemService.findItems(appId, env, branchName, namespaceName);
ItemChangeSets changeSets = itemsComparator.compareIgnoreBlankAndCommentItem(parentNamespace.getBaseInfo().getId(), masterItems, branchItems);
changeSets.setDeleteItems(Collections.emptyList());
changeSets.setDataChangeLastModifiedBy(operator);
return changeSets;
}
use of com.ctrip.framework.apollo.common.dto.ItemChangeSets in project apollo by ctripcorp.
the class ItemService method revokeItem.
public void revokeItem(String appId, Env env, String clusterName, String namespaceName) {
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();
Map<String, String> releaseItemDTOs = new HashMap<>();
ReleaseDTO latestRelease = releaseAPI.loadLatestRelease(appId, env, clusterName, namespaceName);
if (latestRelease != null) {
releaseItemDTOs = GSON.fromJson(latestRelease.getConfigurations(), GsonType.CONFIG);
}
List<ItemDTO> baseItems = itemAPI.findItems(appId, env, clusterName, namespaceName);
Map<String, ItemDTO> oldKeyMapItem = BeanUtils.mapByKey("key", baseItems);
Map<String, ItemDTO> deletedItemDTOs = new HashMap<>();
// deleted items for comment
findDeletedItems(appId, env, clusterName, namespaceName).forEach(item -> {
deletedItemDTOs.put(item.getKey(), item);
});
ItemChangeSets changeSets = new ItemChangeSets();
AtomicInteger lineNum = new AtomicInteger(1);
releaseItemDTOs.forEach((key, value) -> {
ItemDTO oldItem = oldKeyMapItem.get(key);
if (oldItem == null) {
ItemDTO deletedItemDto = deletedItemDTOs.computeIfAbsent(key, k -> new ItemDTO());
changeSets.addCreateItem(buildNormalItem(0L, namespaceId, key, value, deletedItemDto.getComment(), lineNum.get()));
} else if (!oldItem.getValue().equals(value) || lineNum.get() != oldItem.getLineNum()) {
changeSets.addUpdateItem(buildNormalItem(oldItem.getId(), namespaceId, key, value, oldItem.getComment(), lineNum.get()));
}
oldKeyMapItem.remove(key);
lineNum.set(lineNum.get() + 1);
});
oldKeyMapItem.forEach((key, value) -> changeSets.addDeleteItem(oldKeyMapItem.get(key)));
changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
updateItems(appId, env, clusterName, namespaceName, changeSets);
String formatStr = String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName);
Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE_BY_TEXT, formatStr);
Tracer.logEvent(TracerEventType.MODIFY_NAMESPACE, formatStr);
}
use of com.ctrip.framework.apollo.common.dto.ItemChangeSets in project apollo by ctripcorp.
the class PropertyResolverTest method testDeleteItem.
@Test
public void testDeleteItem() {
ItemChangeSets changeSets = resolver.resolve(1, "a=b", mockBaseItemHas3Key());
Assert.assertEquals(2, changeSets.getDeleteItems().size());
}
use of com.ctrip.framework.apollo.common.dto.ItemChangeSets in project apollo by ctripcorp.
the class PropertyResolverTest method testDeleteBlankItem.
@Test
public void testDeleteBlankItem() {
ItemChangeSets changeSets = resolver.resolve(1, "#qqqq\na=b\nb=c", mockBaseItemWith2Key1Comment1Blank());
Assert.assertEquals(1, changeSets.getDeleteItems().size());
Assert.assertEquals(1, changeSets.getUpdateItems().size());
Assert.assertEquals(0, changeSets.getCreateItems().size());
}
use of com.ctrip.framework.apollo.common.dto.ItemChangeSets in project apollo by ctripcorp.
the class PropertyResolverTest method testAddCommentAndBlankItem.
@Test
public void testAddCommentAndBlankItem() {
ItemChangeSets changeSets = resolver.resolve(1, "#ddd\na=b\n\nb=c\nc=d", mockBaseItemHas3Key());
Assert.assertEquals(2, changeSets.getCreateItems().size());
Assert.assertEquals(3, changeSets.getUpdateItems().size());
}
Aggregations