Search in sources :

Example 1 with VariableEntity

use of org.apache.nifi.web.api.entity.VariableEntity in project nifi by apache.

the class DtoFactory method createVariableRegistryDto.

public VariableRegistryDTO createVariableRegistryDto(final ProcessGroup processGroup, final RevisionManager revisionManager) {
    final ComponentVariableRegistry variableRegistry = processGroup.getVariableRegistry();
    final List<String> variableNames = variableRegistry.getVariableMap().keySet().stream().map(descriptor -> descriptor.getName()).collect(Collectors.toList());
    final Set<VariableEntity> variableEntities = new LinkedHashSet<>();
    for (final String variableName : variableNames) {
        final VariableDTO variableDto = new VariableDTO();
        variableDto.setName(variableName);
        variableDto.setValue(variableRegistry.getVariableValue(variableName));
        variableDto.setProcessGroupId(processGroup.getIdentifier());
        final Set<AffectedComponentEntity> affectedComponentEntities = createAffectedComponentEntities(processGroup.getComponentsAffectedByVariable(variableName), revisionManager);
        boolean canWrite = true;
        for (final AffectedComponentEntity affectedComponent : affectedComponentEntities) {
            final PermissionsDTO permissions = affectedComponent.getPermissions();
            if (!permissions.getCanRead() || !permissions.getCanWrite()) {
                canWrite = false;
                break;
            }
        }
        variableDto.setAffectedComponents(affectedComponentEntities);
        final VariableEntity variableEntity = new VariableEntity();
        variableEntity.setVariable(variableDto);
        variableEntity.setCanWrite(canWrite);
        variableEntities.add(variableEntity);
    }
    final VariableRegistryDTO registryDto = new VariableRegistryDTO();
    registryDto.setProcessGroupId(processGroup.getIdentifier());
    registryDto.setVariables(variableEntities);
    return registryDto;
}
Also used : ProcessorStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessorStatusSnapshotEntity) ConnectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ConnectionDiagnosticsDTO) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) FlowModification(org.apache.nifi.web.FlowModification) StringUtils(org.apache.commons.lang3.StringUtils) DropFlowFileStatus(org.apache.nifi.controller.queue.DropFlowFileStatus) QueueSize(org.apache.nifi.controller.queue.QueueSize) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) VariableRegistryUpdateStep(org.apache.nifi.registry.variable.VariableRegistryUpdateStep) Scope(org.apache.nifi.components.state.Scope) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) ControllerFacade(org.apache.nifi.web.controller.ControllerFacade) Map(java.util.Map) InstantiatedVersionedFunnel(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedFunnel) Connection(org.apache.nifi.connectable.Connection) NarClassLoaders(org.apache.nifi.nar.NarClassLoaders) FlowDifferenceFilters(org.apache.nifi.util.FlowDifferenceFilters) NodeEvent(org.apache.nifi.cluster.event.NodeEvent) VariableRegistryUpdateRequest(org.apache.nifi.registry.variable.VariableRegistryUpdateRequest) VersionedFlowStatus(org.apache.nifi.registry.flow.VersionedFlowStatus) AllowableValue(org.apache.nifi.components.AllowableValue) ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.PortStatusSnapshotDTO) AuthorizerCapabilityDetection(org.apache.nifi.authorization.AuthorizerCapabilityDetection) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) ControllerService(org.apache.nifi.controller.ControllerService) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedProcessor(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessor) ExtensionManager(org.apache.nifi.nar.ExtensionManager) Tags(org.apache.nifi.annotation.documentation.Tags) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) RemoteProcessGroupCounts(org.apache.nifi.groups.RemoteProcessGroupCounts) ActionDTO(org.apache.nifi.web.api.dto.action.ActionDTO) Supplier(java.util.function.Supplier) LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) LinkedHashMap(java.util.LinkedHashMap) Relationship(org.apache.nifi.processor.Relationship) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) ProcessGroupCounts(org.apache.nifi.groups.ProcessGroupCounts) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) JVMSystemDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMSystemDiagnosticsSnapshotDTO) Collator(java.text.Collator) Restricted(org.apache.nifi.annotation.behavior.Restricted) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) ConnectionStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusSnapshotDTO) ProvenanceNodeDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceNodeDTO) ComponentDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.ComponentDetailsDTO) RequestAction(org.apache.nifi.authorization.RequestAction) InstantiatedVersionedLabel(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedLabel) HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) TreeMap(java.util.TreeMap) RemoteProcessGroupDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.RemoteProcessGroupDetailsDTO) ReportingTask(org.apache.nifi.reporting.ReportingTask) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Date(java.util.Date) ConnectableType(org.apache.nifi.connectable.ConnectableType) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) RemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO) Locale(java.util.Locale) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) ConnectionStatusSnapshotEntity(org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity) ActiveThreadInfo(org.apache.nifi.controller.ActiveThreadInfo) Label(org.apache.nifi.controller.label.Label) Authorizable(org.apache.nifi.authorization.resource.Authorizable) TimeZone(java.util.TimeZone) Collection(java.util.Collection) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity) ProcessorStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusSnapshotDTO) RevisionManager(org.apache.nifi.web.revision.RevisionManager) Snippet(org.apache.nifi.controller.Snippet) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Collectors(java.util.stream.Collectors) StateMap(org.apache.nifi.components.state.StateMap) Processor(org.apache.nifi.processor.Processor) Entry(java.util.Map.Entry) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) NodeHeartbeat(org.apache.nifi.cluster.coordination.heartbeat.NodeHeartbeat) ComputeLineageResult(org.apache.nifi.provenance.lineage.ComputeLineageResult) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) Group(org.apache.nifi.authorization.Group) BundleDetails(org.apache.nifi.bundle.BundleDetails) Function(java.util.function.Function) GarbageCollectionStatus(org.apache.nifi.controller.status.history.GarbageCollectionStatus) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) HashSet(java.util.HashSet) ActionDetailsDTO(org.apache.nifi.web.api.dto.action.details.ActionDetailsDTO) ThreadDumpDTO(org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO) GarbageCollection(org.apache.nifi.diagnostics.GarbageCollection) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) FlowBreadcrumbEntity(org.apache.nifi.web.api.entity.FlowBreadcrumbEntity) ValidationResult(org.apache.nifi.components.ValidationResult) PurgeDetailsDTO(org.apache.nifi.web.api.dto.action.details.PurgeDetailsDTO) JVMControllerDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMControllerDiagnosticsSnapshotDTO) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) FlowBreadcrumbDTO(org.apache.nifi.web.api.dto.flow.FlowBreadcrumbDTO) ProvenanceLinkDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) ProvenanceEventLineageNode(org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) AccessPolicyEntity(org.apache.nifi.web.api.entity.AccessPolicyEntity) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Comparator(java.util.Comparator) InstantiatedVersionedComponent(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedComponent) Bundle(org.apache.nifi.bundle.Bundle) StorageUsage(org.apache.nifi.diagnostics.StorageUsage) GCDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.GCDiagnosticsSnapshotDTO) GarbageCollectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.GarbageCollectionDiagnosticsDTO) Arrays(java.util.Arrays) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ClassLoaderDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ClassLoaderDiagnosticsDTO) ProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusSnapshotDTO) ClassUtils(org.apache.commons.lang3.ClassUtils) TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Connectable(org.apache.nifi.connectable.Connectable) Bulletin(org.apache.nifi.reporting.Bulletin) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Restriction(org.apache.nifi.annotation.behavior.Restriction) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) History(org.apache.nifi.history.History) AccessPolicySummaryEntity(org.apache.nifi.web.api.entity.AccessPolicySummaryEntity) Set(java.util.Set) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) FlowController(org.apache.nifi.controller.FlowController) ListFlowFileState(org.apache.nifi.controller.queue.ListFlowFileState) Stateful(org.apache.nifi.annotation.behavior.Stateful) ActionDetails(org.apache.nifi.action.details.ActionDetails) Position(org.apache.nifi.connectable.Position) ListFlowFileStatus(org.apache.nifi.controller.queue.ListFlowFileStatus) WebApplicationException(javax.ws.rs.WebApplicationException) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) LineageRequestDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) Resource(org.apache.nifi.authorization.Resource) Counter(org.apache.nifi.controller.Counter) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) NumberFormat(java.text.NumberFormat) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) LineageEdge(org.apache.nifi.provenance.lineage.LineageEdge) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) LinkedHashSet(java.util.LinkedHashSet) ConfigureDetails(org.apache.nifi.action.details.ConfigureDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) MoveDetailsDTO(org.apache.nifi.web.api.dto.action.details.MoveDetailsDTO) InstantiatedVersionedControllerService(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedControllerService) DeprecationNotice(org.apache.nifi.annotation.documentation.DeprecationNotice) DropFlowFileState(org.apache.nifi.controller.queue.DropFlowFileState) Authorizer(org.apache.nifi.authorization.Authorizer) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) JVMFlowDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMFlowDiagnosticsSnapshotDTO) LineageResultsDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageResultsDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Port(org.apache.nifi.connectable.Port) ConfigureDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConfigureDetailsDTO) ComponentAuthorizable(org.apache.nifi.authorization.resource.ComponentAuthorizable) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity) LineageNode(org.apache.nifi.provenance.lineage.LineageNode) DifferenceType(org.apache.nifi.registry.flow.diff.DifferenceType) SortedStateUtils(org.apache.nifi.controller.state.SortedStateUtils) Template(org.apache.nifi.controller.Template) InstantiatedVersionedConnection(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedConnection) GarbageCollectionHistory(org.apache.nifi.controller.status.history.GarbageCollectionHistory) User(org.apache.nifi.authorization.User) JVMDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsDTO) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) PortStatusSnapshotEntity(org.apache.nifi.web.api.entity.PortStatusSnapshotEntity) SystemDiagnostics(org.apache.nifi.diagnostics.SystemDiagnostics) List(java.util.List) RepositoryUsageDTO(org.apache.nifi.web.api.dto.diagnostics.RepositoryUsageDTO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) MoveDetails(org.apache.nifi.action.details.MoveDetails) Action(org.apache.nifi.action.Action) InstantiatedVersionedPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) Revision(org.apache.nifi.web.Revision) CapabilityDescription(org.apache.nifi.annotation.documentation.CapabilityDescription) Funnel(org.apache.nifi.connectable.Funnel) FlowFileSummary(org.apache.nifi.controller.queue.FlowFileSummary) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) HashMap(java.util.HashMap) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) Iterator(java.util.Iterator) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) ExtensionDetails(org.apache.nifi.action.component.details.ExtensionDetails) TimeUnit(java.util.concurrent.TimeUnit) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) FormatUtils(org.apache.nifi.util.FormatUtils) ExtensionDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.ExtensionDetailsDTO) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConnectDetailsDTO) LineageRequestType(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO.LineageRequestType) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 2 with VariableEntity

use of org.apache.nifi.web.api.entity.VariableEntity in project nifi by apache.

the class PGSetVar method doExecute.

@Override
public VoidResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException, CommandException {
    final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
    final String varName = getRequiredArg(properties, CommandOption.PG_VAR_NAME);
    final String varVal = getRequiredArg(properties, CommandOption.PG_VAR_VALUE);
    final ProcessGroupClient pgClient = client.getProcessGroupClient();
    final VariableRegistryEntity variableRegistry = pgClient.getVariables(pgId);
    final VariableRegistryDTO variableRegistryDTO = variableRegistry.getVariableRegistry();
    final VariableDTO variableDTO = new VariableDTO();
    variableDTO.setName(varName);
    variableDTO.setValue(varVal);
    final VariableEntity variableEntity = new VariableEntity();
    variableEntity.setVariable(variableDTO);
    // take the existing DTO and set only the requested variable for this command
    variableRegistryDTO.setVariables(Collections.singleton(variableEntity));
    // initiate the update request by posting the updated variable registry
    final VariableRegistryUpdateRequestEntity createdUpdateRequest = pgClient.updateVariableRegistry(pgId, variableRegistry);
    // poll the update request for up to 30 seconds to see if it has completed
    // if it doesn't complete then an exception will be thrown, but in either case the request will be deleted
    final String updateRequestId = createdUpdateRequest.getRequest().getRequestId();
    try {
        boolean completed = false;
        for (int i = 0; i < 30; i++) {
            final VariableRegistryUpdateRequestEntity updateRequest = pgClient.getVariableRegistryUpdateRequest(pgId, updateRequestId);
            if (updateRequest != null && updateRequest.getRequest().isComplete()) {
                completed = true;
                break;
            } else {
                try {
                    if (getContext().isInteractive()) {
                        println("Waiting for update request to complete...");
                    }
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        if (!completed) {
            throw new NiFiClientException("Unable to update variables of process group, cancelling request");
        }
    } finally {
        pgClient.deleteVariableRegistryUpdateRequest(pgId, updateRequestId);
    }
    return VoidResult.getInstance();
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) VariableRegistryUpdateRequestEntity(org.apache.nifi.web.api.entity.VariableRegistryUpdateRequestEntity) VariableRegistryDTO(org.apache.nifi.web.api.dto.VariableRegistryDTO) VariableRegistryEntity(org.apache.nifi.web.api.entity.VariableRegistryEntity) VariableDTO(org.apache.nifi.web.api.dto.VariableDTO) ProcessGroupClient(org.apache.nifi.toolkit.cli.impl.client.nifi.ProcessGroupClient)

Example 3 with VariableEntity

use of org.apache.nifi.web.api.entity.VariableEntity in project nifi by apache.

the class StandardNiFiServiceFacade method createVariableRegistryEntity.

private VariableRegistryEntity createVariableRegistryEntity(final ProcessGroup processGroup, final boolean includeAncestorGroups) {
    final VariableRegistryDTO registryDto = dtoFactory.createVariableRegistryDto(processGroup, revisionManager);
    final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(processGroup.getIdentifier()));
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroup);
    if (includeAncestorGroups) {
        ProcessGroup parent = processGroup.getParent();
        while (parent != null) {
            final PermissionsDTO parentPerms = dtoFactory.createPermissionsDto(parent);
            if (Boolean.TRUE.equals(parentPerms.getCanRead())) {
                final VariableRegistryDTO parentRegistryDto = dtoFactory.createVariableRegistryDto(parent, revisionManager);
                final Set<VariableEntity> parentVariables = parentRegistryDto.getVariables();
                registryDto.getVariables().addAll(parentVariables);
            }
            parent = parent.getParent();
        }
    }
    return entityFactory.createVariableRegistryEntity(registryDto, revision, permissions);
}
Also used : VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) VariableRegistryDTO(org.apache.nifi.web.api.dto.VariableRegistryDTO) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 4 with VariableEntity

