Browse Source

arbiter 静态变量分类

demon 8 years ago
parent
commit
4950b4a16d

+ 4 - 4
hos-arbiter/src/main/java/com/yihu/hos/arbiter/routers/MycatRouter.java

@ -1,7 +1,7 @@
package com.yihu.hos.arbiter.routers;
import com.yihu.hos.arbiter.configuration.ActivemqConfiguration;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.constant.MycatConstant;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
@ -29,11 +29,11 @@ public class MycatRouter extends RouteBuilder {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                activemqConfiguration.getUser(), activemqConfiguration.getPassword(), activemqConfiguration.getBrokerURL());
        // Note we can explicit name the component
        context.addComponent("service.mycat.event", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        from(ServiceFlowConstant.MYCAT_EVENT_SERVICE)
        context.addComponent(MycatConstant.CAMEL_COMPONENT, JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        from(MycatConstant.CAMEL_ENDPOINT)
                .choice()
                .when(header("tenant").isNotNull()).to("bean:mycatService?method=handleServiceFlow")
                .when(header("event").isEqualTo(ServiceFlowConstant.EXECUTE_MYCAT)).to("bean:mycatService?method=updateMycat")
                .when(header("event").isEqualTo(MycatConstant.EXECUTE_MYCAT)).to("bean:mycatService?method=updateMycat")
                .endChoice();
    }
}

+ 4 - 5
hos-arbiter/src/main/java/com/yihu/hos/arbiter/routers/ShellRouter.java

@ -1,7 +1,7 @@
package com.yihu.hos.arbiter.routers;
import com.yihu.hos.arbiter.configuration.ActivemqConfiguration;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.constant.SSHConstant;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
@ -29,12 +29,11 @@ public class ShellRouter extends RouteBuilder {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                activemqConfiguration.getUser(), activemqConfiguration.getPassword(), activemqConfiguration.getBrokerURL());
        // Note we can explicit name the component
        context.addComponent("service.shell.event", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        from(ServiceFlowConstant.SHELL_EVENT_SERVICE)
        context.addComponent(SSHConstant.CAMEL_COMPONENT, JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        from(SSHConstant.CAMEL_ENDPOINT)
                .choice()
                .when(header("tenant").isNotNull()).to("bean:linuxShellService?method=handleServiceFlow")
                .when(header("event").isEqualTo(ServiceFlowConstant.ARBITER_SHELL_SEND)).to("bean:linuxShellService?method=sendShell")
//                .when(header("event").isEqualTo(ServiceFlowConstant.ARBITER_SHELL_ACEPT)).to("bean:linuxShellService?method=shellBack")
                .when(header("event").isEqualTo(SSHConstant.ARBITER_SHELL_SEND)).to("bean:linuxShellService?method=sendShell")
                .endChoice();
    }
}

+ 7 - 5
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ProxyService.java

