@Override public FlowRegistry removeFlowRegistry(final String registryId) { final FlowRegistry registry = flowRegistryClient.removeFlowRegistry(registryId); if (registry == null) { throw new ResourceNotFoundException("Unable to find Flow Registry with id '" + registryId + "'"); } return registry; }
@Override public Response toResponse(ResourceNotFoundException exception) { // log the error logger.info(String.format("%s. Returning %s response.", exception, Response.Status.NOT_FOUND)); if (logger.isDebugEnabled()) { logger.debug(StringUtils.EMPTY, exception); } return Response.status(Status.NOT_FOUND).entity(exception.getMessage()).type("text/plain").build(); }
@Override public Authorizable getLocalConnectable(String id) { final Connectable connectable = controllerFacade.findLocalConnectable(id); if (connectable == null) { throw new ResourceNotFoundException("Unable to find component with id " + id); } return connectable; }
@Override public AccessPolicy getAccessPolicy(final String accessPolicyId) { final AccessPolicy accessPolicy = accessPolicyProvider.getAccessPolicy(accessPolicyId); if (accessPolicy == null) { throw new ResourceNotFoundException(String.format("Unable to find access policy with id '%s'.", accessPolicyId)); } return accessPolicy; }
private ReportingTaskNode locateReportingTask(final String reportingTaskId) { // get the reporting task final ReportingTaskNode reportingTask = reportingTaskProvider.getReportingTaskNode(reportingTaskId); // ensure the reporting task exists if (reportingTask == null) { throw new ResourceNotFoundException(String.format("Unable to locate reporting task with id '%s'.", reportingTaskId)); } return reportingTask; }
@Override public Group getUserGroup(final String userGroupId) { final Group userGroup = userGroupProvider.getGroup(userGroupId); if (userGroup == null) { throw new ResourceNotFoundException(String.format("Unable to find user group with id '%s'.", userGroupId)); } return userGroup; }
@Override public FlowRegistry getFlowRegistry(final String registryId) { final FlowRegistry registry = flowRegistryClient.getFlowRegistry(registryId); if (registry == null) { throw new ResourceNotFoundException("Unable to find Flow Registry with id '" + registryId + "'"); } return registry; }
@Override public User getUser(final String userId) { final User user = userGroupProvider.getUser(userId); if (user == null) { throw new ResourceNotFoundException(String.format("Unable to find user with id '%s'.", userId)); } return user; }
private ControllerServiceNode locateControllerService(final String controllerServiceId) { // get the controller service final ControllerServiceNode controllerService = serviceProvider.getControllerServiceNode(controllerServiceId); // ensure the controller service exists if (controllerService == null) { throw new ResourceNotFoundException(String.format("Unable to locate controller service with id '%s'.", controllerServiceId)); } return controllerService; }
/** * Resets the counter with the specified id. * * @param id id * @return the counter with the specified id */ public Counter resetCounter(final String id) { final Counter counter = flowController.resetCounter(id); if (counter == null) { throw new ResourceNotFoundException(String.format("Unable to find Counter with id '%s'.", id)); } return counter; }
private StateMap getState(final String componentId, final Scope scope) { try { final StateManager manager = stateManagerProvider.getStateManager(componentId); if (manager == null) { throw new ResourceNotFoundException(String.format("State for the specified component %s could not be found.", componentId)); } return manager.getState(scope); } catch (final IOException ioe) { throw new IllegalStateException(String.format("Unable to get the state for the specified component %s: %s", componentId, ioe), ioe); } }
@Override public AsynchronousWebRequest<T> getRequest(final String type, final String id, final NiFiUser user) { Objects.requireNonNull(type); Objects.requireNonNull(id); Objects.requireNonNull(user); final String key = getKey(type, id); final AsynchronousWebRequest<T> request = requests.get(key); if (request == null) { throw new ResourceNotFoundException("Could not find a Request with identifier " + id); } if (!request.getUser().equals(user)) { throw new IllegalArgumentException("Only the user that submitted the update request can delete it."); } return request; }
private Connectable findConnectable(final String componentId, final String groupId, final Set<ProcessGroup> validProcessGroups) { // Get the component with the given ID and ensure that it belongs to the group that we are looking for. // We do this, rather than calling ProcessGroup.findLocalConnectable because for any component that is buried several // layers of Process Groups deep, that method becomes quite a bit more expensive than this method, due to all of the // Read Locks that must be obtained while recursing through the Process Group's descendant groups. final Connectable connectable = flowController.getFlowManager().findConnectable(componentId); if (connectable == null) { throw new ResourceNotFoundException("Could not find Component with ID " + componentId); } final ProcessGroup connectableGroup = connectable.getProcessGroup(); if (!validProcessGroups.contains(connectableGroup)) { throw new ResourceNotFoundException("Component with ID " + componentId + " does not belong to Process Group " + groupId + " or any of its descendent groups"); } return connectable; }
private StandardSnippet locateSnippet(String snippetId) { final StandardSnippet snippet = flowController.getSnippetManager().getSnippet(snippetId); if (snippet == null) { throw new ResourceNotFoundException(String.format("Unable to find snippet with id '%s'.", snippetId)); } return snippet; }
/** * Locates the specified ProcessGroup. * * @param flowController controller * @param groupId id * @return group */ protected ProcessGroup locateProcessGroup(FlowController flowController, String groupId) { ProcessGroup group = flowController.getFlowManager().getGroup(groupId); if (group == null) { throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId)); } return group; }
@Override public AsynchronousWebRequest<T> removeRequest(final String type, final String id, final NiFiUser user) { Objects.requireNonNull(type); Objects.requireNonNull(id); Objects.requireNonNull(user); final String key = getKey(type, id); final AsynchronousWebRequest<T> request = requests.get(key); if (request == null) { throw new ResourceNotFoundException("Could not find a Request with identifier " + id); } if (!request.getUser().equals(user)) { throw new IllegalArgumentException("Only the user that submitted the update request can delete it."); } if (!request.isComplete()) { throw new IllegalStateException("Cannot remove the request because it is not yet complete"); } return requests.remove(key); }
private void clearState(final String componentId) { try { final StateManager manager = stateManagerProvider.getStateManager(componentId); if (manager == null) { throw new ResourceNotFoundException(String.format("State for the specified component %s could not be found.", componentId)); } // clear both state's at the same time manager.clear(Scope.CLUSTER); manager.clear(Scope.LOCAL); } catch (final IOException ioe) { throw new IllegalStateException(String.format("Unable to clear the state for the specified component %s: %s", componentId, ioe), ioe); } }
@Override public VariableRegistryEntity getVariableRegistry(final String groupId, final boolean includeAncestorGroups) { final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId); if (processGroup == null) { throw new ResourceNotFoundException("Could not find group with ID " + groupId); } return createVariableRegistryEntity(processGroup, includeAncestorGroups); }
@Override public ListFlowFileStatus deleteFlowFileListingRequest(String connectionId, String listingRequestId) { final Connection connection = locateConnection(connectionId); final FlowFileQueue queue = connection.getFlowFileQueue(); final ListFlowFileStatus listFlowFileStatus = queue.cancelListFlowFileRequest(listingRequestId); if (listFlowFileStatus == null) { throw new ResourceNotFoundException(String.format("Unable to find listing request with id '%s'.", listingRequestId)); } return listFlowFileStatus; }
private Port locatePort(final String portId) { final ProcessGroup rootGroup = flowController.getFlowManager().getRootGroup(); final Port port = rootGroup.findOutputPort(portId); if (port == null) { throw new ResourceNotFoundException(String.format("Unable to find port with id '%s'.", portId)); } else { return port; } }