use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class ReleaseController method publish.
@Transactional
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/gray-del-releases")
public ReleaseDTO publish(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @RequestParam("operator") String operator, @RequestParam("releaseName") String releaseName, @RequestParam(name = "comment", required = false) String releaseComment, @RequestParam(name = "isEmergencyPublish", defaultValue = "false") boolean isEmergencyPublish, @RequestParam(name = "grayDelKeys") Set<String> grayDelKeys) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException("Could not find namespace for %s %s %s", appId, clusterName, namespaceName);
}
Release release = releaseService.grayDeletionPublish(namespace, releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys);
// send release message
Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
String messageCluster;
if (parentNamespace != null) {
messageCluster = parentNamespace.getClusterName();
} else {
messageCluster = clusterName;
}
messageSender.sendMessage(ReleaseMessageKeyGenerator.generate(appId, messageCluster, namespaceName), Topics.APOLLO_RELEASE_TOPIC);
return BeanUtils.transform(ReleaseDTO.class, release);
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class InstanceConfigControllerTest method getByRelease.
@Test
public void getByRelease() throws Exception {
long someReleaseId = 1;
long someInstanceId = 1;
long anotherInstanceId = 2;
String someReleaseKey = "someKey";
Release someRelease = new Release();
someRelease.setReleaseKey(someReleaseKey);
String someAppId = "someAppId";
String anotherAppId = "anotherAppId";
String someCluster = "someCluster";
String someDataCenter = "someDC";
String someConfigAppId = "someConfigAppId";
String someConfigNamespace = "someNamespace";
String someIp = "someIp";
Date someReleaseDeliveryTime = new Date();
Date anotherReleaseDeliveryTime = new Date();
when(releaseService.findOne(someReleaseId)).thenReturn(someRelease);
InstanceConfig someInstanceConfig = assembleInstanceConfig(someInstanceId, someConfigAppId, someConfigNamespace, someReleaseKey, someReleaseDeliveryTime);
InstanceConfig anotherInstanceConfig = assembleInstanceConfig(anotherInstanceId, someConfigAppId, someConfigNamespace, someReleaseKey, anotherReleaseDeliveryTime);
List<InstanceConfig> instanceConfigs = Lists.newArrayList(someInstanceConfig, anotherInstanceConfig);
Page<InstanceConfig> instanceConfigPage = new PageImpl<>(instanceConfigs, pageable, instanceConfigs.size());
when(instanceService.findActiveInstanceConfigsByReleaseKey(someReleaseKey, pageable)).thenReturn(instanceConfigPage);
Instance someInstance = assembleInstance(someInstanceId, someAppId, someCluster, someDataCenter, someIp);
Instance anotherInstance = assembleInstance(anotherInstanceId, anotherAppId, someCluster, someDataCenter, someIp);
List<Instance> instances = Lists.newArrayList(someInstance, anotherInstance);
Set<Long> instanceIds = Sets.newHashSet(someInstanceId, anotherInstanceId);
when(instanceService.findInstancesByIds(instanceIds)).thenReturn(instances);
PageDTO<InstanceDTO> result = instanceConfigController.getByRelease(someReleaseId, pageable);
assertEquals(2, result.getContent().size());
InstanceDTO someInstanceDto = null;
InstanceDTO anotherInstanceDto = null;
for (InstanceDTO instanceDTO : result.getContent()) {
if (instanceDTO.getId() == someInstanceId) {
someInstanceDto = instanceDTO;
} else if (instanceDTO.getId() == anotherInstanceId) {
anotherInstanceDto = instanceDTO;
}
}
verifyInstance(someInstance, someInstanceDto);
verifyInstance(anotherInstance, anotherInstanceDto);
assertEquals(1, someInstanceDto.getConfigs().size());
assertEquals(someReleaseDeliveryTime, someInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
assertEquals(1, anotherInstanceDto.getConfigs().size());
assertEquals(anotherReleaseDeliveryTime, anotherInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class NamespaceUnlockAspectTest method testNamespaceDeleteItem.
@Test
public void testNamespaceDeleteItem() {
long namespaceId = 1;
Namespace namespace = createNamespace(namespaceId);
Release release = createRelease("{\"k1\":\"v1\"}");
List<Item> items = Collections.singletonList(createItem("k2", "v2"));
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items);
when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
boolean isModified = namespaceUnlockAspect.isModified(namespace);
Assert.assertTrue(isModified);
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class NamespaceUnlockAspectTest method testNamespaceAddItem.
@Test
public void testNamespaceAddItem() {
long namespaceId = 1;
Namespace namespace = createNamespace(namespaceId);
Release release = createRelease("{\"k1\":\"v1\"}");
List<Item> items = Arrays.asList(createItem("k1", "v1"), createItem("k2", "v2"));
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items);
when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
boolean isModified = namespaceUnlockAspect.isModified(namespace);
Assert.assertTrue(isModified);
}
use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.
the class AbstractConfigService method findRelease.
/**
* Find release
*
* @param clientAppId the client's app id
* @param clientIp the client ip
* @param clientLabel the client label
* @param configAppId the requested config's app id
* @param configClusterName the requested config's cluster name
* @param configNamespace the requested config's namespace name
* @param clientMessages the messages received in client side
* @return the release
*/
private Release findRelease(String clientAppId, String clientIp, String clientLabel, String configAppId, String configClusterName, String configNamespace, ApolloNotificationMessages clientMessages) {
Long grayReleaseId = grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(clientAppId, clientIp, clientLabel, configAppId, configClusterName, configNamespace);
Release release = null;
if (grayReleaseId != null) {
release = findActiveOne(grayReleaseId, clientMessages);
}
if (release == null) {
release = findLatestActiveRelease(configAppId, configClusterName, configNamespace, clientMessages);
}
return release;
}
Aggregations