Search in sources :

Example 11 with ServerException

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

the class AbstractConsoleService method postConstruct.

@SuppressWarnings("unchecked")
@PostConstruct
private void postConstruct() {
    try {
        logger.info("[postConstruct]{}", getClass().getSimpleName());
        Type superClass = getClass().getGenericSuperclass();
        if (superClass instanceof Class<?>) {
            // sanity check, should never happen
            throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information");
        }
        Type type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
        Class clazz = Class.forName(parseTypeName(type.toString()));
        dao = (T) ContainerLoader.getDefaultContainer().lookup(clazz);
    } catch (ComponentLookupException e) {
        throw new ServerException("Dao construct failed.", e);
    } catch (ClassNotFoundException e) {
        throw new ServerException("Dao construct failed due to class not found.", e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Example 12 with ServerException

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

the class ClusterDao method postConstruct.

@PostConstruct
private void postConstruct() {
    try {
        dcTblDao = ContainerLoader.getDefaultContainer().lookup(DcTblDao.class);
        clusterTblDao = ContainerLoader.getDefaultContainer().lookup(ClusterTblDao.class);
        dcClusterTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterTblDao.class);
        shardTblDao = ContainerLoader.getDefaultContainer().lookup(ShardTblDao.class);
        dcClusterShardTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterShardTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.", e);
    }
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Example 13 with ServerException

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

the class DcClusterDao method postConstruct.

@PostConstruct
private void postConstruct() {
    try {
        dcClusterTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterTblDao.class);
        dcClusterShardTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterShardTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.", e);
    }
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Example 14 with ServerException

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

the class RedisDao method generateUniqueKeeperId.

private String generateUniqueKeeperId(final RedisTbl redis) {
    final String runId = idGenerator.generateRunid();
    // check for unique runId
    DcClusterShardTbl targetDcClusterShard = queryHandler.handleQuery(new DalQuery<DcClusterShardTbl>() {

        @Override
        public DcClusterShardTbl doQuery() throws DalException {
            return dcClusterShardTblDao.findByPK(redis.getDcClusterShardId(), DcClusterShardTblEntity.READSET_FULL);
        }
    });
    if (null == targetDcClusterShard)
        throw new BadRequestException("Cannot find related dc-cluster-shard");
    List<RedisTbl> redisWithSameRunId = queryHandler.handleQuery(new DalQuery<List<RedisTbl>>() {

        @Override
        public List<RedisTbl> doQuery() throws DalException {
            return redisTblDao.findByRunid(runId, RedisTblEntity.READSET_FULL);
        }
    });
    if (null != redisWithSameRunId && redisWithSameRunId.size() > 0) {
        for (final RedisTbl tmpRedis : redisWithSameRunId) {
            DcClusterShardTbl tmpDcClusterShard = queryHandler.handleQuery(new DalQuery<DcClusterShardTbl>() {

                @Override
                public DcClusterShardTbl doQuery() throws DalException {
                    return dcClusterShardTblDao.findByPK(tmpRedis.getDcClusterShardId(), DcClusterShardTblEntity.READSET_FULL);
                }
            });
            if (null != tmpDcClusterShard && targetDcClusterShard.getShardId() == tmpDcClusterShard.getShardId()) {
                throw new ServerException("Cannot generate unque keeper id, please retry.");
            }
        }
    }
    return runId;
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) BadRequestException(com.ctrip.xpipe.redis.console.exception.BadRequestException) List(java.util.List) LinkedList(java.util.LinkedList)

Example 15 with ServerException

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

the class RedisDao method postConstruct.

@PostConstruct
private void postConstruct() {
    try {
        redisTblDao = ContainerLoader.getDefaultContainer().lookup(RedisTblDao.class);
        dcClusterShardTblDao = ContainerLoader.getDefaultContainer().lookup(DcClusterShardTblDao.class);
    } catch (ComponentLookupException e) {
        throw new ServerException("Cannot construct dao.", e);
    }
}
Also used : ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)18 PostConstruct (javax.annotation.PostConstruct)7 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)7 DalException (org.unidal.dal.jdbc.DalException)7 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)4 BadRequestException (com.ctrip.xpipe.redis.console.exception.BadRequestException)3 List (java.util.List)3 LinkedList (java.util.LinkedList)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 DalTransaction (com.ctrip.xpipe.redis.console.annotation.DalTransaction)1 ClusterEvent (com.ctrip.xpipe.redis.console.notifier.cluster.ClusterEvent)1 ShardEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent)1 DcMetaQueryVO (com.ctrip.xpipe.redis.console.service.vo.DcMetaQueryVO)1 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)1 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1