Search in sources :

Example 11 with Release

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

the class DefaultConfigServiceTest method testLoadConfigWithDefaultClusterWithNoDataCenterRelease.

@Test
public void testLoadConfigWithDefaultClusterWithNoDataCenterRelease() throws Exception {
    when(releaseService.findLatestActiveRelease(someConfigAppId, someDataCenter, defaultNamespaceName)).thenReturn(null);
    when(releaseService.findLatestActiveRelease(someConfigAppId, defaultClusterName, defaultNamespaceName)).thenReturn(someRelease);
    Release release = configService.loadConfig(someClientAppId, someClientIp, someClientLabel, someConfigAppId, defaultClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    verify(releaseService, times(1)).findLatestActiveRelease(someConfigAppId, someDataCenter, defaultNamespaceName);
    verify(releaseService, times(1)).findLatestActiveRelease(someConfigAppId, defaultClusterName, defaultNamespaceName);
    assertEquals(someRelease, release);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 12 with Release

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

the class NamespaceBranchService method deleteBranch.

@Transactional
public void deleteBranch(String appId, String clusterName, String namespaceName, String branchName, int branchStatus, String operator) {
    Cluster toDeleteCluster = clusterService.findOne(appId, branchName);
    if (toDeleteCluster == null) {
        return;
    }
    Release latestBranchRelease = releaseService.findLatestActiveRelease(appId, branchName, namespaceName);
    long latestBranchReleaseId = latestBranchRelease != null ? latestBranchRelease.getId() : 0;
    // update branch rules
    GrayReleaseRule deleteRule = new GrayReleaseRule();
    deleteRule.setRules("[]");
    deleteRule.setAppId(appId);
    deleteRule.setClusterName(clusterName);
    deleteRule.setNamespaceName(namespaceName);
    deleteRule.setBranchName(branchName);
    deleteRule.setBranchStatus(branchStatus);
    deleteRule.setDataChangeLastModifiedBy(operator);
    deleteRule.setDataChangeCreatedBy(operator);
    doUpdateBranchGrayRules(appId, clusterName, namespaceName, branchName, deleteRule, false, -1);
    // delete branch cluster
    clusterService.delete(toDeleteCluster.getId(), operator);
    int releaseOperation = branchStatus == NamespaceBranchStatus.MERGED ? ReleaseOperation.GRAY_RELEASE_DELETED_AFTER_MERGE : ReleaseOperation.ABANDON_GRAY_RELEASE;
    releaseHistoryService.createReleaseHistory(appId, clusterName, namespaceName, branchName, latestBranchReleaseId, latestBranchReleaseId, releaseOperation, null, operator);
    auditService.audit("Branch", toDeleteCluster.getId(), Audit.OP.DELETE, operator);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Release(com.ctrip.framework.apollo.biz.entity.Release) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with Release

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

the class ReleaseService method masterRelease.

private Release masterRelease(Namespace namespace, String releaseName, String releaseComment, Map<String, String> configurations, String operator, int releaseOperation, Map<String, Object> operationContext) {
    Release lastActiveRelease = findLatestActiveRelease(namespace);
    long previousReleaseId = lastActiveRelease == null ? 0 : lastActiveRelease.getId();
    Release release = createRelease(namespace, releaseName, releaseComment, configurations, operator);
    releaseHistoryService.createReleaseHistory(namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName(), namespace.getClusterName(), release.getId(), previousReleaseId, releaseOperation, operationContext, operator);
    return release;
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 14 with Release

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

the class ReleaseService method mergeFromMasterAndPublishBranch.

private void mergeFromMasterAndPublishBranch(Namespace parentNamespace, Namespace childNamespace, Map<String, String> parentNamespaceItems, String releaseName, String releaseComment, String operator, Release masterPreviousRelease, Release parentRelease, boolean isEmergencyPublish) {
    // create release for child namespace
    Release childNamespaceLatestActiveRelease = findLatestActiveRelease(childNamespace);
    Map<String, String> childReleaseConfiguration;
    Collection<String> branchReleaseKeys;
    if (childNamespaceLatestActiveRelease != null) {
        childReleaseConfiguration = GSON.fromJson(childNamespaceLatestActiveRelease.getConfigurations(), GsonType.CONFIG);
        branchReleaseKeys = getBranchReleaseKeys(childNamespaceLatestActiveRelease.getId());
    } else {
        childReleaseConfiguration = Collections.emptyMap();
        branchReleaseKeys = null;
    }
    Map<String, String> parentNamespaceOldConfiguration = masterPreviousRelease == null ? null : GSON.fromJson(masterPreviousRelease.getConfigurations(), GsonType.CONFIG);
    Map<String, String> childNamespaceToPublishConfigs = calculateChildNamespaceToPublishConfiguration(parentNamespaceOldConfiguration, parentNamespaceItems, childReleaseConfiguration, branchReleaseKeys);
    // compare
    if (!childNamespaceToPublishConfigs.equals(childReleaseConfiguration)) {
        branchRelease(parentNamespace, childNamespace, releaseName, releaseComment, childNamespaceToPublishConfigs, parentRelease.getId(), operator, ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, isEmergencyPublish, branchReleaseKeys);
    }
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 15 with Release

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

the class ReleaseService method publishBranchNamespace.

private Release publishBranchNamespace(Namespace parentNamespace, Namespace childNamespace, Map<String, String> childNamespaceItems, String releaseName, String releaseComment, String operator, boolean isEmergencyPublish, Set<String> grayDelKeys) {
    Release parentLatestRelease = findLatestActiveRelease(parentNamespace);
    Map<String, String> parentConfigurations = parentLatestRelease != null ? GSON.fromJson(parentLatestRelease.getConfigurations(), GsonType.CONFIG) : new LinkedHashMap<>();
    long baseReleaseId = parentLatestRelease == null ? 0 : parentLatestRelease.getId();
    Map<String, String> configsToPublish = mergeConfiguration(parentConfigurations, childNamespaceItems);
    if (!(grayDelKeys == null || grayDelKeys.size() == 0)) {
        for (String key : grayDelKeys) {
            configsToPublish.remove(key);
        }
    }
    return branchRelease(parentNamespace, childNamespace, releaseName, releaseComment, configsToPublish, baseReleaseId, operator, ReleaseOperation.GRAY_RELEASE, isEmergencyPublish, childNamespaceItems.keySet());
}
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