Search in sources :

Example 11 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespacePublishInfoTest method createItem.

private Item createItem(long namespaceId, String key, String value) {
    Item item = new Item();
    item.setNamespaceId(namespaceId);
    item.setKey(key);
    item.setValue(value);
    return item;
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item)

Example 12 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class ReleaseService method getNamespaceItems.

private Map<String, String> getNamespaceItems(Namespace namespace) {
    List<Item> items = itemService.findItemsWithoutOrdered(namespace.getId());
    Map<String, String> configurations = new HashMap<String, String>();
    for (Item item : items) {
        if (StringUtils.isEmpty(item.getKey())) {
            continue;
        }
        configurations.put(item.getKey(), item.getValue());
    }
    return configurations;
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) HashMap(java.util.HashMap)

Example 13 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespaceAcquireLockAspect method requireLockAdvice.

// delete item
@Before("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)")
public void requireLockAdvice(long itemId, String operator) {
    Item item = itemService.findOne(itemId);
    if (item == null) {
        throw new BadRequestException("item not exist.");
    }
    acquireLock(item.getNamespaceId(), operator);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Before(org.aspectj.lang.annotation.Before)

Example 14 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespaceUnlockAspect method requireLockAdvice.

// delete item
@After("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)")
public void requireLockAdvice(long itemId, String operator) {
    Item item = itemService.findOne(itemId);
    if (item == null) {
        throw new BadRequestException("item not exist.");
    }
    tryUnlock(namespaceService.findOne(item.getNamespaceId()));
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) After(org.aspectj.lang.annotation.After)

Example 15 with Item

use of com.ctrip.framework.apollo.biz.entity.Item in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method testNamespaceModifyItem.

@Test
public void testNamespaceModifyItem() {
    long namespaceId = 1;
    Namespace namespace = createNamespace(namespaceId);
    Release release = createRelease("{\"k1\":\"v1\"}");
    List<Item> items = Arrays.asList(createItem("k1", "v2"));
    when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
    when(itemService.findItemsWithOrdered(namespaceId)).thenReturn(items);
    when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
    boolean isModified = namespaceUnlockAspect.isModified(namespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Aggregations

Item (com.ctrip.framework.apollo.biz.entity.Item)30 Test (org.junit.Test)13 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)12 Release (com.ctrip.framework.apollo.biz.entity.Release)11 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)6 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)4 Commit (com.ctrip.framework.apollo.biz.entity.Commit)4 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)4 Sql (org.springframework.test.context.jdbc.Sql)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)3 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)3 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)3 ClusterDTO (com.ctrip.framework.apollo.common.dto.ClusterDTO)3 ItemChangeSets (com.ctrip.framework.apollo.common.dto.ItemChangeSets)3 NamespaceDTO (com.ctrip.framework.apollo.common.dto.NamespaceDTO)3 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)3 TestRestTemplate (org.springframework.boot.test.TestRestTemplate)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3