@QueryParam("create_missing") @DefaultValue("true") boolean createMissing) {
log.info("Hypervisor check-in by principal: " + principal);
Owner owner = this.getOwner(ownerKey);
HypervisorCheckInResult result = new HypervisorCheckInResult();
for (Entry<String, List<GuestId>> hostEntry : hostGuestMap.entrySet()) {
try {
log.info("Checking virt host: " + hostEntry.getKey());
boolean hostConsumerCreated = false;
// Attempt to find a consumer for the given hypervisorId
Consumer consumer =
consumerCurator.getHypervisor(hostEntry.getKey(), owner);
if (consumer == null) {
if (!createMissing) {
log.info("Unable to find hypervisor with id " +
hostEntry.getKey() + " in org " + ownerKey);
result.failed(hostEntry.getKey(), i18n.tr(
"Unable to find hypervisor in org ''{0}''", ownerKey));
continue;
}
log.info("Registering new host consumer");
// Create new consumer
consumer = createConsumerForHypervisorId(
hostEntry.getKey(), owner, principal);
hostConsumerCreated = true;
}
boolean guestIdsUpdated = addGuestIds(consumer, hostEntry.getValue());
// Populate the result with the processed consumer.
if (hostConsumerCreated) {
result.created(consumer);
}
else if (guestIdsUpdated) {
result.updated(consumer);
}
else {
result.unchanged(consumer);
}
}
catch (Exception e) {
log.error("Hypervisor checkin failed", e);
result.failed(hostEntry.getKey(), e.getMessage());
}
}
return result;
}