Search in sources :

Example 56 with Namespace

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);
}
Also used : Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Test(org.junit.Test)

Example 57 with Namespace

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

Example 58 with Namespace

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);
    }
}
Also used : Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release)

Example 59 with Namespace

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

Example 60 with Namespace

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);
    }
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace)

Aggregations

Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)60 Test (org.junit.Test)24 Release (com.ctrip.framework.apollo.biz.entity.Release)22 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)14 Item (com.ctrip.framework.apollo.biz.entity.Item)13 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)10 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)10 Sql (org.springframework.test.context.jdbc.Sql)10 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)8 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)8 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)8 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)4 Commit (com.ctrip.framework.apollo.biz.entity.Commit)3 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)2 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2