log.debug("Updating consumer: " + toUpdate.getUuid());
}
// We need a representation of the consumer before making any modifications.
// If nothing changes we won't send. The new entity needs to be correct though,
// so we should get a Jsonstring now, and finish it off if we're going to send
EventBuilder eventBuilder = eventFactory.getEventBuilder(Target.CONSUMER, Type.MODIFIED)
.setOldEntity(toUpdate);
// version changed on non-checked in consumer, or list of capabilities
// changed on checked in consumer
boolean changesMade = updateCapabilities(toUpdate, updated);
changesMade = checkForFactsUpdate(toUpdate, updated) || changesMade;
changesMade = checkForInstalledProductsUpdate(toUpdate, updated) || changesMade;
changesMade = checkForGuestsUpdate(toUpdate, updated) || changesMade;
changesMade = checkForHypervisorIdUpdate(toUpdate, updated) || changesMade;
// Allow optional setting of the autoheal attribute:
if (updated.isAutoheal() != null &&
!updated.isAutoheal().equals(toUpdate.isAutoheal())) {
if (log.isDebugEnabled()) {
log.debug(" Updating consumer autoheal setting.");
}
toUpdate.setAutoheal(updated.isAutoheal());
changesMade = true;
}
if (updated.getReleaseVer() != null &&
(updated.getReleaseVer().getReleaseVer() != null) &&
!updated.getReleaseVer().equals(toUpdate.getReleaseVer())) {
if (log.isDebugEnabled()) {
log.debug(" Updating consumer releaseVer setting.");
}
toUpdate.setReleaseVer(updated.getReleaseVer());
changesMade = true;
}
// Allow optional setting of the service level attribute:
String level = updated.getServiceLevel();
if (level != null &&
!level.equals(toUpdate.getServiceLevel())) {
if (log.isDebugEnabled()) {
log.debug(" Updating consumer service level setting.");
}
consumerBindUtil.validateServiceLevel(toUpdate.getOwner(), level);
toUpdate.setServiceLevel(level);
changesMade = true;
}
String environmentId =
updated.getEnvironment() == null ? null : updated.getEnvironment().getId();
if (environmentId != null && (toUpdate.getEnvironment() == null ||
!toUpdate.getEnvironment().getId().equals(environmentId))) {
Environment e = environmentCurator.find(environmentId);
if (e == null) {
throw new NotFoundException(i18n.tr(
"Environment with ID ''{0}'' could not be found.", environmentId));
}
toUpdate.setEnvironment(e);
// lazily regenerate certs, so the client can still work
poolManager.regenerateEntitlementCertificates(toUpdate, true);
changesMade = true;
}
// like the other values in an update, if consumer name is null, act as if
// it should remain the same
if (updated.getName() != null && !toUpdate.getName().equals(updated.getName())) {
checkConsumerName(updated);
toUpdate.setName(updated.getName());
// get the new name into the id cert
IdentityCertificate ic = generateIdCert(toUpdate, true);
toUpdate.setIdCert(ic);
}
if (updated.getLastCheckin() != null) {
toUpdate.setLastCheckin(updated.getLastCheckin());
changesMade = true;
}
if (changesMade) {
log.debug("Consumer " + toUpdate.getUuid() + " updated.");
// Set the updated date here b/c @PreUpdate will not get fired
// since only the facts table will receive the update.
toUpdate.setUpdated(new Date());
// this should update compliance on toUpdate, but not call the curator
complianceRules.getStatus(toUpdate, null, false, false);
Event event = eventBuilder.setNewEntity(toUpdate).buildEvent();
sink.queueEvent(event);
}
return changesMade;
}