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);
}
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()));
}
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);
}
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;
}
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);
}
}
Aggregations