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