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);
}
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;
}
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);
}
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;
}
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");
}
Aggregations