[ 
https://issues.apache.org/jira/browse/NIFI-6767?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17009209#comment-17009209
 ] 

Kristjan Antunovic edited comment on NIFI-6767 at 1/7/20 12:06 AM:
-------------------------------------------------------------------

[~bbende] This is the problematic piece of code:
{code:java}
final String registryBaseUrl = uri.getScheme() + "://" + uri.getHost() + ":" + 
uri.getPort();
{code}
I would rewrite the method as so *confirmed working*:
{code:java}
    import org.apache.http.client.utils.URIBuilder;

    @Override
    public FlowRegistry addFlowRegistry(final String registryId, final String 
registryName, final String registryUrl, final String description) {
        final URI uri;
        try {
            // This should remove any trailing paths: /nifi-registry, /../..
            // as well as any query parameters ?a=b and any combo of the two.
            uri = new URIBuilder(registryUrl)
              .setPath("")
              .removeQuery()
              .build();

            //uri = new URI(registryUrl);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("The given Registry URL is not 
valid: " + registryUrl);
        }

        final String uriScheme = uri.getScheme();
        if (uriScheme == null) {
            throw new IllegalArgumentException("The given Registry URL is not 
valid: " + registryUrl);
        }

        // Handles case where the URI entered has a trailing slash, or includes 
the trailing /nifi-registry-api
        // final String registryBaseUrl = uri.getScheme() + "://" + 
uri.getHost() + ":" + uri.getPort();
        
        // This will be the base URI with no paths or params. But will include 
the port if set initially.
        final String registryBaseUrl = uri.toString();  

        final FlowRegistry registry;
        if (uriScheme.equalsIgnoreCase("http") || 
uriScheme.equalsIgnoreCase("https")) {
            final SSLContext sslContext = 
SslContextFactory.createSslContext(nifiProperties);
            if (sslContext == null && uriScheme.equalsIgnoreCase("https")) {
                throw new IllegalStateException("Failed to create Flow Registry 
for URI " + registryUrl
                    + " because this NiFi is not configured with a 
Keystore/Truststore, so it is not capable of communicating with a secure 
Registry. "
                    + "Please populate NiFi's Keystore/Truststore properties or 
connect to a NiFi Registry over http instead of https.");
            }

            registry = new RestBasedFlowRegistry(this, registryId, 
registryBaseUrl, sslContext, registryName);
            registry.setDescription(description);
        } else {
            throw new IllegalArgumentException("Cannot create Flow Registry 
with URI of " + registryUrl
                + " because there are no known implementations of Flow 
Registries that can handle URIs of scheme " + uriScheme);
        }

        addFlowRegistry(registry);
        return registry;
    }
{code}


was (Author: superkool):
[~bbende] This is the problematic piece of code:
{code:java}
final String registryBaseUrl = uri.getScheme() + "://" + uri.getHost() + ":" + 
uri.getPort();
{code}
I would rewrite the method as so:
{code:java}
    import org.apache.http.client.utils.URIBuilder;

    @Override
    public FlowRegistry addFlowRegistry(final String registryId, final String 
registryName, final String registryUrl, final String description) {
        final URI uri;
        try {
            // This should remove any trailing paths: /nifi-registry, /../..
            // as well as any query parameters ?a=b and any combo of the two.
            uri = new URIBuilder(registryUrl)
              .setPath("")
              .removeQuery()
              .build();

            //uri = new URI(registryUrl);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("The given Registry URL is not 
valid: " + registryUrl);
        }

        final String uriScheme = uri.getScheme();
        if (uriScheme == null) {
            throw new IllegalArgumentException("The given Registry URL is not 
valid: " + registryUrl);
        }

        // Handles case where the URI entered has a trailing slash, or includes 
the trailing /nifi-registry-api
        // final String registryBaseUrl = uri.getScheme() + "://" + 
uri.getHost() + ":" + uri.getPort();
        
        // This will be the base URI with no paths or params. But will include 
the port if set initially.
        final String registryBaseUrl = uri.toString();  

        final FlowRegistry registry;
        if (uriScheme.equalsIgnoreCase("http") || 
uriScheme.equalsIgnoreCase("https")) {
            final SSLContext sslContext = 
SslContextFactory.createSslContext(nifiProperties);
            if (sslContext == null && uriScheme.equalsIgnoreCase("https")) {
                throw new IllegalStateException("Failed to create Flow Registry 
for URI " + registryUrl
                    + " because this NiFi is not configured with a 
Keystore/Truststore, so it is not capable of communicating with a secure 
Registry. "
                    + "Please populate NiFi's Keystore/Truststore properties or 
connect to a NiFi Registry over http instead of https.");
            }

            registry = new RestBasedFlowRegistry(this, registryId, 
registryBaseUrl, sslContext, registryName);
            registry.setDescription(description);
        } else {
            throw new IllegalArgumentException("Cannot create Flow Registry 
with URI of " + registryUrl
                + " because there are no known implementations of Flow 
Registries that can handle URIs of scheme " + uriScheme);
        }

        addFlowRegistry(registry);
        return registry;
    }
{code}

> NiFi Registry Config does not persist after a cluster restart
> -------------------------------------------------------------
>
>                 Key: NIFI-6767
>                 URL: https://issues.apache.org/jira/browse/NIFI-6767
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Flow Versioning
>    Affects Versions: 1.10.0, 1.9.2
>            Reporter: John E Fortin
>            Priority: Major
>         Attachments: registry-bad.png
>
>
> After configuring the NiFi Registery and versioning flows the Registry works 
> fine.  However, after restarting the NiFI cluster the Registry Config now has 
> "https://null:-1"; as the value for the Registry URL.  
> If I reconfigure the URL it works fine until the next Cluster restart.
> This has been happening since 1.9.1 (that I know of) and continues into 1.10
> It's not a show stopper, but is quite annoying



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to