Java Code Examples for org.apache.nifi.web.api.dto.ControllerServiceDTO#getParentGroupId()

The following examples show how to use org.apache.nifi.web.api.dto.ControllerServiceDTO#getParentGroupId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardControllerServiceDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // ensure the type is specified
    if (controllerServiceDTO.getType() == null) {
        throw new IllegalArgumentException("The controller service type must be specified.");
    }

    try {
        // create the controller service
        final ControllerServiceNode controllerService = serviceProvider.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), true);

        // ensure we can perform the update
        verifyUpdate(controllerService, controllerServiceDTO);

        // perform the update
        configureControllerService(controllerService, controllerServiceDTO);

        final String groupId = controllerServiceDTO.getParentGroupId();
        if (groupId == null) {
            flowController.addRootControllerService(controllerService);
        } else {
            final ProcessGroup group;
            if (groupId.equals(ROOT_GROUP_ID_ALIAS)) {
                group = flowController.getGroup(flowController.getRootGroupId());
            } else {
                group = flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(groupId);
            }

            if (group == null) {
                throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
            }

            group.addControllerService(controllerService);
        }

        return controllerService;
    } catch (final ControllerServiceInstantiationException csie) {
        throw new NiFiCoreException(csie.getMessage(), csie);
    }
}
 
Example 2
Source File: ControllerResource.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new Controller Service.
 *
 * @param httpServletRequest      request
 * @param requestControllerServiceEntity A controllerServiceEntity.
 * @return A controllerServiceEntity.
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("controller-services")
@ApiOperation(
        value = "Creates a new controller service",
        response = ControllerServiceEntity.class,
        authorizations = {
                @Authorization(value = "Write - /controller", type = ""),
                @Authorization(value = "Read - any referenced Controller Services - /controller-services/{uuid}", type = ""),
                @Authorization(value = "Write - if the Controller Service is restricted - /restricted-components", 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 = 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 createControllerService(
        @Context final HttpServletRequest httpServletRequest,
        @ApiParam(
                value = "The controller service configuration details.",
                required = true
        ) final ControllerServiceEntity requestControllerServiceEntity) {

    if (requestControllerServiceEntity == null || requestControllerServiceEntity.getComponent() == null) {
        throw new IllegalArgumentException("Controller service details must be specified.");
    }

    if (requestControllerServiceEntity.getRevision() == null
            || (requestControllerServiceEntity.getRevision().getVersion() == null || requestControllerServiceEntity.getRevision().getVersion() != 0)) {
        throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Controller service.");
    }

    final ControllerServiceDTO requestControllerService = requestControllerServiceEntity.getComponent();
    if (requestControllerService.getId() != null) {
        throw new IllegalArgumentException("Controller service ID cannot be specified.");
    }

    if (requestControllerService.getParentGroupId() != null) {
        throw new IllegalArgumentException("Parent process group ID cannot be specified.");
    }

    if (StringUtils.isBlank(requestControllerService.getType())) {
        throw new IllegalArgumentException("The type of controller service to create must be specified.");
    }

    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST, requestControllerServiceEntity);
    }

    return withWriteLock(
            serviceFacade,
            requestControllerServiceEntity,
            lookup -> {
                authorizeController(RequestAction.WRITE);

                final ConfigurableComponentAuthorizable authorizable = lookup.getControllerServiceByType(requestControllerService.getType());
                if (authorizable.isRestricted()) {
                    lookup.getRestrictedComponents().authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
                }

                if (requestControllerService.getProperties() != null) {
                    AuthorizeControllerServiceReference.authorizeControllerServiceReferences(requestControllerService.getProperties(), authorizable, authorizer, lookup);
                }
            },
            null,
            (controllerServiceEntity) -> {
                final ControllerServiceDTO controllerService = controllerServiceEntity.getComponent();

                // set the processor id as appropriate
                controllerService.setId(generateUuid());

                // create the controller service and generate the json
                final Revision revision = getRevision(controllerServiceEntity, controllerService.getId());
                final ControllerServiceEntity entity = serviceFacade.createControllerService(revision, null, controllerService);
                controllerServiceResource.populateRemainingControllerServiceEntityContent(entity);

                // build the response
                return clusterContext(generateCreatedResponse(URI.create(entity.getUri()), entity)).build();
            }
    );
}
 
Example 3
Source File: StandardControllerServiceDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // ensure the type is specified
    if (controllerServiceDTO.getType() == null) {
        throw new IllegalArgumentException("The controller service type must be specified.");
    }

    try {
        // create the controller service
        final ExtensionManager extensionManager = serviceProvider.getExtensionManager();
        final FlowManager flowManager = flowController.getFlowManager();
        final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(extensionManager, controllerServiceDTO.getType(), controllerServiceDTO.getBundle());
        final ControllerServiceNode controllerService = flowManager.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getId(), bundleCoordinate,
            Collections.emptySet(), true, true);

        // ensure we can perform the update
        verifyUpdate(controllerService, controllerServiceDTO);

        // perform the update
        configureControllerService(controllerService, controllerServiceDTO);

        final String groupId = controllerServiceDTO.getParentGroupId();
        if (groupId == null) {
            flowManager.addRootControllerService(controllerService);
        } else {
            final ProcessGroup group;
            if (groupId.equals(FlowManager.ROOT_GROUP_ID_ALIAS)) {
                group = flowManager.getRootGroup();
            } else {
                group = flowManager.getRootGroup().findProcessGroup(groupId);
            }

            if (group == null) {
                throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
            }

            group.addControllerService(controllerService);
        }

        return controllerService;
    } catch (final ControllerServiceInstantiationException csie) {
        throw new NiFiCoreException(csie.getMessage(), csie);
    }
}