private boolean isAgentDisconnected(Host host) { if (host == null) { return false; } Agent agent = context.objectManager.loadResource(Agent.class, host.getAgentId()); if (agent != null && (AgentConstants.STATE_RECONNECTING.equals(agent.getState()) || AgentConstants.STATE_DISCONNECTED.equals(agent.getState()) || AgentConstants.STATE_DISCONNECTING .equals(agent.getState()))) { return true; } return false; }
@Override protected Event callSync(RemoteAgent remoteAgent, Event event, EventCallOptions options) { Agent agent = loadResource(Agent.class, remoteAgent.getAgentId()); if (agent != null && (AgentConstants.STATE_RECONNECTING.equals(agent.getState()) || AgentConstants.STATE_DISCONNECTED.equals(agent.getState()))) { return null; } return super.callSync(remoteAgent, event, options); }
@Override public void deleteAgent(Instance instance) { if (!shouldCreateAgent(instance) || instance.getAgentId() == null) { return; } Agent agent = objectManager.loadResource(Agent.class, instance.getAgentId()); if (agent == null) { return; } if (CommonStatesConstants.DEACTIVATING.equals(agent.getState())) { return; } try { processManager.scheduleStandardProcess(StandardProcess.DEACTIVATE, agent, ProcessUtils.chainInData(new HashMap<String, Object>(), AgentConstants.PROCESS_DEACTIVATE, AgentConstants.PROCESS_REMOVE)); } catch (ProcessCancelException e) { try { processManager.scheduleStandardProcess(StandardProcess.REMOVE, agent, null); } catch (ProcessCancelException e1) { } } }
protected void handleReconnecting(ProcessState state, Instance instance) { boolean reconnecting = false; InstanceHealthCheck healthCheck = DataAccessor.field(instance, InstanceConstants.FIELD_HEALTH_CHECK, jsonMapper, InstanceHealthCheck.class); for (InstanceHostMap map : mapDao.findNonRemoved(InstanceHostMap.class, Instance.class, instance.getId())) { Host host = objectManager.loadResource(Host.class, map.getHostId()); Agent agent = host == null ? null : objectManager.loadResource(Agent.class, host.getAgentId()); if (agent != null && (AgentConstants.STATE_RECONNECTING.equals(agent.getState()) || AgentConstants.STATE_DISCONNECTED.equals(agent.getState()))) { reconnecting = true; } else { reconnecting = false; break; } } if (reconnecting && (healthCheck != null || instance.getFirstRunning() == null)) { getObjectProcessManager().scheduleProcessInstance(InstanceConstants.PROCESS_STOP, instance, CollectionUtils.asMap(InstanceConstants.REMOVE_OPTION, true)); } }
protected void pingFailure(Agent agent) { long count = status.getUnchecked(agent.getId()).failed(); if (count < 3) { log.info("Missed ping from agent [{}] count [{}]", agent.getId(), count); } else { log.error("Failed to get ping from agent [{}] count [{}]", agent.getId(), count); } if (count >= BAD_PINGS.get()) { try { agent = objectManager.reload(agent); if (CommonStatesConstants.ACTIVE.equals(agent.getState())) { Host host = objectManager.findAny(Host.class, HOST.AGENT_ID, agent.getId()); if (host != null) { log.error("Scheduling reconnect for agent [{}] host [{}] count [{}]", agent.getId(), host.getId(), count); } else { log.error("Scheduling reconnect for agent [{}] count [{}]", agent.getId(), count); } processManager.scheduleProcessInstance(AgentConstants.PROCESS_RECONNECT, agent, null); } } catch (ProcessInstanceException e) { if (e.getExitReason() != ExitReason.CANCELED) { throw e; } } } }
protected Long getAgent() { ApiRequest request = ApiContext.getContext().getApiRequest(); Long agentId = getRawAgentId(); if (agentId != null) { return agentId; } String type = request.getSchemaFactory().getSchemaName(Agent.class); ResourceManager rm = getLocator().getResourceManagerByType(type); Long id = null; /* This really isn't the best logic. Basically we are looking for agents with state in STATES */ for (Object obj : rm.list(type, null, Pagination.limit(2))) { if (!(obj instanceof Agent)) { continue; } Agent agent = (Agent)obj; if (STATES.contains(agent.getState())) { if (id != null) { throw new ValidationErrorException(ValidationErrorCodes.MISSING_REQUIRED, "agentId"); } else { if (DISCONNECTED.contains(agent.getState())) { processManager.scheduleProcessInstance(AgentConstants.PROCESS_RECONNECT, agent, null); } id = agent.getId(); } } } return id; }
for (Host host : hosts) { Agent agent = objectManager.loadResource(Agent.class, host.getAgentId()); if (agent == null || !CommonStatesConstants.ACTIVE.equals(agent.getState())) { continue;
if (agent == null || !CommonStatesConstants.ACTIVE.equals(agent.getState())) { throw new ClientVisibleException(ResponseCodes.SERVICE_UNAVAILABLE);
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Agent from) { setId(from.getId()); setName(from.getName()); setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setUri(from.getUri()); setManagedConfig(from.getManagedConfig()); setZoneId(from.getZoneId()); setExternalId(from.getExternalId()); }