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);
}
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);
}
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);
}
Aggregations