Search in sources :

Example 1 with AgentResourceComponent

use of com.creditease.agent.spi.AgentResourceComponent in project uavstack by uavorg.

the class NodeInfoWatcher method sendToMQ.

private void sendToMQ(List<Map<String, Object>> mdfList) {
    AgentResourceComponent arc = (AgentResourceComponent) ConfigurationManager.getInstance().getComponent("messageproducer", "MessageProducerResourceComponent");
    MessageProducer producer = (MessageProducer) arc.getResource();
    if (producer == null) {
        log.debug(this, "MessageProducer is null!");
        return;
    }
    List<Map<String, Object>> mdfMsg = null;
    for (Map<String, Object> mdf : mdfList) {
        mdfMsg = new ArrayList<>(1);
        mdfMsg.add(mdf);
        String mesKey = MonitorDataFrame.MessageType.NodeInfo.toString();
        Message msg = MessagingFactory.createMessage(mesKey);
        msg.setParam(mesKey, JSONHelper.toString(mdfMsg));
        boolean check = producer.submit(msg);
        String sendState = mesKey + " Data Sent " + (check ? "SUCCESS" : "FAIL");
        if (log.isDebugEnable()) {
            String mdfDetail = check ? (mdf.get("ip") + "---" + mdf.get("time")) : JSONHelper.toString(mdfMsg);
            log.debug(this, sendState + ". MDF:" + mdfDetail);
        }
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) MessageProducer(com.creditease.uav.messaging.api.MessageProducer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AgentResourceComponent

use of com.creditease.agent.spi.AgentResourceComponent in project uavstack by uavorg.

the class NewLogDataMessageHandler method handle.

/**
 * [ { time:1464248773620, host:"09-201211070016", ip:"127.0.0.1",
 * svrid:"F:/testenv/apache-tomcat-7.0.65---F:/testenv/apache-tomcat-7.0.65", tag:"L", frames:{ "ccsp":[ {
 * "MEId":"log", "Instances":[ { "id":"F:/testenv/apache-tomcat-7.0.65/logs/ccsp.log", "values":{ "content":[ {
 * "content":"2016-localhost-startStop-1INFORootWebApplicationContext:initializationstarted",
 * "_timestamp":"1212345678129", "_lnum" : "123" } ] } }, { "id":"/ccsp/log_error.log", "values":{ "content":[
 * {"content":"xxxxxxxxxx", "_timestamp":"1212345678129", "_lnum" : "123"} ] } } ] } ] } } ]
 */
@Override
public void handle(Message msg) {
    storeToES(msg);
    // NOW, we send out the MDF for runtime notification
    boolean needGoRuntimeNtf = DataConvertHelper.toBoolean(ConfigurationManager.getInstance().getFeatureConfiguration("newlogservice", "to.runtimentf"), true);
    if (needGoRuntimeNtf == false) {
        return;
    }
    AgentResourceComponent arc = (AgentResourceComponent) ConfigurationManager.getInstance().getComponent("messageproducer", "MessageProducerResourceComponent");
    MessageProducer producer = (MessageProducer) arc.getResource();
    if (producer != null) {
        String runtimeKey = MonitorDataFrame.MessageType.RuntimeNtf.toString();
        Message rtntfmsg = MessagingFactory.createMessage(runtimeKey);
        String dataStream = msg.getParam(this.getMsgTypeName());
        rtntfmsg.setParam(runtimeKey, dataStream);
        boolean check = producer.submit(rtntfmsg);
        String sendState = runtimeKey + " Data Sent " + (check ? "SUCCESS" : "FAIL");
        if (log.isDebugEnable()) {
            log.debug(this, sendState + "    " + dataStream);
        }
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) MessageProducer(com.creditease.uav.messaging.api.MessageProducer)

Example 3 with AgentResourceComponent

use of com.creditease.agent.spi.AgentResourceComponent in project uavstack by uavorg.

the class SystemStarter method stop.

public void stop() {
    Set<Object> components = this.configMgr.getComponents();
    for (Object component : components) {
        if (AgentFeatureComponent.class.isAssignableFrom(component.getClass())) {
            AgentFeatureComponent afc = (AgentFeatureComponent) component;
            try {
                afc.stop();
                // this.configMgr.unregisterComponent(afc.getFeature(), afc.getName());
                log.info(this, "stop feature [" + afc.getFeature() + "] component [" + afc.getName() + "] SUCCESS");
            } catch (Exception e) {
                log.err(this, "stop feature [" + afc.getFeature() + "] component [" + afc.getName() + "] FAILs ", e);
            }
        } else if (AgentResourceComponent.class.isAssignableFrom(component.getClass())) {
            AgentResourceComponent arc = (AgentResourceComponent) component;
            try {
                arc.releaseResource();
                // this.configMgr.unregisterComponent(arc.getFeature(), arc.getClass().getSimpleName());
                log.info(this, "stop resource [" + arc.getFeature() + "] component [" + arc.getName() + "] SUCCESS");
            } catch (Exception e) {
                log.err(this, "stop resource [" + arc.getFeature() + "] component [" + arc.getName() + "] FAILs ", e);
            }
        }
    }
    if (sysInvokerMgr != null) {
        sysInvokerMgr.shutdown();
        this.configMgr.unregisterComponent("Global", "ISystemInvokerMgr");
        log.info(this, "System Invoker Manager shutdown");
    }
    if (sysForkjoinWorkerMgr != null) {
        sysForkjoinWorkerMgr.shutdown();
        this.configMgr.unregisterComponent("Global", "I1NQueueWorkerMgr");
        log.info(this, "System ForkjoinWorker Manager shutdown");
    }
    if (sys1nQueueWorkerMgr != null) {
        sys1nQueueWorkerMgr.shutdown();
        this.configMgr.unregisterComponent("Global", "I1NQueueWorkerMgr");
        log.info(this, "System 1+N QueueWorker Manager shutdown");
    }
    if (sysActionEngineMgr != null) {
        sysActionEngineMgr.shutdown();
        this.configMgr.unregisterComponent("Global", "ISystemActionEngineMgr");
        log.info(this, "System ActionEngine Manager shutdown");
    }
    if (timerWorkManager != null) {
        timerWorkManager.shutdown();
        this.configMgr.unregisterComponent("Global", "ITimerWorkManager");
        log.info(this, "System Timer Manager shutdown");
    }
    log.info(this, "CreditEase Agent Server stopped");
}
Also used : AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

Example 4 with AgentResourceComponent

use of com.creditease.agent.spi.AgentResourceComponent in project uavstack by uavorg.

the class SystemStarter method installResources.

/**
 * install resources
 */
private void installResources() {
    Properties config = this.configMgr.getConfigurations();
    Set<Entry<Object, Object>> configEntrys = config.entrySet();
    for (Entry<Object, Object> configEntry : configEntrys) {
        String configName = configEntry.getKey().toString();
        // check if resource configuration
        if (!(configName.indexOf("resource.") == 0)) {
            continue;
        }
        // check if resource configuration
        String[] floader = configName.split("\\.");
        if (floader.length != 3 || !"class".equals(floader[2])) {
            continue;
        }
        // get resource name
        String resourceName = floader[1];
        // using default classloader
        ClassLoader cl = this.getClass().getClassLoader();
        String resourceClsName = config.getProperty("resource." + resourceName + ".class");
        try {
            // load resource class
            Class<?> resourceCls = cl.loadClass(resourceClsName);
            // check if resource class extends AgentResourceComponent
            if (!AgentResourceComponent.class.isAssignableFrom(resourceCls)) {
                continue;
            }
            // get constructor
            Constructor<?> con = resourceCls.getConstructor(new Class<?>[] { String.class, String.class });
            AgentResourceComponent arc = (AgentResourceComponent) con.newInstance(new Object[] { resourceCls.getSimpleName(), resourceName });
            // invoke AgentResourceComponent to init resource object
            Object resource = arc.initResource();
            if (resource != null) {
                // // register resource object & AgentResourceComponent
                // this.configMgr.registerComponent(resourceName, arc.getClass().getSimpleName(), arc);
                log.info(this, "load resource [" + resourceName + "] from resourceClass [" + resourceClsName + "]");
                continue;
            }
            // in case resource object is null
            throw new NullPointerException("init failure of resource object");
        } catch (Exception e) {
            log.err(this, "fail to load resource [" + resourceName + "]:" + e.getMessage(), e);
        }
    }
}
Also used : AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) Properties(java.util.Properties) Entry(java.util.Map.Entry) URLClassLoader(java.net.URLClassLoader)

Example 5 with AgentResourceComponent

use of com.creditease.agent.spi.AgentResourceComponent in project uavstack by uavorg.

the class MonitorDataMessageHandler method handle.

@Override
public void handle(Message msg) {
    super.handle(msg);
    // NOW, we send out the MDF for runtime notification
    AgentResourceComponent arc = (AgentResourceComponent) ConfigurationManager.getInstance().getComponent("messageproducer", "MessageProducerResourceComponent");
    MessageProducer producer = (MessageProducer) arc.getResource();
    if (producer != null) {
        String runtimeKey = MonitorDataFrame.MessageType.RuntimeNtf.toString();
        Message rtntfmsg = MessagingFactory.createMessage(runtimeKey);
        String dataStream = msg.getParam(this.getMsgTypeName());
        rtntfmsg.setParam(runtimeKey, dataStream);
        boolean check = producer.submit(rtntfmsg);
        String sendState = runtimeKey + " Data Sent " + (check ? "SUCCESS" : "FAIL");
        if (log.isDebugEnable()) {
            log.debug(this, sendState + "    " + dataStream);
        }
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) MessageProducer(com.creditease.uav.messaging.api.MessageProducer)

Aggregations

AgentResourceComponent (com.creditease.agent.spi.AgentResourceComponent)6 Message (com.creditease.uav.messaging.api.Message)4 MessageProducer (com.creditease.uav.messaging.api.MessageProducer)4 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1