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/06/14 21:08:33 UTC

[GitHub] [nifi] kevdoran commented on a change in pull request #3492: NIFI-6164 - Added CLI commands related to NiFi Registry extension bun…

kevdoran commented on a change in pull request #3492: NIFI-6164 - Added CLI commands related to NiFi Registry extension bun…
URL: https://github.com/apache/nifi/pull/3492#discussion_r293969006
 
 

 ##########
 File path: nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/registry/extension/UploadBundles.java
 ##########
 @@ -0,0 +1,155 @@
+/*
+ * 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.extension;
+
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.registry.client.BundleVersionClient;
+import org.apache.nifi.registry.client.NiFiRegistryClient;
+import org.apache.nifi.registry.client.NiFiRegistryException;
+import org.apache.nifi.registry.extension.bundle.BundleType;
+import org.apache.nifi.registry.extension.bundle.BundleVersion;
+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.result.StringResult;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class UploadBundles extends AbstractNiFiRegistryCommand<StringResult> {
+
+    public UploadBundles() {
+        super("upload-bundles", StringResult.class);
+    }
+
+    @Override
+    public String getDescription() {
+        return "Performs a bulk upload of multiple bundles to the specified bucket in the registry. This command will look for " +
+                "files in the specified directory, and if recurse (-r) is specified then it will search child directories recursively. " +
+                "If fileExtension is specified then it will only consider files that have the specified extension, such as '.nar'";
+    }
+
+    @Override
+    public void doInitialize(final Context context) {
+        addOption(CommandOption.BUCKET_ID.createOption());
+        addOption(CommandOption.EXT_BUNDLE_TYPE.createOption());
+        addOption(CommandOption.EXT_BUNDLE_DIR.createOption());
+        addOption(CommandOption.FILE_EXTENSION.createOption());
+        addOption(CommandOption.RECURSIVE.createOption());
+        addOption(CommandOption.SKIP_SHA_256.createOption());
+    }
+
+    @Override
+    public StringResult doExecute(final NiFiRegistryClient client, final Properties properties)
+            throws IOException, NiFiRegistryException, ParseException {
+        final String bucketId = getRequiredArg(properties, CommandOption.BUCKET_ID);
+        final String bundleDir = getRequiredArg(properties, CommandOption.EXT_BUNDLE_DIR);
+        final String fileExtension = getArg(properties, CommandOption.FILE_EXTENSION);
+        final boolean recursive = properties.containsKey(CommandOption.RECURSIVE);
+        final boolean skipSha256 = properties.containsKey(CommandOption.SKIP_SHA_256.getLongName());
+        final boolean verbose = isVerbose(properties);
+
+        final BundleType bundleType;
+        try {
+            bundleType = BundleType.fromString(getRequiredArg(properties, CommandOption.EXT_BUNDLE_TYPE));
+        } catch (Exception e) {
 
 Review comment:
   ```suggestion
           } catch (IllegalArgumentException e) {
   ```
   
   `Exception` is too broad. When the required arg is not provided, this will catch `MissingOptionException` and instead of:
   > Missing required option --extensionBundleType
   
   we will get: 
   > Invalid bundle type, should be one of nifi-nar or minifi-cpp
   

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