mirror of https://github.com/apache/nifi.git
NIFI-9969 Add extension restrictions to C2 component definition model
Update test to verify ListHDFS does not have restrictions Fix checkstyle issue Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #6031
This commit is contained in:
parent
dfc8b9c4c8
commit
e2b5773027
|
@ -41,6 +41,10 @@ public class ExtensionComponent extends DefinedType {
|
|||
private Boolean deprecated;
|
||||
private String deprecationReason;
|
||||
|
||||
private Boolean restricted;
|
||||
private String restrictedExplanation;
|
||||
private Set<Restriction> explicitRestrictions;
|
||||
|
||||
@ApiModelProperty("The build metadata for this component")
|
||||
public BuildInfo getBuildInfo() {
|
||||
return buildInfo;
|
||||
|
@ -87,6 +91,33 @@ public class ExtensionComponent extends DefinedType {
|
|||
this.deprecationReason = deprecationReason;
|
||||
}
|
||||
|
||||
@ApiModelProperty("Whether or not the component has a general restriction")
|
||||
public Boolean isRestricted() {
|
||||
return restricted;
|
||||
}
|
||||
|
||||
public void setRestricted(Boolean restricted) {
|
||||
this.restricted = restricted;
|
||||
}
|
||||
|
||||
@ApiModelProperty("An optional description of the general restriction")
|
||||
public String getRestrictedExplanation() {
|
||||
return restrictedExplanation;
|
||||
}
|
||||
|
||||
public void setRestrictedExplanation(String restrictedExplanation) {
|
||||
this.restrictedExplanation = restrictedExplanation;
|
||||
}
|
||||
|
||||
@ApiModelProperty("Explicit restrictions that indicate a require permission to use the component")
|
||||
public Set<Restriction> getExplicitRestrictions() {
|
||||
return explicitRestrictions;
|
||||
}
|
||||
|
||||
public void setExplicitRestrictions(Set<Restriction> explicitRestrictions) {
|
||||
this.explicitRestrictions = explicitRestrictions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.c2.protocol.component.api;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ApiModel
|
||||
public class Restriction {
|
||||
|
||||
private String requiredPermission;
|
||||
private String explanation;
|
||||
|
||||
@ApiModelProperty(value = "The permission required for this restriction")
|
||||
public String getRequiredPermission() {
|
||||
return requiredPermission;
|
||||
}
|
||||
|
||||
public void setRequiredPermission(String requiredPermission) {
|
||||
this.requiredPermission = requiredPermission;
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "The explanation of this restriction")
|
||||
public String getExplanation() {
|
||||
return explanation;
|
||||
}
|
||||
|
||||
public void setExplanation(String explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Restriction that = (Restriction) o;
|
||||
return Objects.equals(requiredPermission, that.requiredPermission) && Objects.equals(explanation, that.explanation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(requiredPermission, explanation);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.apache.nifi.c2.protocol.component.api.PropertyDescriptor;
|
|||
import org.apache.nifi.c2.protocol.component.api.PropertyResourceDefinition;
|
||||
import org.apache.nifi.c2.protocol.component.api.Relationship;
|
||||
import org.apache.nifi.c2.protocol.component.api.ReportingTaskDefinition;
|
||||
import org.apache.nifi.c2.protocol.component.api.Restriction;
|
||||
import org.apache.nifi.c2.protocol.component.api.RuntimeManifest;
|
||||
import org.apache.nifi.c2.protocol.component.api.SchedulingDefaults;
|
||||
import org.apache.nifi.components.resource.ResourceCardinality;
|
||||
|
@ -46,6 +47,7 @@ import org.apache.nifi.extension.manifest.ExtensionManifest;
|
|||
import org.apache.nifi.extension.manifest.Property;
|
||||
import org.apache.nifi.extension.manifest.ProvidedServiceAPI;
|
||||
import org.apache.nifi.extension.manifest.ResourceDefinition;
|
||||
import org.apache.nifi.extension.manifest.Restricted;
|
||||
import org.apache.nifi.logging.LogLevel;
|
||||
import org.apache.nifi.runtime.manifest.ComponentManifestBuilder;
|
||||
import org.apache.nifi.runtime.manifest.RuntimeManifestBuilder;
|
||||
|
@ -57,6 +59,7 @@ import java.util.HashSet;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -348,6 +351,24 @@ public class StandardRuntimeManifestBuilder implements RuntimeManifestBuilder {
|
|||
providedServiceApis.forEach(providedServiceApi -> providedApiTypes.add(createProvidedApiType(providedServiceApi)));
|
||||
extensionComponent.setProvidedApiImplementations(providedApiTypes);
|
||||
}
|
||||
|
||||
final Restricted restricted = extension.getRestricted();
|
||||
if (restricted != null) {
|
||||
extensionComponent.setRestricted(true);
|
||||
extensionComponent.setRestrictedExplanation(restricted.getGeneralRestrictionExplanation());
|
||||
if (restricted.getRestrictions() != null) {
|
||||
final Set<Restriction> explicitRestrictions = new HashSet<>();
|
||||
restricted.getRestrictions().forEach(r -> explicitRestrictions.add(createRestriction(r)));
|
||||
extensionComponent.setExplicitRestrictions(explicitRestrictions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Restriction createRestriction(final org.apache.nifi.extension.manifest.Restriction extensionRestriction) {
|
||||
final Restriction restriction = new Restriction();
|
||||
restriction.setExplanation(extensionRestriction.getExplanation());
|
||||
restriction.setRequiredPermission(extensionRestriction.getRequiredPermission());
|
||||
return restriction;
|
||||
}
|
||||
|
||||
private DefinedType createProvidedApiType(final ProvidedServiceAPI providedServiceApi) {
|
||||
|
|
|
@ -27,8 +27,10 @@ import org.apache.nifi.c2.protocol.component.api.PropertyDescriptor;
|
|||
import org.apache.nifi.c2.protocol.component.api.PropertyResourceDefinition;
|
||||
import org.apache.nifi.c2.protocol.component.api.Relationship;
|
||||
import org.apache.nifi.c2.protocol.component.api.ReportingTaskDefinition;
|
||||
import org.apache.nifi.c2.protocol.component.api.Restriction;
|
||||
import org.apache.nifi.c2.protocol.component.api.RuntimeManifest;
|
||||
import org.apache.nifi.c2.protocol.component.api.SchedulingDefaults;
|
||||
import org.apache.nifi.components.RequiredPermission;
|
||||
import org.apache.nifi.components.resource.ResourceCardinality;
|
||||
import org.apache.nifi.components.resource.ResourceType;
|
||||
import org.apache.nifi.scheduling.SchedulingStrategy;
|
||||
|
@ -39,10 +41,12 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestRuntimeManifest {
|
||||
|
@ -139,6 +143,24 @@ public class TestRuntimeManifest {
|
|||
assertEquals(1, resourceDefinition.getResourceTypes().size());
|
||||
assertEquals(ResourceType.FILE, resourceDefinition.getResourceTypes().stream().findFirst().get());
|
||||
|
||||
assertNull(listHdfsDefinition.isRestricted());
|
||||
assertNull(listHdfsDefinition.getRestrictedExplanation());
|
||||
assertNull(listHdfsDefinition.getExplicitRestrictions());
|
||||
|
||||
// Verify FetchHDFS definition has restrictions
|
||||
final ProcessorDefinition fetchHdfsDefinition = getProcessorDefinition(bundles, "nifi-hadoop-nar",
|
||||
"org.apache.nifi.processors.hadoop.FetchHDFS");
|
||||
assertNotNull(fetchHdfsDefinition.isRestricted());
|
||||
assertTrue(fetchHdfsDefinition.isRestricted());
|
||||
|
||||
final Set<Restriction> restrictions = fetchHdfsDefinition.getExplicitRestrictions();
|
||||
assertNotNull(restrictions);
|
||||
assertEquals(1, restrictions.size());
|
||||
|
||||
final Restriction restriction = restrictions.stream().findFirst().orElse(null);
|
||||
assertEquals(RequiredPermission.READ_DISTRIBUTED_FILESYSTEM.getPermissionLabel(), restriction.getRequiredPermission());
|
||||
assertNotNull(restriction.getExplanation());
|
||||
|
||||
// Verify ConsumeKafka_2_6 definition which has properties with dependencies
|
||||
final ProcessorDefinition consumeKafkaDefinition = getProcessorDefinition(bundles, "nifi-kafka-2-6-nar",
|
||||
"org.apache.nifi.processors.kafka.pubsub.ConsumeKafka_2_6");
|
||||
|
|
Loading…
Reference in New Issue