public Map<String, Host> groupByReportedUUid(List<? extends Host> hostList) { Map<String,Host> hosts = new HashMap<>(); for ( Host host : hostList ) { String uuid = DataAccessor.fields(host).withKey(HostConstants.FIELD_REPORTED_UUID).as(String.class); if ( uuid == null ) { uuid = host.getUuid(); } hosts.put(uuid, host); } return hosts; }
private String getHostUuid(Instance instance) { List<? extends InstanceHostMap> maps = mapDao.findNonRemoved(InstanceHostMap.class, Instance.class, instance.getId()); Long hostId = null; if (maps.size() == 1) { hostId = maps.get(0).getHostId(); } else if (maps.size() > 1) { Set<Long> hostIds = new HashSet<>(); for (InstanceHostMap ihm : maps) { hostIds.add(ihm.getHostId()); } if (hostIds.size() == 1) { hostId = hostIds.iterator().next(); } else { log.warn("Instance {} has {} instance host maps. Cannot determine host uuid. Returning null.", instance.getId(), maps.size()); return null; } } if (hostId != null) { Host h = objectManager.loadResource(Host.class, hostId); return h != null ? h.getUuid() : null; } else { return null; } }
protected String getToken(Host host, Map<String, Object> inputData, Date expiration) { Map<String, Object> data = new HashMap<String, Object>(inputData); String uuid = DataAccessor.fields(host).withKey(HostConstants.FIELD_REPORTED_UUID).as(String.class); if (uuid != null) { data.put(HOST_UUID, uuid); } else { data.put(HOST_UUID, host.getUuid()); } if (expiration == null) { return tokenService.generateToken(data); } else { return tokenService.generateToken(data, expiration); } }
@SuppressWarnings("unchecked") public HostMetaData(String agent_ip, Host host, Account account) { super(); this.agent_ip = agent_ip; String hostname = DataAccessor.fieldString(host, "hostname"); this.name = StringUtils.isEmpty(host.getName()) ? hostname: host.getName(); this.hostname = hostname; this.state = host.getState(); this.agent_state = host.getAgentState(); this.labels = (Map<String, String>) DataAccessor.fields(host) .withKey(InstanceConstants.FIELD_LABELS) .withDefault(Collections.EMPTY_MAP).as(Map.class); this.uuid = host.getUuid(); this.hostId = host.getId(); this.local_storage_mb = host.getLocalStorageMb(); this.memory = host.getMemory(); this.milli_cpu = host.getMilliCpu(); this.environment_uuid = account.getUuid(); this.metadata_kind = "host"; }
setAccountId(from.getAccountId()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState());