Search in sources :

Example 11 with ReleaseHistory

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

the class ReleaseCreationTest method testPublishNormalNamespace.

@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPublishNormalNamespace() {
    long namespaceId = 100;
    String clusterName = "only-master";
    Namespace namespace = instanceNamespace(namespaceId, clusterName);
    releaseService.publish(namespace, "", "", operator, false);
    Release latestRelease = releaseService.findLatestActiveRelease(namespace);
    Assert.assertNotNull(latestRelease);
    Map<String, String> configuration = parseConfiguration(latestRelease.getConfigurations());
    Assert.assertEquals(3, configuration.size());
    Assert.assertEquals("v1", configuration.get("k1"));
    Assert.assertEquals("v2", configuration.get("k2"));
    Assert.assertEquals("v3", configuration.get("k3"));
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, clusterName, testNamespace, pageable);
    ReleaseHistory releaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(1, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.NORMAL_RELEASE, releaseHistory.getOperation());
    Assert.assertEquals(latestRelease.getId(), releaseHistory.getReleaseId());
    Assert.assertEquals(0, releaseHistory.getPreviousReleaseId());
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 12 with ReleaseHistory

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

the class ReleaseHistoryController method transform2PageDTO.

private PageDTO<ReleaseHistoryDTO> transform2PageDTO(Page<ReleaseHistory> releaseHistoriesPage, Pageable pageable) {
    if (!releaseHistoriesPage.hasContent()) {
        return null;
    }
    List<ReleaseHistory> releaseHistories = releaseHistoriesPage.getContent();
    List<ReleaseHistoryDTO> releaseHistoryDTOs = new ArrayList<>(releaseHistories.size());
    for (ReleaseHistory releaseHistory : releaseHistories) {
        releaseHistoryDTOs.add(transformReleaseHistory2DTO(releaseHistory));
    }
    return new PageDTO<>(releaseHistoryDTOs, pageable, releaseHistoriesPage.getTotalElements());
}
Also used : ReleaseHistoryDTO(com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO) PageDTO(com.ctrip.framework.apollo.common.dto.PageDTO) ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) ArrayList(java.util.ArrayList)

Example 13 with ReleaseHistory

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

the class ReleaseHistoryService method createReleaseHistory.

@Transactional
public ReleaseHistory createReleaseHistory(String appId, String clusterName, String namespaceName, String branchName, long releaseId, long previousReleaseId, int operation, Map<String, Object> operationContext, String operator) {
    ReleaseHistory releaseHistory = new ReleaseHistory();
    releaseHistory.setAppId(appId);
    releaseHistory.setClusterName(clusterName);
    releaseHistory.setNamespaceName(namespaceName);
    releaseHistory.setBranchName(branchName);
    releaseHistory.setReleaseId(releaseId);
    releaseHistory.setPreviousReleaseId(previousReleaseId);
    releaseHistory.setOperation(operation);
    if (operationContext == null) {
        // default empty object
        releaseHistory.setOperationContext("{}");
    } else {
        releaseHistory.setOperationContext(GSON.toJson(operationContext));
    }
    releaseHistory.setDataChangeCreatedTime(new Date());
    releaseHistory.setDataChangeCreatedBy(operator);
    releaseHistory.setDataChangeLastModifiedBy(operator);
    releaseHistoryRepository.save(releaseHistory);
    auditService.audit(ReleaseHistory.class.getSimpleName(), releaseHistory.getId(), Audit.OP.INSERT, releaseHistory.getDataChangeCreatedBy());
    return releaseHistory;
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)13 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)11 Test (org.junit.Test)11 Sql (org.springframework.test.context.jdbc.Sql)11 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)8 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)8 Release (com.ctrip.framework.apollo.biz.entity.Release)8 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)1 Commit (com.ctrip.framework.apollo.biz.entity.Commit)1 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)1 Item (com.ctrip.framework.apollo.biz.entity.Item)1 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)1 ReleaseHistoryDTO (com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO)1 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1