All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qcloud.dlc.common.DLCMetastoreException Maven / Gradle / Ivy

The newest version!
package com.qcloud.dlc.common;

import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.thrift.TException;

public class DLCMetastoreException extends MetaException {
    public enum ErrorCode {
        // TODO:暂时只能从云sdk的字符串中识别出这些
        RETRY_EXCEED_MAX_CHANCE,
        NO_SUCH_OBJECT,
        UN_KNOW_DB,
        INVALID_OPERATION,
        ALREADY_EXIST;
    }

    private ErrorCode errorCode;
    private String message;

    public DLCMetastoreException(ErrorCode errorCode, String message) {
        super(String.format("ErrorCode: %s, Message: %s.", errorCode, message));
    }

    public DLCMetastoreException(ErrorCode errorCode, Exception e) {
        super(String.format("ErrorCode: %s, Message: %s.", errorCode, e.toString()));
    }

    public static TException convert(TException e) {
        if (e == null) {
            return null;
        } else if (e.getMessage() == null) {
            return e;
        }

        if (e.getMessage().startsWith("ErrorCode: " + ErrorCode.NO_SUCH_OBJECT)) {
            return new NoSuchObjectException(e.getMessage());
        } else if (e.getMessage().startsWith("ErrorCode: " + ErrorCode.ALREADY_EXIST)) {
            return new AlreadyExistsException(e.getMessage());
        }
        return e;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy