Search in sources :

Example 1 with VariableRegistryDTO

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

the class StandardNiFiServiceFacade method updateVariableRegistry.

@Override
public VariableRegistryEntity updateVariableRegistry(NiFiUser user, Revision revision, VariableRegistryDTO variableRegistryDto) {
    final ProcessGroup processGroupNode = processGroupDAO.getProcessGroup(variableRegistryDto.getProcessGroupId());
    final RevisionUpdate<VariableRegistryDTO> snapshot = updateComponent(user, revision, processGroupNode, () -> processGroupDAO.updateVariableRegistry(user, variableRegistryDto), processGroup -> dtoFactory.createVariableRegistryDto(processGroup, revisionManager));
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroupNode);
    final RevisionDTO updatedRevision = dtoFactory.createRevisionDTO(snapshot.getLastModification());
    return entityFactory.createVariableRegistryEntity(snapshot.getComponent(), updatedRevision, permissions);
}
Also used : 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 2 with VariableRegistryDTO

use of org.apache.nifi.web.api.dto.VariableRegistryDTO 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 VariableRegistryDTO

use of org.apache.nifi.web.api.dto.VariableRegistryDTO 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 VariableRegistryDTO

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

the class StandardNiFiServiceFacade method populateAffectedComponents.

@Override
public VariableRegistryEntity populateAffectedComponents(final VariableRegistryDTO variableRegistryDto) {
    final String groupId = variableRegistryDto.getProcessGroupId();
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    if (processGroup == null) {
        throw new ResourceNotFoundException("Could not find group with ID " + groupId);
    }
    final VariableRegistryDTO registryDto = dtoFactory.populateAffectedComponents(variableRegistryDto, processGroup, revisionManager);
    final RevisionDTO revision = dtoFactory.createRevisionDTO(revisionManager.getRevision(processGroup.getIdentifier()));
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processGroup);
    return entityFactory.createVariableRegistryEntity(registryDto, revision, permissions);
}
Also used : 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 5 with VariableRegistryDTO

use of org.apache.nifi.web.api.dto.VariableRegistryDTO 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)

Aggregations

VariableRegistryDTO (org.apache.nifi.web.api.dto.VariableRegistryDTO)8 VariableRegistryEntity (org.apache.nifi.web.api.entity.VariableRegistryEntity)5 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 ProcessGroup (org.apache.nifi.groups.ProcessGroup)3 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)3 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)3 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)3 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)3 VariableDTO (org.apache.nifi.web.api.dto.VariableDTO)3 VariableEntity (org.apache.nifi.web.api.entity.VariableEntity)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2