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);
}
}
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);
});
}
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);
}
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;
}
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();
}
Aggregations