use of org.ovirt.engine.core.common.businessentities.BusinessEntity in project ovirt-engine by oVirt.
the class BackendAssignedAffinityLabelsResource method add.
@Override
public Response add(AffinityLabel label) {
validateParameters(label, "id");
IdQueryParameters parameters = new IdQueryParameters(GuidUtils.asGuid(label.getId()));
org.ovirt.engine.core.common.businessentities.Label entity = getEntity(org.ovirt.engine.core.common.businessentities.Label.class, QueryType.GetLabelById, parameters, label.getId(), true);
BusinessEntity<Guid> parent = constructor.create();
parent.setId(GuidUtils.asGuid(parentId));
org.ovirt.engine.core.common.businessentities.Label updatedLabel = new LabelBuilder(entity).entity(parent).build();
// Add the affinity label using the backend "update" operation. As the backend will return the added label as
// the result of the operation, we can fetch it using a simple "identity" resolver, that just returns the same
// value it is passed.
LabelActionParameters updateParams = new LabelActionParameters(updatedLabel);
return performCreate(ActionType.UpdateLabel, updateParams, (IResolver<Label, Label>) result -> result);
}
use of org.ovirt.engine.core.common.businessentities.BusinessEntity in project ovirt-engine by oVirt.
the class CommandCompensator method compensate.
@SuppressWarnings({ "unchecked", "synthetic-access" })
public void compensate(Guid commandId, String commandType, CompensationContext compensationContext) {
TransactionSupport.executeInNewTransaction(() -> {
Deserializer deserializer = SerializationFactory.getDeserializer();
List<BusinessEntitySnapshot> entitySnapshots = businessEntitySnapshotDao.getAllForCommandId(commandId);
log.debug("Command [id={}]: {} compensation data.", commandId, entitySnapshots.isEmpty() ? "No" : "Going over");
for (BusinessEntitySnapshot snapshot : entitySnapshots) {
Class<Serializable> snapshotClass = (Class<Serializable>) ReflectionUtils.getClassFor(snapshot.getSnapshotClass());
Serializable snapshotData = deserializer.deserialize(snapshot.getEntitySnapshot(), snapshotClass);
log.info("Command [id={}]: Compensating {} of {}; snapshot: {}.", commandId, snapshot.getSnapshotType(), snapshot.getEntityType(), snapshot.getSnapshotType() == BusinessEntitySnapshot.SnapshotType.DELETED_OR_UPDATED_ENTITY ? "id=" + snapshot.getEntityId() : snapshotData.toString());
Class<BusinessEntity<Serializable>> entityClass = (Class<BusinessEntity<Serializable>>) ReflectionUtils.getClassFor(snapshot.getEntityType());
switch(snapshot.getSnapshotType()) {
case CHANGED_STATUS_ONLY:
BusinessEntitySnapshot.EntityStatusSnapshot entityStatusSnapshot = (BusinessEntitySnapshot.EntityStatusSnapshot) snapshotData;
((StatusAwareDao<Serializable, Enum<?>>) getDaoForEntity(entityClass)).updateStatus(entityStatusSnapshot.getId(), entityStatusSnapshot.getStatus());
break;
case DELETED_OR_UPDATED_ENTITY:
deletedOrUpdateEntity(entityClass, (BusinessEntity<Serializable>) snapshotData);
break;
case UPDATED_ONLY_ENTITY:
getDaoForEntity(entityClass).update((BusinessEntity<Serializable>) snapshotData);
break;
case NEW_ENTITY_ID:
getDaoForEntity(entityClass).remove(snapshotData);
break;
case TRANSIENT_ENTITY:
objectCompensation.compensate(commandType, (TransientCompensationBusinessEntity) snapshotData);
break;
default:
throw new IllegalArgumentException(String.format("Unknown %s value, unable to compensate value %s.", BusinessEntitySnapshot.SnapshotType.class.getName(), snapshot.getSnapshotType()));
}
}
if (compensationContext == null) {
businessEntitySnapshotDao.removeAllForCommandId(commandId);
} else {
compensationContext.afterCompensationCleanup();
}
return null;
});
}
Aggregations