Search in sources :

Example 16 with VersionControlInformationDTO

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

the class ProcessGroupEntityMerger method mergeVersionControlInformation.

private void mergeVersionControlInformation(ProcessGroupEntity targetGroup, ProcessGroupEntity toMerge) {
    final ProcessGroupDTO targetGroupDto = targetGroup.getComponent();
    final ProcessGroupDTO toMergeGroupDto = toMerge.getComponent();
    if (targetGroupDto == null || toMergeGroupDto == null) {
        return;
    }
    final VersionControlInformationDTO targetVersionControl = targetGroupDto.getVersionControlInformation();
    final VersionControlInformationDTO toMergeVersionControl = toMergeGroupDto.getVersionControlInformation();
    if (targetVersionControl == null) {
        targetGroupDto.setVersionControlInformation(toMergeGroupDto.getVersionControlInformation());
    } else if (toMergeVersionControl != null) {
        VersionControlInformationEntityMerger.updateFlowState(targetVersionControl, toMergeVersionControl);
    }
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO)

Example 17 with VersionControlInformationDTO

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

the class VersionControlInformationEntityMerger method merge.

public void merge(final VersionControlInformationEntity clientEntity, final Map<NodeIdentifier, VersionControlInformationEntity> entityMap) {
    final VersionControlInformationDTO clientDto = clientEntity.getVersionControlInformation();
    // We need to merge the 'current' and 'modified' flags because these are updated by nodes in the background. Since
    // the nodes can synchronize with the Flow Registry at different intervals, we have to determine how to handle these
    // flags if different nodes report different values for them.
    entityMap.values().stream().filter(entity -> entity != clientEntity).forEach(entity -> {
        final VersionControlInformationDTO dto = entity.getVersionControlInformation();
        updateFlowState(clientDto, dto);
    });
}
Also used : VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) Map(java.util.Map) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO)

Example 18 with VersionControlInformationDTO

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

the class SnippetUtils method verifyNoVersionControlConflicts.

public static void verifyNoVersionControlConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup destination) {
    final List<VersionControlInformationDTO> vcis = new ArrayList<>();
    for (final ProcessGroupDTO childGroup : snippetContents.getProcessGroups()) {
        findAllVersionControlInfo(childGroup, vcis);
    }
    verifyNoDuplicateVersionControlInfoDtos(destination, vcis);
}
Also used : ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO)

Example 19 with VersionControlInformationDTO

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

the class FlowFromDOMFactory method getVersionControlInformation.

private static VersionControlInformationDTO getVersionControlInformation(final Element versionControlInfoElement) {
    if (versionControlInfoElement == null) {
        return null;
    }
    final VersionControlInformationDTO dto = new VersionControlInformationDTO();
    dto.setRegistryId(getString(versionControlInfoElement, "registryId"));
    dto.setBucketId(getString(versionControlInfoElement, "bucketId"));
    dto.setBucketName(getString(versionControlInfoElement, "bucketName"));
    dto.setFlowId(getString(versionControlInfoElement, "flowId"));
    dto.setFlowName(getString(versionControlInfoElement, "flowName"));
    dto.setFlowDescription(getString(versionControlInfoElement, "flowDescription"));
    dto.setVersion(getInt(versionControlInfoElement, "version"));
    return dto;
}
Also used : VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO)

Example 20 with VersionControlInformationDTO

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

the class PGChangeVersion 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 VersionsClient versionsClient = client.getVersionsClient();
    final VersionControlInformationEntity existingVersionControlInfo = versionsClient.getVersionControlInfo(pgId);
    final VersionControlInformationDTO existingVersionControlDTO = existingVersionControlInfo.getVersionControlInformation();
    if (existingVersionControlDTO == null) {
        throw new NiFiClientException("Process group is not under version control");
    }
    // start with the version specified in the arguments
    Integer newVersion = getIntArg(properties, CommandOption.FLOW_VERSION);
    // if no version was specified, automatically determine the latest and change to that
    if (newVersion == null) {
        newVersion = getLatestVersion(client, existingVersionControlDTO);
        if (newVersion.intValue() == existingVersionControlDTO.getVersion().intValue()) {
            throw new NiFiClientException("Process group already at latest version");
        }
    }
    // update the version in the existing DTO to the new version so we can submit it back
    existingVersionControlDTO.setVersion(newVersion);
    // initiate the version change which creates an update request that must be checked for completion
    final VersionedFlowUpdateRequestEntity initialUpdateRequest = versionsClient.updateVersionControlInfo(pgId, existingVersionControlInfo);
    // 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 = initialUpdateRequest.getRequest().getRequestId();
    try {
        boolean completed = false;
        for (int i = 0; i < 30; i++) {
            final VersionedFlowUpdateRequestEntity updateRequest = versionsClient.getUpdateRequest(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 change version of process group, cancelling request");
        }
    } finally {
        versionsClient.deleteUpdateRequest(updateRequestId);
    }
    return VoidResult.getInstance();
}
Also used : NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) VersionControlInformationEntity(org.apache.nifi.web.api.entity.VersionControlInformationEntity) VersionsClient(org.apache.nifi.toolkit.cli.impl.client.nifi.VersionsClient) VersionedFlowUpdateRequestEntity(org.apache.nifi.web.api.entity.VersionedFlowUpdateRequestEntity) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO)

Aggregations

VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)25 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)9 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)9 ProcessGroup (org.apache.nifi.groups.ProcessGroup)7 Bucket (org.apache.nifi.registry.bucket.Bucket)7 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)7 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)7 VersionedFlowState (org.apache.nifi.registry.flow.VersionedFlowState)7 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)7 VersionControlInformationEntity (org.apache.nifi.web.api.entity.VersionControlInformationEntity)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Consumes (javax.ws.rs.Consumes)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 AccessDeniedException (org.apache.nifi.authorization.AccessDeniedException)6 Authorizable (org.apache.nifi.authorization.resource.Authorizable)6 HashSet (java.util.HashSet)5