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