You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/03/08 18:15:17 UTC

[GitHub] [nifi-registry] bbende commented on a change in pull request #159: NIFIREG-232 Introducing flow persistence provider migrator and toolkit

bbende commented on a change in pull request #159: NIFIREG-232 Introducing flow persistence provider migrator and toolkit
URL: https://github.com/apache/nifi-registry/pull/159#discussion_r263874567
 
 

 ##########
 File path: nifi-registry-toolkit/nifi-registry-toolkit-persistence/src/main/java/org/apache/nifi/registry/toolkit/persistence/FlowPersistenceProviderMigrator.java
 ##########
 @@ -0,0 +1,106 @@
+/*
+ * 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.toolkit.persistence;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.nifi.registry.NiFiRegistry;
+import org.apache.nifi.registry.db.DataSourceFactory;
+import org.apache.nifi.registry.db.DatabaseMetadataService;
+import org.apache.nifi.registry.db.entity.BucketEntity;
+import org.apache.nifi.registry.db.entity.FlowEntity;
+import org.apache.nifi.registry.db.entity.FlowSnapshotEntity;
+import org.apache.nifi.registry.extension.ExtensionManager;
+import org.apache.nifi.registry.flow.FlowPersistenceProvider;
+import org.apache.nifi.registry.properties.NiFiRegistryProperties;
+import org.apache.nifi.registry.provider.StandardProviderFactory;
+import org.apache.nifi.registry.provider.flow.StandardFlowSnapshotContext;
+import org.apache.nifi.registry.service.DataModelMapper;
+import org.apache.nifi.registry.service.MetadataService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+public class FlowPersistenceProviderMigrator {
+    private static final Logger log = LoggerFactory.getLogger(FlowPersistenceProviderMigrator.class);
+    public static final int PARSE_EXCEPTION = 1;
+
+    public void doMigrate(MetadataService fromMetadata, FlowPersistenceProvider fromProvider, FlowPersistenceProvider toProvider) {
+        for (BucketEntity bucket : fromMetadata.getAllBuckets()) {
+            for (FlowEntity flow : fromMetadata.getFlowsByBucket(bucket.getId())) {
+                for (FlowSnapshotEntity flowSnapshot : fromMetadata.getSnapshots(flow.getId())) {
+                    StandardFlowSnapshotContext context = new StandardFlowSnapshotContext.Builder(
+                            DataModelMapper.map(bucket),
+                            DataModelMapper.map(bucket, flow),
+                            DataModelMapper.map(bucket, flowSnapshot)).build();
+
+                    int version = flowSnapshot.getVersion();
+
+                    toProvider.saveFlowContent(context, fromProvider.getFlowContent(bucket.getId(), flow.getId(), version));
+
+                    log.info("Migrated flow {} version {}", flow.getName(), version);
+                }
+            }
+        }
+    }
+
+    public static void main(String[] args) {
+        Options options = new Options();
+        options.addOption("t", "to", true, "Providers xml to migrate to.");
 
 Review comment:
   Would it make sense to have an argument to specify the nifi-registry home dir so that the script didn't have to be executed from already being in that location?
   
   I'm just thinking how my normal thought would be to navigate to where the toolkit is and then run something from bin.
   
   I guess if we did change it allow specifying the location of nifi-registry, then the tool itself has to cd to that location first since config in the conf dir could be referencing relative paths.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services