use of org.apache.nifi.web.InvalidRevisionException in project nifi by apache.
the class RuleResource method getCriteria.
private Criteria getCriteria(final NiFiWebConfigurationContext configurationContext, final NiFiWebRequestContext requestContext) {
final ComponentDetails processorDetails;
try {
// load the processor configuration
processorDetails = configurationContext.getComponentDetails(requestContext);
} catch (final InvalidRevisionException ire) {
throw new WebApplicationException(ire, invalidRevision(ire.getMessage()));
} catch (final Exception e) {
final String message = String.format("Unable to get UpdateAttribute[id=%s] criteria: %s", requestContext.getId(), e);
logger.error(message, e);
throw new WebApplicationException(e, error(message));
}
Criteria criteria = null;
if (processorDetails != null) {
try {
criteria = CriteriaSerDe.deserialize(processorDetails.getAnnotationData());
} catch (final IllegalArgumentException iae) {
final String message = String.format("Unable to deserialize existing rules for UpdateAttribute[id=%s]. Deserialization error: %s", requestContext.getId(), iae);
logger.error(message, iae);
throw new WebApplicationException(iae, error(message));
}
}
// ensure the criteria isn't null
if (criteria == null) {
criteria = new Criteria();
}
return criteria;
}
use of org.apache.nifi.web.InvalidRevisionException in project nifi by apache.
the class NaiveRevisionManager method updateRevision.
@Override
public <T> RevisionUpdate<T> updateRevision(final RevisionClaim originalClaim, final NiFiUser user, final UpdateRevisionTask<T> task) throws ExpiredRevisionClaimException {
Objects.requireNonNull(user);
logger.debug("Attempting to update revision using {}", originalClaim);
final List<Revision> revisionList = new ArrayList<>(originalClaim.getRevisions());
revisionList.sort(new RevisionComparator());
for (final Revision revision : revisionList) {
final Revision currentRevision = getRevision(revision.getComponentId());
final boolean verified = revision.equals(currentRevision);
if (!verified) {
// Throw an Exception indicating that we failed to obtain the locks
throw new InvalidRevisionException("Invalid Revision was given for component with ID '" + revision.getComponentId() + "'");
}
}
// We successfully verified all revisions.
logger.debug("Successfully verified Revision Claim for all revisions");
RevisionUpdate<T> updatedComponent = null;
try {
updatedComponent = task.update();
} finally {
// Release the lock that we are holding and update the revision.
// To do this, we need to map the old revision to the new revision
// so that we have an efficient way to lookup the pairing, so that
// we can easily obtain the old revision and the new revision for
// the same component in order to call #unlock on the RevisionLock
final Map<Revision, Revision> updatedRevisions = new HashMap<>();
final Map<String, Revision> revisionsByComponentId = new HashMap<>();
for (final Revision revision : revisionList) {
updatedRevisions.put(revision, revision);
revisionsByComponentId.put(revision.getComponentId(), revision);
}
if (updatedComponent != null) {
for (final Revision updatedRevision : updatedComponent.getUpdatedRevisions()) {
final Revision oldRevision = revisionsByComponentId.get(updatedRevision.getComponentId());
if (oldRevision != null) {
updatedRevisions.put(oldRevision, updatedRevision);
}
}
}
for (final Revision revision : revisionList) {
final Revision updatedRevision = updatedRevisions.get(revision);
revisionMap.put(updatedRevision.getComponentId(), updatedRevision);
if (updatedRevision.getVersion() != revision.getVersion()) {
logger.debug("Unlocked Revision {} and updated associated Version to {}", revision, updatedRevision.getVersion());
} else {
logger.debug("Unlocked Revision {} without updating Version", revision);
}
}
}
return updatedComponent;
}
use of org.apache.nifi.web.InvalidRevisionException in project nifi by apache.
the class RuleResource method saveCriteria.
private void saveCriteria(final NiFiWebConfigurationRequestContext requestContext, final Criteria criteria) {
// serialize the criteria
final String annotationData = CriteriaSerDe.serialize(criteria);
// get the web context
final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
try {
// save the annotation data
configurationContext.updateComponent(requestContext, annotationData, null);
} catch (final InvalidRevisionException ire) {
throw new WebApplicationException(ire, invalidRevision(ire.getMessage()));
} catch (final Exception e) {
final String message = String.format("Unable to save UpdateAttribute[id=%s] criteria: %s", requestContext.getId(), e);
logger.error(message, e);
throw new WebApplicationException(e, error(message));
}
}
Aggregations