Search in sources :

Example 6 with TisException

use of com.qlangtech.tis.lang.TisException in project plugins by qlangtech.

the class DorisSourceFactory method getConnection.

@Override
public Connection getConnection(String jdbcUrl) throws SQLException {
    Properties props = new Properties();
    props.put("user", StringUtils.trimToEmpty(this.userName));
    props.put("password", StringUtils.trimToEmpty(password));
    try {
        return mysql5Driver.connect(jdbcUrl, props);
    } catch (SQLException e) {
        throw new TisException(e.getMessage() + ",jdbcUrl:" + jdbcUrl + ",props:" + props.toString(), e);
    }
// return DriverManager.getConnection(jdbcUrl, StringUtils.trimToNull(this.userName), StringUtils.trimToNull(this.password));
}
Also used : SQLException(java.sql.SQLException) TisException(com.qlangtech.tis.lang.TisException) Properties(java.util.Properties)

Example 7 with TisException

use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.

the class TisExceptionInterceptor method doIntercept.

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
    HttpServletResponse response = ServletActionContext.getResponse();
    HttpServletRequest request = ServletActionContext.getRequest();
    boolean disableTransaction = Boolean.parseBoolean(request.getParameter(IParamContext.KEY_REQUEST_DISABLE_TRANSACTION));
    TransactionStatus status = null;
    if (!disableTransaction) {
        status = transactionManager.getTransaction(new DefaultTransactionDefinition());
    }
    ActionProxy proxy = invocation.getProxy();
    AjaxValve.ActionExecResult execResult = null;
    try {
        if (disableTransaction) {
            return invocation.invoke();
        } else {
            invocation.getInvocationContext().put(TransactionStatus.class.getSimpleName(), status);
            final String result = invocation.invoke();
            execResult = MockContext.getActionExecResult();
            // 一定要invoke之后再执行
            if (!execResult.isSuccess()) {
                // 业务失败也要回滚
                transactionManager.rollback(status);
                return result;
            }
            if (!status.isCompleted()) {
                transactionManager.commit(status);
            }
            return result;
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        if (!disableTransaction && !status.isCompleted()) {
            transactionManager.rollback(status);
        }
        // if (TisActionMapper.REQUEST_EXTENDSION_AJAX.equals(mapping.getExtension())) {
        if (StringUtils.endsWith(proxy.getNamespace(), TisActionMapper.ACTION_TOKEN)) {
            // logger.error(e.getMessage(), e);
            List<String> errors = new ArrayList<String>();
            errors.add("服务端发生异常,请联系系统管理员");
            TisException tisExcept = TisException.find(e);
            // }
            if (tisExcept == null) {
                errors.add(ExceptionUtils.getRootCauseMessage(e));
            } else {
                errors.add(tisExcept.getMessage());
            }
            // execResult = MockContext.getActionExecResult();
            // execResult.addErrorMsg(errors);
            AjaxValve.writeInfo2Client(() -> false, response, false, errors, Collections.emptyList(), Collections.emptyList(), null);
            return Action.NONE;
        } else {
            throw e;
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) ActionProxy(com.opensymphony.xwork2.ActionProxy) TisException(com.qlangtech.tis.lang.TisException) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionStatus(org.springframework.transaction.TransactionStatus) HttpServletRequest(javax.servlet.http.HttpServletRequest) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with TisException

use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.

the class DataSourceFactory method validateConnection.

protected void validateConnection(String jdbcUrl, BasicDataSourceFactory.IConnProcessor p) {
    Connection conn = null;
    try {
        conn = getConnection(jdbcUrl);
        p.vist(conn);
    } catch (Exception e) {
        throw new TisException(e.getMessage() + ",jdbcUrl:" + jdbcUrl, e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Throwable e) {
            }
        }
    }
}
Also used : TisException(com.qlangtech.tis.lang.TisException) TisException(com.qlangtech.tis.lang.TisException)

Example 9 with TisException

use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.

the class ConfigFileContext method processContent.

public static <T> T processContent(URL url, StreamProcess<T> process, HTTPMethod method, byte[] content, final int maxRetry) {
    InputStream reader = null;
    int retryCount = 0;
    while (true) {
        try {
            HttpURLConnection conn = getNetInputStream(url, process.getHeaders(), method, content);
            try {
                reader = conn.getInputStream();
            } catch (IOException e) {
                InputStream errStream = null;
                try {
                    errStream = conn.getErrorStream();
                    process.error(conn.getResponseCode(), errStream, e);
                    return null;
                } finally {
                    IOUtils.closeQuietly(errStream);
                }
            }
            return process.p(conn, reader);
        } catch (Exception e) {
            if (++retryCount >= maxRetry) {
                throw new TisException("maxRetry:" + maxRetry + ",url:" + url.toString(), e);
            } else {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e1) {
                    throw new RuntimeException(e1);
                }
                logger.warn(e.getMessage(), e);
            }
        } finally {
            try {
                reader.close();
            } catch (Throwable e) {
            }
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStream(java.io.InputStream) TisException(com.qlangtech.tis.lang.TisException) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TisException(com.qlangtech.tis.lang.TisException)

Example 10 with TisException

use of com.qlangtech.tis.lang.TisException in project tis by qlangtech.

the class SysInitializeAction method initializeZkPath.

// 初始化ZK内容
public boolean initializeZkPath(String zkHost) {
    Matcher matcher = PATTERN_ZK_ADDRESS.matcher(zkHost);
    if (!matcher.matches()) {
        throw new IllegalStateException("zk address " + zkHost + " is not match " + PATTERN_ZK_ADDRESS);
    }
    final String zkServer = matcher.group(1);
    String zkSubDir = StringUtils.trimToEmpty(matcher.group(2));
    logger.info("zkServer:{},zkSubDir:{}", zkServer, zkSubDir);
    if (StringUtils.endsWith(zkSubDir, "/")) {
        zkSubDir = StringUtils.substring(zkSubDir, 0, zkSubDir.length() - 1);
    }
    ZooKeeper zk = null;
    StringBuffer buildLog = new StringBuffer();
    String createPath = null;
    List<String> createPaths = Lists.newArrayList();
    try {
        // final Watcher watcher = new Watcher() {
        // @Override
        // public void process(WatchedEvent event) {
        // logger.info(event.getType() + "," + event.getState() + "," + event.getPath());
        // }
        // };
        // new ZooKeeper(zkServer, 50000, watcher);
        zk = this.createZK(zkServer);
        zk.getChildren("/", false);
        buildLog.append("create zkServer ").append(zkServer);
        createPath = zkSubDir + "/tis";
        ITISCoordinator coordinator = getCoordinator(zk);
        logger.info("guaranteeExist:{}", createPath);
        createPaths.add(createPath);
        ZkUtils.guaranteeExist(coordinator, createPath);
        buildLog.append(",path1:").append(createPath);
        createPath = zkSubDir + "/tis-lock/dumpindex";
        createPaths.add(createPath);
        ZkUtils.guaranteeExist(coordinator, createPath);
        buildLog.append(",path2:").append(createPath);
        // createPath = zkSubDir + "/configs/" + CoreAction.DEFAULT_SOLR_CONFIG;
        // createPaths.add(createPath);
        // ZkUtils.guaranteeExist(coordinator, createPath);
        // buildLog.append(",path3:").append(createPath);
        logger.info(buildLog.toString());
    } catch (Throwable e) {
        throw new IllegalStateException("zk address:" + zkServer + " can not connect Zookeeper server", e);
    } finally {
        try {
            zk.close();
        } catch (Throwable e) {
        }
    }
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
    }
    try {
        zk = this.createZK(zkServer);
        for (String p : createPaths) {
            if (zk.exists(p, false) == null) {
                throw new TisException("create path:" + p + " must be exist");
            }
        }
    } catch (TisException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            zk.close();
        } catch (InterruptedException e) {
        }
    }
    // }
    return true;
}
Also used : ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) Matcher(java.util.regex.Matcher) TisException(com.qlangtech.tis.lang.TisException) SQLException(java.sql.SQLException) IOException(java.io.IOException) TisException(com.qlangtech.tis.lang.TisException)

Aggregations

TisException (com.qlangtech.tis.lang.TisException)10 IOException (java.io.IOException)5 FlinkCluster (com.qlangtech.plugins.incr.flink.common.FlinkCluster)2 MalformedURLException (java.net.MalformedURLException)2 SQLException (java.sql.SQLException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 RestClusterClient (org.apache.flink.client.program.rest.RestClusterClient)2 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 ITISCoordinator (com.qlangtech.tis.cloud.ITISCoordinator)1 IndexStreamCodeGenerator (com.qlangtech.tis.compiler.streamcode.IndexStreamCodeGenerator)1 Func (com.qlangtech.tis.manage.spring.aop.Func)1 V1Status (io.kubernetes.client.openapi.models.V1Status)1 File (java.io.File)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1