use of org.apache.nifi.web.api.entity.VariableEntity in project nifi by apache.

the class VariableRegistryEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(final VariableRegistryEntity clientEntity, final Map<NodeIdentifier, VariableRegistryEntity> entityMap, final Set<NodeResponse> successfulResponses, final Set<NodeResponse> problematicResponses) {
    final VariableRegistryDTO clientVariableRegistry = clientEntity.getVariableRegistry();
    final Set<VariableEntity> clientVariableEntities = clientVariableRegistry.getVariables();
    if (clientVariableEntities != null) {
        for (final Iterator<VariableEntity> i = clientVariableEntities.iterator(); i.hasNext(); ) {
            final VariableEntity clientVariableEntity = i.next();
            final VariableDTO clientVariable = clientVariableEntity.getVariable();
            final Map<NodeIdentifier, Set<AffectedComponentEntity>> nodeAffectedComponentEntities = new HashMap<>();
            boolean retainClientVariable = true;
            for (final Map.Entry<NodeIdentifier, VariableRegistryEntity> nodeEntry : entityMap.entrySet()) {
                final VariableRegistryEntity nodeVariableRegistry = nodeEntry.getValue();
                final Set<VariableEntity> nodeVariableEntities = nodeVariableRegistry.getVariableRegistry().getVariables();
                // if this node has no variables, then the current client variable should be removed
                if (nodeVariableEntities == null) {
                    retainClientVariable = false;
                    break;
                }
                boolean variableFound = false;
                for (final VariableEntity nodeVariableEntity : nodeVariableEntities) {
                    final VariableDTO nodeVariable = nodeVariableEntity.getVariable();
                    // identify the current clientVariable for each node
                    if (clientVariable.getProcessGroupId().equals(nodeVariable.getProcessGroupId()) && clientVariable.getName().equals(nodeVariable.getName())) {
                        variableFound = true;
                        if (Boolean.FALSE.equals(nodeVariableEntity.getCanWrite())) {
                            clientVariableEntity.setCanWrite(false);
                        }
                        nodeAffectedComponentEntities.put(nodeEntry.getKey(), nodeVariableEntity.getVariable().getAffectedComponents());
                        break;
                    }
                }
                if (!variableFound) {
                    retainClientVariable = false;
                    break;
                }
            }
            if (!retainClientVariable) {
                i.remove();
            } else {
                final Set<AffectedComponentEntity> clientAffectedComponentEntities = clientVariableEntity.getVariable().getAffectedComponents();
                affectedComponentEntityMerger.mergeAffectedComponents(clientAffectedComponentEntities, nodeAffectedComponentEntities);
            }
        }
    }
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) VariableRegistryDTO(org.apache.nifi.web.api.dto.VariableRegistryDTO) VariableRegistryEntity(org.apache.nifi.web.api.entity.VariableRegistryEntity) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) VariableDTO(org.apache.nifi.web.api.dto.VariableDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) HashMap(java.util.HashMap) Map(java.util.Map) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 5 with VariableEntity

