protected String getAccountUuid(Agent agent) { return "agentAccount" + agent.getId(); }
protected String getAccountUuid(Agent agent, String role) { return "agentAccount" + agent.getId() + "-" + role; }
public AgentResourceCreateLock(Agent agent) { super("AGENT.RESOUCE.CREATE." + agent.getId()); }
public AgentConnectionLockDefinition(Agent agent) { this(agent.getId()); }
@Override public Host getHost(Object obj) { if (!(obj instanceof Agent)) { return null; } Agent agent = (Agent) obj; return objectManager.findAny(Host.class, HOST.AGENT_ID, agent.getId(), HOST.REMOVED, null); }
public static Ping newPing(Agent agent) { if (agent == null) { return null; } return newPing(agent.getId()); }
protected EventService buildDelegate(long agentId) { Map<String, Object> instanceData = new LinkedHashMap<>(); Agent hostAgent = getAgentForDelegate(agentId, instanceData); if (hostAgent == null) { return null; } String hostAgentUri = hostAgent.getUri(); if (hostAgentUri != null && !hostAgentUri.startsWith(EVENTING)) { return null; } return new WrappedEventService(hostAgent.getId(), true, eventService, instanceData, jsonMapper, delegateDao); }
protected Map<String, Object> createData(Agent agent, String uuid, Map<String, Object> data) { Map<String, Object> properties = new HashMap<>(data); properties.put(HostConstants.FIELD_REPORTED_UUID, uuid); properties.remove(ObjectMetaDataManager.UUID_FIELD); Long accountId = DataAccessor.fromDataFieldOf(agent).withKey(AgentConstants.DATA_AGENT_RESOURCES_ACCOUNT_ID).as(Long.class); if (accountId == null) { accountId = agent.getAccountId(); } properties.put(ObjectMetaDataManager.ACCOUNT_FIELD, accountId); properties.put(AgentConstants.ID_REF, agent.getId()); return properties; }
@Override public Instance doWithLock() { Instance instance = factoryDao.getInstanceByAgent(agent.getId()); if (instance == null) { instance = DeferredUtils.nest(new Callable<Instance>() { @Override public Instance call() throws Exception { return resourceDao.createAndSchedule(Instance.class, properties); } }); } return instance; } });
protected void pingSuccess(Agent agent, Ping pong) { status.getUnchecked(agent.getId()).success(); agentResourceManager.processPingReply(pong); pingInstanceMonitor.pingReply(pong); }
private Map<String, Object> getInstanceProperties(Agent agent, AgentInstanceBuilderImpl builder) { Map<Object, Object> properties = new HashMap<Object, Object>(); properties.put(INSTANCE.ACCOUNT_ID, getAccountId(builder)); properties.put(INSTANCE.AGENT_ID, agent.getId()); properties.put(InstanceConstants.FIELD_IMAGE_UUID, builder.getImageUuid()); properties.put(INSTANCE.NAME, builder.getName()); properties.put(INSTANCE.ZONE_ID, agent.getZoneId()); properties.put(INSTANCE.KIND, builder.getInstanceKind()); properties.put(InstanceConstants.FIELD_PRIVILEGED, builder.isPrivileged()); properties.put(InstanceConstants.FIELD_NETWORK_IDS, getNetworkIds(agent, builder)); properties.putAll(builder.getParams()); addAdditionalProperties(properties, agent, builder); return objectManager.convertToPropertiesFor(Instance.class, properties); }
private Instance getInstance(Agent agent, AgentInstanceBuilderImpl builder) { Instance instance = factoryDao.getInstanceByAgent(agent.getId()); if (instance != null) { return instance; } Map<String, Object> properties = getInstanceProperties(agent, builder); return createInstance(agent, properties, builder); }
@Override public HandlerResult handle(ProcessState state, ProcessInstance process) { Instance instance = (Instance)state.getResource(); Agent agent = agentInstanceFactory.createAgent(instance); return agent == null ? null : new HandlerResult((Object)INSTANCE.AGENT_ID, agent.getId()); }
@Override public List<? extends Instance> getInstances(Object obj) { Host host = null; if (obj instanceof Agent) { Agent agent = (Agent) obj; host = objectManager.findAny(Host.class, HOST.AGENT_ID, agent.getId(), HOST.REMOVED, null); } else if (obj instanceof Host) { host = (Host) obj; } if (host == null) { return null; } return serviceDao.getInstancesWithHealtcheckEnabled(host.getAccountId()); } }
protected Agent getAgent() { Agent agent = objectManager.loadResource(Agent.class, ApiUtils.getPolicy().getOption(Policy.AGENT_ID)); if (agent == null) { throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT); } return agentDao.getHostAgentForDelegate(agent.getId()); }
protected void validate(HostApiProxyToken proxyToken) { String reportedUuid = proxyToken.getReportedUuid(); Policy policy = ApiUtils.getPolicy(); Agent agent = objectManager.loadResource(Agent.class, policy.getOption(Policy.AGENT_ID)); if (agent == null) { throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT); } Map<String, Host> hosts = agentDao.getHosts(agent.getId()); Host host = hosts.get(reportedUuid); if (host == null) { throw new ValidationErrorException(ValidationErrorCodes.INVALID_REFERENCE, HostConstants.FIELD_REPORTED_UUID); } } }
protected AgentAndHost loadAgentAndHostData(ImmutablePair<Long, String> agentIdAndHostUuid) { Long agentId = agentIdAndHostUuid.left; String hostUuid = agentIdAndHostUuid.right; Agent agent = objectManager.loadResource(Agent.class, agentId); Host host = null; Map<String, Host> hosts = null; if (agent != null) { hosts = agentDao.getHosts(agent.getId()); host = hosts.get(hostUuid); } if (agent == null || agent.getAccountId() == null || host == null) throw new CantFindAgentAndHostException(); return new AgentAndHost(agent.getAccountId(), host.getId()); }
public Event handle(Agent agent, Event event) throws IOException { ConfigUpdate update = jsonMapper.convertValue(event, ConfigUpdate.class); Map<String, Object> authMap = AgentUtils.getAgentAuth(agent, objectManager); if (authMap == null) { return null; } String auth = ObjectUtils.toString(authMap.get("CATTLE_AGENT_INSTANCE_AUTH"), null); if (auth == null) { throw new IllegalStateException("Failed to get auth for agent [" + agent.getId() + "]"); } for (ConfigUpdateItem item : update.getData().getItems()) { downloadAndPost(auth, update.getData().getConfigUrl(), item); } return EventVO.reply(event); }
protected ConfigUpdateRequest before(ConfigUpdateRequest request, Agent agent) { if (request == null) { request = ConfigUpdateRequest.forResource(Agent.class, agent.getId()); for (String item : ITEMS.get()) { request.addItem(item).withIncrement(false).setCheckInSyncOnly(true); } } statusManager.updateConfig(request); return request; }
@Override public Instance getInstance(Agent agent) { return create() .selectFrom(INSTANCE) .where(INSTANCE.AGENT_ID.eq(agent.getId()) .and(INSTANCE.REMOVED.isNull()) .and(INSTANCE.STATE.notIn(InstanceConstants.STATE_ERROR, InstanceConstants.STATE_ERRORING, CommonStatesConstants.REMOVING))) .fetchOne(); }