use of org.apache.nifi.toolkit.cli.impl.client.nifi.VersionsClient 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();
}
use of org.apache.nifi.toolkit.cli.impl.client.nifi.VersionsClient in project nifi by apache.
the class PGGetAllVersions method doExecute.
@Override
public VersionedFlowSnapshotMetadataSetResult doExecute(final NiFiClient client, final Properties properties) throws NiFiClientException, IOException, MissingOptionException {
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");
}
final String registryId = existingVersionControlDTO.getRegistryId();
final String bucketId = existingVersionControlDTO.getBucketId();
final String flowId = existingVersionControlDTO.getFlowId();
final FlowClient flowClient = client.getFlowClient();
final VersionedFlowSnapshotMetadataSetEntity versions = flowClient.getVersions(registryId, bucketId, flowId);
if (versions.getVersionedFlowSnapshotMetadataSet() == null || versions.getVersionedFlowSnapshotMetadataSet().isEmpty()) {
throw new NiFiClientException("No versions available");
}
return new VersionedFlowSnapshotMetadataSetResult(getResultType(properties), versions);
}
Aggregations