Search in sources :

Example 46 with Namespace

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

the class ReleaseControllerTest method testMessageSendAfterBuildRelease.

@Test
public void testMessageSendAfterBuildRelease() throws Exception {
    String someAppId = "someAppId";
    String someNamespaceName = "someNamespace";
    String someCluster = "someCluster";
    String someName = "someName";
    String someComment = "someComment";
    String someUserName = "someUser";
    NamespaceService someNamespaceService = mock(NamespaceService.class);
    ReleaseService someReleaseService = mock(ReleaseService.class);
    MessageSender someMessageSender = mock(MessageSender.class);
    Namespace someNamespace = mock(Namespace.class);
    ReleaseController releaseController = new ReleaseController(someReleaseService, someNamespaceService, someMessageSender, null);
    when(someNamespaceService.findOne(someAppId, someCluster, someNamespaceName)).thenReturn(someNamespace);
    releaseController.publish(someAppId, someCluster, someNamespaceName, someName, someComment, "test", false);
    verify(someMessageSender, times(1)).sendMessage(Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).join(someAppId, someCluster, someNamespaceName), Topics.APOLLO_RELEASE_TOPIC);
}
Also used : ReleaseService(com.ctrip.framework.apollo.biz.service.ReleaseService) NamespaceService(com.ctrip.framework.apollo.biz.service.NamespaceService) MessageSender(com.ctrip.framework.apollo.biz.message.MessageSender) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Test(org.junit.Test)

Example 47 with Namespace

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

the class ItemController method update.

@PreAcquireNamespaceLock
@PutMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}")
public ItemDTO update(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @PathVariable("itemId") long itemId, @RequestBody ItemDTO itemDTO) {
    Item managedEntity = itemService.findOne(itemId);
    if (managedEntity == null) {
        throw new NotFoundException("item not found for itemId " + itemId);
    }
    Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
    // In case someone constructs an attack scenario
    if (namespace == null || namespace.getId() != managedEntity.getNamespaceId()) {
        throw new BadRequestException("Invalid request, item and namespace do not match!");
    }
    Item entity = BeanUtils.transform(Item.class, itemDTO);
    ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
    Item beforeUpdateItem = BeanUtils.transform(Item.class, managedEntity);
    // protect. only value,comment,lastModifiedBy can be modified
    managedEntity.setValue(entity.getValue());
    managedEntity.setComment(entity.getComment());
    managedEntity.setDataChangeLastModifiedBy(entity.getDataChangeLastModifiedBy());
    entity = itemService.update(managedEntity);
    builder.updateItem(beforeUpdateItem, entity);
    itemDTO = BeanUtils.transform(ItemDTO.class, entity);
    if (builder.hasContent()) {
        Commit commit = new Commit();
        commit.setAppId(appId);
        commit.setClusterName(clusterName);
        commit.setNamespaceName(namespaceName);
        commit.setChangeSets(builder.build());
        commit.setDataChangeCreatedBy(itemDTO.getDataChangeLastModifiedBy());
        commit.setDataChangeLastModifiedBy(itemDTO.getDataChangeLastModifiedBy());
        commitService.save(commit);
    }
    return itemDTO;
}
Also used : ConfigChangeContentBuilder(com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder) Item(com.ctrip.framework.apollo.biz.entity.Item) Commit(com.ctrip.framework.apollo.biz.entity.Commit) ItemDTO(com.ctrip.framework.apollo.common.dto.ItemDTO) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) PutMapping(org.springframework.web.bind.annotation.PutMapping) PreAcquireNamespaceLock(com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)

Example 48 with Namespace

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

the class NamespaceBranchController method checkBranch.

private void checkBranch(String appId, String clusterName, String namespaceName, String branchName) {
    // 1. check parent namespace
    checkNamespace(appId, clusterName, namespaceName);
    // 2. check child namespace
    Namespace childNamespace = namespaceService.findOne(appId, branchName, namespaceName);
    if (childNamespace == null) {
        throw new BadRequestException("Namespace's branch not exist. AppId = %s, ClusterName = %s, NamespaceName = %s, BranchName = %s", appId, clusterName, namespaceName, branchName);
    }
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace)

Example 49 with Namespace

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

the class NamespaceController method delete.

@DeleteMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}")
public void delete(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @RequestParam String operator) {
    Namespace entity = namespaceService.findOne(appId, clusterName, namespaceName);
    if (entity == null) {
        throw new NotFoundException("namespace not found for %s %s %s", appId, clusterName, namespaceName);
    }
    namespaceService.deleteNamespace(entity, operator);
}
Also used : NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 50 with Namespace

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

the class NamespaceLockTest method mockNamespace.

private Namespace mockNamespace() {
    Namespace namespace = new Namespace();
    namespace.setId(NAMESPACE_ID);
    namespace.setAppId(APP);
    namespace.setClusterName(CLUSTER);
    namespace.setNamespaceName(NAMESPACE);
    return namespace;
}
Also used : Namespace(com.ctrip.framework.apollo.biz.entity.Namespace)

Aggregations

Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)60 Test (org.junit.Test)24 Release (com.ctrip.framework.apollo.biz.entity.Release)22 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)14 Item (com.ctrip.framework.apollo.biz.entity.Item)13 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)10 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)10 Sql (org.springframework.test.context.jdbc.Sql)10 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)8 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)8 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)8 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)4 Commit (com.ctrip.framework.apollo.biz.entity.Commit)3 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)2 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2