use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class NamespaceUnlockAspectTest method testNamespaceHasNoNormalItemsAndRelease.
@Test
public void testNamespaceHasNoNormalItemsAndRelease() {
long namespaceId = 1;
Namespace namespace = createNamespace(namespaceId);
when(releaseService.findLatestActiveRelease(namespace)).thenReturn(null);
when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(Collections.singletonList(createItem("", "")));
boolean isModified = namespaceUnlockAspect.isModified(namespace);
Assert.assertFalse(isModified);
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseService method grayDeletionPublish.
@Transactional
public Release grayDeletionPublish(Namespace namespace, String releaseName, String releaseComment, String operator, boolean isEmergencyPublish, Set<String> grayDelKeys) {
checkLock(namespace, isEmergencyPublish, operator);
Map<String, String> operateNamespaceItems = getNamespaceItems(namespace);
Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
// branch release
if (parentNamespace != null) {
return publishBranchNamespace(parentNamespace, namespace, operateNamespaceItems, releaseName, releaseComment, operator, isEmergencyPublish, grayDelKeys);
}
throw new NotFoundException("Parent namespace not found");
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseService method rollbackChildNamespace.
private void rollbackChildNamespace(String appId, String clusterName, String namespaceName, List<Release> parentNamespaceTwoLatestActiveRelease, String operator) {
Namespace parentNamespace = namespaceService.findOne(appId, clusterName, namespaceName);
Namespace childNamespace = namespaceService.findChildNamespace(appId, clusterName, namespaceName);
if (parentNamespace == null || childNamespace == null) {
return;
}
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;
}
Release abandonedRelease = parentNamespaceTwoLatestActiveRelease.get(0);
Release parentNamespaceNewLatestRelease = parentNamespaceTwoLatestActiveRelease.get(1);
Map<String, String> parentNamespaceAbandonedConfiguration = GSON.fromJson(abandonedRelease.getConfigurations(), GsonType.CONFIG);
Map<String, String> parentNamespaceNewLatestConfiguration = GSON.fromJson(parentNamespaceNewLatestRelease.getConfigurations(), GsonType.CONFIG);
Map<String, String> childNamespaceNewConfiguration = calculateChildNamespaceToPublishConfiguration(parentNamespaceAbandonedConfiguration, parentNamespaceNewLatestConfiguration, childReleaseConfiguration, branchReleaseKeys);
// compare
if (!childNamespaceNewConfiguration.equals(childReleaseConfiguration)) {
branchRelease(parentNamespace, childNamespace, TIMESTAMP_FORMAT.format(new Date()) + "-master-rollback-merge-to-gray", "", childNamespaceNewConfiguration, parentNamespaceNewLatestRelease.getId(), operator, ReleaseOperation.MATER_ROLLBACK_MERGE_TO_GRAY, false, branchReleaseKeys);
}
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class ReleaseService method publish.
@Transactional
public Release publish(Namespace namespace, String releaseName, String releaseComment, String operator, boolean isEmergencyPublish) {
checkLock(namespace, isEmergencyPublish, operator);
Map<String, String> operateNamespaceItems = getNamespaceItems(namespace);
Namespace parentNamespace = namespaceService.findParentNamespace(namespace);
// branch release
if (parentNamespace != null) {
return publishBranchNamespace(parentNamespace, namespace, operateNamespaceItems, releaseName, releaseComment, operator, isEmergencyPublish);
}
Namespace childNamespace = namespaceService.findChildNamespace(namespace);
Release previousRelease = null;
if (childNamespace != null) {
previousRelease = findLatestActiveRelease(namespace);
}
// master release
Map<String, Object> operationContext = Maps.newLinkedHashMap();
operationContext.put(ReleaseOperationContext.IS_EMERGENCY_PUBLISH, isEmergencyPublish);
Release release = masterRelease(namespace, releaseName, releaseComment, operateNamespaceItems, operator, ReleaseOperation.NORMAL_RELEASE, operationContext);
// merge to branch and auto release
if (childNamespace != null) {
mergeFromMasterAndPublishBranch(namespace, childNamespace, operateNamespaceItems, releaseName, releaseComment, operator, previousRelease, release, isEmergencyPublish);
}
return release;
}
use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.
the class AppNamespaceService method createNamespaceForAppNamespaceInAllCluster.
public void createNamespaceForAppNamespaceInAllCluster(String appId, String namespaceName, String createBy) {
List<Cluster> clusters = clusterService.findParentClusters(appId);
for (Cluster cluster : clusters) {
// in case there is some dirty data, e.g. public namespace deleted in other app and now created in this app
if (!namespaceService.isNamespaceUnique(appId, cluster.getName(), namespaceName)) {
continue;
}
Namespace namespace = new Namespace();
namespace.setClusterName(cluster.getName());
namespace.setAppId(appId);
namespace.setNamespaceName(namespaceName);
namespace.setDataChangeCreatedBy(createBy);
namespace.setDataChangeLastModifiedBy(createBy);
namespaceService.save(namespace);
}
}
Aggregations