Search in sources :

Example 61 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method testNamespaceModifyItem.

@Test
public void testNamespaceModifyItem() {
    long namespaceId = 1;
    Namespace namespace = createNamespace(namespaceId);
    Release release = createRelease("{\"k1\":\"v1\"}");
    List<Item> items = Collections.singletonList(createItem("k1", "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 62 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method testChildNamespaceModified.

@Test
public void testChildNamespaceModified() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    List<Item> childItems = Collections.singletonList(createItem("k1", "v3"));
    Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    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 63 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class NamespaceUnlockAspectTest method createRelease.

private Release createRelease(String configuration) {
    Release release = new Release();
    release.setConfigurations(configuration);
    return release;
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 64 with Release

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

Example 65 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class ReleaseService method mergeBranchChangeSetsAndRelease.

@Transactional
public Release mergeBranchChangeSetsAndRelease(Namespace namespace, String branchName, String releaseName, String releaseComment, boolean isEmergencyPublish, ItemChangeSets changeSets) {
    checkLock(namespace, isEmergencyPublish, changeSets.getDataChangeLastModifiedBy());
    itemSetService.updateSet(namespace, changeSets);
    Release branchRelease = findLatestActiveRelease(namespace.getAppId(), branchName, namespace.getNamespaceName());
    long branchReleaseId = branchRelease == null ? 0 : branchRelease.getId();
    Map<String, String> operateNamespaceItems = getNamespaceItems(namespace);
    Map<String, Object> operationContext = Maps.newLinkedHashMap();
    operationContext.put(ReleaseOperationContext.SOURCE_BRANCH, branchName);
    operationContext.put(ReleaseOperationContext.BASE_RELEASE_ID, branchReleaseId);
    operationContext.put(ReleaseOperationContext.IS_EMERGENCY_PUBLISH, isEmergencyPublish);
    return masterRelease(namespace, releaseName, releaseComment, operateNamespaceItems, changeSets.getDataChangeLastModifiedBy(), ReleaseOperation.GRAY_RELEASE_MERGE_TO_MASTER, operationContext);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Transactional(org.springframework.transaction.annotation.Transactional)

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