Search in sources :

Example 1 with BasicModule

use of com.qlangtech.tis.runtime.module.action.BasicModule in project tis by qlangtech.

the class AuthorityCheckAdvice method doIntercept.

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
    BasicModule action = (BasicModule) invocation.getAction();
    ActionProxy proxy = invocation.getProxy();
    String namespace = proxy.getNamespace();
    final Method method = action.getExecuteMethod();
    Func func = method.getAnnotation(Func.class);
    final Rundata rundata = BasicModule.getRundataInstance();
    // }
    final IUser user = UserUtils.getUser(ServletActionContext.getRequest(), daoContextGetter.get());
    if (!user.hasLogin() && !(action instanceof LoginAction || StringUtils.startsWith(namespace, "/config"))) {
        rundata.redirectTo("/runtime/login.htm");
        return Action.NONE;
    }
    action.setAuthtoken(user);
    if (func == null) {
        log.debug("target:" + proxy.getActionName() + ",method:" + method.getName() + " has not set FUNC");
        return invocation.invoke();
    }
    // }
    return invocation.invoke();
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) Rundata(com.qlangtech.tis.runtime.module.action.BasicModule.Rundata) IUser(com.qlangtech.tis.manage.common.IUser) Method(java.lang.reflect.Method) LoginAction(com.qlangtech.tis.runtime.module.action.LoginAction)

Example 2 with BasicModule

use of com.qlangtech.tis.runtime.module.action.BasicModule in project tis by qlangtech.

the class CoreAction method pushConfig2Engine.

