use of org.apache.nifi.registry.client.NiFiRegistryClient in project nifi by apache.
the class AbstractNiFiRegistryCommand method getSourceClient.
/*
* If srcProps was specified then load the properties and create a new client for the source,
* but if it wasn't then assume the source is the same registry we already know about
*/
protected NiFiRegistryClient getSourceClient(final NiFiRegistryClient client, final String srcPropsValue) throws IOException, org.apache.commons.cli.MissingOptionException {
final NiFiRegistryClient srcClient;
if (!StringUtils.isBlank(srcPropsValue)) {
final Properties srcProps = new Properties();
try (final InputStream in = new FileInputStream(srcPropsValue)) {
srcProps.load(in);
}
final ClientFactory<NiFiRegistryClient> clientFactory = getContext().getNiFiRegistryClientFactory();
srcClient = clientFactory.createClient(srcProps);
} else {
srcClient = client;
}
return srcClient;
}
use of org.apache.nifi.registry.client.NiFiRegistryClient 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());
}
use of org.apache.nifi.registry.client.NiFiRegistryClient in project nifi by apache.
the class TestCLICompleter method setupCompleter.
@BeforeClass
public static void setupCompleter() {
final Session session = new InMemorySession();
final ClientFactory<NiFiClient> niFiClientFactory = new NiFiClientFactory();
final ClientFactory<NiFiRegistryClient> nifiRegClientFactory = new NiFiRegistryClientFactory();
final Context context = new StandardContext.Builder().output(System.out).session(session).nifiClientFactory(niFiClientFactory).nifiRegistryClientFactory(nifiRegClientFactory).build();
final Map<String, Command> commands = CommandFactory.createTopLevelCommands(context);
final Map<String, CommandGroup> commandGroups = CommandFactory.createCommandGroups(context);
completer = new CLICompleter(commands.values(), commandGroups.values());
lineReader = Mockito.mock(LineReader.class);
}
use of org.apache.nifi.registry.client.NiFiRegistryClient in project nifi-registry by apache.
the class SecureNiFiRegistryClientIT method setup.
@Before
public void setup() {
final String baseUrl = createBaseURL();
LOGGER.info("Using base url = " + baseUrl);
final NiFiRegistryClientConfig clientConfig = createClientConfig(baseUrl);
Assert.assertNotNull(clientConfig);
final NiFiRegistryClient client = new JerseyNiFiRegistryClient.Builder().config(clientConfig).build();
Assert.assertNotNull(client);
this.client = client;
}
Aggregations