@ -4,6 +4,8 @@ import com.yihu.hos.arbiter.configuration.ArbiterServerConfiguration;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.web.framework.constant.EndPointConstant;
import com.yihu.hos.web.framework.constant.MycatConstant;
import com.yihu.hos.web.framework.constant.SSHConstant;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
@ -94,7 +96,7 @@ public class ProxyService {
            header.put("event", message.getHead("event"));
            ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
            producerTemplate.sendBodyAndHeaders(ServiceFlowConstant.MYCAT_EVENT_SERVICE, message.getBodyString(), header);
            producerTemplate.sendBodyAndHeaders(MycatConstant.CAMEL_ENDPOINT, message.getBodyString(), header);
        }
        public void start() {
@ -104,7 +106,7 @@ public class ProxyService {
            }
            try {
                consumer = new Consumer(zbusBroker, ServiceFlowConstant.MYCAT_UPDATE + "@" + configuration.getMycatName());
                consumer = new Consumer(zbusBroker, MycatConstant.ZBUS_MQ + "@" + configuration.getMycatName());
                consumer.start(this::handle);
            } catch (IOException e) {
                e.printStackTrace();
@ -131,7 +133,7 @@ public class ProxyService {
            header.put("event", message.getHead("event"));
            ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
            producerTemplate.sendBodyAndHeaders(ServiceFlowConstant.SHELL_EVENT_SERVICE, message.getBodyString(), header);
            producerTemplate.sendBodyAndHeaders(SSHConstant.CAMEL_ENDPOINT, message.getBodyString(), header);
        }
        public void start() {
@ -140,7 +142,7 @@ public class ProxyService {
                return;
            }
            try {
                consumer = new Consumer(zbusBroker, ServiceFlowConstant.SHELL_REQUEST + "@" + configuration.getTenant());
                consumer = new Consumer(zbusBroker, SSHConstant.SHELL_REQUEST + "@" + configuration.getTenant());
                consumer.start(this::handle);
            } catch (IOException e) {
                e.printStackTrace();
@ -166,7 +168,7 @@ public class ProxyService {
            header.put("event", message.getHead("event"));
            ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
            producerTemplate.sendBodyAndHeaders(ServiceFlowConstant.SHELL_EVENT_SERVICE, message.getBodyString(), header);
            producerTemplate.sendBodyAndHeaders(SSHConstant.CAMEL_ENDPOINT, message.getBodyString(), header);
        }
        public void start() {

+ 2 - 2
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ShellService.java

@ -3,7 +3,7 @@ package com.yihu.hos.arbiter.services;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.core.http.HTTPResponse;
import com.yihu.hos.core.http.HttpClientKit;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.constant.SSHConstant;
import com.yihu.hos.web.framework.model.bo.BrokerServer;
import com.yihu.hos.web.framework.model.bo.ServiceShell;
import org.apache.log4j.LogManager;
@ -47,7 +47,7 @@ public class ShellService {
                    logger.debug("发送shell请求到broker成功");
                    // shell执行成功,见执行结果返回到中心zbus显示。
                    ServiceShell serviceShell = objectMapper.readValue(msg,ServiceShell.class);
                    Producer producer = new Producer(zbusBroker, ServiceFlowConstant.SHELL_RESPONSE + "@" + serviceShell.getTenant());
                    Producer producer = new Producer(zbusBroker,  SSHConstant.SHELL_RESPONSE + "@" + serviceShell.getTenant());
                    producer.createMQ();    //确定为创建消息队列需要显示调用
                    Message message = new Message();
                    message.setHead("event", serviceShell.getType());

+ 13 - 4
hos-web-framework/src/main/java/com/yihu/hos/web/framework/constant/MycatConstant.java

@ -5,11 +5,20 @@ package com.yihu.hos.web.framework.constant;
 * @vsrsion 1.0
 * Created at 2017/1/24.
 */
public class MycatConstant {
    public static final String MYCAT = "mycat";   // mycat dataNode前缀
public interface MycatConstant {
    public static final String DATA_NODE = "dn_";   // mycat dataNode前缀
    public static final String DATA_BASE = "db_";   // mycat database前缀
    String ZBUS_MQ = "mycat"; //zbus消息,admin到arbiter上的通讯
    String ACTIVE_MQ = "operation.mycat";   //active-mq消息,arbiter到broker的通讯
    String CAMEL_COMPONENT = "event.mycat";  //camel组件命名
    String CAMEL_ENDPOINT = CAMEL_COMPONENT + ":queue:" + ACTIVE_MQ;   //camel的Endpoint
    //Arbiter mycat 操作事件
    String EXECUTE_MYCAT = "execute_mycat"; //shell 命令执行消息
    //arbiter mycat修改 消息队列
    String DATA_NODE = "dn_";   // mycat dataNode前缀
    String DATA_BASE = "db_";   // mycat database前缀

+ 26 - 0
hos-web-framework/src/main/java/com/yihu/hos/web/framework/constant/SSHConstant.java

@ -0,0 +1,26 @@
package com.yihu.hos.web.framework.constant;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2017/1/24.
 */
public interface SSHConstant {
    String ZBUS_MQ = "shell"; //zbus消息,admin到arbiter上的通讯
    String ACTIVE_MQ = "operation.shell";   //active-mq消息,arbiter到broker的通讯
    String CAMEL_COMPONENT = "event.shell";  //camel组件命名
    String CAMEL_ENDPOINT = CAMEL_COMPONENT + ":queue:" + ACTIVE_MQ;   //camel的Endpoint
    //Arbiter shell
    String ARBITER_SHELL_SEND = "arbiterShellSend"; //shell 命令执行消息
    //arbiter 发送shell命令 消息队列
    String SHELL_REQUEST = "shell_request";
    // hos-admin 接收shell执行结果
    String SHELL_RESPONSE = "shell_response";
}

+ 0 - 21
hos-web-framework/src/main/java/com/yihu/hos/web/framework/constant/ServiceFlowConstant.java

@ -38,25 +38,4 @@ public interface ServiceFlowConstant {
    String BROKER_SERVER_ON = "brokerServerOn"; //Broker启动
    String BROKER_SERVER_OFF = "brokerServerOff";//Broker停止
    /* *******   shell相关  ******  */
    // shell 请求命令,对列名称
    String SHELL_EVENT_QUEUE = "configuration.service.shell";
    String SHELL_EVENT_SERVICE = "service.shell.event:queue:configuration.service.shell";
    //Arbiter shell
    String ARBITER_SHELL_SEND = "arbiterShellSend"; //shell 命令执行消息
    String ARBITER_SHELL_ACEPT = "arbiterShellAcept"; //shell 执行结果消息
    //arbiter 发送shell命令 消息队列
    String SHELL_REQUEST = "shell_request";
    // hos-admin 接收shell执行结果
    String SHELL_RESPONSE = "shell_response";
    /* ********************** mycat相关  ************************ */
    // shell 请求命令,对列名称
    String MYCAT_EVENT_QUEUE = "configuration.service.mycat";
    String MYCAT_EVENT_SERVICE = "service.mycat.event:queue:configuration.service.mycat";
    //Arbiter mycat 操作事件
    String EXECUTE_MYCAT = "execute_mycat"; //shell 命令执行消息
    //arbiter mycat修改 消息队列
    String MYCAT_UPDATE = "mycat_update";
}

+ 4 - 4
src/main/java/com/yihu/hos/remoteManage/service/RemoteShellService.java

@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.common.constants.ContextAttributes;
import com.yihu.hos.interceptor.LocalContext;
import com.yihu.hos.services.ServiceShellEventService;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.constant.SSHConstant;
import com.yihu.hos.web.framework.model.bo.ServiceShell;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -83,10 +83,10 @@ public class RemoteShellService {
        }
        try {
            if (!cunsumerNap.containsKey(ServiceFlowConstant.SHELL_RESPONSE + "@" + attachment)){
                consumer = new Consumer(zbusBroker, ServiceFlowConstant.SHELL_RESPONSE + "@" + attachment);
            if (!cunsumerNap.containsKey(SSHConstant.SHELL_RESPONSE + "@" + attachment)){
                consumer = new Consumer(zbusBroker, SSHConstant.SHELL_RESPONSE + "@" + attachment);
                consumer.start(this::handle);
                cunsumerNap.put(ServiceFlowConstant.SHELL_RESPONSE + "@" + attachment,attachment);
                cunsumerNap.put(SSHConstant.SHELL_RESPONSE + "@" + attachment,attachment);
            }
            System.out.println("start success~");
        } catch (Exception e) {

+ 3 - 3
src/main/java/com/yihu/hos/services/ServiceMycatEventService.java

@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.constant.MycatConstant;
import com.yihu.hos.web.framework.model.bo.ServiceMycat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -35,7 +35,7 @@ public class ServiceMycatEventService {
    }
    public void executeMycatConfig(ServiceMycat servviceMycat, String tenant) {
        this.sendMsg(ServiceFlowConstant.EXECUTE_MYCAT, servviceMycat, tenant);
        this.sendMsg(MycatConstant.EXECUTE_MYCAT, servviceMycat, tenant);
    }
@ -48,7 +48,7 @@ public class ServiceMycatEventService {
        try {
            String msg = objectMapper.writeValueAsString(servviceMycat);
            Producer producer = new Producer(zbusBroker, ServiceFlowConstant.MYCAT_UPDATE + "@" + tenant);
            Producer producer = new Producer(zbusBroker, MycatConstant.ZBUS_MQ + "@" + tenant);
            producer.createMQ();    //确定为创建消息队列需要显示调用
            Message message = new Message();
            message.setHead("event", event);

+ 4 - 9
src/main/java/com/yihu/hos/services/ServiceShellEventService.java

@ -5,7 +5,7 @@ import com.yihu.hos.common.constants.ContextAttributes;
import com.yihu.hos.core.log.Logger;
import com.yihu.hos.core.log.LoggerFactory;
import com.yihu.hos.interceptor.LocalContext;
import com.yihu.hos.web.framework.constant.ServiceFlowConstant;
import com.yihu.hos.web.framework.constant.SSHConstant;
import com.yihu.hos.web.framework.model.bo.ServiceShell;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -37,16 +37,11 @@ public class ServiceShellEventService {
    }
    public void serviceShellSend(ServiceShell serviceShell) {
        serviceShell.setType(ServiceFlowConstant.ARBITER_SHELL_SEND);
        this.sendMsg(ServiceFlowConstant.ARBITER_SHELL_SEND, serviceShell);
        serviceShell.setType(SSHConstant.ARBITER_SHELL_SEND);
        this.sendMsg(SSHConstant.ARBITER_SHELL_SEND, serviceShell);
    }
    public void serviceShellAccept(ServiceShell serviceShell) {
        serviceShell.setType(ServiceFlowConstant.ARBITER_SHELL_ACEPT);
        this.sendMsg(ServiceFlowConstant.ARBITER_SHELL_ACEPT, serviceShell);
    }
    private void sendMsg(String event, ServiceShell serviceShell) {
        if (zbusBroker == null) {
            logger.error("zbusBroker is null.");
@ -57,7 +52,7 @@ public class ServiceShellEventService {
            String msg = objectMapper.writeValueAsString(serviceShell);
            String tenant = LocalContext.getContext().getAttachment(ContextAttributes.TENANT_NAME);
            Producer producer = new Producer(zbusBroker, ServiceFlowConstant.SHELL_REQUEST + "@" + tenant);
            Producer producer = new Producer(zbusBroker, SSHConstant.SHELL_REQUEST + "@" + tenant);
            producer.createMQ();    //确定为创建消息队列需要显示调用
            Message message = new Message();
            message.setHead("event", event);

+ 2 - 2
src/main/java/com/yihu/hos/tenant/service/TenantService.java

@ -95,10 +95,10 @@ public class TenantService {
                //TODO  mycat操作消息发送;使用zbus;tenant: "mycat"+ IP
                ServiceMycat serrviceMycat = new ServiceMycat();
                serrviceMycat.setSchema(obj.getSchema());
                serrviceMycat.setTenant(MycatConstant.MYCAT+db.getHost());
                serrviceMycat.setTenant(MycatConstant.ZBUS_MQ+db.getHost());
                serrviceMycat.setLoginName(obj.getLoginName());
                serrviceMycat.setPassword(obj.getPassword());
                serviceMycatEventService.executeMycatConfig(serrviceMycat, MycatConstant.MYCAT+dbInfo.getHost());
                serviceMycatEventService.executeMycatConfig(serrviceMycat, MycatConstant.ZBUS_MQ+dbInfo.getHost());
                tenantDao.saveEntity(obj);
                return Result.success("保存成功");
            }else {