use of com.ctrip.framework.apollo.common.exception.BadRequestException 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);
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException 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;
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException 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);
}
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException 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);
}
use of com.ctrip.framework.apollo.common.exception.BadRequestException 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()));
}
Aggregations