use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardProcessGroup method getComponentsAffectedByVariable.
@Override
public Set<ConfiguredComponent> getComponentsAffectedByVariable(final String variableName) {
final Set<ConfiguredComponent> affected = new HashSet<>();
// Determine any Processors that references the variable
for (final ProcessorNode processor : getProcessors()) {
for (final VariableImpact impact : getVariableImpact(processor)) {
if (impact.isImpacted(variableName)) {
affected.add(processor);
}
}
}
// find any references to that service and add it.
for (final ControllerServiceNode service : getControllerServices(false)) {
for (final VariableImpact impact : getVariableImpact(service)) {
if (impact.isImpacted(variableName)) {
affected.add(service);
final ControllerServiceReference reference = service.getReferences();
affected.addAll(reference.findRecursiveReferences(ConfiguredComponent.class));
}
}
}
// is overriding the variable and its components are actually referencing a different variable.
for (final ProcessGroup childGroup : getProcessGroups()) {
final ComponentVariableRegistry childRegistry = childGroup.getVariableRegistry();
final VariableDescriptor descriptor = childRegistry.getVariableKey(variableName);
final boolean overridden = childRegistry.getVariableMap().containsKey(descriptor);
if (!overridden) {
affected.addAll(childGroup.getComponentsAffectedByVariable(variableName));
}
}
return affected;
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardProcessGroup method removeControllerService.
@Override
public void removeControllerService(final ControllerServiceNode service) {
boolean removed = false;
writeLock.lock();
try {
final ControllerServiceNode existing = controllerServices.get(requireNonNull(service).getIdentifier());
if (existing == null) {
throw new IllegalStateException("ControllerService " + service.getIdentifier() + " is not a member of this Process Group");
}
service.verifyCanDelete();
try (final NarCloseable x = NarCloseable.withComponentNarLoader(service.getControllerServiceImplementation().getClass(), service.getIdentifier())) {
final ConfigurationContext configurationContext = new StandardConfigurationContext(service, controllerServiceProvider, null, variableRegistry);
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext);
}
for (final Map.Entry<PropertyDescriptor, String> entry : service.getProperties().entrySet()) {
final PropertyDescriptor descriptor = entry.getKey();
if (descriptor.getControllerServiceDefinition() != null) {
final String value = entry.getValue() == null ? descriptor.getDefaultValue() : entry.getValue();
if (value != null) {
final ControllerServiceNode referencedNode = getControllerService(value);
if (referencedNode != null) {
referencedNode.removeReference(service);
}
}
}
}
controllerServices.remove(service.getIdentifier());
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.
service.getReferences().getReferencingComponents().stream().map(ConfiguredComponent::getProcessGroupIdentifier).filter(id -> !id.equals(getIdentifier())).forEach(groupId -> {
final ProcessGroup descendant = findProcessGroup(groupId);
if (descendant != null) {
descendant.onComponentModified();
}
});
flowController.getStateManagerProvider().onComponentRemoved(service.getIdentifier());
removed = true;
LOG.info("{} removed from {}", service, this);
} finally {
if (removed) {
try {
ExtensionManager.removeInstanceClassLoader(service.getIdentifier());
} catch (Throwable t) {
}
}
writeLock.unlock();
}
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardControllerServiceNode method verifyCanDisable.
@Override
public void verifyCanDisable(final Set<ControllerServiceNode> ignoreReferences) {
if (!this.isActive()) {
throw new IllegalStateException("Cannot disable " + getControllerServiceImplementation().getIdentifier() + " because it is not enabled");
}
final ControllerServiceReference references = getReferences();
final Set<String> activeReferencesIdentifiers = new HashSet<>();
for (final ConfiguredComponent activeReference : references.getActiveReferences()) {
if (!ignoreReferences.contains(activeReference)) {
activeReferencesIdentifiers.add(activeReference.getIdentifier());
}
}
if (!activeReferencesIdentifiers.isEmpty()) {
throw new IllegalStateException(getControllerServiceImplementation().getIdentifier() + " cannot be disabled because it is referenced by " + activeReferencesIdentifiers.size() + " components that are currently running: [" + StringUtils.join(activeReferencesIdentifiers, ", ") + "]");
}
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class ControllerServiceAuditor method getUpdateActionsForReferencingComponents.
/**
* Gets the update actions for all specified referencing components.
*
* @param user user
* @param actions actions
* @param visitedServices services
* @param referencingComponents components
*/
private void getUpdateActionsForReferencingComponents(final NiFiUser user, final Collection<Action> actions, final Collection<String> visitedServices, final Set<ConfiguredComponent> referencingComponents) {
// consider each component updates
for (final ConfiguredComponent component : referencingComponents) {
if (component instanceof ProcessorNode) {
final ProcessorNode processor = ((ProcessorNode) component);
// create the processor details
FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
processorDetails.setType(processor.getComponentType());
// create a processor action
FlowChangeAction processorAction = new FlowChangeAction();
processorAction.setUserIdentity(user.getIdentity());
processorAction.setTimestamp(new Date());
processorAction.setSourceId(processor.getIdentifier());
processorAction.setSourceName(processor.getName());
processorAction.setSourceType(Component.Processor);
processorAction.setComponentDetails(processorDetails);
processorAction.setOperation(ScheduledState.RUNNING.equals(processor.getScheduledState()) ? Operation.Start : Operation.Stop);
actions.add(processorAction);
} else if (component instanceof ReportingTask) {
final ReportingTaskNode reportingTask = ((ReportingTaskNode) component);
// create the reporting task details
FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
taskDetails.setType(reportingTask.getComponentType());
// create a reporting task action
FlowChangeAction reportingTaskAction = new FlowChangeAction();
reportingTaskAction.setUserIdentity(user.getIdentity());
reportingTaskAction.setTimestamp(new Date());
reportingTaskAction.setSourceId(reportingTask.getIdentifier());
reportingTaskAction.setSourceName(reportingTask.getName());
reportingTaskAction.setSourceType(Component.ReportingTask);
reportingTaskAction.setComponentDetails(taskDetails);
reportingTaskAction.setOperation(ScheduledState.RUNNING.equals(reportingTask.getScheduledState()) ? Operation.Start : Operation.Stop);
actions.add(reportingTaskAction);
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode controllerService = ((ControllerServiceNode) component);
// create the controller service details
FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
serviceDetails.setType(controllerService.getComponentType());
// create a controller service action
FlowChangeAction serviceAction = new FlowChangeAction();
serviceAction.setUserIdentity(user.getIdentity());
serviceAction.setTimestamp(new Date());
serviceAction.setSourceId(controllerService.getIdentifier());
serviceAction.setSourceName(controllerService.getName());
serviceAction.setSourceType(Component.ControllerService);
serviceAction.setComponentDetails(serviceDetails);
serviceAction.setOperation(isDisabled(controllerService) ? Operation.Disable : Operation.Enable);
actions.add(serviceAction);
// need to consider components referencing this controller service (transitive)
if (!visitedServices.contains(controllerService.getIdentifier())) {
getUpdateActionsForReferencingComponents(user, actions, visitedServices, controllerService.getReferences().getReferencingComponents());
}
}
}
}
use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.
the class StandardAuthorizableLookup method getControllerServiceReferencingComponent.
@Override
public Authorizable getControllerServiceReferencingComponent(String controllerServiceId, String id) {
final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId);
final ControllerServiceReference referencingComponents = controllerService.getReferences();
final ConfiguredComponent reference = findControllerServiceReferencingComponent(referencingComponents, id);
if (reference == null) {
throw new ResourceNotFoundException("Unable to find referencing component with id " + id);
}
return reference;
}
Aggregations