use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.
the class QuickImport method createQuickImportFlow.
private String createQuickImportFlow(final NiFiRegistryClient registryClient, final String quickImportBucketId, final boolean isInteractive) throws ParseException, IOException, NiFiRegistryException {
final String flowName = FLOW_NAME + System.currentTimeMillis();
final String flowDescription = FLOW_DESC + (new Date()).toString();
final Properties createFlowProps = new Properties();
createFlowProps.setProperty(CommandOption.FLOW_NAME.getLongName(), flowName);
createFlowProps.setProperty(CommandOption.FLOW_DESC.getLongName(), flowDescription);
createFlowProps.setProperty(CommandOption.BUCKET_ID.getLongName(), quickImportBucketId);
final StringResult createdFlow = createFlow.doExecute(registryClient, createFlowProps);
final String quickImportFlowId = createdFlow.getResult();
if (isInteractive) {
println();
println("Created new flow '" + flowName + "'...");
}
return quickImportFlowId;
}
use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.
the class QuickImport method getQuickImportBucketId.
private String getQuickImportBucketId(final NiFiRegistryClient registryClient, final boolean isInteractive) throws IOException, NiFiRegistryException, MissingOptionException {
final BucketsResult bucketsResult = listBuckets.doExecute(registryClient, new Properties());
final Bucket quickImportBucket = bucketsResult.getResult().stream().filter(b -> BUCKET_NAME.equals(b.getName())).findFirst().orElse(null);
// if it doesn't exist, then create the quick import bucket
String quickImportBucketId = null;
if (quickImportBucket != null) {
quickImportBucketId = quickImportBucket.getIdentifier();
if (isInteractive) {
println();
println("Found existing bucket '" + BUCKET_NAME + "'...");
}
} else {
final Properties createBucketProps = new Properties();
createBucketProps.setProperty(CommandOption.BUCKET_NAME.getLongName(), BUCKET_NAME);
createBucketProps.setProperty(CommandOption.BUCKET_DESC.getLongName(), BUCKET_DESC);
final StringResult createdBucketId = createBucket.doExecute(registryClient, createBucketProps);
quickImportBucketId = createdBucketId.getResult();
if (isInteractive) {
println();
println("Created new bucket '" + BUCKET_NAME + "'...");
}
}
return quickImportBucketId;
}
use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.
the class QuickImport method doExecute.
@Override
public StringResult doExecute(final CommandLine cli, final NiFiClient nifiClient, final Properties nifiProps, final NiFiRegistryClient registryClient, final Properties registryProps) throws IOException, NiFiRegistryException, ParseException, NiFiClientException {
final boolean isInteractive = getContext().isInteractive();
// determine the registry client in NiFi to use, or create one
// do this first so that we don't get through creating buckets, flows, etc, and then fail on the reg client
final String registryClientBaseUrl = registryProps.getProperty(CommandOption.URL.getLongName());
final String registryClientId = getRegistryClientId(nifiClient, registryClientBaseUrl, isInteractive);
// get or create the quick import bucket
final String quickImportBucketId = getQuickImportBucketId(registryClient, isInteractive);
// create a new flow in the quick-import bucket
final String quickImportFlowId = createQuickImportFlow(registryClient, quickImportBucketId, isInteractive);
// import the versioned flow snapshot into newly created quick-import flow
final String inputSource = cli.getOptionValue(CommandOption.INPUT_SOURCE.getLongName());
if (StringUtils.isBlank(inputSource)) {
throw new MissingOptionException("Missing required option --" + CommandOption.INPUT_SOURCE.getLongName());
}
final String quickImportFlowVersion = importFlowVersion(registryClient, quickImportFlowId, isInteractive, inputSource);
// pg-import to nifi
final Properties pgImportProps = new Properties();
pgImportProps.setProperty(CommandOption.REGISTRY_CLIENT_ID.getLongName(), registryClientId);
pgImportProps.setProperty(CommandOption.BUCKET_ID.getLongName(), quickImportBucketId);
pgImportProps.setProperty(CommandOption.FLOW_ID.getLongName(), quickImportFlowId);
pgImportProps.setProperty(CommandOption.FLOW_VERSION.getLongName(), quickImportFlowVersion);
final StringResult createdPgResult = pgImport.doExecute(nifiClient, pgImportProps);
if (isInteractive) {
println();
println("Imported process group to NiFi...");
println();
}
return createdPgResult;
}
use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.
the class QuickImport method importFlowVersion.
private String importFlowVersion(final NiFiRegistryClient registryClient, final String quickImportFlowId, final boolean isInteractive, final String inputSource) throws ParseException, IOException, NiFiRegistryException {
final Properties importVersionProps = new Properties();
importVersionProps.setProperty(CommandOption.FLOW_ID.getLongName(), quickImportFlowId);
importVersionProps.setProperty(CommandOption.INPUT_SOURCE.getLongName(), inputSource);
final StringResult createdVersion = importFlowVersion.doExecute(registryClient, importVersionProps);
final String quickImportFlowVersion = createdVersion.getResult();
if (isInteractive) {
println();
println("Imported flow version...");
}
return quickImportFlowVersion;
}
use of org.apache.nifi.toolkit.cli.impl.result.StringResult in project nifi by apache.
the class QuickImport method getRegistryClientId.
private String getRegistryClientId(final NiFiClient nifiClient, final String registryClientBaseUrl, final boolean isInteractive) throws NiFiClientException, IOException, MissingOptionException {
final Properties getRegClientProps = new Properties();
getRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_URL.getLongName(), registryClientBaseUrl);
String registryClientId;
try {
final RegistryClientIDResult registryClientResult = getRegistryClientId.doExecute(nifiClient, getRegClientProps);
registryClientId = registryClientResult.getResult().getId();
if (isInteractive) {
println();
println("Found existing registry client '" + registryClientResult.getResult().getName() + "'...");
}
} catch (Exception e) {
registryClientId = null;
}
if (registryClientId == null) {
final Properties createRegClientProps = new Properties();
createRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_NAME.getLongName(), REG_CLIENT_NAME);
createRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_DESC.getLongName(), REG_CLIENT_DESC + new Date().toString());
createRegClientProps.setProperty(CommandOption.REGISTRY_CLIENT_URL.getLongName(), registryClientBaseUrl);
final StringResult createdRegClient = createRegistryClient.doExecute(nifiClient, createRegClientProps);
registryClientId = createdRegClient.getResult();
if (isInteractive) {
println();
println("Created new registry client '" + REG_CLIENT_NAME + "'...");
}
}
return registryClientId;
}
Aggregations