Search in sources :

Example 6 with MockConfigurationVO

use of com.cloud.simulator.MockConfigurationVO 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 7 with MockConfigurationVO

use of com.cloud.simulator.MockConfigurationVO in project cloudstack by apache.

the class ConfigureSimulatorCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    if (hostId != null && jsonResponse != null) {
        jsonResponse = jsonResponse.replace("\"hostId\":0", "\"hostId\":" + hostId);
    }
    Long id = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values, count, jsonResponse);
    if (id == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure simulator");
    }
    MockConfigurationVO config = _simMgr.querySimulatorMock(id);
    if (config == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to query simulator mock");
    }
    MockResponse response = new MockResponse();
    response.setId(config.getId());
    response.setZoneId(config.getDataCenterId());
    response.setPodId(config.getPodId());
    response.setClusterId(config.getClusterId());
    response.setHostId(config.getHostId());
    response.setName(config.getName());
    response.setCount(config.getCount());
    response.setResponseName("simulatormock");
    this.setResponseObject(response);
}
Also used : MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) MockResponse(com.cloud.api.response.MockResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 8 with MockConfigurationVO

use of com.cloud.simulator.MockConfigurationVO in project cloudstack by apache.

the class QuerySimulatorMockCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    MockConfigurationVO config = _simMgr.querySimulatorMock(id);
    if (config == null) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to query mock");
    }
    MockResponse response = new MockResponse();
    response.setId(config.getId());
    response.setZoneId(config.getDataCenterId());
    response.setPodId(config.getPodId());
    response.setClusterId(config.getClusterId());
    response.setHostId(config.getHostId());
    response.setName(config.getName());
    response.setCount(config.getCount());
    response.setResponseName("simulatormock");
    this.setResponseObject(response);
}
Also used : MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) MockResponse(com.cloud.api.response.MockResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

MockConfigurationVO (com.cloud.simulator.MockConfigurationVO)8 ConfigurationException (javax.naming.ConfigurationException)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 Answer (com.cloud.agent.api.Answer)2 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)2 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)2 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)2 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)2 ComputeChecksumCommand (com.cloud.agent.api.ComputeChecksumCommand)2 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)2 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)2 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)2 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)2 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)2 GetDomRVersionCmd (com.cloud.agent.api.GetDomRVersionCmd)2 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)2 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)2 GetVmStatsCommand (com.cloud.agent.api.GetVmStatsCommand)2