You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2022/01/20 17:57:28 UTC

[nifi] 02/02: NIFI-9593 - This closes #5679. Missing catch clauses in Confluent Schema Registry client

This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git

commit 695c3aabcb920668b5bc89134b1614e8dbc99c76
Author: Pierre Villard <pi...@gmail.com>
AuthorDate: Wed Jan 19 17:17:40 2022 +0100

    NIFI-9593 - This closes #5679. Missing catch clauses in Confluent Schema Registry client
    
    Signed-off-by: Joe Witt <jo...@apache.org>
---
 .../client/RestSchemaRegistryClient.java           | 60 ++++++++++++----------
 1 file changed, 34 insertions(+), 26 deletions(-)

diff --git a/nifi-nar-bundles/nifi-confluent-platform-bundle/nifi-confluent-schema-registry-service/src/main/java/org/apache/nifi/confluent/schemaregistry/client/RestSchemaRegistryClient.java b/nifi-nar-bundles/nifi-confluent-platform-bundle/nifi-confluent-schema-registry-service/src/main/java/org/apache/nifi/confluent/schemaregistry/client/RestSchemaRegistryClient.java
index 3bc663c..bc09ab0 100644
--- a/nifi-nar-bundles/nifi-confluent-platform-bundle/nifi-confluent-schema-registry-service/src/main/java/org/apache/nifi/confluent/schemaregistry/client/RestSchemaRegistryClient.java
+++ b/nifi-nar-bundles/nifi-confluent-platform-bundle/nifi-confluent-schema-registry-service/src/main/java/org/apache/nifi/confluent/schemaregistry/client/RestSchemaRegistryClient.java
@@ -151,46 +151,54 @@ public class RestSchemaRegistryClient implements SchemaRegistryClient {
             }
 
         } catch (SchemaNotFoundException e) {
-            logger.debug("Could not find schema name in registry by id in: " + schemaPath);
+            logger.debug("Could not find schema metadata in registry by id and subjects in: " + schemaPath);
         }
 
         // Get all couples (subject name, version) for a given schema ID
         // GET /schemas/ids/{int: id}/versions
         if(completeSchema == null) {
-            JsonNode subjectsVersions = fetchJsonResponse(schemaPath + "/versions", "schema name");
-
-            if(subjectsVersions != null) {
-                final ArrayNode subjectsVersionsList = (ArrayNode) subjectsVersions;
-                // we want to make sure we get the latest version
-                int maxVersion = 0;
-                String subjectName = null;
-                for (JsonNode subjectVersion: subjectsVersionsList) {
-                    int currentVersion = subjectVersion.get(VERSION_FIELD_NAME).asInt();
-                    String currentSubjectName = subjectVersion.get(SUBJECT_FIELD_NAME).asText();
-                    if(currentVersion > maxVersion) {
-                        maxVersion = currentVersion;
-                        subjectName = currentSubjectName;
+            try {
+                JsonNode subjectsVersions = fetchJsonResponse(schemaPath + "/versions", "schema name");
+
+                if(subjectsVersions != null) {
+                    final ArrayNode subjectsVersionsList = (ArrayNode) subjectsVersions;
+                    // we want to make sure we get the latest version
+                    int maxVersion = 0;
+                    String subjectName = null;
+                    for (JsonNode subjectVersion: subjectsVersionsList) {
+                        int currentVersion = subjectVersion.get(VERSION_FIELD_NAME).asInt();
+                        String currentSubjectName = subjectVersion.get(SUBJECT_FIELD_NAME).asText();
+                        if(currentVersion > maxVersion) {
+                            maxVersion = currentVersion;
+                            subjectName = currentSubjectName;
+                        }
                     }
-                }
 
-                if(subjectName != null) {
-                    return createRecordSchema(subjectName, maxVersion, schemaId, schemaJson.get(SCHEMA_TEXT_FIELD_NAME).asText());
+                    if(subjectName != null) {
+                        return createRecordSchema(subjectName, maxVersion, schemaId, schemaJson.get(SCHEMA_TEXT_FIELD_NAME).asText());
+                    }
                 }
+            } catch (SchemaNotFoundException e) {
+                logger.debug("Could not find schema metadata in registry by id and versions in: " + schemaPath);
             }
         }
 
         // Last resort option: we get the full list of subjects and check one by one to get the complete schema info
         if(completeSchema == null) {
-            final JsonNode subjectsAllJson = fetchJsonResponse("/subjects", "subjects array");
-            final ArrayNode subjectsAllList = (ArrayNode) subjectsAllJson;
-            for (JsonNode subject: subjectsAllList) {
-                try {
-                    final String searchName = subject.asText();
-                    completeSchema = postJsonResponse("/subjects/" + searchName, schemaJson, "schema id: " + schemaId);
-                    break;
-                } catch (SchemaNotFoundException e) {
-                    continue;
+            try {
+                final JsonNode subjectsAllJson = fetchJsonResponse("/subjects", "subjects array");
+                final ArrayNode subjectsAllList = (ArrayNode) subjectsAllJson;
+                for (JsonNode subject: subjectsAllList) {
+                    try {
+                        final String searchName = subject.asText();
+                        completeSchema = postJsonResponse("/subjects/" + searchName, schemaJson, "schema id: " + schemaId);
+                        break;
+                    } catch (SchemaNotFoundException e) {
+                        continue;
+                    }
                 }
+            } catch (SchemaNotFoundException e) {
+                logger.debug("Could not find schema metadata in registry by iterating through subjects");
             }
         }