Github user mcgilman commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2051#discussion_r131995022
  
    --- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/FlowResource.java
 ---
    @@ -640,7 +643,128 @@ public Response scheduleComponents(
                                 
componentsToSchedule.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
 e -> getRevision(e.getValue(), e.getKey())));
     
                         // update the process group
    -                    final ScheduleComponentsEntity entity = 
serviceFacade.scheduleComponents(id, scheduledState, componentRevisions);
    +                final ScheduleComponentsEntity entity = 
serviceFacade.scheduleComponents(id, scheduledState, componentRevisions);
    +                    return generateOkResponse(entity).build();
    +                }
    +        );
    +    }
    +
    +
    +    @PUT
    +    @Consumes(MediaType.APPLICATION_JSON)
    +    @Produces(MediaType.APPLICATION_JSON)
    +    @Path("process-groups/{id}/controller-services")
    +    @ApiOperation(value = "Enable or disable Controller Services in the 
specified Process Group.",
    +        response = ActivateControllerServicesEntity.class,
    +        authorizations = {
    +            @Authorization(value = "Read - /flow", type = ""),
    +            @Authorization(value = "Write - /{component-type}/{uuid} - For 
every service being enabled/disabled", type = "")
    +        })
    +    @ApiResponses(
    +            value = {
    +                    @ApiResponse(code = 400, message = "NiFi was unable to 
complete the request because it was invalid. The request should not be retried 
without modification."),
    +                    @ApiResponse(code = 401, message = "Client could not 
be authenticated."),
    +                    @ApiResponse(code = 403, message = "Client is not 
authorized to make this request."),
    +                    @ApiResponse(code = 404, message = "The specified 
resource could not be found."),
    +                    @ApiResponse(code = 409, message = "The request was 
valid but NiFi was not in the appropriate state to process it. Retrying the 
same request later may be successful.")
    +            }
    +    )
    +    public Response activateControllerServices(
    +            @Context HttpServletRequest httpServletRequest,
    +            @ApiParam(value = "The process group id.", required = true)
    +            @PathParam("id") String id,
    +            @ApiParam(value = "The request to schedule or unschedule. If 
the comopnents in the request are not specified, all authorized components will 
be considered.", required = true)
    +            final ActivateControllerServicesEntity requestEntity) {
    +
    +        // ensure the same id is being used
    +        if (!id.equals(requestEntity.getId())) {
    +            throw new IllegalArgumentException(String.format("The process 
group id (%s) in the request body does "
    +                + "not equal the process group id of the requested 
resource (%s).", requestEntity.getId(), id));
    +        }
    +
    +        final ControllerServiceState state;
    +        if (requestEntity.getState() == null) {
    +            throw new IllegalArgumentException("The scheduled state must 
be specified.");
    +        } else {
    +            try {
    +                state = 
ControllerServiceState.valueOf(requestEntity.getState());
    +            } catch (final IllegalArgumentException iae) {
    +                throw new IllegalArgumentException(String.format("The 
scheduled must be one of [%s].",
    +                    
StringUtils.join(EnumSet.of(ControllerServiceState.ENABLED, 
ControllerServiceState.DISABLED), ", ")));
    +            }
    +        }
    +
    +        // ensure its a supported scheduled state
    +        if (ControllerServiceState.DISABLING.equals(state) || 
ControllerServiceState.ENABLING.equals(state)) {
    +            throw new IllegalArgumentException(String.format("The 
scheduled must be one of [%s].",
    +                
StringUtils.join(EnumSet.of(ControllerServiceState.ENABLED, 
ControllerServiceState.DISABLED), ", ")));
    +        }
    +
    +        // if the components are not specified, gather all components and 
their current revision
    +        if (requestEntity.getComponents() == null) {
    +            // get the current revisions for the components being updated
    +            final Set<Revision> revisions = 
serviceFacade.getRevisionsFromGroup(id, group -> {
    +                final Set<String> componentIds = new HashSet<>();
    +
    +                final Predicate<ControllerServiceNode> filter;
    +                if (ControllerServiceState.ENABLED.equals(state)) {
    +                    filter = service -> !service.isActive() && 
service.isValid();
    +                } else {
    +                    filter = service -> service.isActive();
    +                }
    +
    +                group.findAllControllerServices().stream()
    +                    .filter(filter)
    --- End diff --
    
    This filter should be finding all Controller Services that are going to be 
enabled/disabled. Part of this check should be whether this current user is 
allowed to perform this action.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to