use of org.apache.nifi.web.api.entity.VariableEntity in project nifi by apache.

the class DtoFactory method populateAffectedComponents.

public VariableRegistryDTO populateAffectedComponents(final VariableRegistryDTO variableRegistry, final ProcessGroup group, final RevisionManager revisionManager) {
    if (!group.getIdentifier().equals(variableRegistry.getProcessGroupId())) {
        throw new IllegalArgumentException("Variable Registry does not have the same Group ID as the given Process Group");
    }
    final Set<VariableEntity> variableEntities = new LinkedHashSet<>();
    if (variableRegistry.getVariables() != null) {
        for (final VariableEntity inputEntity : variableRegistry.getVariables()) {
            final VariableEntity entity = new VariableEntity();
            final VariableDTO inputDto = inputEntity.getVariable();
            final VariableDTO variableDto = new VariableDTO();
            variableDto.setName(inputDto.getName());
            variableDto.setValue(inputDto.getValue());
            variableDto.setProcessGroupId(group.getIdentifier());
            final Set<AffectedComponentEntity> affectedComponentEntities = createAffectedComponentEntities(group.getComponentsAffectedByVariable(variableDto.getName()), revisionManager);
            boolean canWrite = true;
            for (final AffectedComponentEntity affectedComponent : affectedComponentEntities) {
                final PermissionsDTO permissions = affectedComponent.getPermissions();
                if (!permissions.getCanRead() || !permissions.getCanWrite()) {
                    canWrite = false;
                    break;
                }
            }
            variableDto.setAffectedComponents(affectedComponentEntities);
            entity.setCanWrite(canWrite);
            entity.setVariable(inputDto);
            variableEntities.add(entity);
        }
    }
    final VariableRegistryDTO registryDto = new VariableRegistryDTO();
    registryDto.setProcessGroupId(group.getIdentifier());
    registryDto.setVariables(variableEntities);
    return registryDto;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Aggregations

VariableEntity (org.apache.nifi.web.api.entity.VariableEntity)5 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 VariableRegistryDTO (org.apache.nifi.web.api.dto.VariableRegistryDTO)2 AffectedComponentEntity (org.apache.nifi.web.api.entity.AffectedComponentEntity)2 Collator (java.text.Collator)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1