Search in sources :

Example 1 with StringResult

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;
}
Also used : StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Properties(java.util.Properties) Date(java.util.Date)

Example 2 with StringResult

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;
}
Also used : BucketsResult(org.apache.nifi.toolkit.cli.impl.result.BucketsResult) Bucket(org.apache.nifi.registry.bucket.Bucket) CreateBucket(org.apache.nifi.toolkit.cli.impl.command.registry.bucket.CreateBucket) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Properties(java.util.Properties)

Example 3 with StringResult

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;
}
Also used : StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Properties(java.util.Properties) MissingOptionException(org.apache.commons.cli.MissingOptionException)

Example 4 with StringResult

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;
}
Also used : StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Properties(java.util.Properties)

Example 5 with StringResult

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;
}
Also used : RegistryClientIDResult(org.apache.nifi.toolkit.cli.impl.result.RegistryClientIDResult) StringResult(org.apache.nifi.toolkit.cli.impl.result.StringResult) Properties(java.util.Properties) NiFiClientException(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) ParseException(org.apache.commons.cli.ParseException) Date(java.util.Date)

Aggregations

StringResult (org.apache.nifi.toolkit.cli.impl.result.StringResult)11 Properties (java.util.Properties)5 MissingOptionException (org.apache.commons.cli.MissingOptionException)3 IOException (java.io.IOException)2 Date (java.util.Date)2 Bucket (org.apache.nifi.registry.bucket.Bucket)2 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)2 NiFiClientException (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClientException)2 RegistryClientEntity (org.apache.nifi.web.api.entity.RegistryClientEntity)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 ParseException (org.apache.commons.cli.ParseException)1 BucketClient (org.apache.nifi.registry.client.BucketClient)1 FlowClient (org.apache.nifi.registry.client.FlowClient)1 FlowSnapshotClient (org.apache.nifi.registry.client.FlowSnapshotClient)1 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)1 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)1 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)1