Search in sources :

Example 1 with BadRequestException

use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.

the class MigrationEventDao method loadMigrationEvent.

private MigrationEvent loadMigrationEvent(List<MigrationEventTbl> details) {
    if (!CollectionUtils.isEmpty(details)) {
        MigrationEvent event = new DefaultMigrationEvent(details.get(0));
        for (MigrationEventTbl detail : details) {
            MigrationClusterTbl cluster = detail.getRedundantClusters();
            MigrationShardTbl shard = detail.getRedundantShards();
            if (null == event.getMigrationCluster(cluster.getClusterId())) {
                event.addMigrationCluster(new DefaultMigrationCluster(executors, scheduled, event, detail.getRedundantClusters(), dcService, clusterService, shardService, redisService, migrationService));
            }
            MigrationCluster migrationCluster = event.getMigrationCluster(cluster.getClusterId());
            migrationCluster.addNewMigrationShard(new DefaultMigrationShard(migrationCluster, shard, migrationCluster.getClusterShards().get(shard.getShardId()), migrationCluster.getClusterDcs(), migrationService));
        }
        return event;
    }
    throw new BadRequestException("Cannot load migration event from null.");
}
Also used : DefaultMigrationEvent(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent) DefaultMigrationCluster(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) DefaultMigrationCluster(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) DefaultMigrationShard(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard) MigrationEvent(com.ctrip.xpipe.redis.console.migration.model.MigrationEvent) DefaultMigrationEvent(com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)

Example 2 with BadRequestException

use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.

the class ClusterServiceImpl method deleteCluster.

@Override
public void deleteCluster(String clusterName) {
    ClusterTbl proto = find(clusterName);
    if (null == proto)
        throw new BadRequestException("Cannot find cluster");
    proto.setClusterLastModifiedTime(DataModifiedTimeGenerator.generateModifiedTime());
    List<DcTbl> relatedDcs = dcService.findClusterRelatedDc(clusterName);
    final ClusterTbl queryProto = proto;
    // Call cluster delete event
    ClusterEvent clusterEvent = clusterDeleteEventFactory.createClusterEvent(clusterName);
    try {
        clusterDao.deleteCluster(queryProto);
    } catch (Exception e) {
        throw new ServerException(e.getMessage());
    }
    clusterEvent.onEvent();
    /**
     * Notify meta server *
     */
    notifier.notifyClusterDelete(clusterName, relatedDcs);
}
Also used : ClusterEvent(com.ctrip.xpipe.redis.console.notifier.cluster.ClusterEvent) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) DalException(org.unidal.dal.jdbc.DalException)

Example 3 with BadRequestException

use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.

the class ClusterServiceImpl method unbindDc.

@Override
public void unbindDc(String clusterName, String dcName) {
    final ClusterTbl cluster = find(clusterName);
    final DcTbl dc = dcService.find(dcName);
    if (null == dc || null == cluster)
        throw new BadRequestException("Cannot unbind dc due to unknown dc or cluster");
    queryHandler.handleQuery(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterDao.unbindDc(cluster, dc);
        }
    });
    /**
     * Notify meta server *
     */
    notifier.notifyClusterDelete(clusterName, Arrays.asList(new DcTbl[] { dc }));
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 4 with BadRequestException

use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.

the class ClusterServiceImpl method bindDc.

@Override
public void bindDc(String clusterName, String dcName) {
    final ClusterTbl cluster = find(clusterName);
    final DcTbl dc = dcService.find(dcName);
    if (null == dc || null == cluster)
        throw new BadRequestException("Cannot bind dc due to unknown dc or cluster");
    queryHandler.handleQuery(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterDao.bindDc(cluster, dc);
        }
    });
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException)

Example 5 with BadRequestException

use of com.ctrip.xpipe.redis.console.exception.BadRequestException in project x-pipe by ctripcorp.

the class ClusterDao method createCluster.

@DalTransaction
public ClusterTbl createCluster(final ClusterTbl cluster) throws DalException {
    // check for unique cluster name
    ClusterTbl clusterWithSameName = queryHandler.handleQuery(new DalQuery<ClusterTbl>() {

        @Override
        public ClusterTbl doQuery() throws DalException {
            return clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL);
        }
    });
    if (null != clusterWithSameName)
        throw new BadRequestException("Duplicated cluster name");
    cluster.setCreateTime(new Date());
    // cluster meta
    queryHandler.handleInsert(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return clusterTblDao.insert(cluster);
        }
    });
    // related dc-cluster
    ClusterTbl newCluster = clusterTblDao.findClusterByClusterName(cluster.getClusterName(), ClusterTblEntity.READSET_FULL);
    DcTbl activeDc = dcTblDao.findByPK(cluster.getActivedcId(), DcTblEntity.READSET_FULL);
    DcClusterTbl protoDcCluster = dcClusterTblDao.createLocal();
    protoDcCluster.setDcId(activeDc.getId()).setClusterId(newCluster.getId());
    queryHandler.handleInsert(new DalQuery<Integer>() {

        @Override
        public Integer doQuery() throws DalException {
            return dcClusterTblDao.insert(protoDcCluster);
        }
    });
    return newCluster;
}
Also used : DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) Date(java.util.Date) DalTransaction(com.ctrip.xpipe.redis.console.annotation.DalTransaction)

Aggregations

BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)9 DalException (org.unidal.dal.jdbc.DalException)7 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)3 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 MigrationCluster (com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)1 MigrationEvent (com.ctrip.xpipe.redis.console.migration.model.MigrationEvent)1 DefaultMigrationCluster (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationCluster)1 DefaultMigrationEvent (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationEvent)1 DefaultMigrationShard (com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard)1 ClusterEvent (com.ctrip.xpipe.redis.console.notifier.cluster.ClusterEvent)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1