@Override public void purgeResourceConfigurationUpdate(Subject subject, int configurationUpdateId, boolean purgeInProgress) { ResourceConfigurationUpdate doomedRequest = entityManager.find(ResourceConfigurationUpdate.class, configurationUpdateId); if (doomedRequest == null) { if (LOG.isDebugEnabled()) { LOG.debug("Asked to purge a non-existing config update request [" + configurationUpdateId + "]"); } return; } if ((doomedRequest.getStatus() == ConfigurationUpdateStatus.INPROGRESS) && !purgeInProgress) { throw new IllegalStateException( "The update request is still in the in-progress state. Please wait for it to complete: " + doomedRequest); } // make sure the user has the proper permissions to do this Resource resource = doomedRequest.getResource(); if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_WRITE, resource.getId())) { throw new PermissionException("User [" + subject.getName() + "] does not have permission to purge a configuration update audit trail for resource [" + resource + "]"); } resource.getResourceConfigurationUpdates().remove(doomedRequest); entityManager.remove(doomedRequest); entityManager.flush(); return; }
private boolean waitForConfigurationUpdateToFinish(Subject subject, ResourceConfigurationUpdateCriteria criteria, int maxAttempts) { if (maxAttempts == 0) return false; PageList<ResourceConfigurationUpdate> configUpdates = configurationManager .findResourceConfigurationUpdatesByCriteria(subject, criteria); switch (configUpdates.get(0).getStatus()) { case INPROGRESS: // try it again in 2.5 sec break; case FAILURE: return false; default: return true; } try { Thread.sleep(2500L); } catch (InterruptedException e) { return false; } return waitForConfigurationUpdateToFinish(subject, criteria, maxAttempts - 1); }
@Override public boolean isResourceConfigurationUpdateInProgress(Subject subject, int resourceId) { boolean updateInProgress; try { Query query = entityManager.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_LATEST_BY_RESOURCE_ID); query.setParameter("resourceId", resourceId); ResourceConfigurationUpdate latestConfigUpdate = (ResourceConfigurationUpdate) query.getSingleResult(); if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, latestConfigUpdate .getResource().getId())) { throw new PermissionException("User [" + subject.getName() + "] does not have permission to view Resource configuration for [" + latestConfigUpdate.getResource() + "]"); } updateInProgress = (latestConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS); } catch (NoResultException nre) { // The resource config history is empty, so there's obviously no update in progress. updateInProgress = false; } return updateInProgress; }
ResourceConfigurationUpdate resourceConfigUpdate = entityManager.find(ResourceConfigurationUpdate.class, resourceConfigUpdateId); if (resourceConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS) {
query.setParameter("resourceId", resourceId); latest = (ResourceConfigurationUpdate) query.getSingleResult(); if (latest.getStatus() == ConfigurationUpdateStatus.INPROGRESS) {
current = (ResourceConfigurationUpdate) result; if (ConfigurationUpdateStatus.INPROGRESS == current.getStatus()) {
private String toCSV(ResourceConfigurationUpdate configurationUpdate) { return configurationUpdate.getId() + "," + formatDateTime(configurationUpdate.getCreatedTime())+"," + formatDateTime(configurationUpdate.getModifiedTime())+"," + configurationUpdate.getStatus()+"," + cleanForCSV(configurationUpdate.getResource().getName())+ "," + cleanForCSV(ReportFormatHelper.parseAncestry(configurationUpdate.getResource().getAncestry())) + "," + getDetailsURL(configurationUpdate); //@todo: check dates, user, update-type }