use of com.cloud.agent.api.PingCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpResourceTest method testPingCommandStatusFail.
@Test
public void testPingCommandStatusFail() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("unstable");
when(nvpApi.getControlClusterStatus()).thenReturn(ccs);
final PingCommand ping = resource.getCurrentStatus(42);
assertTrue(ping == null);
}
use of com.cloud.agent.api.PingCommand in project cloudstack by apache.
the class Agent method processOtherTask.
public void processOtherTask(final Task task) {
final Object obj = task.get();
if (obj instanceof Response) {
if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * _shell.getPingRetries()) {
s_logger.error("Ping Interval has gone past " + _pingInterval * _shell.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
return;
}
final PingCommand ping = _resource.getCurrentStatus(getId());
final Request request = new Request(_id, -1, ping, false);
request.setSequence(getNextSequence());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending ping: " + request.toString());
}
try {
task.getLink().send(request.toBytes());
// if i can send pingcommand out, means the link is ok
setLastPingResponseTime();
} catch (final ClosedChannelException e) {
s_logger.warn("Unable to send request: " + request.toString());
}
} else if (obj instanceof Request) {
final Request req = (Request) obj;
final Command command = req.getCommand();
if (command.getContextParam("logid") != null) {
MDC.put("logcontextid", command.getContextParam("logid"));
}
Answer answer = null;
_inProgress.incrementAndGet();
try {
answer = _resource.executeRequest(command);
} finally {
_inProgress.decrementAndGet();
}
if (answer != null) {
final Response response = new Response(req, answer);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Watch Sent: " + response.toString());
}
try {
task.getLink().send(response.toBytes());
} catch (final ClosedChannelException e) {
s_logger.warn("Unable to send response: " + response.toString());
}
}
} else {
s_logger.warn("Ignoring an unknown task");
}
}
use of com.cloud.agent.api.PingCommand in project cosmic by MissionCriticalCloud.
the class Agent method processOtherTask.
public void processOtherTask(final Task task) {
final Object obj = task.get();
if (obj instanceof Response) {
if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * agentProperties.getPingRetries()) {
logger.error("Ping Interval has gone past " + _pingInterval * agentProperties.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
return;
}
final PingCommand ping = resource.getCurrentStatus(getId());
final Request request = new Request(_id, -1, ping, false);
request.setSequence(getNextSequence());
if (logger.isDebugEnabled()) {
logger.debug("Sending ping: " + request.toString());
}
try {
task.getLink().send(request.toBytes());
// if i can send pingcommand out, means the link is ok
setLastPingResponseTime();
} catch (final ClosedChannelException e) {
logger.warn("Unable to send request: " + request.toString());
}
} else if (obj instanceof Request) {
final Request req = (Request) obj;
final Command command = req.getCommand();
if (command.getContextParam("logid") != null) {
MDC.put("logcontextid", command.getContextParam("logid"));
}
Answer answer = null;
_inProgress.incrementAndGet();
try {
answer = resource.executeRequest(command);
} finally {
_inProgress.decrementAndGet();
}
if (answer != null) {
final Response response = new Response(req, answer);
if (logger.isDebugEnabled()) {
logger.debug("Watch Sent: " + response.toString());
}
try {
task.getLink().send(response.toBytes());
} catch (final ClosedChannelException e) {
logger.warn("Unable to send response: " + response.toString());
}
}
} else {
logger.warn("Ignoring an unknown task");
}
}
use of com.cloud.agent.api.PingCommand in project cloudstack by apache.
the class CiscoVnmcResourceTest method testPingCommandStatusFail.
@Test
public void testPingCommandStatusFail() throws ConfigurationException, ExecutionException {
_resource.setConnection(_connection);
when(_connection.login()).thenReturn(false);
PingCommand ping = _resource.getCurrentStatus(1);
assertTrue(ping == null);
}
use of com.cloud.agent.api.PingCommand 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);
}
Aggregations