use of org.apache.nifi.toolkit.cli.impl.result.OkResult in project nifi by apache.
the class SyncFlowVersions method doExecute.
@Override
public StringResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, ParseException {
final String srcPropsValue = getArg(properties, CommandOption.SRC_PROPS);
final String srcFlowId = getRequiredArg(properties, CommandOption.SRC_FLOW_ID);
final String destFlowId = getRequiredArg(properties, CommandOption.FLOW_ID);
final NiFiRegistryClient srcClient = getSourceClient(client, srcPropsValue);
final String srcBucketId = getBucketId(srcClient, srcFlowId);
final String destBucketId = getBucketId(client, destFlowId);
final List<Integer> srcVersions = getVersions(srcClient, srcBucketId, srcFlowId);
final List<Integer> destVersions = getVersions(client, destBucketId, destFlowId);
if (destVersions.size() > srcVersions.size()) {
throw new NiFiRegistryException("Destination flow has more versions than source flow");
}
srcVersions.removeAll(destVersions);
if (srcVersions.isEmpty()) {
if (getContext().isInteractive()) {
println();
println("Source and destination already in sync");
}
return new OkResult(getContext().isInteractive());
}
// the REST API returns versions in decreasing order, but we want them in increasing order
Collections.sort(srcVersions);
for (final Integer srcVersion : srcVersions) {
final VersionedFlowSnapshot srcFlowSnapshot = srcClient.getFlowSnapshotClient().get(srcBucketId, srcFlowId, srcVersion);
srcFlowSnapshot.setFlow(null);
srcFlowSnapshot.setBucket(null);
final VersionedFlowSnapshotMetadata destMetadata = new VersionedFlowSnapshotMetadata();
destMetadata.setBucketIdentifier(destBucketId);
destMetadata.setFlowIdentifier(destFlowId);
destMetadata.setVersion(srcVersion);
destMetadata.setComments(srcFlowSnapshot.getSnapshotMetadata().getComments());
srcFlowSnapshot.setSnapshotMetadata(destMetadata);
client.getFlowSnapshotClient().create(srcFlowSnapshot);
if (getContext().isInteractive()) {
println();
println("Synced version " + srcVersion);
}
}
return new OkResult(getContext().isInteractive());
}
use of org.apache.nifi.toolkit.cli.impl.result.OkResult in project nifi by apache.
the class DeleteBucket method doExecute.
@Override
public OkResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, ParseException {
final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
final boolean forceDelete = properties.containsKey(CommandOption.FORCE.getLongName());
final FlowClient flowClient = client.getFlowClient();
final List<VersionedFlow> flowsInBucket = flowClient.getByBucket(bucketId);
if (flowsInBucket != null && flowsInBucket.size() > 0 && !forceDelete) {
throw new NiFiRegistryException("Bucket is not empty, use --" + CommandOption.FORCE.getLongName() + " to delete");
} else {
final BucketClient bucketClient = client.getBucketClient();
bucketClient.delete(bucketId);
return new OkResult(getContext().isInteractive());
}
}
use of org.apache.nifi.toolkit.cli.impl.result.OkResult in project nifi by apache.
the class DeleteFlow method doExecute.
@Override
public OkResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, ParseException {
final String flowId = getRequiredArg(properties, CommandOption.FLOW_ID);
final boolean forceDelete = properties.containsKey(CommandOption.FORCE.getLongName());
final String bucketId = getBucketId(client, flowId);
final FlowSnapshotClient flowSnapshotClient = client.getFlowSnapshotClient();
final List<VersionedFlowSnapshotMetadata> snapshotMetadata = flowSnapshotClient.getSnapshotMetadata(bucketId, flowId);
if (snapshotMetadata != null && snapshotMetadata.size() > 0 && !forceDelete) {
throw new NiFiRegistryException("Flow has versions, use --" + CommandOption.FORCE.getLongName() + " to delete");
} else {
final FlowClient flowClient = client.getFlowClient();
flowClient.delete(bucketId, flowId);
return new OkResult(getContext().isInteractive());
}
}
use of org.apache.nifi.toolkit.cli.impl.result.OkResult in project nifi by apache.
the class TransferFlowVersion method doExecute.
@Override
public StringResult doExecute(final NiFiRegistryClient client, final Properties properties) throws IOException, NiFiRegistryException, ParseException {
final String srcPropsValue = getArg(properties, CommandOption.SRC_PROPS);
final String srcFlowId = getRequiredArg(properties, CommandOption.SRC_FLOW_ID);
final Integer srcFlowVersion = getIntArg(properties, CommandOption.SRC_FLOW_VERSION);
final String destFlowId = getRequiredArg(properties, CommandOption.FLOW_ID);
final NiFiRegistryClient srcClient = getSourceClient(client, srcPropsValue);
// determine the bucket ids of the source and dest flows
final String srcBucketId = getBucketId(srcClient, srcFlowId);
final String destBucketId = getBucketId(client, destFlowId);
// get the snapshot of the source flow, either the version specified or the latest
final VersionedFlowSnapshot srcSnapshot;
if (srcFlowVersion == null) {
srcSnapshot = srcClient.getFlowSnapshotClient().getLatest(srcBucketId, srcFlowId);
} else {
srcSnapshot = srcClient.getFlowSnapshotClient().get(srcBucketId, srcFlowId, srcFlowVersion);
}
// determine the next version number for the destination flow
final List<Integer> destVersions = getVersions(client, destBucketId, destFlowId);
final Integer destFlowVersion = destVersions.isEmpty() ? 1 : destVersions.get(0) + 1;
// create the new metadata for the destination snapshot
final VersionedFlowSnapshotMetadata destMetadata = new VersionedFlowSnapshotMetadata();
destMetadata.setBucketIdentifier(destBucketId);
destMetadata.setFlowIdentifier(destFlowId);
destMetadata.setVersion(destFlowVersion);
destMetadata.setComments(srcSnapshot.getSnapshotMetadata().getComments());
// update the source snapshot with the destination metadata
srcSnapshot.setFlow(null);
srcSnapshot.setBucket(null);
srcSnapshot.setSnapshotMetadata(destMetadata);
// create the destination snapshot
client.getFlowSnapshotClient().create(srcSnapshot);
if (getContext().isInteractive()) {
println();
println("Transferred version " + srcSnapshot.getSnapshotMetadata().getVersion() + " of source flow to version " + destFlowVersion + " of destination flow");
}
return new OkResult(getContext().isInteractive());
}
Aggregations