Search in sources :

Example 6 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardControllerServiceDAO method updateControllerService.

@Override
public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // get the controller service
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());
    // ensure we can perform the update
    verifyUpdate(controllerService, controllerServiceDTO);
    // perform the update
    configureControllerService(controllerService, controllerServiceDTO);
    // attempt to change the underlying controller service if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(controllerService, controllerServiceDTO);
    // enable or disable as appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
        // only attempt an action if it is changing
        if (!purposedControllerServiceState.equals(controllerService.getState())) {
            if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                serviceProvider.enableControllerService(controllerService);
            } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                serviceProvider.disableControllerService(controllerService);
            }
        }
    }
    final ProcessGroup group = controllerService.getProcessGroup();
    if (group != null) {
        group.onComponentModified();
        // For any component that references this Controller Service, find the component's Process Group
        // and notify the Process Group that a component has been modified. This way, we know to re-calculate
        // whether or not the Process Group has local modifications.
        controllerService.getReferences().getReferencingComponents().stream().map(ConfiguredComponent::getProcessGroupIdentifier).filter(id -> !id.equals(group.getIdentifier())).forEach(groupId -> {
            final ProcessGroup descendant = group.findProcessGroup(groupId);
            if (descendant != null) {
                descendant.onComponentModified();
            }
        });
    }
    return controllerService;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ArrayList(java.util.ArrayList) ComponentStateDAO(org.apache.nifi.web.dao.ComponentStateDAO) ControllerServiceDAO(org.apache.nifi.web.dao.ControllerServiceDAO) ROOT_GROUP_ID_ALIAS(org.apache.nifi.controller.FlowController.ROOT_GROUP_ID_ALIAS) Scope(org.apache.nifi.components.state.Scope) Map(java.util.Map) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) Set(java.util.Set) BundleUtils(org.apache.nifi.util.BundleUtils) StateMap(org.apache.nifi.components.state.StateMap) FlowController(org.apache.nifi.controller.FlowController) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) List(java.util.List) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ExtensionManager(org.apache.nifi.nar.ExtensionManager) Collections(java.util.Collections) ValidationException(org.apache.nifi.controller.exception.ValidationException) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 7 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardControllerServiceDAO method deleteControllerService.

@Override
public void deleteControllerService(final String controllerServiceId) {
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceId);
    serviceProvider.removeControllerService(controllerService);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode)

Example 8 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardControllerServiceDAO method createControllerService.

@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(), BundleUtils.getBundle(controllerServiceDTO.getType(), controllerServiceDTO.getBundle()), Collections.emptySet(), 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);
    }
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException)

Example 9 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardControllerServiceDAO method verifyUpdate.

@Override
public void verifyUpdate(final ControllerServiceDTO controllerServiceDTO) {
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());
    verifyUpdate(controllerService, controllerServiceDTO);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode)

Example 10 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardControllerServiceDAO method clearState.

@Override
public void clearState(final String controllerServiceId) {
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceId);
    componentStateDAO.clearState(controllerService);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode)

Aggregations

ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)88 HashSet (java.util.HashSet)29 ProcessGroup (org.apache.nifi.groups.ProcessGroup)26 HashMap (java.util.HashMap)25 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)25 ArrayList (java.util.ArrayList)24 Map (java.util.Map)24 LinkedHashSet (java.util.LinkedHashSet)22 Test (org.junit.Test)19 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)18 ProcessorNode (org.apache.nifi.controller.ProcessorNode)18 ConfiguredComponent (org.apache.nifi.controller.ConfiguredComponent)17 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)17 Set (java.util.Set)16 Connection (org.apache.nifi.connectable.Connection)16 List (java.util.List)15 Port (org.apache.nifi.connectable.Port)15 Label (org.apache.nifi.controller.label.Label)15 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)15 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)15