brosander 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_r264226522
 
 

 ##########
 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:
   Looks like there's not a great way to do that from inside Java, we'd 
probably need to add special handling for that argument w/in the shell scripts 
to support it.

----------------------------------------------------------------
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