private List<Long> getAgentResource(Long accountId, List<Instance> instances) { List<Long> agentIds = agentInstanceDao.getAgentProvider(SystemLabels.LABEL_AGENT_SERVICE_SCHEDULING_PROVIDER, accountId); for (Instance instance : instances) { if (agentIds.contains(instance.getAgentId())) { return new ArrayList<>(); } } return agentIds; }
@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) { } } }
@Override protected Object getAgentResource(ProcessState state, ProcessInstance process, Object dataResource) { Instance instance = getInstance(state); if (!isPod(instance)) { return false; } Long accountId = instance.getAccountId(); List<Long> agentIds = agentInstanceDao.getAgentProvider(SystemLabels.LABEL_AGENT_SERVICE_LABELS_PROVIDER, accountId); Long agentId = agentIds.size() == 0 ? null : agentIds.get(0); if ((instance instanceof Instance) && (agentIds.contains(instance.getAgentId()) || instance.getSystem())) { return null; } if (agentId == null) { if (k8sRequired(instance)) { throw new ExecutionException("Failed to find labels provider", instance); } else { return null; } } return agentId; }
Agent agent = objectManager.loadResource(Agent.class, instance.getAgentId()); if (agent == null) { return;
deleteAgentAccount(instance.getAgentId(), state.getData());
setZoneId(from.getZoneId()); setInstanceTriggeredStop(from.getInstanceTriggeredStop()); setAgentId(from.getAgentId()); setDomain(from.getDomain()); setFirstRunning(from.getFirstRunning());