diff options
author | Patrick Brady <pb071s@att.com> | 2017-06-01 10:45:37 -0700 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-06-02 13:05:15 -0700 |
commit | c7d0075d223eab9f89fd28853c4b138792059be9 (patch) | |
tree | 40aa3e41e598ea7a59bcf6899a2004c1abab11c2 /appc-asdc-listener | |
parent | 8aac2df744820304ee29354333661699e9695939 (diff) |
Merge of new rebased code
Change-Id: I9b8d1f69eb3e0af1935ed8304fea4bf54c1aac47
Signed-off-by: Patrick Brady <pb071s@att.com>
Diffstat (limited to 'appc-asdc-listener')
21 files changed, 2110 insertions, 61 deletions
diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml b/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml index 1c5e7dd75..607ab7745 100644 --- a/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml +++ b/appc-asdc-listener/appc-asdc-listener-bundle/pom.xml @@ -1,7 +1,7 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> + <parent> <artifactId>appc-asdc-listener</artifactId> <groupId>org.openecomp.appc</groupId> @@ -31,12 +31,12 @@ <dependency> <groupId>org.openecomp.sdc</groupId> <artifactId>sdc-distribution-client</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.0</version> </dependency> <dependency> <groupId>org.openecomp.appc</groupId> - <artifactId>appc-dmaap-adapter-bundle</artifactId> + <artifactId>appc-message-adapter-api</artifactId> <version>${project.version}</version> </dependency> @@ -98,6 +98,35 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> + + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-tosca-lib</artifactId> + <version>${toscalib.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + <version>1.7</version> + </dependency> + + <dependency> + <groupId>org.opendaylight.yangtools</groupId> + <artifactId>yang-parser-impl</artifactId> + <version>${odl.yangtools.version}</version> + </dependency> + + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-inet-types</artifactId> + <version>${odl.ietf-inet-types.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-yang-types</artifactId> + <version>${odl.ietf-yang-types.version}</version> + </dependency> </dependencies> @@ -128,35 +157,15 @@ <Export-Package>org.openecomp.appc.sdc.listener</Export-Package> <Import-Package> org.openecomp.appc.licmgr, - org.openecomp.appc.adapter.dmaap, - !ch.qos.*, - !com.att.*, - !fj.*, - !groovy.lang, - !javax.jms, - !javax.mail.*, - !org.apache.log4j.*, - !org.codehaus.commons.compiler, - !org.codehaus.groovy.*, - !org.codehaus.janino, - !org.jasypt.*, - !org.yaml.snakeyaml.*, - !com.ibm.icu.text, - !org.apache.log, - !com.sun.faces.spi, + org.openecomp.appc.adapter.messaging.*, + com.att.eelf.*, *;resolution:=optional </Import-Package> <Embed-Dependency> - sdc-distribution-client, appc-common, - appc-dmaap-adapter-bundle, appc-license-manager-api, - snakeyaml, - logback-core, - logback-classic, eelf-core, - saClientLibrary, - cambriaClient, - functionaljava, - httpcore,httpclient, - gson;scope=compile|runtime;inline=false + sdc-distribution-client,snakeyaml, + saClientLibrary,cambriaClient,saToolkit, + functionaljava,httpcore,httpclient,gson; + scope=compile|runtime;inline=false </Embed-Dependency> <Embed-Transitive>true</Embed-Transitive> </instructions> diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java index 651ea282c..5084771f1 100644 --- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java +++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcCallback.java @@ -21,26 +21,25 @@ package org.openecomp.appc.sdc.listener; -import java.net.URI; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.openecomp.appc.adapter.dmaap.EventSender; - +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.openecomp.appc.adapter.message.EventSender; import org.openecomp.sdc.api.IDistributionClient; import org.openecomp.sdc.api.consumer.INotificationCallback; import org.openecomp.sdc.api.notification.IArtifactInfo; import org.openecomp.sdc.api.notification.INotificationData; import org.openecomp.sdc.api.notification.IResourceInstance; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; +import java.net.URI; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + public class AsdcCallback implements INotificationCallback { private final EELFLogger logger = EELFManager.getInstance().getLogger(AsdcCallback.class); diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcConfig.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcConfig.java index e73b90695..f415e2ef1 100644 --- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcConfig.java +++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcConfig.java @@ -21,17 +21,12 @@ package org.openecomp.appc.sdc.listener; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.openecomp.sdc.api.consumer.IConfiguration; -import org.openecomp.sdc.utils.ArtifactTypeEnum; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import org.openecomp.sdc.api.consumer.IConfiguration; + +import java.net.URI; +import java.util.*; public class AsdcConfig implements IConfiguration { @@ -106,6 +101,11 @@ public class AsdcConfig implements IConfiguration { return false; } + //@Override + public boolean isFilterInEmptyResources() { + return false; + } + @Override public String getAsdcAddress() { return host; diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcListener.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcListener.java index 2d6192749..762ec18eb 100644 --- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcListener.java +++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/AsdcListener.java @@ -20,6 +20,8 @@ */ package org.openecomp.appc.sdc.listener; +import org.openecomp.sdc.impl.DistributionClientFactory; +import org.openecomp.sdc.utils.DistributionActionResultEnum; import java.net.URL; import java.util.HashMap; @@ -37,7 +39,6 @@ import org.openecomp.sdc.utils.DistributionActionResultEnum; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; - public class AsdcListener { /** @@ -111,7 +112,7 @@ public class AsdcListener { Map<String, String> headers = new HashMap<>(); // TODO - Replace the header below to sdc's requirements. What should the new value be - headers.put("HTTP_CSP_ID", "test"); + headers.put("USER_ID", "test"); // TODO - How to format the url. Always same endpoint or ports? String host = config.getAsdcAddress(); diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/DownloadAndStoreOp.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/DownloadAndStoreOp.java index fcc5e7dda..a5a786f62 100644 --- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/DownloadAndStoreOp.java +++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/DownloadAndStoreOp.java @@ -21,11 +21,11 @@ package org.openecomp.appc.sdc.listener; -import org.openecomp.appc.adapter.dmaap.EventSender; -import org.openecomp.appc.adapter.dmaap.DmaapDestination; -import org.openecomp.appc.adapter.dmaap.event.EventHeader; -import org.openecomp.appc.adapter.dmaap.event.EventMessage; -import org.openecomp.appc.adapter.dmaap.event.EventStatus; +import org.openecomp.appc.adapter.message.EventSender; +import org.openecomp.appc.adapter.message.MessageDestination; +import org.openecomp.appc.adapter.message.event.EventHeader; +import org.openecomp.appc.adapter.message.event.EventMessage; +import org.openecomp.appc.adapter.message.event.EventStatus; import org.openecomp.appc.exceptions.APPCException; import org.openecomp.appc.licmgr.Constants; import org.openecomp.appc.licmgr.LicenseManager; @@ -136,11 +136,10 @@ public class DownloadAndStoreOp implements Runnable { String vnfType = artifactPayload.get(RESOURCE_NAME.name()); String version = artifactPayload.get(RESOURCE_VERSION.name()); String packageArtifactID = artifactPayload.get(ARTIFACT_UUID.name()); - String packageArtifactVersion = artifactPayload.get(INTERNAL_VERSION.name()); try { - if (null == vnfType || null == version || null == packageArtifactID || null == packageArtifactVersion || vnfType.isEmpty() || version.isEmpty() || packageArtifactID.isEmpty() || packageArtifactVersion.isEmpty()) { - throw new APPCException(String.format("Missing information in ASDC request. Details: resource_type='%s', resource_version='%s', artifactID='%s', artifactVersion='%s'", vnfType, version, packageArtifactID, packageArtifactVersion)); + if (null == vnfType || null == version || null == packageArtifactID || vnfType.isEmpty() || version.isEmpty() || packageArtifactID.isEmpty()) { + throw new APPCException(String.format("Missing information in ASDC request. Details: resource_type='%s', resource_version='%s', artifactID='%s'", vnfType, version, packageArtifactID)); } Map<String, String> existingArtifactPayload = licenseService.retrieveLicenseModelData(vnfType, version); @@ -221,7 +220,7 @@ public class DownloadAndStoreOp implements Runnable { new EventHeader((new java.util.Date()).toString(), serviceVersion, distributionID), new EventStatus(401, errorDescription)); - eventSender.sendEvent(DmaapDestination.DCAE, eventMessage); + eventSender.sendEvent(MessageDestination.DCAE, eventMessage); } } diff --git a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/Util.java b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/Util.java index 46efba438..87045b3e5 100644 --- a/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/Util.java +++ b/appc-asdc-listener/appc-asdc-listener-bundle/src/main/java/org/openecomp/appc/sdc/listener/Util.java @@ -20,6 +20,7 @@ */ package org.openecomp.appc.sdc.listener; +import org.openecomp.sdc.utils.DistributionStatusEnum; import org.json.JSONException; import org.json.JSONObject; diff --git a/appc-asdc-listener/appc-asdc-listener-features/src/main/resources/features.xml b/appc-asdc-listener/appc-asdc-listener-features/src/main/resources/features.xml index 0af2a9d70..6780def7c 100644 --- a/appc-asdc-listener/appc-asdc-listener-features/src/main/resources/features.xml +++ b/appc-asdc-listener/appc-asdc-listener-features/src/main/resources/features.xml @@ -31,6 +31,7 @@ <feature name='appc-asdc-listener' description="asdc listener" version='${project.version}'> <!-- Most applications will have a dependency on the ODL MD-SAL Broker --> <feature version="${broker-mdsal.version}">odl-mdsal-broker</feature> + <bundle dependency="true">mvn:org.openecomp.appc/appc-common/${project.version}</bundle> <bundle>mvn:org.openecomp.appc/appc-asdc-listener-bundle/${project.version}</bundle> </feature> diff --git a/appc-asdc-listener/appc-yang-generator/pom.xml b/appc-asdc-listener/appc-yang-generator/pom.xml new file mode 100644 index 000000000..6834bd85d --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/pom.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>appc-asdc-listener</artifactId> + <groupId>org.openecomp.appc</groupId> + <version>1.1.0-SNAPSHOT</version> + </parent> + + <artifactId>appc-yang-generator</artifactId> + <packaging>jar</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>com.att.eelf</groupId> + <artifactId>eelf-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + <version>1.7</version> + </dependency> + <dependency> + <groupId>org.opendaylight.yangtools</groupId> + <artifactId>yang-parser-impl</artifactId> + <version>${odl.yangtools.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-tosca-lib</artifactId> + <version>${toscalib.version}</version> + </dependency> + </dependencies> + + +</project>
\ No newline at end of file diff --git a/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/YANGGenerator.java b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/YANGGenerator.java new file mode 100644 index 000000000..112790d86 --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/YANGGenerator.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.yang; + +import org.openecomp.appc.yang.exception.YANGGenerationException; + +import java.io.OutputStream; + +/** + * The Interface YANGGenerator - provides method to generate YANG file from TOSCA. + */ +public interface YANGGenerator { + + /** + * Generate YANG from TOSCA. + * if any exceptional Type is coming in the input tosca as a part of configuration parameter property, YANGGenerationException will be thrown. + * This API is not supporting below mentioned built-in Types: + * bits, decimal64, enumeration, identityref, leafref, union + * + * @param uniqueID - Set as module name in the yang, mandatory, cannot be null or empty + * @param tosca - TOSCA String from which the YANG is to be generated, mandatory, cannot be null or empty + * @param stream - The outputStream to which the generated yang is written, mandatory, cannot be null + * @throws YANGGenerationException - Thrown when any error occurred during method execution, the origin can be found from ex.getCause() or ex.getMessage() + */ + + void generateYANG(String uniqueID, String tosca, OutputStream stream) throws YANGGenerationException; +} diff --git a/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/exception/YANGGenerationException.java b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/exception/YANGGenerationException.java new file mode 100644 index 000000000..b049e6f21 --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/exception/YANGGenerationException.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.yang.exception; + +/** + * The Class YANGGenerationException. + */ +public class YANGGenerationException extends Exception { + + + /** + * Instantiates a new YANG generation exception. + * + * @param message - the appropriate message + * @param cause -the appropriate cause + */ + public YANGGenerationException(String message,Throwable cause){ + super(message,cause); + } + + + /** + * Instantiates new YANG generation exception + * @param message + */ + public YANGGenerationException(String message){ + super(message); + } +} diff --git a/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/impl/YANGGeneratorFactory.java b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/impl/YANGGeneratorFactory.java new file mode 100644 index 000000000..ca5c0ae7d --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/impl/YANGGeneratorFactory.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.yang.impl; + +import org.openecomp.appc.yang.YANGGenerator; + +/** + * A factory for creating YANGGenerator objects. + */ +public class YANGGeneratorFactory { + + private YANGGeneratorFactory(){} + + private static class InstanceHolder + { + private static YANGGeneratorImpl instance = new YANGGeneratorImpl(); + private InstanceHolder(){} + } + + /** + * Gets the YANG generator. + * + * @return the YANG generator + */ + public static YANGGenerator getYANGGenerator() + { + return InstanceHolder.instance; + } + +} diff --git a/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/impl/YANGGeneratorImpl.java b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/impl/YANGGeneratorImpl.java new file mode 100644 index 000000000..0ca7878a9 --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/impl/YANGGeneratorImpl.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.yang.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; +import org.openecomp.appc.yang.YANGGenerator; +import org.openecomp.appc.yang.exception.YANGGenerationException; +import org.openecomp.appc.yang.objects.Leaf; +import org.openecomp.appc.yang.type.YangTypes; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.services.yamlutil.ToscaExtensionYamlUtil; + +import java.io.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("CheckStyle") +public class YANGGeneratorImpl implements YANGGenerator { + + private static final EELFLogger Log = EELFManager.getInstance().getLogger(YANGGeneratorImpl.class); + private static final String MODULE_TYPE = "moduleType"; + private static final String LEAVES = "leaves"; + + + /* (non-Javadoc) + * @see org.openecomp.appc.yang.YANGGenerator#generateYANG(java.lang.String, java.lang.String, java.io.OutputStream) + */ + @Override + public void generateYANG(String uniqueID, String tosca, OutputStream stream) + throws YANGGenerationException { + Log.info("Entered into generateYANG."); + Log.debug("Received Tosca:\n" + tosca +"\n Received uniqueID: "+uniqueID); + + validateInput(uniqueID, tosca, stream); + Map<String,Object> parsedToscaMap = parseTosca(tosca); + String moduleType =parsedToscaMap.get(MODULE_TYPE).toString(); + List<Leaf> leaves = (List<Leaf>) parsedToscaMap.get(LEAVES); + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + ve.init(); + Template template; + + try { + template = ve.getTemplate("templates/YangTemplate.vm"); + } catch ( ResourceNotFoundException | ParseErrorException ex) { + Log.error("Error while retrieving YANG Template", ex); + throw new YANGGenerationException("Error while retrieving YANG Template",ex); + } + + VelocityContext vc = new VelocityContext(); + + vc.put("moduleName", uniqueID); + vc.put(MODULE_TYPE, moduleType); + vc.put(LEAVES, leaves); + + StringWriter sw = new StringWriter(); + template.merge(vc,sw); + Log.debug("generated YANG \n "+sw.toString()); + try { + String yang = sw.toString(); + validateYang(yang); + stream.write(yang.getBytes()); + stream.flush(); + } catch (IOException e) { + Log.error("Error while writing to outputstream", e); + throw new YANGGenerationException("Error writing to outputstream",e); + } finally { + try { + stream.close(); + } catch (IOException e) { + Log.error("Error while closing outputstream", e); + } + } + Log.info("exiting generateYANG method."); + } + + private void validateYang(String yang) throws YANGGenerationException { + + try(InputStream inputYangStream = new ByteArrayInputStream(yang.getBytes())){ + YangStatementSourceImpl statementSource = new YangStatementSourceImpl(inputYangStream); + if(statementSource.getYangAST()==null){ + throw new YANGGenerationException("Syntax Error in Generated YANG = " + yang); + } + } + catch(IOException e){ + Log.error("Error validating yang file "+ yang,e); + throw new YANGGenerationException("Invalid YANG generated",e); + } + } + + private Map<String,Object> parseTosca(String tosca) throws YANGGenerationException { + Log.info("Entered into parseTosca."); + ServiceTemplate serviceTemplate = new ToscaExtensionYamlUtil().yamlToObject(tosca, ServiceTemplate.class); + Map<String, NodeType> nodeTypeMap = serviceTemplate.getNode_types(); + String kind = nodeTypeMap.keySet().toArray(new String[0])[0]; + NodeType nodeType = nodeTypeMap.get(kind); + Map<String,Object> returnMap= new HashMap<>(); + Map<String, PropertyDefinition> propertyDefinitionFromTOSCA = nodeType.getProperties(); + returnMap.put(MODULE_TYPE, kind); + List<Leaf> leaves = new LinkedList<>(); + + for(Map.Entry<String, PropertyDefinition> entry: propertyDefinitionFromTOSCA.entrySet()){ + Leaf leaf = new Leaf(); + leaf.setName(entry.getKey()); + PropertyDefinition pd = entry.getValue(); + Map<String,String> typeMap=YangTypes.getYangTypeMap(); + if (typeMap.containsKey(pd.getType())) { + String paramType = typeMap.get(pd.getType()); + leaf.setType(paramType); + leaf.setDescription(!StringUtils.isEmpty(pd.getDescription()) ? pd.getDescription() : ""); + leaf.setMandatory((pd.getRequired() != null) ? Boolean.toString(pd.getRequired()) : Boolean.toString(false)); + leaf.setDefaultValue((pd.get_default() != null) ? pd.get_default().toString(): ""); + leaves.add(leaf); + } else { + YANGGenerationException yangGenerationException = new YANGGenerationException(pd.getType() + " Type is not supported ", null); + Log.error(pd.getType() + " Type is not supported ", yangGenerationException); + throw yangGenerationException; + } + } + returnMap.put(LEAVES, leaves); + Log.info("exiting parseTosca method with return MAP "+returnMap); + return returnMap; + } + + private void validateInput(String uniqueID, String tosca, OutputStream stream) throws YANGGenerationException { + Log.info("Entered into validateInput."); + if(StringUtils.isEmpty(uniqueID)) { + throw new YANGGenerationException("uniqueID is mandatory, cannot be null or empty.",null); + } + if(StringUtils.isEmpty(tosca)) { + throw new YANGGenerationException("tosca is mandatory, cannot be null or empty.",null); + } + if(stream == null){ + throw new YANGGenerationException("stream is mandatory, cannot be null.",null); + } + Log.info("exiting validateInput method."); + } + +} diff --git a/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/objects/Leaf.java b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/objects/Leaf.java new file mode 100644 index 000000000..d7f328db1 --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/objects/Leaf.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.yang.objects; + +public class Leaf { + private String name; + private String type; + private String description; + private String mandatory; + private String defaultValue; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getMandatory() { + return mandatory; + } + public void setMandatory(String mandatory) { + this.mandatory = mandatory; + } + public String getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + @Override + public String toString() { + return "Leaf [name=" + name + ", type=" + type + ", description=" + description + ", mandatory=" + mandatory + + ", defaultValue=" + defaultValue + "]"; + } + + + +} diff --git a/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/type/YangTypes.java b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/type/YangTypes.java new file mode 100644 index 000000000..3e818623d --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/java/org/openecomp/appc/yang/type/YangTypes.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.yang.type; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class YangTypes { + + private static final Map<String, String> yangTypeMap; + private YangTypes(){} + static { + Map<String, String> typeMap = new HashMap<>(); + + /* standard Types */ + /* typeMap.put("bits","bits"); + typeMap.put("leafref","leafref"); + typeMap.put("decimal64","decimal64"); + typeMap.put("enumeration","enumeration"); + typeMap.put("identityref","identityref"); + typeMap.put("union","union");*/ + typeMap.put("binary","binary"); + typeMap.put("boolean","boolean"); + typeMap.put("empty","empty"); + typeMap.put("instance-identifier","instance-identifier"); + typeMap.put("int8","int8"); + typeMap.put("int16","int16"); + typeMap.put("int32","int32"); + typeMap.put("int64","int64"); + typeMap.put("string","string"); + typeMap.put("uint8","uint8"); + typeMap.put("uint16","uint16"); + typeMap.put("uint32","uint32"); + typeMap.put("uint64","uint64"); + + + /* ietf-yang-types */ + + typeMap.put("counter32","yang:counter32"); + typeMap.put("zero-based-counter32","yang:zero-based-counter32"); + typeMap.put("counter64","yang:counter64"); + typeMap.put("zero-based-counter64","yang:zero-based-counter64"); + typeMap.put("gauge32","yang:gauge32"); + typeMap.put("gauge64","yang:gauge64"); + typeMap.put("object-identifier","yang:object-identifier"); + typeMap.put("object-identifier-128","yang:object-identifier-128"); + typeMap.put("yang-identifier","yang:yang-identifier"); + typeMap.put("date-and-time","yang:date-and-time"); + typeMap.put("timeticks","yang:timeticks"); + typeMap.put("timestamp","yang:timestamp"); + typeMap.put("phys-address","yang:phys-address"); + typeMap.put("mac-address","yang:mac-address"); + typeMap.put("xpath1.0","yang:xpath1.0"); + typeMap.put("hex-string","yang:hex-string"); + typeMap.put("uuid","yang:uuid"); + typeMap.put("dotted-quad","yang:dotted-quad"); + + /* ietf-inet-types */ + + typeMap.put("ip-version","inet:ip-version"); + typeMap.put("dscp","inet:dscp"); + typeMap.put("ipv6-flow-label","inet:ipv6-flow-label"); + typeMap.put("port-number","inet:port-number"); + typeMap.put("as-number","inet:as-number"); + typeMap.put("ip-address","inet:ip-address"); + typeMap.put("ipv4-address","inet:ipv4-address"); + typeMap.put("ipv6-address","inet:ipv6-address"); + typeMap.put("ip-address-no-zone","inet:ip-address-no-zone"); + typeMap.put("ipv4-address-no-zone","inet:ipv4-address-no-zone"); + typeMap.put("ipv6-address-no-zone","inet:ipv6-address-no-zone"); + typeMap.put("ip-prefix","inet:ip-prefix"); + typeMap.put("ipv4-prefix","inet:ipv4-prefix"); + typeMap.put("ipv6-prefix","inet:ipv6-prefix"); + typeMap.put("domain-name","inet:domain-name"); + typeMap.put("host","inet:host"); + typeMap.put("uri","inet:uri"); + + yangTypeMap = Collections.unmodifiableMap(typeMap); + } + + public static Map<String, String> getYangTypeMap(){ + return yangTypeMap; + } + +} diff --git a/appc-asdc-listener/appc-yang-generator/src/main/resources/templates/YangTemplate.vm b/appc-asdc-listener/appc-yang-generator/src/main/resources/templates/YangTemplate.vm new file mode 100644 index 000000000..ab608c5e1 --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/main/resources/templates/YangTemplate.vm @@ -0,0 +1,47 @@ +module $moduleName { + yang-version 1; + namespace "org:openecomp:appc:vnf:$moduleName"; + prefix appc-vnf; + organization "Copyright 2017 AT&T Intellectual Property."; + + description + "$moduleType description"; + + revision "2017-01-01" { + description + "$moduleName Configuration"; + } + + import ietf-inet-types { + prefix inet; + } + + import ietf-yang-types { + prefix yang; + } + + grouping vnf-config-grp { + container vnf-config { + #foreach( $data in $leaves ) + leaf $data.getName() { + type $data.getType(); + description "$data.getDescription()"; + mandatory $data.getMandatory(); + default "$data.getDefaultValue()"; + } + #end +} + } + + container vnf-config-repo { + list vnf-config-list { + key "vnf-identifier"; + leaf vnf-identifier { + type string; + } + uses vnf-config-grp; + } + + } + +} diff --git a/appc-asdc-listener/appc-yang-generator/src/test/java/org/openecomp/appc/TestYANGGenerator.java b/appc-asdc-listener/appc-yang-generator/src/test/java/org/openecomp/appc/TestYANGGenerator.java new file mode 100644 index 000000000..398a8587b --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/test/java/org/openecomp/appc/TestYANGGenerator.java @@ -0,0 +1,194 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc; + +import org.junit.*; +import org.junit.rules.TemporaryFolder; +import org.openecomp.appc.yang.YANGGenerator; +import org.openecomp.appc.yang.exception.YANGGenerationException; +import org.openecomp.appc.yang.impl.YANGGeneratorFactory; + +import java.io.*; + +/** + * The Class TestYANGGenerator - Junit Test Class for all related test cases. + */ +@Ignore +public class TestYANGGenerator { + + private YANGGenerator yangGenerator = YANGGeneratorFactory.getYANGGenerator(); + private static String tosca; + private static String toscaWithSyntaxError; + private static String expectedYang; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + /** + * Run before test method. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + @Before + public void runBeforeTestMethod() throws IOException { + tosca= getFileContent("tosca/toscaFile.yml"); + toscaWithSyntaxError = getFileContent("tosca/toscaFileWithSyntaxError.yml"); + expectedYang = getFileContent("yang/expectedYang.yang"); + } + + /** + * Test YANG generator for success. + * + * @throws IOException Signals that an I/O exception has occurred. + * @throws YANGGenerationException the YANG generation exception + */ + @Test + public void TestYANGGeneratorForSuccess() throws IOException, YANGGenerationException { + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + Assert.assertNotNull(tosca); + Assert.assertFalse("tosca file is emply or blank", tosca.equals("")); + yangGenerator.generateYANG("ATD456", tosca, out); + out.flush(); + out.close(); + String generatedYang = getFileContent(tempFile); + Assert.assertEquals(expectedYang,generatedYang); + } + + @Test(expected = YANGGenerationException.class) + public void testYangGenerationForSyntaxError() throws IOException, YANGGenerationException { + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + yangGenerator.generateYANG("ATD456",toscaWithSyntaxError,out); + } + + + /** + * Test for Yang Generator which generates YANG that is not matching with expected YANG. + * + * @throws IOException Signals that an I/O exception has occurred. + * @throws YANGGenerationException - the YANG generation exception + */ + @Test + public void unmatchedYangGenerationTest() throws IOException, YANGGenerationException { + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + yangGenerator.generateYANG("112476", tosca, out); + out.flush(); + out.close(); + String generatedYang = getFileContent(tempFile); + Assert.assertNotSame(expectedYang, generatedYang); + + } + + /** + * Yang generation test for empty tosca input. + * + * @throws YANGGenerationException the YANG generation exception + */ + @Test(expected = YANGGenerationException.class) + public void YangGenerationTestForEmptyUniqueIDInput() throws IOException, YANGGenerationException { +// OutputStream out = new FileOutputStream(classLoader.getResource("yang/generatedYang.yang").getFile()); + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + yangGenerator.generateYANG("", tosca, out); + } + + /** + * Yang generation test for empty tosca input. + * + * @throws YANGGenerationException the YANG generation exception + */ + @Test(expected = YANGGenerationException.class) + public void YangGenerationTestForUnSupportedType() throws IOException, YANGGenerationException { + tosca= getFileContent("tosca/toscaFileWithUnsupportedTypes.yml"); + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + yangGenerator.generateYANG("", tosca, out); + } + + /** + * Yang generation test for empty tosca input. + * + * @throws YANGGenerationException the YANG generation exception + */ + @Test(expected = YANGGenerationException.class) + public void YangGenerationTestForEmptyToscaInput() throws IOException, YANGGenerationException { + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + yangGenerator.generateYANG("1111", "", out); + } + + /** + * YANG generation test with invalid method arguments. + * + * @throws YANGGenerationException the YANG generation exception + */ + @Test(expected = YANGGenerationException.class) + public void YANGGenerationTestWithInvalidMethodArguments() throws YANGGenerationException { + yangGenerator.generateYANG("112476", "ToscaSAMPLE", null); + } + + @Test(expected = YANGGenerationException.class) + public void YANGGenerationTestWithIOException() throws IOException, YANGGenerationException { + File tempFile = temporaryFolder.newFile("generatedYang.yang"); + OutputStream out = new FileOutputStream(tempFile); + out.flush(); + out.close(); + yangGenerator.generateYANG("1111", tosca, out); + } + + + private String getFileContent(String fileName) throws IOException + { + ClassLoader classLoader = new TestYANGGenerator().getClass().getClassLoader(); + InputStream is = new FileInputStream(classLoader.getResource(fileName).getFile()); + BufferedReader buf = new BufferedReader(new InputStreamReader(is)); + String line = buf.readLine(); + StringBuilder sb = new StringBuilder(); + + while (line != null) { + sb.append(line).append("\n"); + line = buf.readLine(); + } + String fileString = sb.toString(); + is.close(); + return fileString; + } + + private String getFileContent(File file) throws IOException + { + InputStream is = new FileInputStream(file); + BufferedReader buf = new BufferedReader(new InputStreamReader(is)); + String line = buf.readLine(); + StringBuilder sb = new StringBuilder(); + + while (line != null) { + sb.append(line).append("\n"); + line = buf.readLine(); + } + String fileString = sb.toString(); + is.close(); + return fileString; + } + +} diff --git a/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFile.yml b/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFile.yml new file mode 100644 index 000000000..22a29b69b --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFile.yml @@ -0,0 +1,295 @@ +node_types: + Property Definition: + derived_from: org.openecomp.genericvnf + version: V1 + description: '' + properties: + param1: + type: domain-name + description: param1 desc + required: true + default: param1 def val + status: SUPPORTED + param2: + type: ipv4-address-no-zone + description: param2 desc + required: true + default: param2 def val + status: SUPPORTED + param3: + type: instance-identifier + description: param3 desc + required: true + default: param3 def val + status: SUPPORTED + param4: + type: uuid + description: param4 desc + required: true + default: param4 def val + status: SUPPORTED + param5: + type: empty + description: param5 desc + required: true + default: param5 def val + status: SUPPORTED + param6: + type: object-identifier-128 + description: param6 desc + required: true + default: param6 def val + status: SUPPORTED + param7: + type: dscp + description: param7 desc + required: true + default: param7 def val + status: SUPPORTED + param8: + type: int64 + description: param8 desc + required: true + default: param8 def val + status: SUPPORTED + param9: + type: zero-based-counter64 + description: param9 desc + required: true + default: param9 def val + status: SUPPORTED + param10: + type: int8 + description: param10 desc + required: true + default: param10 def val + status: SUPPORTED + param11: + type: host + description: param11 desc + required: true + default: param11 def val + status: SUPPORTED + param12: + type: uint32 + description: param12 desc + required: true + default: param12 def val + status: SUPPORTED + param13: + type: timeticks + description: param13 desc + required: true + default: param13 def val + status: SUPPORTED + param15: + type: mac-address + description: param15 desc + required: true + default: param15 def val + status: SUPPORTED + param16: + type: as-number + description: param16 desc + required: true + default: param16 def val + status: SUPPORTED + param17: + type: counter64 + description: param17 desc + required: true + default: param17 def val + status: SUPPORTED + param19: + type: xpath1.0 + description: param19 desc + required: true + default: param19 def val + status: SUPPORTED + param20: + type: ip-version + description: param20 desc + required: true + default: param20 def val + status: SUPPORTED + param21: + type: port-number + description: param21 desc + required: true + default: param21 def val + status: SUPPORTED + param22: + type: int16 + description: param22 desc + required: true + default: param22 def val + status: SUPPORTED + param23: + type: ipv6-address-no-zone + description: param23 desc + required: true + default: param23 def val + status: SUPPORTED + param24: + type: hex-string + description: param24 desc + required: true + default: param24 def val + status: SUPPORTED + param26: + type: uint64 + description: param26 desc + required: true + default: param26 def val + status: SUPPORTED + param27: + type: uint8 + description: param27 desc + required: true + default: param27 def val + status: SUPPORTED + param28: + type: ipv4-prefix + description: param28 desc + required: true + default: param28 def val + status: SUPPORTED + param29: + type: ipv6-prefix + description: param29 desc + required: true + default: param29 def val + status: SUPPORTED + param30: + type: gauge64 + description: param30 desc + required: true + default: param30 def val + status: SUPPORTED + param31: + type: counter32 + description: param31 desc + required: true + default: param31 def val + status: SUPPORTED + param32: + type: string + description: param32 desc + required: true + default: param32 def val + status: SUPPORTED + param33: + type: object-identifier + description: param33 desc + required: true + default: param33 def val + status: SUPPORTED + param34: + type: ip-address-no-zone + description: param34 desc + required: true + default: param34 def val + status: SUPPORTED + param36: + type: gauge32 + description: param36 desc + required: true + default: param36 def val + status: SUPPORTED + param37: + type: ipv4-address + description: param37 desc + required: true + default: param37 def val + status: SUPPORTED + param38: + type: ip-prefix + description: param38 desc + required: true + default: param38 def val + status: SUPPORTED + param39: + type: uint16 + description: param39 desc + required: true + default: param39 def val + status: SUPPORTED + param40: + type: timestamp + description: param40 desc + required: true + default: param40 def val + status: SUPPORTED + param42: + type: dotted-quad + description: param42 desc + required: true + default: param42 def val + status: SUPPORTED + param43: + type: uri + description: param43 desc + required: true + default: param43 def val + status: SUPPORTED + param44: + type: ipv6-address + description: param44 desc + required: true + default: param44 def val + status: SUPPORTED + param45: + type: ipv6-flow-label + description: param45 desc + required: true + default: param45 def val + status: SUPPORTED + param46: + type: zero-based-counter32 + description: param46 desc + required: true + default: param46 def val + status: SUPPORTED + param47: + type: ip-address + description: param47 desc + required: true + default: param47 def val + status: SUPPORTED + param48: + type: boolean + description: param48 desc + required: true + default: param48 def val + status: SUPPORTED + param50: + type: yang-identifier + description: param50 desc + required: true + default: param50 def val + status: SUPPORTED + param51: + type: int32 + description: param51 desc + required: true + default: param51 def val + status: SUPPORTED + param52: + type: date-and-time + description: param52 desc + required: true + default: param52 def val + status: SUPPORTED + param53: + type: phys-address + description: param53 desc + required: true + default: param53 def val + status: SUPPORTED +topology_template: + node_templates: + Property Definition_Template: + type: Property Definition + properties: + param 1: <rule-type:rule1> <resk1:resk2 , resk2:resv2 , resk3:resv3> param1 source <reqk1:reqv1 , reqk2:reqv2 , reqk3:reqv3> + param 2: <rule-type:rule2> <resk1:resk2 , resk2:resv2> param2 source <reqk1:reqv1 , reqk2:reqv2 , reqk3:reqv3> diff --git a/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFileWithSyntaxError.yml b/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFileWithSyntaxError.yml new file mode 100644 index 000000000..61c0af5c8 --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFileWithSyntaxError.yml @@ -0,0 +1,295 @@ +node_types: + Property Definition: + derived_from: org.openecomp.genericvnf + version: V1 + description: '' + properties: + param 1: + type: domain-name + description: param1 desc + required: true + default: param1 def val + status: SUPPORTED + param2: + type: ipv4-address-no-zone + description: param2 desc + required: true + default: param2 def val + status: SUPPORTED + param3: + type: instance-identifier + description: param3 desc + required: true + default: param3 def val + status: SUPPORTED + param4: + type: uuid + description: param4 desc + required: true + default: param4 def val + status: SUPPORTED + param5: + type: empty + description: param5 desc + required: true + default: param5 def val + status: SUPPORTED + param6: + type: object-identifier-128 + description: param6 desc + required: true + default: param6 def val + status: SUPPORTED + param7: + type: dscp + description: param7 desc + required: true + default: param7 def val + status: SUPPORTED + param8: + type: int64 + description: param8 desc + required: true + default: param8 def val + status: SUPPORTED + param9: + type: zero-based-counter64 + description: param9 desc + required: true + default: param9 def val + status: SUPPORTED + param10: + type: int8 + description: param10 desc + required: true + default: param10 def val + status: SUPPORTED + param11: + type: host + description: param11 desc + required: true + default: param11 def val + status: SUPPORTED + param12: + type: uint32 + description: param12 desc + required: true + default: param12 def val + status: SUPPORTED + param13: + type: timeticks + description: param13 desc + required: true + default: param13 def val + status: SUPPORTED + param15: + type: mac-address + description: param15 desc + required: true + default: param15 def val + status: SUPPORTED + param16: + type: as-number + description: param16 desc + required: true + default: param16 def val + status: SUPPORTED + param17: + type: counter64 + description: param17 desc + required: true + default: param17 def val + status: SUPPORTED + param19: + type: xpath1.0 + description: param19 desc + required: true + default: param19 def val + status: SUPPORTED + param20: + type: ip-version + description: param20 desc + required: true + default: param20 def val + status: SUPPORTED + param21: + type: port-number + description: param21 desc + required: true + default: param21 def val + status: SUPPORTED + param22: + type: int16 + description: param22 desc + required: true + default: param22 def val + status: SUPPORTED + param23: + type: ipv6-address-no-zone + description: param23 desc + required: true + default: param23 def val + status: SUPPORTED + param24: + type: hex-string + description: param24 desc + required: true + default: param24 def val + status: SUPPORTED + param26: + type: uint64 + description: param26 desc + required: true + default: param26 def val + status: SUPPORTED + param27: + type: uint8 + description: param27 desc + required: true + default: param27 def val + status: SUPPORTED + param28: + type: ipv4-prefix + description: param28 desc + required: true + default: param28 def val + status: SUPPORTED + param29: + type: ipv6-prefix + description: param29 desc + required: true + default: param29 def val + status: SUPPORTED + param30: + type: gauge64 + description: param30 desc + required: true + default: param30 def val + status: SUPPORTED + param31: + type: counter32 + description: param31 desc + required: true + default: param31 def val + status: SUPPORTED + param32: + type: string + description: param32 desc + required: true + default: param32 def val + status: SUPPORTED + param33: + type: object-identifier + description: param33 desc + required: true + default: param33 def val + status: SUPPORTED + param34: + type: ip-address-no-zone + description: param34 desc + required: true + default: param34 def val + status: SUPPORTED + param36: + type: gauge32 + description: param36 desc + required: true + default: param36 def val + status: SUPPORTED + param37: + type: ipv4-address + description: param37 desc + required: true + default: param37 def val + status: SUPPORTED + param38: + type: ip-prefix + description: param38 desc + required: true + default: param38 def val + status: SUPPORTED + param39: + type: uint16 + description: param39 desc + required: true + default: param39 def val + status: SUPPORTED + param40: + type: timestamp + description: param40 desc + required: true + default: param40 def val + status: SUPPORTED + param42: + type: dotted-quad + description: param42 desc + required: true + default: param42 def val + status: SUPPORTED + param43: + type: uri + description: param43 desc + required: true + default: param43 def val + status: SUPPORTED + param44: + type: ipv6-address + description: param44 desc + required: true + default: param44 def val + status: SUPPORTED + param45: + type: ipv6-flow-label + description: param45 desc + required: true + default: param45 def val + status: SUPPORTED + param46: + type: zero-based-counter32 + description: param46 desc + required: true + default: param46 def val + status: SUPPORTED + param47: + type: ip-address + description: param47 desc + required: true + default: param47 def val + status: SUPPORTED + param48: + type: boolean + description: param48 desc + required: true + default: param48 def val + status: SUPPORTED + param50: + type: yang-identifier + description: param50 desc + required: true + default: param50 def val + status: SUPPORTED + param51: + type: int32 + description: param51 desc + required: true + default: param51 def val + status: SUPPORTED + param52: + type: date-and-time + description: param52 desc + required: true + default: param52 def val + status: SUPPORTED + param53: + type: phys-address + description: param53 desc + required: true + default: param53 def val + status: SUPPORTED +topology_template: + node_templates: + Property Definition_Template: + type: Property Definition + properties: + param 1: <rule-type:rule1> <resk1:resk2 , resk2:resv2 , resk3:resv3> param1 source <reqk1:reqv1 , reqk2:reqv2 , reqk3:reqv3> + param 2: <rule-type:rule2> <resk1:resk2 , resk2:resv2> param2 source <reqk1:reqv1 , reqk2:reqv2 , reqk3:reqv3> diff --git a/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFileWithUnsupportedTypes.yml b/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFileWithUnsupportedTypes.yml new file mode 100644 index 000000000..7f27a018f --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/test/resources/tosca/toscaFileWithUnsupportedTypes.yml @@ -0,0 +1,349 @@ +node_types: + Property Definition: + derived_from: org.openecomp.genericvnf + version: V1 + description: '' + properties: + param1: + type: domain-name + description: param1 desc + required: true + default: param1 def val + status: SUPPORTED + param2: + type: ipv4-address-no-zone + description: param2 desc + required: true + default: param2 def val + status: SUPPORTED + param3: + type: instance-identifier + description: param3 desc + required: true + default: param3 def val + status: SUPPORTED + param4: + type: uuid + description: param4 desc + required: true + default: param4 def val + status: SUPPORTED + param5: + type: empty + description: param5 desc + required: true + default: param5 def val + status: SUPPORTED + param6: + type: object-identifier-128 + description: param6 desc + required: true + default: param6 def val + status: SUPPORTED + param7: + type: dscp + description: param7 desc + required: true + default: param7 def val + status: SUPPORTED + param8: + type: int64 + description: param8 desc + required: true + default: param8 def val + status: SUPPORTED + param9: + type: zero-based-counter64 + description: param9 desc + required: true + default: param9 def val + status: SUPPORTED + param10: + type: int8 + description: param10 desc + required: true + default: param10 def val + status: SUPPORTED + param11: + type: host + description: param11 desc + required: true + default: param11 def val + status: SUPPORTED + param12: + type: uint32 + description: param12 desc + required: true + default: param12 def val + status: SUPPORTED + param13: + type: timeticks + description: param13 desc + required: true + default: param13 def val + status: SUPPORTED + param14: + type: enumeration + description: param14 desc + required: true + default: param14 def val + status: SUPPORTED + param15: + type: mac-address + description: param15 desc + required: true + default: param15 def val + status: SUPPORTED + param16: + type: as-number + description: param16 desc + required: true + default: param16 def val + status: SUPPORTED + param17: + type: counter64 + description: param17 desc + required: true + default: param17 def val + status: SUPPORTED + param18: + type: bits + description: param18 desc + required: true + default: param18 def val + status: SUPPORTED + param19: + type: xpath1.0 + description: param19 desc + required: true + default: param19 def val + status: SUPPORTED + param20: + type: ip-version + description: param20 desc + required: true + default: param20 def val + status: SUPPORTED + param21: + type: port-number + description: param21 desc + required: true + default: param21 def val + status: SUPPORTED + param22: + type: int16 + description: param22 desc + required: true + default: param22 def val + status: SUPPORTED + param23: + type: ipv6-address-no-zone + description: param23 desc + required: true + default: param23 def val + status: SUPPORTED + param24: + type: hex-string + description: param24 desc + required: true + default: param24 def val + status: SUPPORTED + param25: + type: decimal64 + description: param25 desc + required: true + default: param25 def val + status: SUPPORTED + param26: + type: uint64 + description: param26 desc + required: true + default: param26 def val + status: SUPPORTED + param27: + type: uint8 + description: param27 desc + required: true + default: param27 def val + status: SUPPORTED + param28: + type: ipv4-prefix + description: param28 desc + required: true + default: param28 def val + status: SUPPORTED + param29: + type: ipv6-prefix + description: param29 desc + required: true + default: param29 def val + status: SUPPORTED + param30: + type: gauge64 + description: param30 desc + required: true + default: param30 def val + status: SUPPORTED + param31: + type: counter32 + description: param31 desc + required: true + default: param31 def val + status: SUPPORTED + param32: + type: string + description: param32 desc + required: true + default: param32 def val + status: SUPPORTED + param33: + type: object-identifier + description: param33 desc + required: true + default: param33 def val + status: SUPPORTED + param34: + type: ip-address-no-zone + description: param34 desc + required: true + default: param34 def val + status: SUPPORTED + param35: + type: identityref + description: param35 desc + required: true + default: param35 def val + status: SUPPORTED + param36: + type: gauge32 + description: param36 desc + required: true + default: param36 def val + status: SUPPORTED + param37: + type: ipv4-address + description: param37 desc + required: true + default: param37 def val + status: SUPPORTED + param38: + type: ip-prefix + description: param38 desc + required: true + default: param38 def val + status: SUPPORTED + param39: + type: uint16 + description: param39 desc + required: true + default: param39 def val + status: SUPPORTED + param40: + type: timestamp + description: param40 desc + required: true + default: param40 def val + status: SUPPORTED + param41: + type: union + description: param41 desc + required: true + default: param41 def val + status: SUPPORTED + param42: + type: dotted-quad + description: param42 desc + required: true + default: param42 def val + status: SUPPORTED + param43: + type: uri + description: param43 desc + required: true + default: param43 def val + status: SUPPORTED + param44: + type: ipv6-address + description: param44 desc + required: true + default: param44 def val + status: SUPPORTED + param45: + type: ipv6-flow-label + description: param45 desc + required: true + default: param45 def val + status: SUPPORTED + param46: + type: zero-based-counter32 + description: param46 desc + required: true + default: param46 def val + status: SUPPORTED + param47: + type: ip-address + description: param47 desc + required: true + default: param47 def val + status: SUPPORTED + param48: + type: boolean + description: param48 desc + required: true + default: param48 def val + status: SUPPORTED + param49: + type: leafref + description: param49 desc + required: true + default: param49 def val + status: SUPPORTED + param50: + type: yang-identifier + description: param50 desc + required: true + default: param50 def val + status: SUPPORTED + param51: + type: int32 + description: param51 desc + required: true + default: param51 def val + status: SUPPORTED + param52: + type: date-and-time + description: param52 desc + required: true + default: param52 def val + status: SUPPORTED + param53: + type: phys-address + description: param53 desc + required: true + default: param53 def val + status: SUPPORTED + param54: + type: phys-add + description: param54 desc + required: true + default: param54 def val + status: SUPPORTED + param55: + type: null + description: param55 desc + required: true + default: param55 def val + status: SUPPORTED + param56: + type: + description: param56 desc + required: true + default: param56 def val + status: SUPPORTED +topology_template: + node_templates: + Property Definition_Template: + type: Property Definition + properties: + param 1: <rule-type:rule1> <resk1:resk2 , resk2:resv2 , resk3:resv3> param1 source <reqk1:reqv1 , reqk2:reqv2 , reqk3:reqv3> + param 2: <rule-type:rule2> <resk1:resk2 , resk2:resv2> param2 source <reqk1:reqv1 , reqk2:reqv2 , reqk3:reqv3> diff --git a/appc-asdc-listener/appc-yang-generator/src/test/resources/yang/expectedYang.yang b/appc-asdc-listener/appc-yang-generator/src/test/resources/yang/expectedYang.yang new file mode 100644 index 000000000..3515ce69b --- /dev/null +++ b/appc-asdc-listener/appc-yang-generator/src/test/resources/yang/expectedYang.yang @@ -0,0 +1,321 @@ +module ATD456 { + yang-version 1; + namespace "org:openecomp:appc:vnf:ATD456"; + prefix appc-vnf; + organization "Copyright 2017 AT&T Intellectual Property."; + + description + "Property Definition description"; + + revision "2017-01-01" { + description + "ATD456 Configuration"; + } + + import ietf-inet-types { + prefix inet; + } + + import ietf-yang-types { + prefix yang; + } + + grouping vnf-config-grp { + container vnf-config { + leaf param1 { + type inet:domain-name; + description "param1 desc"; + mandatory true; + default "param1 def val"; + } + leaf param2 { + type inet:ipv4-address-no-zone; + description "param2 desc"; + mandatory true; + default "param2 def val"; + } + leaf param3 { + type instance-identifier; + description "param3 desc"; + mandatory true; + default "param3 def val"; + } + leaf param4 { + type yang:uuid; + description "param4 desc"; + mandatory true; + default "param4 def val"; + } + leaf param5 { + type empty; + description "param5 desc"; + mandatory true; + default "param5 def val"; + } + leaf param6 { + type yang:object-identifier-128; + description "param6 desc"; + mandatory true; + default "param6 def val"; + } + leaf param7 { + type inet:dscp; + description "param7 desc"; + mandatory true; + default "param7 def val"; + } + leaf param8 { + type int64; + description "param8 desc"; + mandatory true; + default "param8 def val"; + } + leaf param9 { + type yang:zero-based-counter64; + description "param9 desc"; + mandatory true; + default "param9 def val"; + } + leaf param10 { + type int8; + description "param10 desc"; + mandatory true; + default "param10 def val"; + } + leaf param11 { + type inet:host; + description "param11 desc"; + mandatory true; + default "param11 def val"; + } + leaf param12 { + type uint32; + description "param12 desc"; + mandatory true; + default "param12 def val"; + } + leaf param13 { + type yang:timeticks; + description "param13 desc"; + mandatory true; + default "param13 def val"; + } + leaf param15 { + type yang:mac-address; + description "param15 desc"; + mandatory true; + default "param15 def val"; + } + leaf param16 { + type inet:as-number; + description "param16 desc"; + mandatory true; + default "param16 def val"; + } + leaf param17 { + type yang:counter64; + description "param17 desc"; + mandatory true; + default "param17 def val"; + } + leaf param19 { + type yang:xpath1.0; + description "param19 desc"; + mandatory true; + default "param19 def val"; + } + leaf param20 { + type inet:ip-version; + description "param20 desc"; + mandatory true; + default "param20 def val"; + } + leaf param21 { + type inet:port-number; + description "param21 desc"; + mandatory true; + default "param21 def val"; + } + leaf param22 { + type int16; + description "param22 desc"; + mandatory true; + default "param22 def val"; + } + leaf param23 { + type inet:ipv6-address-no-zone; + description "param23 desc"; + mandatory true; + default "param23 def val"; + } + leaf param24 { + type yang:hex-string; + description "param24 desc"; + mandatory true; + default "param24 def val"; + } + leaf param26 { + type uint64; + description "param26 desc"; + mandatory true; + default "param26 def val"; + } + leaf param27 { + type uint8; + description "param27 desc"; + mandatory true; + default "param27 def val"; + } + leaf param28 { + type inet:ipv4-prefix; + description "param28 desc"; + mandatory true; + default "param28 def val"; + } + leaf param29 { + type inet:ipv6-prefix; + description "param29 desc"; + mandatory true; + default "param29 def val"; + } + leaf param30 { + type yang:gauge64; + description "param30 desc"; + mandatory true; + default "param30 def val"; + } + leaf param31 { + type yang:counter32; + description "param31 desc"; + mandatory true; + default "param31 def val"; + } + leaf param32 { + type string; + description "param32 desc"; + mandatory true; + default "param32 def val"; + } + leaf param33 { + type yang:object-identifier; + description "param33 desc"; + mandatory true; + default "param33 def val"; + } + leaf param34 { + type inet:ip-address-no-zone; + description "param34 desc"; + mandatory true; + default "param34 def val"; + } + leaf param36 { + type yang:gauge32; + description "param36 desc"; + mandatory true; + default "param36 def val"; + } + leaf param37 { + type inet:ipv4-address; + description "param37 desc"; + mandatory true; + default "param37 def val"; + } + leaf param38 { + type inet:ip-prefix; + description "param38 desc"; + mandatory true; + default "param38 def val"; + } + leaf param39 { + type uint16; + description "param39 desc"; + mandatory true; + default "param39 def val"; + } + leaf param40 { + type yang:timestamp; + description "param40 desc"; + mandatory true; + default "param40 def val"; + } + leaf param42 { + type yang:dotted-quad; + description "param42 desc"; + mandatory true; + default "param42 def val"; + } + leaf param43 { + type inet:uri; + description "param43 desc"; + mandatory true; + default "param43 def val"; + } + leaf param44 { + type inet:ipv6-address; + description "param44 desc"; + mandatory true; + default "param44 def val"; + } + leaf param45 { + type inet:ipv6-flow-label; + description "param45 desc"; + mandatory true; + default "param45 def val"; + } + leaf param46 { + type yang:zero-based-counter32; + description "param46 desc"; + mandatory true; + default "param46 def val"; + } + leaf param47 { + type inet:ip-address; + description "param47 desc"; + mandatory true; + default "param47 def val"; + } + leaf param48 { + type boolean; + description "param48 desc"; + mandatory true; + default "param48 def val"; + } + leaf param50 { + type yang:yang-identifier; + description "param50 desc"; + mandatory true; + default "param50 def val"; + } + leaf param51 { + type int32; + description "param51 desc"; + mandatory true; + default "param51 def val"; + } + leaf param52 { + type yang:date-and-time; + description "param52 desc"; + mandatory true; + default "param52 def val"; + } + leaf param53 { + type yang:phys-address; + description "param53 desc"; + mandatory true; + default "param53 def val"; + } + } + } + + container vnf-config-repo { + list vnf-config-list { + key "vnf-identifier"; + leaf vnf-identifier { + type string; + } + uses vnf-config-grp; + } + + } + +} diff --git a/appc-asdc-listener/pom.xml b/appc-asdc-listener/pom.xml index 18179f552..23b6e86f7 100644 --- a/appc-asdc-listener/pom.xml +++ b/appc-asdc-listener/pom.xml @@ -98,6 +98,7 @@ </reporting> <modules> + <module>appc-yang-generator</module> <module>appc-asdc-listener-bundle</module> <module>appc-asdc-listener-features</module> <module>appc-asdc-listener-installer</module> |