use of com.ctrip.framework.apollo.biz.entity.Commit in project apollo by ctripcorp.
the class NamespaceServiceIntegrationTest method testGetCommitsByModifiedTime.
@Test
@Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testGetCommitsByModifiedTime() throws ParseException {
String format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date lastModifiedTime = simpleDateFormat.parse("2020-08-22 09:00:00");
List<Commit> commitsByDate = commitService.find(commitTestApp, testCluster, testPrivateNamespace, lastModifiedTime, null);
Date lastModifiedTimeGreater = simpleDateFormat.parse("2020-08-22 11:00:00");
List<Commit> commitsByDateGreater = commitService.find(commitTestApp, testCluster, testPrivateNamespace, lastModifiedTimeGreater, null);
Date lastModifiedTimePage = simpleDateFormat.parse("2020-08-22 09:30:00");
List<Commit> commitsByDatePage = commitService.find(commitTestApp, testCluster, testPrivateNamespace, lastModifiedTimePage, PageRequest.of(0, 1));
assertEquals(1, commitsByDate.size());
assertEquals(0, commitsByDateGreater.size());
assertEquals(1, commitsByDatePage.size());
}
use of com.ctrip.framework.apollo.biz.entity.Commit in project apollo by ctripcorp.
the class ItemSetService method createCommit.
private void createCommit(String appId, String clusterName, String namespaceName, String configChangeContent, String operator) {
Commit commit = new Commit();
commit.setAppId(appId);
commit.setClusterName(clusterName);
commit.setNamespaceName(namespaceName);
commit.setChangeSets(configChangeContent);
commit.setDataChangeCreatedBy(operator);
commit.setDataChangeLastModifiedBy(operator);
commitService.save(commit);
}
use of com.ctrip.framework.apollo.biz.entity.Commit in project apollo by ctripcorp.
the class ItemController method create.
@PreAcquireNamespaceLock
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items")
public ItemDTO create(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName, @RequestBody ItemDTO dto) {
Item entity = BeanUtils.transform(Item.class, dto);
ConfigChangeContentBuilder builder = new ConfigChangeContentBuilder();
Item managedEntity = itemService.findOne(appId, clusterName, namespaceName, entity.getKey());
if (managedEntity != null) {
throw new BadRequestException("item already exists");
}
entity = itemService.save(entity);
builder.createItem(entity);
dto = BeanUtils.transform(ItemDTO.class, entity);
Commit commit = new Commit();
commit.setAppId(appId);
commit.setClusterName(clusterName);
commit.setNamespaceName(namespaceName);
commit.setChangeSets(builder.build());
commit.setDataChangeCreatedBy(dto.getDataChangeLastModifiedBy());
commit.setDataChangeLastModifiedBy(dto.getDataChangeLastModifiedBy());
commitService.save(commit);
return dto;
}
use of com.ctrip.framework.apollo.biz.entity.Commit in project apollo by ctripcorp.
the class ItemController method delete.
@PreAcquireNamespaceLock
@DeleteMapping("/items/{itemId}")
public void delete(@PathVariable("itemId") long itemId, @RequestParam String operator) {
Item entity = itemService.findOne(itemId);
if (entity == null) {
throw new NotFoundException("item not found for itemId " + itemId);
}
itemService.delete(entity.getId(), operator);
Namespace namespace = namespaceService.findOne(entity.getNamespaceId());
Commit commit = new Commit();
commit.setAppId(namespace.getAppId());
commit.setClusterName(namespace.getClusterName());
commit.setNamespaceName(namespace.getNamespaceName());
commit.setChangeSets(new ConfigChangeContentBuilder().deleteItem(entity).build());
commit.setDataChangeCreatedBy(operator);
commit.setDataChangeLastModifiedBy(operator);
commitService.save(commit);
}
use of com.ctrip.framework.apollo.biz.entity.Commit in project apollo by ctripcorp.
the class NamespaceServiceIntegrationTest method testDeleteNamespace.
@Test
@Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testDeleteNamespace() {
Namespace namespace = new Namespace();
namespace.setAppId(testApp);
namespace.setClusterName(testCluster);
namespace.setNamespaceName(testPrivateNamespace);
namespace.setId(1);
namespaceService.deleteNamespace(namespace, testUser);
List<Item> items = itemService.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
InstanceConfig instanceConfig = instanceConfigRepository.findById(1L).orElse(null);
List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster, testPrivateNamespace, PageRequest.of(0, 10));
Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
assertEquals(0, items.size());
assertEquals(0, commits.size());
assertNotNull(appNamespace);
assertEquals(0, childClusters.size());
assertEquals(0, parentNamespaceReleases.size());
assertEquals(0, childNamespaceReleases.size());
assertTrue(!releaseHistories.hasContent());
assertNull(instanceConfig);
}
Aggregations