brosander commented on a change in pull request #162: NIFIREG-238: Allow 
aliasing of registry url
URL: https://github.com/apache/nifi-registry/pull/162#discussion_r269328710
 
 

 ##########
 File path: 
nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/alias/RegistryUrlAliasService.java
 ##########
 @@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.registry.service.alias;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.nifi.registry.flow.VersionedFlowCoordinates;
+import org.apache.nifi.registry.flow.VersionedProcessGroup;
+import org.apache.nifi.registry.properties.NiFiRegistryProperties;
+import org.apache.nifi.registry.provider.ProviderFactoryException;
+import org.apache.nifi.registry.provider.StandardProviderFactory;
+import org.apache.nifi.registry.url.aliaser.generated.Aliases;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.xml.sax.SAXException;
+
+import javax.xml.XMLConstants;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Allows aliasing of registry url(s) without modifying the flows on disk.
+ */
+@Service
+public class RegistryUrlAliasService {
+    private static final String ALIASES_XSD = "/aliases.xsd";
+    private static final String JAXB_GENERATED_PATH = 
"org.apache.nifi.registry.url.aliaser.generated";
+    private static final JAXBContext JAXB_CONTEXT = initializeJaxbContext();
+
+    /**
+     * Load the JAXBContext.
+     */
+    private static JAXBContext initializeJaxbContext() {
+        try {
+            return JAXBContext.newInstance(JAXB_GENERATED_PATH, 
RegistryUrlAliasService.class.getClassLoader());
+        } catch (JAXBException e) {
+            throw new RuntimeException("Unable to create JAXBContext.", e);
+        }
+    }
+
+    private final List<Pair<String, String>> aliases;
+
+    @Autowired
+    public RegistryUrlAliasService(NiFiRegistryProperties 
niFiRegistryProperties) {
+        this(createAliases(niFiRegistryProperties));
+    }
+
+    private static List<Pair<String, String>> 
createAliases(NiFiRegistryProperties niFiRegistryProperties) {
 
 Review comment:
   It makes migration from URLs in the registry coordinates to a token possible 
while still allowing nifi to point at older versions of flows.
   
   Ex:
   ```
   <aliases>
       <alias>
           <internal>INTERNAL_NIFI_REGISTRY_TOKEN</internal>
           <external>https://my.new.secure.registry.url:18443</external>
       </alias>
       <alias>
           <internal>http://my.old.insecure.registry.url:18080</internal>
           <external>https://my.new.secure.registry.url:18443</external>
       </alias>
   </aliases>
   ```
   
   Should allow you to spin up the registry, nifi pointing at the new url able 
to point at arbitrary old revisions of flows.  If you write them back they 
should go into the registry with INTERNAL_NIFI_REGISTRY_TOKEN.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to