Search in sources :

Example 51 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class TestFlowController method testInstantiateSnippetWhenControllerServiceMissingBundle.

@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenControllerServiceMissingBundle() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    // use a different id
    csDto.setId(UUID.randomUUID().toString());
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    // missing bundle
    csDto.setBundle(null);
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());
    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getControllerServices(false).size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

Example 52 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class ControllerServiceEntityMerger method mergeDtos.

private static void mergeDtos(final ControllerServiceDTO clientDto, final Map<NodeIdentifier, ControllerServiceDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    final Set<ControllerServiceReferencingComponentEntity> referencingComponents = clientDto.getReferencingComponents();
    final Map<NodeIdentifier, Set<ControllerServiceReferencingComponentEntity>> nodeReferencingComponentsMap = new HashMap<>();
    final Map<String, Map<NodeIdentifier, PropertyDescriptorDTO>> propertyDescriptorMap = new HashMap<>();
    String state = null;
    for (final Map.Entry<NodeIdentifier, ControllerServiceDTO> nodeEntry : dtoMap.entrySet()) {
        final ControllerServiceDTO nodeControllerService = nodeEntry.getValue();
        // consider the node controller service if authorized
        if (nodeControllerService != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            if (state == null) {
                if (ControllerServiceState.DISABLING.name().equals(nodeControllerService.getState())) {
                    state = ControllerServiceState.DISABLING.name();
                } else if (ControllerServiceState.ENABLING.name().equals(nodeControllerService.getState())) {
                    state = ControllerServiceState.ENABLING.name();
                }
            }
            nodeReferencingComponentsMap.put(nodeId, nodeControllerService.getReferencingComponents());
            // merge the validation errors
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeControllerService.getValidationErrors());
            // aggregate the property descriptors
            final Map<String, PropertyDescriptorDTO> descriptors = nodeControllerService.getDescriptors();
            if (descriptors != null) {
                descriptors.values().stream().forEach(propertyDescriptor -> {
                    propertyDescriptorMap.computeIfAbsent(propertyDescriptor.getName(), nodeIdToPropertyDescriptor -> new HashMap<>()).put(nodeId, propertyDescriptor);
                });
            }
        }
    }
    // merge property descriptors
    for (Map<NodeIdentifier, PropertyDescriptorDTO> propertyDescriptorByNodeId : propertyDescriptorMap.values()) {
        final Collection<PropertyDescriptorDTO> nodePropertyDescriptors = propertyDescriptorByNodeId.values();
        if (!nodePropertyDescriptors.isEmpty()) {
            // get the name of the property descriptor and find that descriptor being returned to the client
            final PropertyDescriptorDTO propertyDescriptor = nodePropertyDescriptors.iterator().next();
            final PropertyDescriptorDTO clientPropertyDescriptor = clientDto.getDescriptors().get(propertyDescriptor.getName());
            PropertyDescriptorDtoMerger.merge(clientPropertyDescriptor, propertyDescriptorByNodeId);
        }
    }
    // merge the referencing components
    mergeControllerServiceReferences(referencingComponents, nodeReferencingComponentsMap);
    // store the 'transition' state is applicable
    if (state != null) {
        clientDto.setState(state);
    }
    // set the merged the validation errors
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Also used : PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceReferencingComponentDTO(org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) Collection(java.util.Collection) Map(java.util.Map) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) Set(java.util.Set) HashMap(java.util.HashMap) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Set(java.util.Set) HashMap(java.util.HashMap) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO)

Example 53 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class ControllerServiceEntityMerger method mergeComponents.

/**
 * Merges the ControllerServiceEntity responses.
 *
 * @param clientEntity the entity being returned to the client
 * @param entityMap    all node responses
 */
@Override
public void mergeComponents(final ControllerServiceEntity clientEntity, final Map<NodeIdentifier, ControllerServiceEntity> entityMap) {
    final ControllerServiceDTO clientDto = clientEntity.getComponent();
    final Map<NodeIdentifier, ControllerServiceDTO> dtoMap = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, ControllerServiceEntity> entry : entityMap.entrySet()) {
        final ControllerServiceEntity nodeControllerServiceEntity = entry.getValue();
        final ControllerServiceDTO nodeControllerServiceDto = nodeControllerServiceEntity.getComponent();
        dtoMap.put(entry.getKey(), nodeControllerServiceDto);
    }
    mergeDtos(clientDto, dtoMap);
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class FlowFromDOMFactory method getControllerService.

public static ControllerServiceDTO getControllerService(final Element element, final StringEncryptor encryptor) {
    final ControllerServiceDTO dto = new ControllerServiceDTO();
    dto.setId(getString(element, "id"));
    dto.setVersionedComponentId(getString(element, "versionedComponentId"));
    dto.setName(getString(element, "name"));
    dto.setComments(getString(element, "comment"));
    dto.setType(getString(element, "class"));
    dto.setBundle(getBundle(DomUtils.getChild(element, "bundle")));
    final boolean enabled = getBoolean(element, "enabled");
    dto.setState(enabled ? ControllerServiceState.ENABLED.name() : ControllerServiceState.DISABLED.name());
    dto.setProperties(getProperties(element, encryptor));
    dto.setAnnotationData(getString(element, "annotationData"));
    return dto;
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO)

Example 55 with ControllerServiceDTO

use of org.apache.nifi.web.api.dto.ControllerServiceDTO in project nifi by apache.

the class ControllerServiceLoader method enableControllerServices.

public static void enableControllerServices(final Map<ControllerServiceNode, Element> nodeMap, final FlowController controller, final StringEncryptor encryptor, final boolean autoResumeState) {
    // Start services
    if (autoResumeState) {
        final Set<ControllerServiceNode> nodesToEnable = new HashSet<>();
        for (final ControllerServiceNode node : nodeMap.keySet()) {
            final Element controllerServiceElement = nodeMap.get(node);
            final ControllerServiceDTO dto;
            synchronized (controllerServiceElement.getOwnerDocument()) {
                dto = FlowFromDOMFactory.getControllerService(controllerServiceElement, encryptor);
            }
            final ControllerServiceState state = ControllerServiceState.valueOf(dto.getState());
            if (state == ControllerServiceState.ENABLED) {
                nodesToEnable.add(node);
            }
        }
        enableControllerServices(nodesToEnable, controller, autoResumeState);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) Element(org.w3c.dom.Element) HashSet(java.util.HashSet)

Aggregations

ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)60 HashSet (java.util.HashSet)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)17 List (java.util.List)16 Set (java.util.Set)16 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)15 Collectors (java.util.stream.Collectors)14 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)14 Collections (java.util.Collections)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)13 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)13 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 Optional (java.util.Optional)12 Nonnull (javax.annotation.Nonnull)11 NifiProperty (com.thinkbiganalytics.nifi.rest.model.NifiProperty)10