Search in sources :

Example 1 with PingRoutingWithNwGroupsCommand

use of com.cloud.agent.api.PingRoutingWithNwGroupsCommand in project cloudstack by apache.

the class AgentRoutingResource method getCurrentStatus.

@Override
public PingCommand getCurrentStatus(long id) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        MockConfigurationVO config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(), agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingCommand");
        if (config != null) {
            Map<String, String> configParameters = config.getParameters();
            for (Map.Entry<String, String> entry : configParameters.entrySet()) {
                if (entry.getKey().equalsIgnoreCase("result")) {
                    String value = entry.getValue();
                    if (value.equalsIgnoreCase("fail")) {
                        return null;
                    }
                }
            }
        }
        config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(), agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingRoutingWithNwGroupsCommand");
        if (config != null) {
            String message = config.getJsonResponse();
            if (message != null) {
                // json response looks like {"<Type>":....}
                String objectType = message.split(":")[0].substring(2).replace("\"", "");
                String objectData = message.substring(message.indexOf(':') + 1, message.length() - 1);
                if (objectType != null) {
                    Class<?> clz = null;
                    try {
                        clz = Class.forName(objectType);
                    } catch (ClassNotFoundException e) {
                        s_logger.info("[ignored] ping returned class", e);
                    }
                    if (clz != null) {
                        StringReader reader = new StringReader(objectData);
                        JsonReader jsonReader = new JsonReader(reader);
                        jsonReader.setLenient(true);
                        return (PingCommand) s_gson.fromJson(jsonReader, clz);
                    }
                }
            }
        }
    } catch (Exception e) {
        txn.rollback();
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    if (isStopped()) {
        return null;
    }
    HashMap<String, Pair<Long, Long>> nwGrpStates = _simMgr.syncNetworkGroups(hostGuid);
    return new PingRoutingWithNwGroupsCommand(getType(), id, getHostVmStateReport(), nwGrpStates);
}
Also used : MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) ConfigurationException(javax.naming.ConfigurationException) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingWithNwGroupsCommand(com.cloud.agent.api.PingRoutingWithNwGroupsCommand) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 2 with PingRoutingWithNwGroupsCommand

use of com.cloud.agent.api.PingRoutingWithNwGroupsCommand in project cloudstack by apache.

the class SecurityGroupListener method processCommands.

@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
    boolean processed = false;
    for (Command cmd : commands) {
        if (cmd instanceof PingRoutingWithNwGroupsCommand) {
            PingRoutingWithNwGroupsCommand ping = (PingRoutingWithNwGroupsCommand) cmd;
            if (ping.getNewGroupStates().size() > 0) {
                _securityGroupManager.fullSync(agentId, ping.getNewGroupStates());
            }
            processed = true;
        }
    }
    return processed;
}
Also used : PingRoutingWithNwGroupsCommand(com.cloud.agent.api.PingRoutingWithNwGroupsCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) PingRoutingWithNwGroupsCommand(com.cloud.agent.api.PingRoutingWithNwGroupsCommand) Command(com.cloud.agent.api.Command) StartupCommand(com.cloud.agent.api.StartupCommand)

Aggregations

PingRoutingWithNwGroupsCommand (com.cloud.agent.api.PingRoutingWithNwGroupsCommand)2 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)1 Command (com.cloud.agent.api.Command)1 PingCommand (com.cloud.agent.api.PingCommand)1 StartupCommand (com.cloud.agent.api.StartupCommand)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1 MockConfigurationVO (com.cloud.simulator.MockConfigurationVO)1 Pair (com.cloud.utils.Pair)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 JsonReader (com.google.gson.stream.JsonReader)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigurationException (javax.naming.ConfigurationException)1