Search in sources :

Example 26 with Release

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);
}
Also used : NotFoundException(com.ctrip.framework.apollo.common.exception.NotFoundException) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with 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());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Instance(com.ctrip.framework.apollo.biz.entity.Instance) Date(java.util.Date) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 28 with Release

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);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 29 with Release

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);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 30 with Release

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;
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release)

Aggregations

Release (com.ctrip.framework.apollo.biz.entity.Release)71 Test (org.junit.Test)36 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)22 Item (com.ctrip.framework.apollo.biz.entity.Item)12 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)9 Transactional (org.springframework.transaction.annotation.Transactional)9 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)7 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)7 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)7 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)7 Sql (org.springframework.test.context.jdbc.Sql)7 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)5 Instance (com.ctrip.framework.apollo.biz.entity.Instance)4 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)4 Date (java.util.Date)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)3 ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)3 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PageRequest (org.springframework.data.domain.PageRequest)3