NIFI-9379 Add dependent properties and resource definitions to manifest model

Signed-off-by: Joe Gresock <jgresock@gmail.com>

This closes #5522.
This commit is contained in:
Bryan Bende 2021-11-15 16:29:59 -05:00 committed by Joe Gresock
parent 15465bb4b8
commit 77f235bf1c
No known key found for this signature in database
GPG Key ID: 37F5B9B6E258C8B7
8 changed files with 3519 additions and 0 deletions

View File

@ -16,10 +16,16 @@
*/
package org.apache.nifi.registry.bundle.extract.nar.docs;
import org.apache.nifi.registry.extension.component.manifest.Cardinality;
import org.apache.nifi.registry.extension.component.manifest.Dependency;
import org.apache.nifi.registry.extension.component.manifest.DependentValues;
import org.apache.nifi.registry.extension.component.manifest.Extension;
import org.apache.nifi.registry.extension.component.manifest.ExtensionManifest;
import org.apache.nifi.registry.extension.component.manifest.ExtensionType;
import org.apache.nifi.registry.extension.component.manifest.Property;
import org.apache.nifi.registry.extension.component.manifest.ProvidedServiceAPI;
import org.apache.nifi.registry.extension.component.manifest.ResourceDefinition;
import org.apache.nifi.registry.extension.component.manifest.ResourceType;
import org.apache.nifi.registry.extension.component.manifest.Restriction;
import org.junit.Before;
import org.junit.Test;
@ -164,6 +170,83 @@ public class TestJacksonExtensionManifestParser {
}
@Test
public void testDocsWithDependentProperties() throws IOException {
final ExtensionManifest extensionManifest = parse("src/test/resources/descriptors/extension-manifest-kafka-2-6-nar.xml");
assertNotNull(extensionManifest);
assertEquals("1.16.0-SNAPSHOT", extensionManifest.getSystemApiVersion());
final List<Extension> extensionDetails = extensionManifest.getExtensions();
final Extension consumeKafkaExtension = extensionDetails.stream()
.filter(e -> e.getName().equals("org.apache.nifi.processors.kafka.pubsub.ConsumeKafka_2_6"))
.findFirst()
.orElse(null);
assertNotNull(consumeKafkaExtension);
assertEquals(ExtensionType.PROCESSOR, consumeKafkaExtension.getType());
final List<Property> properties = consumeKafkaExtension.getProperties();
assertNotNull(properties);
final Property maxUncommittedOffsetWaitProperty = properties.stream()
.filter(p -> p.getName().equals("max-uncommit-offset-wait"))
.findFirst()
.orElse(null);
assertNotNull(maxUncommittedOffsetWaitProperty);
final List<Dependency> dependencies = maxUncommittedOffsetWaitProperty.getDependencies();
assertNotNull(dependencies);
assertEquals(1, dependencies.size());
final Dependency dependency = dependencies.get(0);
assertEquals("Commit Offsets", dependency.getPropertyName());
assertEquals("Commit Offsets", dependency.getPropertyDisplayName());
final DependentValues dependentValues = dependency.getDependentValues();
assertNotNull(dependentValues);
final List<String> dependentValuesList = dependentValues.getValues();
assertNotNull(dependentValuesList);
assertEquals(1, dependentValuesList.size());
assertEquals("true", dependentValuesList.get(0));
}
@Test
public void testDocsWithResourceDefinitions() throws IOException {
final ExtensionManifest extensionManifest = parse("src/test/resources/descriptors/extension-manifest-kafka-2-6-nar.xml");
assertNotNull(extensionManifest);
assertEquals("1.16.0-SNAPSHOT", extensionManifest.getSystemApiVersion());
final List<Extension> extensionDetails = extensionManifest.getExtensions();
final Extension consumeKafkaExtension = extensionDetails.stream()
.filter(e -> e.getName().equals("org.apache.nifi.processors.kafka.pubsub.ConsumeKafka_2_6"))
.findFirst()
.orElse(null);
assertNotNull(consumeKafkaExtension);
assertEquals(ExtensionType.PROCESSOR, consumeKafkaExtension.getType());
final List<Property> properties = consumeKafkaExtension.getProperties();
assertNotNull(properties);
final Property keytabProperty = properties.stream()
.filter(p -> p.getName().equals("sasl.kerberos.keytab"))
.findFirst()
.orElse(null);
assertNotNull(keytabProperty);
final ResourceDefinition resourceDefinition = keytabProperty.getResourceDefinition();
assertNotNull(resourceDefinition);
assertEquals(Cardinality.SINGLE, resourceDefinition.getCardinality());
final List<ResourceType> resourceTypes = resourceDefinition.getResourceTypes();
assertNotNull(resourceTypes);
assertEquals(1, resourceTypes.size());
assertEquals(ResourceType.FILE, resourceTypes.get(0));
}
private ExtensionManifest parse(final String file) throws IOException {
try (final InputStream inputStream = new FileInputStream(file)) {
return parser.parse(inputStream);

View File

@ -0,0 +1,34 @@
/*
* 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.extension.component.manifest;
import io.swagger.annotations.ApiModel;
@ApiModel
public enum Cardinality {
/**
* Exactly one resource must be specified
*/
SINGLE,
/**
* One or more resources may be supplied, as a comma-separated list
*/
MULTIPLE;
}

View File

@ -0,0 +1,59 @@
/*
* 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.extension.component.manifest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ApiModel
@XmlAccessorType(XmlAccessType.FIELD)
public class Dependency {
private String propertyName;
private String propertyDisplayName;
private DependentValues dependentValues;
@ApiModelProperty(value = "The name of the dependent property")
public String getPropertyName() {
return propertyName;
}
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
@ApiModelProperty(value = "The display name of the dependent property")
public String getPropertyDisplayName() {
return propertyDisplayName;
}
public void setPropertyDisplayName(String propertyDisplayName) {
this.propertyDisplayName = propertyDisplayName;
}
@ApiModelProperty(value = "The values of the dependent property that enable the depending property")
public DependentValues getDependentValues() {
return dependentValues;
}
public void setDependentValues(DependentValues dependentValues) {
this.dependentValues = dependentValues;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.extension.component.manifest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;
@ApiModel
@XmlAccessorType(XmlAccessType.FIELD)
public class DependentValues {
@XmlElement(name = "dependentValue")
private List<String> values;
@ApiModelProperty(value = "The dependent values")
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
}

View File

@ -48,6 +48,11 @@ public class Property {
private boolean dynamicallyModifiesClasspath;
private boolean dynamic;
@XmlElementWrapper
@XmlElement(name = "dependency")
private List<Dependency> dependencies;
private ResourceDefinition resourceDefinition;
@ApiModelProperty(value = "The name of the property")
public String getName() {
@ -156,4 +161,22 @@ public class Property {
public void setDynamic(boolean dynamic) {
this.dynamic = dynamic;
}
@ApiModelProperty(value = "The properties that this property depends on")
public List<Dependency> getDependencies() {
return dependencies;
}
public void setDependencies(List<Dependency> dependencies) {
this.dependencies = dependencies;
}
@ApiModelProperty(value = "The optional resource definition")
public ResourceDefinition getResourceDefinition() {
return resourceDefinition;
}
public void setResourceDefinition(ResourceDefinition resourceDefinition) {
this.resourceDefinition = resourceDefinition;
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.extension.component.manifest;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
@ApiModel
@XmlAccessorType(XmlAccessType.FIELD)
public class ResourceDefinition {
private Cardinality cardinality;
@XmlElementWrapper
@XmlElement(name = "resourceType")
private List<ResourceType> resourceTypes;
@ApiModelProperty(value = "The cardinality of the resource definition")
public Cardinality getCardinality() {
return cardinality;
}
public void setCardinality(Cardinality cardinality) {
this.cardinality = cardinality;
}
@ApiModelProperty(value = "The types of resources")
public List<ResourceType> getResourceTypes() {
return resourceTypes;
}
public void setResourceTypes(List<ResourceType> resourceTypes) {
this.resourceTypes = resourceTypes;
}
}

View File

@ -0,0 +1,45 @@
/*
* 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.extension.component.manifest;
import io.swagger.annotations.ApiModel;
@ApiModel
public enum ResourceType {
/**
* Referenced Resource is a File on a local (or mounted) file system
*/
FILE,
/**
* Referenced Resource is a directory on a local (or mounted) file system
*/
DIRECTORY,
/**
* Referenced Resource is UTF-8 text, rather than an external entity
*/
TEXT,
/**
* Referenced Resource is a URL that uses the HTTP, HTTPS, or file protocol
* (i.e., <code>http://...</code>, <code>https://...</code>, or <code>file:...</code>)
*/
URL
}