public static void pushConfig2Engine(BasicModule module, Context context, DocCollection collection, int snapshotId, boolean needReload) throws Exception {
    // module.errorsPageShow(context);
    if (traverseCollectionReplic(collection, false, /* collection */
    new ReplicaCallback() {

        @Override
        public boolean process(boolean isLeader, final Replica replica) throws Exception {
            try {
                URL url = new URL(replica.getStr(BASE_URL_PROP) + "/admin/cores?action=CREATEALIAS&" + ICoreAdminAction.EXEC_ACTION + "=" + ICoreAdminAction.ACTION_UPDATE_CONFIG + "&core=" + replica.getStr(CORE_NAME_PROP) + "&" + ZkStateReader.COLLECTION_PROP + "=" + collection.getName() + "&needReload=" + needReload + "&" + ICoreAdminAction.TARGET_SNAPSHOT_ID + "=" + snapshotId);
                return HttpUtils.processContent(url, new StreamProcess<Boolean>() {

                    @Override
                    public Boolean p(int status, InputStream stream, Map<String, List<String>> headerFields) {
                        ProcessResponse result = null;
                        if ((result = ProcessResponse.processResponse(stream, (err) -> module.addErrorMessage(context, replica.getName() + "," + err))).success) {
                        // addActionMessage(context, "成功触发了创建索引集群" + groupNum + "组,组内" + repliationCount + "个副本");
                        // return true;
                        }
                        return true;
                    }
                });
            } catch (MalformedURLException e) {
                // e.printStackTrace();
                log.error(collection.getName(), e);
                module.addErrorMessage(context, e.getMessage());
            }
            return true;
        }
    })) {
    // module.addActionMessage(context, "已经更新全部服务器配置文件");
    }
}
Also used : ServerGroupAdapter(com.qlangtech.tis.runtime.pojo.ServerGroupAdapter) StringUtils(org.apache.commons.lang.StringUtils) IExecChainContext(com.qlangtech.tis.exec.IExecChainContext) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) URL(java.net.URL) TIS(com.qlangtech.tis.TIS) IndexStreamCodeGenerator(com.qlangtech.tis.compiler.streamcode.IndexStreamCodeGenerator) LoggerFactory(org.slf4j.LoggerFactory) com.qlangtech.tis.manage(com.qlangtech.tis.manage) ExecResult(com.qlangtech.tis.assemble.ExecResult) CORE_NAME_PROP(org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP) Stat(org.apache.zookeeper.data.Stat) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) DBNode(com.qlangtech.tis.sql.parser.DBNode) SolrServerException(org.apache.solr.client.solrj.SolrServerException) JSONObject(org.json.JSONObject) Matcher(java.util.regex.Matcher) BASE_URL_PROP(org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP) GenerateDAOAndIncrScript(com.qlangtech.tis.compiler.streamcode.GenerateDAOAndIncrScript) SelectableServer(com.qlangtech.tis.coredefine.module.control.SelectableServer) IPluginStore(com.qlangtech.tis.plugin.IPluginStore) PostParam(com.qlangtech.tis.manage.common.HttpUtils.PostParam) com.qlangtech.tis.manage.biz.dal.pojo(com.qlangtech.tis.manage.biz.dal.pojo) IStreamIncrGenerateStrategy(com.qlangtech.tis.sql.parser.tuple.creator.IStreamIncrGenerateStrategy) IncrStreamFactory(com.qlangtech.tis.plugin.incr.IncrStreamFactory) org.apache.solr.common.cloud(org.apache.solr.common.cloud) com.qlangtech.tis.manage.common(com.qlangtech.tis.manage.common) DataxWriter(com.qlangtech.tis.datax.impl.DataxWriter) Descriptor(com.qlangtech.tis.extension.Descriptor) Collectors(java.util.stream.Collectors) IFullBuildContext(com.qlangtech.tis.fullbuild.IFullBuildContext) ViewPojo(com.qlangtech.tis.runtime.module.screen.ViewPojo) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) FCoreRequest(com.qlangtech.tis.coredefine.biz.FCoreRequest) FlinkJobDeploymentDetails(com.qlangtech.tis.coredefine.module.action.impl.FlinkJobDeploymentDetails) SolrQuery(org.apache.solr.client.solrj.SolrQuery) QueryCloudSolrClient(com.qlangtech.tis.manage.servlet.QueryCloudSolrClient) RunEnvironment(com.qlangtech.tis.pubhook.common.RunEnvironment) com.qlangtech.tis.workflow.pojo(com.qlangtech.tis.workflow.pojo) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Pager(com.koubei.web.tag.pager.Pager) java.util(java.util) BasicScreen(com.qlangtech.tis.runtime.module.screen.BasicScreen) RcDeployment(com.qlangtech.tis.coredefine.module.action.impl.RcDeployment) Func(com.qlangtech.tis.manage.spring.aop.Func) QueryIndexServlet(com.qlangtech.tis.manage.servlet.QueryIndexServlet) Context(com.alibaba.citrus.turbine.Context) IAppSourcePipelineController(com.qlangtech.tis.order.center.IAppSourcePipelineController) Lists(com.google.common.collect.Lists) DataxProcessor(com.qlangtech.tis.datax.impl.DataxProcessor) QueryResutStrategy(com.qlangtech.tis.manage.servlet.QueryResutStrategy) ClusterStateCollectAction(com.qlangtech.tis.runtime.module.action.ClusterStateCollectAction) StreamProcess(com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess) InstanceDirDesc(com.qlangtech.tis.coredefine.module.screen.Corenodemanage.InstanceDirDesc) ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) StringWriter(java.io.StringWriter) JSONTokener(org.json.JSONTokener) IOException(java.io.IOException) ICoreAdminAction(com.qlangtech.tis.cloud.ICoreAdminAction) Maps(com.google.common.collect.Maps) StreamCodeContext(com.qlangtech.tis.sql.parser.stream.generate.StreamCodeContext) ReplicState(com.qlangtech.tis.coredefine.module.screen.Corenodemanage.ReplicState) IParamContext(com.qlangtech.tis.order.center.IParamContext) JSON(com.alibaba.fastjson.JSON) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) TisException(com.qlangtech.tis.lang.TisException) IWorkFlowBuildHistoryDAO(com.qlangtech.tis.workflow.dao.IWorkFlowBuildHistoryDAO) ZkUtils(com.qlangtech.tis.solrj.util.ZkUtils) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) TisAppLaunchPort(com.qlangtech.tis.web.start.TisAppLaunchPort) Feature(com.alibaba.fastjson.parser.Feature) InputStream(java.io.InputStream) MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TisException(com.qlangtech.tis.lang.TisException) URL(java.net.URL) StreamProcess(com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 3 with BasicModule

use of com.qlangtech.tis.runtime.module.action.BasicModule in project tis by qlangtech.

the class OperationLogInterceptor method doIntercept.

@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
    BasicModule action = (BasicModule) invocation.getAction();
    final Method method = action.getExecuteMethod();
    final String result = invocation.invoke();
    Func func = method.getAnnotation(Func.class);
    if (func != null && !func.sideEffect()) {
        return result;
    }
    AppDomainInfo appDomain = CheckAppDomainExistValve.getAppDomain(daoContext);
    OperationLog log = new OperationLog();
    log.setOpType(BasicModule.parseMehtodName());
    if (StringUtils.startsWith(log.getOpType(), "doGet")) {
        return result;
    }
    log.setCreateTime(new Date());
    if (!(appDomain instanceof Nullable)) {
        log.setAppName(appDomain.getAppName());
    }
    ActionProxy proxy = invocation.getProxy();
    // log.setOpType(proxy.getMethod());
    HttpServletRequest request = ServletActionContext.getRequest();
    if (StringUtils.indexOf(request.getClass().getSimpleName(), "Mock") > -1) {
        // 当前是测试流程的话就不需要记录日志了
        return result;
    }
    IUser user = UserUtils.getUser(request, daoContext);
    if (user == null) {
        throw new IllegalStateException("user can not be null");
    }
    StringBuffer jsonObject = new StringBuffer();
    JSONObject params = null;
    Map<String, String[]> paramsMap = null;
    String url = request.getRequestURL().toString();
    jsonObject.append("request:");
    jsonObject.append(url).append("\n");
    String requestBody = null;
    if (!ConfigFileContext.HTTPMethod.GET.name().equals(request.getMethod())) {
        paramsMap = request.getParameterMap();
        if (paramsMap.size() > 0) {
            params = new JSONObject();
            for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
                if (entry.getValue().length == 1) {
                    params.put(entry.getKey(), entry.getValue()[0]);
                } else {
                    params.put(entry.getKey(), entry.getValue());
                }
            }
            jsonObject.append("params:").append("\n");
            jsonObject.append(params.toString(1)).append("\n");
        }
        try (ServletInputStream input = request.getInputStream()) {
            if (!input.isFinished()) {
                requestBody = IOUtils.toString(input, TisUTF8.get());
                jsonObject.append("body:").append("\n");
                jsonObject.append(requestBody).append("\n");
            }
        }
    }
    Context context = new MockContext();
    jsonObject.append("\n=================================");
    jsonObject.append("response:").append("\n");
    jsonObject.append(AjaxValve.buildResultStruct(context));
    log.setTabName(proxy.getActionName());
    log.setUsrId(user.getId());
    log.setUsrName(user.getName());
    log.setOpDesc(jsonObject.toString());
    operationLogDAO.insertSelective(log);
    return result;
}
Also used : Context(com.alibaba.citrus.turbine.Context) ServletActionContext(org.apache.struts2.ServletActionContext) ActionProxy(com.opensymphony.xwork2.ActionProxy) Func(com.qlangtech.tis.manage.spring.aop.Func) BasicModule(com.qlangtech.tis.runtime.module.action.BasicModule) OperationLog(com.qlangtech.tis.manage.biz.dal.pojo.OperationLog) Method(java.lang.reflect.Method) Date(java.util.Date) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) JSONObject(org.json.JSONObject) Map(java.util.Map) Nullable(com.qlangtech.tis.pubhook.common.Nullable)

