use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardNiFiServiceFacade method getActiveComponentsAffectedByVariableRegistryUpdate.
@Override
public Set<AffectedComponentDTO> getActiveComponentsAffectedByVariableRegistryUpdate(final VariableRegistryDTO variableRegistryDto) {
final ProcessGroup group = processGroupDAO.getProcessGroup(variableRegistryDto.getProcessGroupId());
if (group == null) {
throw new ResourceNotFoundException("Could not find Process Group with ID " + variableRegistryDto.getProcessGroupId());
}
final Map<String, String> variableMap = new HashMap<>();
// have to use forEach here instead of using Collectors.toMap because value may be null
variableRegistryDto.getVariables().stream().map(VariableEntity::getVariable).forEach(var -> variableMap.put(var.getName(), var.getValue()));
final Set<AffectedComponentDTO> affectedComponentDtos = new HashSet<>();
final Set<String> updatedVariableNames = getUpdatedVariables(group, variableMap);
for (final String variableName : updatedVariableNames) {
final Set<ConfiguredComponent> affectedComponents = group.getComponentsAffectedByVariable(variableName);
for (final ConfiguredComponent component : affectedComponents) {
if (component instanceof ProcessorNode) {
final ProcessorNode procNode = (ProcessorNode) component;
if (procNode.isRunning()) {
affectedComponentDtos.add(dtoFactory.createAffectedComponentDto(procNode));
}
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode serviceNode = (ControllerServiceNode) component;
if (serviceNode.isActive()) {
affectedComponentDtos.add(dtoFactory.createAffectedComponentDto(serviceNode));
}
} else {
throw new RuntimeException("Found unexpected type of Component [" + component.getCanonicalClassName() + "] dependending on variable");
}
}
}
return affectedComponentDtos;
}
use of org.apache.nifi.controller.ConfiguredComponent 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;
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardAuthorizableLookup method findControllerServiceReferencingComponent.
private ConfiguredComponent findControllerServiceReferencingComponent(final ControllerServiceReference referencingComponents, final String id) {
ConfiguredComponent reference = null;
for (final ConfiguredComponent component : referencingComponents.getReferencingComponents()) {
if (component.getIdentifier().equals(id)) {
reference = component;
break;
}
if (component instanceof ControllerServiceNode) {
final ControllerServiceNode refControllerService = (ControllerServiceNode) component;
reference = findControllerServiceReferencingComponent(refControllerService.getReferences(), id);
if (reference != null) {
break;
}
}
}
return reference;
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class NiFiRegistryFlowMapper method mapProperties.
private Map<String, String> mapProperties(final ConfiguredComponent component, final ControllerServiceProvider serviceProvider) {
final Map<String, String> mapped = new HashMap<>();
component.getProperties().keySet().stream().filter(property -> !property.isSensitive()).forEach(property -> {
String value = component.getProperty(property);
if (value == null) {
value = property.getDefaultValue();
}
if (value != null && property.getControllerServiceDefinition() != null) {
// Property references a Controller Service. Instead of storing the existing value, we want
// to store the Versioned Component ID of the service.
final ControllerServiceNode controllerService = serviceProvider.getControllerServiceNode(value);
if (controllerService != null) {
value = getId(controllerService.getVersionedComponentId(), controllerService.getIdentifier());
}
}
mapped.put(property.getName(), value);
});
return mapped;
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardControllerServiceProvider method scheduleReferencingComponents.
@Override
public Set<ConfiguredComponent> scheduleReferencingComponents(final ControllerServiceNode serviceNode) {
// find all of the schedulable components (processors, reporting tasks) that refer to this Controller Service,
// or a service that references this controller service, etc.
final List<ProcessorNode> processors = serviceNode.getReferences().findRecursiveReferences(ProcessorNode.class);
final List<ReportingTaskNode> reportingTasks = serviceNode.getReferences().findRecursiveReferences(ReportingTaskNode.class);
final Set<ConfiguredComponent> updated = new HashSet<>();
// verify that we can start all components (that are not disabled) before doing anything
for (final ProcessorNode node : processors) {
if (node.getScheduledState() != ScheduledState.DISABLED) {
node.verifyCanStart();
updated.add(node);
}
}
for (final ReportingTaskNode node : reportingTasks) {
if (node.getScheduledState() != ScheduledState.DISABLED) {
node.verifyCanStart();
updated.add(node);
}
}
// start all of the components that are not disabled
for (final ProcessorNode node : processors) {
if (node.getScheduledState() != ScheduledState.DISABLED) {
node.getProcessGroup().startProcessor(node, true);
updated.add(node);
}
}
for (final ReportingTaskNode node : reportingTasks) {
if (node.getScheduledState() != ScheduledState.DISABLED) {
processScheduler.schedule(node);
updated.add(node);
}
}
return updated;
}
Aggregations