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