Search in sources :

Example 6 with Cluster

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

the class ClusterService method saveWithInstanceOfAppNamespaces.

@Transactional
public Cluster saveWithInstanceOfAppNamespaces(Cluster entity) {
    Cluster savedCluster = saveWithoutInstanceOfAppNamespaces(entity);
    namespaceService.instanceOfAppNamespaces(savedCluster.getAppId(), savedCluster.getName(), savedCluster.getDataChangeCreatedBy());
    return savedCluster;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Cluster

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

the class ClusterService method update.

@Transactional
public Cluster update(Cluster cluster) {
    Cluster managedCluster = clusterRepository.findByAppIdAndName(cluster.getAppId(), cluster.getName());
    BeanUtils.copyEntityProperties(cluster, managedCluster);
    managedCluster = clusterRepository.save(managedCluster);
    auditService.audit(Cluster.class.getSimpleName(), managedCluster.getId(), Audit.OP.UPDATE, managedCluster.getDataChangeLastModifiedBy());
    return managedCluster;
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Cluster

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

the class AdminService method deleteApp.

@Transactional
public void deleteApp(App app, String operator) {
    String appId = app.getAppId();
    logger.info("{} is deleting App:{}", operator, appId);
    List<Cluster> managedClusters = clusterService.findParentClusters(appId);
    // 1. delete clusters
    if (Objects.nonNull(managedClusters)) {
        for (Cluster cluster : managedClusters) {
            clusterService.delete(cluster.getId(), operator);
        }
    }
    // 2. delete appNamespace
    appNamespaceService.batchDelete(appId, operator);
    // 3. delete app
    appService.delete(app.getId(), operator);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Cluster

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

the class ClusterController method create.

@PostMapping("/apps/{appId}/clusters")
public ClusterDTO create(@PathVariable("appId") String appId, @RequestParam(value = "autoCreatePrivateNamespace", defaultValue = "true") boolean autoCreatePrivateNamespace, @Valid @RequestBody ClusterDTO dto) {
    Cluster entity = BeanUtils.transform(Cluster.class, dto);
    Cluster managedEntity = clusterService.findOne(appId, entity.getName());
    if (managedEntity != null) {
        throw new BadRequestException("cluster already exist.");
    }
    if (autoCreatePrivateNamespace) {
        entity = clusterService.saveWithInstanceOfAppNamespaces(entity);
    } else {
        entity = clusterService.saveWithoutInstanceOfAppNamespaces(entity);
    }
    return BeanUtils.transform(ClusterDTO.class, entity);
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 10 with Cluster

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

the class ClusterControllerTest method testDeleteSuccess.

@Test
public void testDeleteSuccess() {
    Cluster cluster = new Cluster();
    when(clusterService.findOne(any(String.class), any(String.class))).thenReturn(cluster);
    clusterController.delete("1", "2", "d");
    verify(clusterService, times(1)).findOne("1", "2");
}
Also used : Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)24 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)10 Transactional (org.springframework.transaction.annotation.Transactional)8 Test (org.junit.Test)7 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)6 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)5 Item (com.ctrip.framework.apollo.biz.entity.Item)4 Release (com.ctrip.framework.apollo.biz.entity.Release)4 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)3 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Audit (com.ctrip.framework.apollo.biz.entity.Audit)1 Commit (com.ctrip.framework.apollo.biz.entity.Commit)1 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)1 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)1 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)1 App (com.ctrip.framework.apollo.common.entity.App)1 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)1 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)1 Date (java.util.Date)1