Search in sources :

Example 11 with NotFoundException

use of com.ctrip.framework.apollo.common.exception.NotFoundException in project apollo by ctripcorp.

the class ClusterController method delete.

@DeleteMapping("/apps/{appId}/clusters/{clusterName:.+}")
public void delete(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @RequestParam String operator) {
    Cluster entity = clusterService.findOne(appId, clusterName);
    if (entity == null) {
        throw new NotFoundException("cluster not found for clusterName " + clusterName);
    }
    if (ConfigConsts.CLUSTER_NAME_DEFAULT.equals(entity.getName())) {
        throw new BadRequestException("can not delete default cluster!");
    }
    clusterService.delete(entity.getId(), operator);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 12 with NotFoundException

use of com.ctrip.framework.apollo.common.exception.NotFoundException 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 13 with NotFoundException

use of com.ctrip.framework.apollo.common.exception.NotFoundException 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 14 with NotFoundException

use of com.ctrip.framework.apollo.common.exception.NotFoundException in project apollo by ctripcorp.

the class ReleaseService method rollbackTo.

@Transactional
public Release rollbackTo(long releaseId, long toReleaseId, String operator) {
    if (releaseId == toReleaseId) {
        throw new BadRequestException("current release equal to target release");
    }
    Release release = findOne(releaseId);
    Release toRelease = findOne(toReleaseId);
    if (release == null || toRelease == null) {
        throw new NotFoundException("release not found");
    }
    if (release.isAbandoned() || toRelease.isAbandoned()) {
        throw new BadRequestException("release is not active");
    }
    String appId = release.getAppId();
    String clusterName = release.getClusterName();
    String namespaceName = release.getNamespaceName();
    List<Release> releases = findActiveReleasesBetween(appId, clusterName, namespaceName, toReleaseId, releaseId);
    for (int i = 0; i < releases.size() - 1; i++) {
        releases.get(i).setAbandoned(true);
        releases.get(i).setDataChangeLastModifiedBy(operator);
    }
    releaseRepository.saveAll(releases);
    releaseHistoryService.createReleaseHistory(appId, clusterName, namespaceName, clusterName, toReleaseId, release.getId(), ReleaseOperation.ROLLBACK, null, operator);
    // publish child namespace if namespace has child
    rollbackChildNamespace(appId, clusterName, namespaceName, Lists.newArrayList(release, toRelease), operator);
    return release;
}
Also used : BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) Release(com.ctrip.framework.apollo.biz.entity.Release) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with NotFoundException

use of com.ctrip.framework.apollo.common.exception.NotFoundException in project apollo by ctripcorp.

the class ReleaseService method grayDeletionPublish.

@Transactional
public Release grayDeletionPublish(Namespace namespace, String releaseName, String releaseComment, String operator, boolean isEmergencyPublish, Set<String> grayDelKeys) {
    checkLock(namespace, isEmergencyPublish, operator);
    Map<String, String> operateNamespaceItems = getNamespaceItems(namespace);
    Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
    // branch release
    if (parentNamespace != null) {
        return publishBranchNamespace(parentNamespace, namespace, operateNamespaceItems, releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys);
    }
    throw new NotFoundException("Parent namespace not found");
}
Also used : NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)16 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)8 Release (com.ctrip.framework.apollo.biz.entity.Release)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Item (com.ctrip.framework.apollo.biz.entity.Item)4 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)4 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)3 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)3 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PageRequest (org.springframework.data.domain.PageRequest)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)2 Commit (com.ctrip.framework.apollo.biz.entity.Commit)2 Instance (com.ctrip.framework.apollo.biz.entity.Instance)2 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)2 InstanceService (com.ctrip.framework.apollo.biz.service.InstanceService)2 ReleaseService (com.ctrip.framework.apollo.biz.service.ReleaseService)2 InstanceConfigDTO (com.ctrip.framework.apollo.common.dto.InstanceConfigDTO)2 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)2 ItemDTO (com.ctrip.framework.apollo.common.dto.ItemDTO)2