Aggregations

BasicModule (com.qlangtech.tis.runtime.module.action.BasicModule)3 Context (com.alibaba.citrus.turbine.Context)2 ActionProxy (com.opensymphony.xwork2.ActionProxy)2 Func (com.qlangtech.tis.manage.spring.aop.Func)2 JSON (com.alibaba.fastjson.JSON)1 Feature (com.alibaba.fastjson.parser.Feature)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Pager (com.koubei.web.tag.pager.Pager)1 TIS (com.qlangtech.tis.TIS)1 ExecResult (com.qlangtech.tis.assemble.ExecResult)1 ICoreAdminAction (com.qlangtech.tis.cloud.ICoreAdminAction)1 ITISCoordinator (com.qlangtech.tis.cloud.ITISCoordinator)1 GenerateDAOAndIncrScript (com.qlangtech.tis.compiler.streamcode.GenerateDAOAndIncrScript)1 IndexStreamCodeGenerator (com.qlangtech.tis.compiler.streamcode.IndexStreamCodeGenerator)1 FCoreRequest (com.qlangtech.tis.coredefine.biz.FCoreRequest)1 FlinkJobDeploymentDetails (com.qlangtech.tis.coredefine.module.action.impl.FlinkJobDeploymentDetails)1 RcDeployment (com.qlangtech.tis.coredefine.module.action.impl.RcDeployment)1 SelectableServer (com.qlangtech.tis.coredefine.module.control.SelectableServer)1 CoreNode (com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)1