timeabarna commented on code in PR #7092:
URL: https://github.com/apache/nifi/pull/7092#discussion_r1171164642


##########
nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/registry/flow/ImportAllFlows.java:
##########
@@ -0,0 +1,331 @@
+/*
+ * 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.toolkit.cli.impl.command.registry.flow;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.cli.MissingOptionException;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.curator.shaded.com.google.common.collect.ComparisonChain;
+import org.apache.nifi.flow.VersionedFlowCoordinates;
+import org.apache.nifi.flow.VersionedProcessGroup;
+import org.apache.nifi.registry.bucket.Bucket;
+import org.apache.nifi.registry.client.BucketClient;
+import org.apache.nifi.registry.client.FlowClient;
+import org.apache.nifi.registry.client.FlowSnapshotClient;
+import org.apache.nifi.registry.client.NiFiRegistryClient;
+import org.apache.nifi.registry.client.NiFiRegistryException;
+import org.apache.nifi.registry.flow.VersionedFlow;
+import org.apache.nifi.registry.flow.VersionedFlowSnapshot;
+import org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata;
+import org.apache.nifi.toolkit.cli.api.CommandException;
+import org.apache.nifi.toolkit.cli.api.Context;
+import org.apache.nifi.toolkit.cli.impl.command.CommandOption;
+import 
org.apache.nifi.toolkit.cli.impl.command.registry.AbstractNiFiRegistryCommand;
+import org.apache.nifi.toolkit.cli.impl.command.registry.bucket.ListBuckets;
+import org.apache.nifi.toolkit.cli.impl.result.StringResult;
+import org.apache.nifi.toolkit.cli.impl.util.JacksonUtils;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class ImportAllFlows extends AbstractNiFiRegistryCommand<StringResult> {
+    private static final String FILE_NAME_PREFIX = 
"toolkit_registry_export_all_";
+    private static final String SKIPPING_BUCKET_CREATION = " already exists, 
skipping bucket creation...";
+    private static final String SKIPPING_IMPORT = " already exists, skipping 
import...";
+    private static final String SKIPPING_FLOW_CREATION = " already exists, 
skipping flow creation...";
+    private static final String IMPORT_COMPLETED = "Import completed...";
+    private static final String ALL_BUCKETS_COLLECTED = "All buckets 
collected...";
+    private static final String ALL_FLOWS_COLLECTED = "All flows collected...";
+    private static final String ALL_FLOW_VERSIONS_COLLECTED = "All flow 
versions collected...";
+    private static final String FILE_NAME_SEPARATOR = "_";
+    private static final String STORAGE_LOCATION_URL = 
"%s/nifi-registry-api/buckets/%s/flows/%s/versions/%s";
+    private static final ObjectMapper MAPPER = JacksonUtils.getObjectMapper();
+    private final ListBuckets listBuckets;
+    private final ListFlows listFlows;
+    private final ListFlowVersions listFlowVersions;
+
+    public ImportAllFlows() {
+        super("import-all-flows", StringResult.class);
+        this.listBuckets = new ListBuckets();
+        this.listFlows = new ListFlows();
+        this.listFlowVersions = new ListFlowVersions();
+    }
+
+    @Override
+    protected void doInitialize(Context context) {
+        addOption(CommandOption.INPUT_SOURCE.createOption());
+        addOption(CommandOption.SKIP_EXISTING.createOption());
+
+        listBuckets.initialize(context);
+        listFlows.initialize(context);
+        listFlowVersions.initialize(context);
+    }
+
+    @Override
+    public String getDescription() {
+        return "From a provided directory as input, the directory content must 
be generated by the export-all-flows command, " +
+                "based on the file contents, the corresponding buckets, flows 
and flow versions will be created." +
+                "If not configured otherwise, already existing objects will be 
skipped.";
+    }
+
+    @Override
+    public StringResult doExecute(final NiFiRegistryClient client, final 
Properties properties) throws IOException, NiFiRegistryException, 
ParseException, CommandException {
+        final boolean skip = Boolean.parseBoolean(getRequiredArg(properties, 
CommandOption.SKIP_EXISTING));

Review Comment:
   Is there a situation in one of the uses cases where you would want to use 
--skipExisting true and not get v3 imported?
   The only scenario comes to my mind when there are 2 buckets in Registry A 
and only one of this buckets can be found in Registry B. There is no continuous 
synchronisation is needed however creating the missing bucket with all its 
flows and versions can be done without changing anything in the existing bucket.
   
   You are right though this does not fit into the provided two use cases.
   
   I am fine having --skipExisting with noArg for now however I would keep the 
option for possible future enhancements.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to