Search in sources :

Example 11 with NiFiRegistryClient

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;
}
Also used : NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 12 with NiFiRegistryClient

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());
}
Also used : OkResult(org.apache.nifi.toolkit.cli.impl.result.OkResult) NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)

Example 13 with NiFiRegistryClient

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);
}
Also used : StandardContext(org.apache.nifi.toolkit.cli.impl.context.StandardContext) Context(org.apache.nifi.toolkit.cli.api.Context) NiFiClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiClientFactory) NiFiClient(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient) NiFiRegistryClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory) NiFiRegistryCommandGroup(org.apache.nifi.toolkit.cli.impl.command.registry.NiFiRegistryCommandGroup) CommandGroup(org.apache.nifi.toolkit.cli.api.CommandGroup) NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) Command(org.apache.nifi.toolkit.cli.api.Command) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession) StandardContext(org.apache.nifi.toolkit.cli.impl.context.StandardContext) LineReader(org.jline.reader.LineReader) Session(org.apache.nifi.toolkit.cli.api.Session) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession) BeforeClass(org.junit.BeforeClass)

Example 14 with NiFiRegistryClient

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;
}
Also used : NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) JerseyNiFiRegistryClient(org.apache.nifi.registry.client.impl.JerseyNiFiRegistryClient) NiFiRegistryClientConfig(org.apache.nifi.registry.client.NiFiRegistryClientConfig) Before(org.junit.Before)

Aggregations

NiFiRegistryClient (org.apache.nifi.registry.client.NiFiRegistryClient)14 JerseyNiFiRegistryClient (org.apache.nifi.registry.client.impl.JerseyNiFiRegistryClient)6 NiFiClient (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient)4 IOException (java.io.IOException)3 Properties (java.util.Properties)3 NiFiRegistryClientConfig (org.apache.nifi.registry.client.NiFiRegistryClientConfig)3 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)3 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)3 Session (org.apache.nifi.toolkit.cli.api.Session)3 NiFiClientFactory (org.apache.nifi.toolkit.cli.impl.client.NiFiClientFactory)3 NiFiRegistryClientFactory (org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory)3 InMemorySession (org.apache.nifi.toolkit.cli.impl.session.InMemorySession)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ParseException (org.apache.commons.cli.ParseException)2 FlowSnapshotClient (org.apache.nifi.registry.client.FlowSnapshotClient)2 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)2 Command (org.apache.nifi.toolkit.cli.api.Command)2 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)2 CommandGroup (org.apache.nifi.toolkit.cli.api.CommandGroup)2