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