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/07/01 14:19:30 UTC

[GitHub] [nifi] mcgilman commented on a change in pull request #3536: NIFI-6380: Introduced the notion of Parameters and Parameter Contexts…

mcgilman commented on a change in pull request #3536: NIFI-6380: Introduced the notion of Parameters and Parameter Contexts…
URL: https://github.com/apache/nifi/pull/3536#discussion_r299065273
 
 

 ##########
 File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java
 ##########
 @@ -0,0 +1,279 @@
+/*
+ * 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.parameter;
+
+import org.apache.nifi.authorization.Resource;
+import org.apache.nifi.authorization.resource.Authorizable;
+import org.apache.nifi.authorization.resource.ResourceFactory;
+import org.apache.nifi.authorization.resource.ResourceType;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ComponentNode;
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.controller.PropertyConfiguration;
+import org.apache.nifi.controller.service.ControllerServiceNode;
+import org.apache.nifi.controller.service.ControllerServiceState;
+import org.apache.nifi.groups.ProcessGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class StandardParameterContext implements ParameterContext {
+    private static final Logger logger = LoggerFactory.getLogger(StandardParameterContext.class);
+
+    private final String id;
+    private final ParameterReferenceManager parameterReferenceManager;
+
+    private String name;
+    private long version = 0L;
+    private final Map<ParameterDescriptor, Parameter> parameters = new LinkedHashMap<>();
+    private volatile String description;
+
+    private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+    private final Lock readLock = rwLock.readLock();
+    private final Lock writeLock = rwLock.writeLock();
+
+
+    public StandardParameterContext(final String id, final String name, final ParameterReferenceManager parameterReferenceManager) {
+        this.id = Objects.requireNonNull(id);
+        this.name = Objects.requireNonNull(name);
+        this.parameterReferenceManager = parameterReferenceManager;
+    }
+
+    @Override
+    public String getIdentifier() {
+        return id;
+    }
+
+    public String getName() {
+        readLock.lock();
+        try {
+            return name;
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    public void setName(final String name) {
+        writeLock.lock();
+        try {
+            this.version++;
+            this.name = name;
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public String getDescription() {
+        return description;
+    }
+
+    public void setParameters(final Set<Parameter> updatedParameters) {
+        writeLock.lock();
+        try {
+            this.version++;
+
+            verifyCanSetParameters(updatedParameters);
+
+            for (final Parameter parameter : updatedParameters) {
+                if (parameter.getValue() == null) {
+                    parameters.remove(parameter.getDescriptor());
 
 Review comment:
   When a user opts to update a sensitive parameter, the front end does not have the value to re-submit. As a result, the request would be mis-interrupted as a request to delete instead of a request to update the description. What are your thoughts on only considering the incoming request as a delete request when the description is not specified? The name and the sensitive flag are technically immutable so these could be considered optional. If the description is specified then update the parameter. If the parameter is sensitive, then only update the value if the value is non-null in the incoming request. I believe this convention is something that we could easily document in the annotations in the DTO and would not be ambiguous. 

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