aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/ajsc/babel_v1/babel/v1/conf/coreBeans.groovy9
-rw-r--r--src/main/ajsc/babel_v1/babel/v1/routes/coreServices.route4
-rw-r--r--src/main/bin/start.sh24
-rw-r--r--src/main/java/org/onap/aai/auth/AAIAuthException.java25
-rw-r--r--src/main/java/org/onap/aai/auth/AAIMicroServiceAuth.java11
-rw-r--r--src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java18
-rw-r--r--src/main/java/org/onap/aai/auth/FileWatcher.java14
-rw-r--r--src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java39
-rw-r--r--src/main/java/org/onap/aai/babel/csar/CsarConverterException.java6
-rw-r--r--src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java27
-rw-r--r--src/main/java/org/onap/aai/babel/csar/extractor/InvalidArchiveException.java10
-rw-r--r--src/main/java/org/onap/aai/babel/csar/extractor/YamlExtractor.java62
-rw-r--r--src/main/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverter.java56
-rw-r--r--src/main/java/org/onap/aai/babel/csar/vnfcatalog/InvalidNumberOfNodesException.java33
-rw-r--r--src/main/java/org/onap/aai/babel/csar/vnfcatalog/ToscaToCatalogException.java49
-rw-r--r--src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java104
-rw-r--r--src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java265
-rw-r--r--src/main/java/org/onap/aai/babel/logging/ApplicationMsgs.java33
-rw-r--r--src/main/java/org/onap/aai/babel/logging/LogHelper.java520
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java302
-rw-r--r--src/main/java/org/onap/aai/babel/request/RequestHeaders.java84
-rw-r--r--src/main/java/org/onap/aai/babel/service/GenerateArtifactsService.java12
-rw-r--r--src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java127
-rw-r--r--src/main/java/org/onap/aai/babel/service/InfoService.java80
-rw-r--r--src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java31
-rw-r--r--src/main/java/org/onap/aai/babel/service/data/BabelRequest.java32
-rw-r--r--src/main/java/org/onap/aai/babel/util/RequestValidationException.java12
-rw-r--r--src/main/java/org/onap/aai/babel/util/RequestValidator.java15
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/ArtifactGenerator.java18
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java51
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/XmlArtifactGenerationException.java10
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java239
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java64
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java260
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/ArtifactGenerator.java41
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/AdditionalParams.java35
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java96
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/ArtifactType.java27
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java65
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java92
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java65
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GroupType.java26
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java43
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/error/IllegalAccessException.java30
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java29
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java248
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java54
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java24
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Service.java43
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java44
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java109
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java31
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java211
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java25
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/Model.java53
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/ModelType.java27
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java45
-rw-r--r--src/main/resources/babel-logging-resources.properties36
75 files changed, 4354 insertions, 303 deletions
diff --git a/src/main/ajsc/babel_v1/babel/v1/conf/coreBeans.groovy b/src/main/ajsc/babel_v1/babel/v1/conf/coreBeans.groovy
new file mode 100644
index 0000000..37043d8
--- /dev/null
+++ b/src/main/ajsc/babel_v1/babel/v1/conf/coreBeans.groovy
@@ -0,0 +1,9 @@
+beans{
+ xmlns cxf: "http://camel.apache.org/schema/cxf"
+ xmlns jaxrs: "http://cxf.apache.org/jaxrs"
+ xmlns util: "http://www.springframework.org/schema/util"
+
+ infoService(org.onap.aai.babel.service.InfoService)
+
+ util.list(id: 'jaxrsServices') { ref(bean:'infoService') }
+}
diff --git a/src/main/ajsc/babel_v1/babel/v1/routes/coreServices.route b/src/main/ajsc/babel_v1/babel/v1/routes/coreServices.route
new file mode 100644
index 0000000..076fb36
--- /dev/null
+++ b/src/main/ajsc/babel_v1/babel/v1/routes/coreServices.route
@@ -0,0 +1,4 @@
+<route xmlns="http://camel.apache.org/schema/spring" trace="true">
+ <from uri="att-dme2-servlet:///__module_ajsc_namespace_name__/__module_ajsc_namespace_version__/core?matchOnUriPrefix=true" />
+ <to uri="cxfbean:jaxrsServices" />
+</route>
diff --git a/src/main/bin/start.sh b/src/main/bin/start.sh
index 1854884..00d7dd6 100644
--- a/src/main/bin/start.sh
+++ b/src/main/bin/start.sh
@@ -3,8 +3,8 @@
# ============LICENSE_START=======================================================
# org.onap.aai
# ================================================================================
-# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
-# Copyright © 2017 European Software Marketing Ltd.
+# Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright © 2017-2018 European Software Marketing Ltd.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
BASEDIR="/opt/app/babel/"
AJSC_HOME="$BASEDIR"
@@ -29,6 +27,22 @@ if [ -z "$CONFIG_HOME" ]; then
exit 1
fi
+foo () {
+if [ -z "$KEY_STORE_PASSWORD" ]; then
+ echo "KEY_STORE_PASSWORD must be set in order to start up process"
+ exit 1
+else
+ echo "KEY_STORE_PASSWORD=$KEY_STORE_PASSWORD\n" >> $AJSC_CONF_HOME/etc/sysprops/sys-props.properties
+fi
+
+if [ -z "$KEY_MANAGER_PASSWORD" ]; then
+ echo "KEY_MANAGER_PASSWORD must be set in order to start up process"
+ exit 1
+else
+ echo "KEY_MANAGER_PASSWORD=$KEY_MANAGER_PASSWORD\n" >> $AJSC_CONF_HOME/etc/sysprops/sys-props.properties
+fi
+}
+
CLASSPATH="$AJSC_HOME/lib/*"
CLASSPATH="$CLASSPATH:$AJSC_HOME/extJars/"
CLASSPATH="$CLASSPATH:$AJSC_HOME/etc/"
@@ -41,8 +55,6 @@ PROPS="$PROPS -DAJSC_SERVICE_VERSION=v1"
PROPS="$PROPS -Dserver.port=9516"
PROPS="$PROPS -DCONFIG_HOME=$CONFIG_HOME"
PROPS="$PROPS -Dartifactgenerator.config=$CONFIG_HOME/artifact-generator.properties"
-PROPS="$PROPS -DKEY_STORE_PASSWORD=$KEY_STORE_PASSWORD"
-PROPS="$PROPS -DKEY_MANAGER_PASSWORD=$KEY_MANAGER_PASSWORD"
JVM_MAX_HEAP=${MAX_HEAP:-1024}
echo $CLASSPATH
diff --git a/src/main/java/org/onap/aai/auth/AAIAuthException.java b/src/main/java/org/onap/aai/auth/AAIAuthException.java
index 13593ab..a29ee98 100644
--- a/src/main/java/org/onap/aai/auth/AAIAuthException.java
+++ b/src/main/java/org/onap/aai/auth/AAIAuthException.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,23 +17,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.auth;
public class AAIAuthException extends Exception {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
+ /** */
+ private static final long serialVersionUID = 1L;
- public AAIAuthException(String string) {
- super(string);
- }
-
- public AAIAuthException(String string, Exception e) {
- super(string, e);
- }
+ public AAIAuthException(String string) {
+ super(string);
+ }
+ public AAIAuthException(String string, Exception e) {
+ super(string, e);
+ }
}
diff --git a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuth.java b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuth.java
index f678498..e4367f1 100644
--- a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuth.java
+++ b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuth.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.auth;
@@ -28,16 +26,15 @@ import javax.security.auth.x500.X500Principal;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
import org.onap.aai.babel.config.BabelAuthConfig;
+import org.onap.aai.babel.logging.LogHelper;
import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-
/**
* Public class for authentication and authorization operations. Authorization is applied according to user and role
*/
public class AAIMicroServiceAuth {
- private static Logger applicationLogger = LoggerFactory.getInstance().getLogger(AAIMicroServiceAuth.class);
+ private static final Logger applicationLogger = LogHelper.INSTANCE;
private BabelAuthConfig babelAuthConfig;
diff --git a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java
index b148440..6f000b8 100644
--- a/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java
+++ b/src/main/java/org/onap/aai/auth/AAIMicroServiceAuthCore.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.auth;
@@ -38,16 +36,12 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import org.onap.aai.babel.logging.ApplicationMsgs;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.babel.logging.LogHelper;
-/**
- * Authentication and authorization by user and role.
- *
- */
+/** Authentication and authorization by user and role. */
public class AAIMicroServiceAuthCore {
- private static Logger applicationLogger = LoggerFactory.getInstance().getLogger(AAIMicroServiceAuthCore.class);
+ private static LogHelper applicationLogger = LogHelper.INSTANCE;
public static final String FILESEP =
(System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
@@ -83,7 +77,6 @@ public class AAIMicroServiceAuthCore {
}
public static synchronized void init(String authPolicyFile) throws AAIAuthException {
-
try {
policyAuthFileName = AAIMicroServiceAuthCore.getConfigFile(authPolicyFile);
} catch (IOException e) {
@@ -237,7 +230,6 @@ public class AAIMicroServiceAuthCore {
public void setUser(String myuser) {
this.username = myuser;
}
-
}
public static class AAIAuthRole {
diff --git a/src/main/java/org/onap/aai/auth/FileWatcher.java b/src/main/java/org/onap/aai/auth/FileWatcher.java
index e3b9923..d974e66 100644
--- a/src/main/java/org/onap/aai/auth/FileWatcher.java
+++ b/src/main/java/org/onap/aai/auth/FileWatcher.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.auth;
@@ -41,15 +39,15 @@ public abstract class FileWatcher extends TimerTask {
/**
* runs a timer task
- *
+ *
* @see java.util.TimerTask.run
*/
@Override
public final void run() {
- long newTimeStamp = file.lastModified();
+ long newTimestamp = file.lastModified();
- if ((newTimeStamp - this.timeStamp) > 500) {
- this.timeStamp = newTimeStamp;
+ if ((newTimestamp - this.timeStamp) > 500) {
+ this.timeStamp = newTimestamp;
onChange(file);
}
}
diff --git a/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java b/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java
index 5fdc01f..21525a1 100644
--- a/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java
+++ b/src/main/java/org/onap/aai/babel/config/BabelAuthConfig.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.config;
@@ -26,26 +24,25 @@ import org.springframework.beans.factory.annotation.Value;
public class BabelAuthConfig {
- @Value("${auth.authentication.disable}")
- private boolean authenticationDisable;
-
- @Value("${auth.policy.file}")
- private String authPolicyFile;
+ @Value("${auth.authentication.disable}")
+ private boolean authenticationDisable;
- public boolean isAuthenticationDisable() {
- return authenticationDisable;
- }
+ @Value("${auth.policy.file}")
+ private String authPolicyFile;
- public void setAuthenticationDisable(boolean authenticationDisable) {
- this.authenticationDisable = authenticationDisable;
- }
+ public boolean isAuthenticationDisable() {
+ return authenticationDisable;
+ }
- public String getAuthPolicyFile() {
- return authPolicyFile;
- }
+ public void setAuthenticationDisable(boolean authenticationDisable) {
+ this.authenticationDisable = authenticationDisable;
+ }
- public void setAuthPolicyFile(String authPolicyFile) {
- this.authPolicyFile = authPolicyFile;
- }
+ public String getAuthPolicyFile() {
+ return authPolicyFile;
+ }
+ public void setAuthPolicyFile(String authPolicyFile) {
+ this.authPolicyFile = authPolicyFile;
+ }
}
diff --git a/src/main/java/org/onap/aai/babel/csar/CsarConverterException.java b/src/main/java/org/onap/aai/babel/csar/CsarConverterException.java
index b9316fc..eb81014 100644
--- a/src/main/java/org/onap/aai/babel/csar/CsarConverterException.java
+++ b/src/main/java/org/onap/aai/babel/csar/CsarConverterException.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.csar;
diff --git a/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java b/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java
index 55cf652..1322c9c 100644
--- a/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java
+++ b/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,30 +17,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.csar;
import java.util.List;
import java.util.Objects;
+import org.apache.commons.lang.time.StopWatch;
import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
import org.onap.aai.babel.csar.extractor.YamlExtractor;
import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
import org.onap.aai.babel.service.data.BabelArtifact;
-import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
-import org.onap.aai.babel.xml.generator.ArtifactGenerator;
import org.onap.aai.babel.xml.generator.ModelGenerator;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-
-import org.openecomp.sdc.generator.data.Artifact;
+import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
+import org.onap.aai.babel.xml.generator.data.Artifact;
/**
* This class is responsible for converting content in a csar archive into one or more xml artifacts.
*/
public class CsarToXmlConverter {
- private static Logger logger = LoggerFactory.getInstance().getLogger(CsarToXmlConverter.class);
+ private static final LogHelper logger = LogHelper.INSTANCE;
/**
* This method is responsible for extracting one or more yaml files from the given csarArtifact and then using them
@@ -54,6 +50,10 @@ public class CsarToXmlConverter {
*/
public List<BabelArtifact> generateXmlFromCsar(byte[] csarArchive, String name, String version)
throws CsarConverterException {
+
+ StopWatch stopwatch = new StopWatch();
+ stopwatch.start();
+
validateArguments(csarArchive, name, version);
logger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
@@ -65,8 +65,7 @@ public class CsarToXmlConverter {
List<Artifact> ymlFiles = YamlExtractor.extract(csarArchive, name, version);
logger.debug("Calling XmlArtifactGenerator to generateXmlArtifacts");
- ArtifactGenerator modelGenerator = new ModelGenerator();
- xmlArtifacts = modelGenerator.generateArtifacts(ymlFiles);
+ xmlArtifacts = new ModelGenerator().generateArtifacts(csarArchive, ymlFiles);
logger.debug(xmlArtifacts.size() + " xml artifacts have been generated");
} catch (InvalidArchiveException e) {
@@ -75,6 +74,8 @@ public class CsarToXmlConverter {
} catch (XmlArtifactGenerationException e) {
throw new CsarConverterException(
"An error occurred trying to generate xml files from a collection of yml files : " + e);
+ } finally {
+ logger.logMetrics(stopwatch, LogHelper.getCallerMethodName(0));
}
return xmlArtifacts;
diff --git a/src/main/java/org/onap/aai/babel/csar/extractor/InvalidArchiveException.java b/src/main/java/org/onap/aai/babel/csar/extractor/InvalidArchiveException.java
index aac893b..97d72d4 100644
--- a/src/main/java/org/onap/aai/babel/csar/extractor/InvalidArchiveException.java
+++ b/src/main/java/org/onap/aai/babel/csar/extractor/InvalidArchiveException.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +17,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.csar.extractor;
-/**
- * This class represents an exception encountered when processing an archive in memory.
- */
+/** This class represents an exception encountered when processing an archive in memory. */
public class InvalidArchiveException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/org/onap/aai/babel/csar/extractor/YamlExtractor.java b/src/main/java/org/onap/aai/babel/csar/extractor/YamlExtractor.java
index fb51933..7700a54 100644
--- a/src/main/java/org/onap/aai/babel/csar/extractor/YamlExtractor.java
+++ b/src/main/java/org/onap/aai/babel/csar/extractor/YamlExtractor.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,20 +17,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.csar.extractor;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
@@ -38,11 +31,10 @@ import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
import org.onap.aai.babel.xml.generator.ModelGenerator;
+import org.onap.aai.babel.xml.generator.data.Artifact;
import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.openecomp.sdc.generator.data.Artifact;
-import org.yaml.snakeyaml.Yaml;
/**
* The purpose of this class is to process a .csar file in the form of a byte array and extract yaml files from it.
@@ -51,19 +43,11 @@ import org.yaml.snakeyaml.Yaml;
* file.
*/
public class YamlExtractor {
- private static Logger logger = LoggerFactory.getInstance().getLogger(YamlExtractor.class);
+ private static Logger logger = LogHelper.INSTANCE;
- private static final String TYPE = "type";
private static final Pattern YAMLFILE_EXTENSION_REGEX = Pattern.compile("(?i).*\\.ya?ml$");
- private static final Set<String> INVALID_TYPES = new HashSet<>();
-
- static {
- Collections.addAll(INVALID_TYPES, "CP", "VL", "VFC", "VFCMT", "ABSTRACT");
- }
- /**
- * Private constructor
- */
+ /** Private constructor */
private YamlExtractor() {
throw new IllegalAccessError("Utility class");
}
@@ -91,7 +75,7 @@ public class YamlExtractor {
ZipFile zipFile = new ZipFile(inMemoryByteChannel)) {
for (Enumeration<ZipArchiveEntry> enumeration = zipFile.getEntries(); enumeration.hasMoreElements();) {
ZipArchiveEntry entry = enumeration.nextElement();
- if (fileShouldBeExtracted(zipFile, entry)) {
+ if (fileShouldBeExtracted(entry)) {
ymlFiles.add(ModelGenerator.createArtifact(IOUtils.toByteArray(zipFile.getInputStream(entry)),
entry.getName(), version));
}
@@ -120,30 +104,14 @@ public class YamlExtractor {
}
}
- @SuppressWarnings("unchecked")
- private static boolean fileShouldBeExtracted(ZipFile zipFile, ZipArchiveEntry entry) throws IOException {
- logger.debug(ApplicationMsgs.DISTRIBUTION_EVENT, "Checking if " + entry.getName() + " should be extracted...");
-
- boolean extractFile = false;
- if (YAMLFILE_EXTENSION_REGEX.matcher(entry.getName()).matches()) {
- try {
- Yaml yamlParser = new Yaml();
- HashMap<String, Object> yaml =
- (LinkedHashMap<String, Object>) yamlParser.load(zipFile.getInputStream(entry));
- HashMap<String, Object> metadata = (LinkedHashMap<String, Object>) yaml.get("metadata");
-
- extractFile = metadata != null && metadata.containsKey(TYPE)
- && !INVALID_TYPES.contains(metadata.get(TYPE).toString().toUpperCase())
- && !metadata.get(TYPE).toString().isEmpty();
- } catch (Exception e) {
- logger.error(ApplicationMsgs.DISTRIBUTION_EVENT,
- "Unable to verify " + entry.getName() + " contains a valid resource type: " + e.getMessage());
- }
- }
-
- logger.debug(ApplicationMsgs.DISTRIBUTION_EVENT, "Keeping file: " + entry.getName() + "? : " + extractFile);
-
+ /**
+ * @param entry
+ * @return
+ */
+ private static boolean fileShouldBeExtracted(ZipArchiveEntry entry) {
+ boolean extractFile = YAMLFILE_EXTENSION_REGEX.matcher(entry.getName()).matches();
+ logger.debug(ApplicationMsgs.DISTRIBUTION_EVENT,
+ "Checking if " + entry.getName() + " should be extracted... " + extractFile);
return extractFile;
}
}
-
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverter.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverter.java
new file mode 100644
index 0000000..983c810
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/ConfigurationsToBabelArtifactConverter.java
@@ -0,0 +1,56 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.csar.vnfcatalog;
+
+import com.google.gson.Gson;
+import java.util.List;
+import org.onap.aai.babel.service.data.BabelArtifact;
+import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
+
+/**
+ * This class is responsible for converting a collection of VendorImageConfigurations into an instance of a
+ * BabelArtifact.
+ */
+class ConfigurationsToBabelArtifactConverter {
+ private ConfigurationsToBabelArtifactConverter() {}
+
+ /**
+ * This method converts a collection of VendorImageConfiguration objects into an instance of a BabelArtifact.
+ *
+ * <p>
+ * The method will convert the configurations objects into JSON and this will be stored in the BabelArtifact's
+ * payload property.
+ *
+ * <p>
+ * The method will return null if there are no configurations (null or empty) to process.
+ *
+ * @param configurations collection of VendorImageConfiguration objects into an instance of a BabelArtifact
+ * @return BabelArtifact instance representing the configurations or null if there are no configurations.
+ */
+ static BabelArtifact convert(List<VendorImageConfiguration> configurations) {
+ if (configurations != null && !configurations.isEmpty()) {
+ String payload = new Gson().toJson(configurations, configurations.getClass());
+ return new BabelArtifact("vnfVendorImageConfigurations", ArtifactType.VNFCATALOG, payload);
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/InvalidNumberOfNodesException.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/InvalidNumberOfNodesException.java
new file mode 100644
index 0000000..425982b
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/InvalidNumberOfNodesException.java
@@ -0,0 +1,33 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.csar.vnfcatalog;
+
+/**
+ * This class represents a scenario when there are invalid number of Nodes found during processing.
+ */
+class InvalidNumberOfNodesException extends Exception {
+ /** Default ID */
+ private static final long serialVersionUID = 1L;
+
+ InvalidNumberOfNodesException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/ToscaToCatalogException.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/ToscaToCatalogException.java
new file mode 100644
index 0000000..2ef9dc8
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/ToscaToCatalogException.java
@@ -0,0 +1,49 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.csar.vnfcatalog;
+
+/**
+ * This class represents an exception raised when trying to extract VNFCatalog data out of a CSAR file.
+ */
+public class ToscaToCatalogException extends Exception {
+
+ /** Defaulted */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor with message and cause
+ *
+ * @param message Friendly information about the exception encountered
+ * @param cause the root cause of the exception
+ */
+ public ToscaToCatalogException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructor with message only
+ *
+ * @param message Friendly information about the exception encountered
+ */
+ public ToscaToCatalogException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java
new file mode 100644
index 0000000..bd9aac7
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VendorImageConfiguration.java
@@ -0,0 +1,104 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.csar.vnfcatalog;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * This class represents Vendor Image data gleaned from tosca files within a csar file.
+ *
+ * <p>
+ * Example: Where the value application property is 'VM00' this comes from the VNFConfiguration NodeTemplate under a
+ * path:
+ *
+ * <pre>
+ * node_templates:
+ * vFW_VNF_Configuration:
+ * type: org.openecomp.nodes.VnfConfiguration
+ * properties:
+ * allowed_flavors:
+ * ATT_part_12345_for_FortiGate-VM00: Note the value of this element is dynamic
+ * vendor_info:
+ * vendor_model: VM00
+ * </pre>
+ *
+ * Where the value applicationVendor property is 'ATT (Tosca)' this comes from the VNFConfiguration NodeTemplate under a
+ * path:
+ *
+ * <pre>
+ * node_templates:
+ * vFW_VNF_Configuration:
+ * type: org.openecomp.nodes.VnfConfiguration
+ * metadata:
+ * resourceVendor: ATT (Tosca)
+ * </pre>
+ *
+ * Where the value applicationVersion property is '3.16.9' this comes from the MultiFlavorVFC NodeTemplate under a path:
+ *
+ * <pre>
+ * node_templates:
+ * vWAN_VFC:
+ * type: org.openecomp.resource.abstract.nodes.MultiFlavorVFC
+ * properties:
+ * images:
+ * 3.16.1: Note the value of this element is dynamic - represents the name of each image
+ * software_version: 3.16.1
+ * </pre>
+ */
+class VendorImageConfiguration {
+ private String application;
+
+ @SerializedName("application-vendor")
+ private String applicationVendor;
+
+ @SerializedName("application-version")
+ private String applicationVersion;
+
+ VendorImageConfiguration(String application, String applicationVendor, String applicationVersion) {
+ this.application = application;
+ this.applicationVendor = applicationVendor;
+ this.applicationVersion = applicationVersion;
+ }
+
+ public String getApplication() {
+ return application;
+ }
+
+ public void setApplication(String application) {
+ this.application = application;
+ }
+
+ public String getApplicationVendor() {
+ return applicationVendor;
+ }
+
+ public void setApplicationVendor(String applicationVendor) {
+ this.applicationVendor = applicationVendor;
+ }
+
+ public String getApplicationVersion() {
+ return applicationVersion;
+ }
+
+ public void setApplicationVersion(String applicationVersion) {
+ this.applicationVersion = applicationVersion;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java
new file mode 100644
index 0000000..e76c0c1
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java
@@ -0,0 +1,265 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.csar.vnfcatalog;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.time.StopWatch;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.service.data.BabelArtifact;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.onap.sdc.tosca.parser.impl.SdcTypes;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.SubstitutionMappings;
+
+/**
+ * This class is responsible for extracting Virtual Network Function (VNF) information from a TOSCA 1.1 CSAR package.
+ *
+ * <p>
+ * CSAR is a compressed format that stores multiple TOSCA files. Each TOSCA file may define Topology Templates and/or
+ * Node Templates along with other model data.
+ *
+ * <p>
+ * A VNF is a virtualized functional capability (e.g. a Router) that may be defined by an external Vendor. Within the
+ * model defined by the TOSCA files the VNF is considered to be a Resource (part of a Service).
+ *
+ * <p>
+ * A VNF is specified by a Topology Template. Because this TOSCA construct does not allow properties to be defined
+ * directly, Node Templates are defined (identified by a VNF type value) storing the VNF metadata and properties.
+ *
+ * <p>
+ * A VNF may be composed of multiple images, each running on its own Virtual Machine. The function of a deployed image
+ * is designated the Virtual Function Component (VFC). A VFC is a sub-component of the VNF. A VFC may have different
+ * "Flavors" (see the Deployment Flavors description below).
+ *
+ * <p>
+ * An individual VNF (template) may be deployed with varying configuration values, according to
+ * environment/customer/business needs. For example, a VNF deployed in a testing environment would typically use fewer
+ * computational resources than in a production setting.
+ *
+ * <p>
+ * A Vendor may define one or more "Deployment Flavors". A Deployment Flavor describes a set of pre-determined
+ * parameterised values for a specific aspect of the model. Within the TOSCA model there is a DeploymentFlavor
+ * definition, which has its own data types, and also an ImageInfo definition.
+ */
+public class VnfVendorImageExtractor {
+ private static LogHelper applicationLogger = LogHelper.INSTANCE;
+
+ private static final String AN_ERROR_OCCURRED = "An error occurred trying to get the vnf catalog from a csar file.";
+
+ // The following constants describe the expected naming conventions for TOSCA Node Templates which
+ // store the VNF
+ // configuration and the VFC data items.
+
+ // The name of the property (for a VNF Configuration type) storing the Images Information
+ private static final String IMAGES = "images";
+
+ // Name of property key that contains the value of the software version
+ private static final String SOFTWARE_VERSION = "software_version";
+
+ // The name of the property (for a VNF Configuration type) storing the Vendor Information
+ private static final String VNF_CONF_TYPE_PROPERTY_VENDOR_INFO_CONTAINER = "allowed_flavors";
+
+ // Name of property key that contains the value of model of the vendor application
+ private static final String VENDOR_MODEL = "vendor_model";
+
+ /**
+ * This method is responsible for parsing the vnfConfiguration entity in the same topology_template (there's an
+ * assumption that there's only one per file, awaiting verification).
+ *
+ * <p>
+ * It is possible that csar file does not contain a vnfConfiguration and this is valid.
+ *
+ * <p>
+ * Where multiple vnfConfigurations are found an exception will be thrown.
+ *
+ * <p>
+ * The ASDC model anticipates the following permutations of vnfConfiguration and multiflavorVFC:
+ *
+ * <pre>
+ * <ol>
+ * <li>Single vnfConfiguration, single multiFlavorVFC with multiple images.</li>
+ * <li>Single vnfConfiguration, multi multiFlavorVFC with single images.</li>
+ * </ol>
+ * </pre>
+ *
+ * All ImageInfo sections found apply to all "Deployment Flavors", therefore we can apply a cross product of
+ * "Deployment Flavors" x "ImageInfo" - concretely
+ *
+ * @param csar compressed format that stores multiple TOSCA files and in particular a vnfConfiguration
+ * @return BabelArtifact VendorImageConfiguration objects created during processing represented as the Babel service
+ * public data structure
+ */
+ public BabelArtifact extract(byte[] csar) throws ToscaToCatalogException {
+ StopWatch stopwatch = new StopWatch();
+ stopwatch.start();
+
+ Objects.requireNonNull(csar, "A CSAR file must be supplied");
+
+ applicationLogger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
+ "Starting to find and extract any vnf configuration data");
+
+ List<VendorImageConfiguration> vendorImageConfigurations;
+ Path path = null;
+
+ try {
+ path = createTempFile(csar);
+ vendorImageConfigurations = createVendorImageConfigurations(path.toAbsolutePath().toString());
+ } catch (InvalidNumberOfNodesException | IOException | SdcToscaParserException e) {
+ throw new ToscaToCatalogException(AN_ERROR_OCCURRED + " " + e.getLocalizedMessage(), e);
+ } finally {
+ if (path != null) {
+ FileUtils.deleteQuietly(path.toFile());
+ }
+ }
+
+ String msg = vendorImageConfigurations.isEmpty() ? "No Vnf Configuration has been found in the csar"
+ : "Vnf Configuration has been found in the csar";
+ applicationLogger.info(ApplicationMsgs.DISTRIBUTION_EVENT, msg);
+ applicationLogger.logMetrics(stopwatch, LogHelper.getCallerMethodName(0));
+
+ return ConfigurationsToBabelArtifactConverter.convert(vendorImageConfigurations);
+ }
+
+ private Path createTempFile(byte[] bytes) throws IOException {
+ applicationLogger.debug("Creating temp file on file system for the csar");
+ Path path = Files.createTempFile("temp", ".csar");
+ Files.write(path, bytes);
+ return path;
+ }
+
+ private List<VendorImageConfiguration> createVendorImageConfigurations(String csarFilepath)
+ throws SdcToscaParserException, ToscaToCatalogException, InvalidNumberOfNodesException {
+ applicationLogger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
+ "Getting instance of ISdcCsarHelper to use in finding vnf configuration data");
+ ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance().getSdcCsarHelper(csarFilepath);
+
+ List<VendorImageConfiguration> vendorImageConfigurations = new ArrayList<>();
+ NodeTemplate vnfConfigurationNode = findVnfConfigurationNode(csarHelper);
+
+ if (vnfConfigurationNode != null) {
+ List<NodeTemplate> serviceVfNodes = csarHelper.getServiceVfList();
+
+ for (NodeTemplate node : serviceVfNodes) {
+ vendorImageConfigurations.addAll(buildVendorImageConfigurations(vnfConfigurationNode, node));
+ }
+ }
+
+ return vendorImageConfigurations;
+ }
+
+ private NodeTemplate findVnfConfigurationNode(ISdcCsarHelper csarHelper) throws InvalidNumberOfNodesException {
+ applicationLogger.debug("Tryng to find the vnf configuration node");
+
+ List<NodeTemplate> configNodes =
+ csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF).stream().map(serviceNodeTemplate -> {
+ String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNodeTemplate);
+ applicationLogger.debug("Node Template Customization Uuid is " + uuid);
+ return csarHelper.getVnfConfig(uuid);
+ }).filter(Objects::nonNull).collect(Collectors.toList());
+
+ if (configNodes.size() > 1) {
+ throw new InvalidNumberOfNodesException("Only one vnf configuration node is allowed however "
+ + configNodes.size() + " nodes were found in the csar.");
+ }
+
+ return configNodes.size() == 1 ? configNodes.get(0) : null;
+ }
+
+ private List<VendorImageConfiguration> buildVendorImageConfigurations(NodeTemplate vendorInfoNode,
+ NodeTemplate node) throws ToscaToCatalogException {
+ List<VendorImageConfiguration> vendorImageConfigurations = new ArrayList<>();
+
+ List<String> softwareVersions = extractSoftwareVersions(node.getSubMappingToscaTemplate());
+
+ Consumer<? super Pair<String, String>> buildConfigurations = vi -> vendorImageConfigurations.addAll(
+ softwareVersions.stream().map(sv -> (new VendorImageConfiguration(vi.getRight(), vi.getLeft(), sv)))
+ .collect(Collectors.toList()));
+
+ String resourceVendor = node.getMetaData().getValue("resourceVendor");
+ buildVendorInfo(resourceVendor, vendorInfoNode).forEach(buildConfigurations);
+
+ return vendorImageConfigurations;
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<Pair<String, String>> buildVendorInfo(String resourceVendor, NodeTemplate vendorInfoNode) {
+ Map<String, Object> otherFlavorProperties =
+ (Map<String, Object>) vendorInfoNode.getPropertyValue(VNF_CONF_TYPE_PROPERTY_VENDOR_INFO_CONTAINER);
+
+ return otherFlavorProperties.keySet().stream()
+ .map(key -> createVendorInfoPair((Map<String, Object>) otherFlavorProperties.get(key), resourceVendor))
+ .collect(Collectors.toList());
+ }
+
+ private Pair<String, String> createVendorInfoPair(Map<String, Object> otherFlavor, String resourceVendor) {
+ @SuppressWarnings("unchecked")
+ String vendorModel = otherFlavor.entrySet().stream() //
+ .filter(entry -> "vendor_info".equals(entry.getKey()))
+ .map(e -> ((Map<String, String>) e.getValue()).get(VENDOR_MODEL)) //
+ .findFirst().orElse(null);
+
+ applicationLogger.debug("Creating vendor info pair object for vendorModel = " + vendorModel
+ + " and resourceVendor = " + resourceVendor);
+
+ return new ImmutablePair<>(resourceVendor, vendorModel);
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<String> extractSoftwareVersions(SubstitutionMappings sm) throws ToscaToCatalogException {
+ applicationLogger.debug("Trying to extract the software versions for the vnf configuration");
+
+ List<NodeTemplate> imagesNodes = sm.getNodeTemplates().stream()
+ .filter(nodeTemplate -> nodeTemplate.getPropertyValue(IMAGES) != null).collect(Collectors.toList());
+
+ if (imagesNodes != null && !imagesNodes.isEmpty()) {
+ applicationLogger.debug("Found NodeTemplates containing properties with a key called 'images'");
+ return imagesNodes.stream()
+ .flatMap(imagesNode -> ((Map<String, Object>) imagesNode.getPropertyValue(IMAGES)) //
+ .entrySet().stream())
+ .map(property -> findSoftwareVersion((Map<String, Object>) property.getValue()))
+ .collect(Collectors.toList());
+ } else {
+ throw new ToscaToCatalogException("No software versions could be found for this csar file");
+ }
+ }
+
+ private String findSoftwareVersion(Map<String, Object> image) {
+ applicationLogger.debug("Getting the software version value from the map of image properties");
+
+ return (String) image.entrySet().stream().filter(entry -> SOFTWARE_VERSION.equals(entry.getKey()))
+ .map(Entry::getValue).findFirst().orElse(null);
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/logging/ApplicationMsgs.java b/src/main/java/org/onap/aai/babel/logging/ApplicationMsgs.java
index 9b9f9d5..84b426b 100644
--- a/src/main/java/org/onap/aai/babel/logging/ApplicationMsgs.java
+++ b/src/main/java/org/onap/aai/babel/logging/ApplicationMsgs.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.logging;
@@ -26,19 +24,22 @@ import com.att.eelf.i18n.EELFResourceManager;
import org.onap.aai.cl.eelf.LogMessageEnum;
public enum ApplicationMsgs implements LogMessageEnum {
- //@formatter:off
- /**
- * Arguments: {0} = message.
- */
- DISTRIBUTION_EVENT,
-
- PROCESS_REQUEST_ERROR,
-
- INVALID_CSAR_FILE,
+ /** Arguments: {0} = message. */
+ // @formatter:off
+ DISTRIBUTION_EVENT,
+ MESSAGE_AUDIT,
+ MESSAGE_METRIC,
+ MISSING_REQUEST_ID,
+ PROCESS_REQUEST_ERROR,
+ INVALID_CSAR_FILE,
+ INVALID_REQUEST_JSON,
+ BABEL_REQUEST_PAYLOAD,
+ BABEL_RESPONSE_PAYLOAD,
+ LOAD_PROPERTIES,
+ PROCESSING_VNF_CATALOG_ERROR,
+ TEMP_FILE_ERROR;
- INVALID_REQUEST_JSON;
-
- //@formatter:on
+ // @formatter:on
/**
* Static initializer to ensure the resource bundles for this class are loaded... Here this application loads
diff --git a/src/main/java/org/onap/aai/babel/logging/LogHelper.java b/src/main/java/org/onap/aai/babel/logging/LogHelper.java
new file mode 100644
index 0000000..54c5361
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/logging/LogHelper.java
@@ -0,0 +1,520 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.logging;
+
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+
+import ch.qos.logback.classic.AsyncAppender;
+import ch.qos.logback.core.FileAppender;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResolvableErrorEnum;
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Optional;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import javax.servlet.ServletRequest;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response.Status;
+import org.apache.commons.lang.time.StopWatch;
+import org.onap.aai.babel.request.RequestHeaders;
+import org.onap.aai.cl.api.LogFields;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.cl.mdc.MdcOverride;
+import org.onap.aai.restclient.client.Headers;
+import org.slf4j.MDC;
+
+/*-
+ * This Log Helper mimics the interface of a Common Logging Logger
+ * but adds helper methods for audit and metrics logging requirements.
+ *
+ * Messages are logged to the appropriate EELF functional logger as described below.
+ *
+ * Error Log: INFO/WARN/ERROR/FATAL
+ * Debug Log: DEBUG/TRACE
+ * Audit Log: summary view of transaction processing
+ * Metrics Log: detailed timings of transaction processing interactions
+ *
+ * Audit and Metrics log messages record the following fields:
+ *
+ * RequestID - an RFC4122 UUID for the transaction request
+ * ServiceName - the API provided by this service
+ * PartnerName - invoker of the API
+ * ClassName - name of the class creating the log record
+ *
+ * The above list is not exhaustive.
+ */
+public enum LogHelper implements Logger {
+ INSTANCE; // Joshua Bloch's singleton pattern
+
+ @FunctionalInterface
+ public interface TriConsumer<T, U, V> {
+ public void accept(T t, U u, V v);
+ }
+
+ /** Audit log message status code values. See {@code MdcParameter.STATUS_CODE} */
+ public enum StatusCode {
+ COMPLETE,
+ ERROR;
+ }
+
+ /**
+ * Mapped Diagnostic Context parameter names.
+ *
+ * <p>
+ * Note that MdcContext.MDC_START_TIME is used for audit messages, and indicates the start of a transaction.
+ * Messages in the metrics log record sub-operations of a transaction and thus use different timestamps.
+ */
+ public enum MdcParameter {
+ REQUEST_ID(MdcContext.MDC_REQUEST_ID),
+ CLASS_NAME("ClassName"),
+ BEGIN_TIMESTAMP("BeginTimestamp"),
+ END_TIMESTAMP("EndTimestamp"),
+ ELAPSED_TIME("ElapsedTime"),
+ STATUS_CODE("StatusCode"),
+ RESPONSE_CODE("ResponseCode"),
+ RESPONSE_DESCRIPTION("ResponseDescription"),
+ TARGET_ENTITY("TargetEntity"),
+ TARGET_SERVICE_NAME("TargetServiceName"),
+ USER("User");
+
+ private final String parameterName;
+
+ MdcParameter(String parameterName) {
+ this.parameterName = parameterName;
+ }
+
+ /**
+ * Get the MDC logging context parameter name as referenced by the logback configuration
+ *
+ * @return the MDC parameter name
+ */
+ public String value() {
+ return parameterName;
+ }
+ }
+
+ /** Our externally advertised service API */
+ private static final String SERVICE_NAME_VALUE = "AAI-BAS";
+
+ private static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
+ private static final EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
+ private static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+
+ /** Formatting for timestamps logged as Strings (from the MDC) */
+ private DateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
+
+ // Records the elapsed time (since the start of servicing a request) for audit logging
+ private StopWatch auditStopwatch;
+
+ /**
+ * Initialises the MDC (logging context) with default values, to support any logging of messages BEFORE the
+ * startAudit() method is invoked.
+ */
+ private LogHelper() {
+ setContextValue(MDC_SERVICE_NAME, SERVICE_NAME_VALUE);
+ // This value is not expected to be used in the default logging configuration
+ setContextValue(MdcContext.MDC_START_TIME, timestampFormat.format(new Date()));
+ }
+
+ /**
+ * Begin recording transaction information for a new request. This data is intended for logging purposes. This
+ * method does not actually write any messages to the log(s).
+ *
+ * <p>
+ * Initialise the MDC logging context for auditing and metrics, using the HTTP request headers. This information
+ * includes: the correlation ID, local application service name/ID, calling host details and authentication data.
+ *
+ * <p>
+ * The request object is used to find the client details (e.g. IP address)
+ *
+ * @param headers raw HTTP headers
+ * @param servletRequest the request
+ */
+ public void startAudit(final HttpHeaders headers, ServletRequest servletRequest) {
+ auditStopwatch = new StopWatch();
+ auditStopwatch.start();
+
+ Optional<String> requestId = Optional.empty();
+ String serviceInstanceId = null;
+ Optional<String> partnerName = Optional.empty();
+
+ if (headers != null) {
+ RequestHeaders requestHeaders = new RequestHeaders(headers);
+ requestId = Optional.ofNullable(requestHeaders.getCorrelationId());
+ serviceInstanceId = requestHeaders.getInstanceId();
+ partnerName = Optional.ofNullable(headers.getHeaderString(Headers.FROM_APP_ID));
+ }
+
+ String clientHost = null;
+ String clientIPAddress = null;
+ String user = "<UNKNOWN_USER>";
+
+ if (servletRequest != null) {
+ clientHost = servletRequest.getRemoteHost();
+ clientIPAddress = servletRequest.getRemoteAddr();
+
+ if (!partnerName.isPresent()) {
+ partnerName = Optional.ofNullable(clientHost);
+ }
+ }
+
+ // Populate standard MDC keys - note that the initialize method calls MDC.clear()
+ MdcContext.initialize(requestId.orElse("missing-request-id"), SERVICE_NAME_VALUE, serviceInstanceId,
+ partnerName.orElse("<UNKNOWN_PARTNER>"), clientIPAddress);
+
+ setContextValue(MdcParameter.USER, user);
+ setContextValue(MdcContext.MDC_REMOTE_HOST, clientHost);
+ }
+
+ /**
+ * Store a value in the current thread's logging context.
+ *
+ * @param key non-null parameter name
+ * @param value the value to store against the key
+ */
+ public void setContextValue(String key, String value) {
+ debug(key + "=" + value);
+ MDC.put(key, value);
+ }
+
+ /**
+ * Store a value in the current thread's logging context.
+ *
+ * @param param identifier of the context parameter
+ * @param value the value to store for this parameter
+ */
+ public void setContextValue(MdcParameter param, String value) {
+ setContextValue(param.value(), value);
+ }
+
+ /**
+ * Set a value in the current thread's logging context, only if this is not already set.
+ *
+ * @param key non-null parameter name
+ * @param value the value to store against the key (only if the current value is null)
+ */
+ public void setDefaultContextValue(String key, String value) {
+ if (MDC.get(key) == null) {
+ setContextValue(key, value);
+ }
+ }
+
+ /**
+ * Set a value in the current thread's logging context, only if this is not already set.
+ *
+ * @param param identifier of the context parameter
+ * @param value the value to store for this parameter (only if the current value is null)
+ */
+ public void setDefaultContextValue(MdcParameter param, String value) {
+ setContextValue(param.value(), value);
+ }
+
+ /** Clear all logging context values. This should be called at start-up only. */
+ public void clearContext() {
+ debug("Clearing MDC context");
+ MDC.clear();
+ }
+
+ /**
+ * Log an audit message to the audit logger. This method is expected to be called when a response is returned to the
+ * caller and/or when the processing of the request completes.
+ *
+ * @param status status of the service request: COMPLETE/ERROR
+ * @param responseCode optional application error code
+ * @param responseDescription human-readable description of the response code
+ * @param args the argument(s) required to populate the Audit Message log content
+ */
+ public void logAudit(StatusCode status, String responseCode, String responseDescription, final String... args) {
+ if (auditStopwatch == null) {
+ debug("Unexpected program state: audit stopwatch not started");
+ auditStopwatch = new StopWatch();
+ auditStopwatch.start();
+ }
+
+ if (auditLogger.isInfoEnabled()) {
+ setMdcElapsedTime(auditStopwatch);
+ setContextValue(MdcParameter.STATUS_CODE, status.toString());
+ setContextValue(MdcParameter.RESPONSE_CODE, responseCode);
+ setContextValue(MdcParameter.RESPONSE_DESCRIPTION, responseDescription);
+ invokeLogger(auditLogger::info, ApplicationMsgs.MESSAGE_AUDIT, args);
+ }
+ }
+
+ /**
+ * Log an audit message to the audit logger representing a non-specific processing success message.
+ *
+ * @param msg
+ */
+ public void logAuditSuccess(String msg) {
+ Status status = Status.OK;
+ logAudit(StatusCode.COMPLETE, Integer.toString(status.getStatusCode()), status.getReasonPhrase(), msg);
+ }
+
+ /**
+ * Log an audit message to the audit logger representing an internal error (e.g. for an exception thrown by the
+ * implementation). This method is expected to be called when a generic error response is returned to the caller to
+ * indicate a processing failure.
+ *
+ * @param e Exception
+ */
+ public void logAuditError(Exception e) {
+ Status status = Status.INTERNAL_SERVER_ERROR;
+ logAudit(StatusCode.ERROR, Integer.toString(status.getStatusCode()), status.getReasonPhrase(), e.getMessage());
+ }
+
+ /**
+ * Log a message to the metrics log.
+ *
+ * @param error the log code
+ * @param args the info messages
+ */
+ public void logMetrics(final String... args) {
+ if (metricsLogger.isInfoEnabled()) {
+ invokeLogger(metricsLogger::info, ApplicationMsgs.MESSAGE_METRIC, args);
+ }
+ }
+
+ /**
+ * @param stopwatch
+ * @param args
+ */
+ public void logMetrics(final StopWatch stopwatch, String... args) {
+ setMdcElapsedTime(stopwatch);
+ logMetrics(args);
+ }
+
+ @Override
+ public String formatMsg(@SuppressWarnings("rawtypes") Enum arg0, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return debugLogger != null && debugLogger.isDebugEnabled();
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return errorLogger.isErrorEnabled();
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return errorLogger.isInfoEnabled();
+ }
+
+ @Override
+ public boolean isTraceEnabled() {
+ return debugLogger.isTraceEnabled();
+ }
+
+ @Override
+ public boolean isWarnEnabled() {
+ return errorLogger.isWarnEnabled();
+ }
+
+ /**
+ * Log a DEBUG level message to the debug logger.
+ *
+ * @param message the debug message
+ */
+ @Override
+ public void debug(String message) {
+ if (isDebugEnabled()) {
+ invokeLogger(debugLogger::debug, message);
+ }
+ }
+
+ @Override
+ public void debug(@SuppressWarnings("rawtypes") Enum errorCode, String... args) {
+ if (isDebugEnabled()) {
+ invokeErrorCodeLogger(debugLogger::debug, (EELFResolvableErrorEnum) errorCode, args);
+ }
+ }
+
+ @Override
+ public void debug(@SuppressWarnings("rawtypes") Enum errorCode, LogFields arg1, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void error(@SuppressWarnings("rawtypes") Enum errorCode, String... args) {
+ if (isErrorEnabled()) {
+ invokeErrorCodeLogger(errorLogger::error, (EELFResolvableErrorEnum) errorCode, args);
+ }
+ }
+
+ @Override
+ public void error(@SuppressWarnings("rawtypes") Enum errorCode, Throwable t, String... args) {
+ if (isErrorEnabled()) {
+ invokeErrorCodeLogger(errorLogger::error, (EELFResolvableErrorEnum) errorCode, t, args);
+ }
+ }
+
+ @Override
+ public void error(@SuppressWarnings("rawtypes") Enum errorCode, LogFields arg1, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void error(@SuppressWarnings("rawtypes") Enum errorCode, LogFields arg1, Throwable arg2, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void info(@SuppressWarnings("rawtypes") Enum errorCode, String... args) {
+ if (isInfoEnabled()) {
+ invokeErrorCodeLogger(errorLogger::info, (EELFResolvableErrorEnum) errorCode, args);
+ }
+ }
+
+ @Override
+ public void info(@SuppressWarnings("rawtypes") Enum arg0, LogFields arg1, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void info(@SuppressWarnings("rawtypes") Enum arg0, LogFields arg1, MdcOverride arg2, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void trace(@SuppressWarnings("rawtypes") Enum errorCode, String... args) {
+ if (isTraceEnabled()) {
+ invokeErrorCodeLogger(debugLogger::trace, (EELFResolvableErrorEnum) errorCode, args);
+ }
+ }
+
+ @Override
+ public void trace(@SuppressWarnings("rawtypes") Enum arg0, LogFields arg1, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void warn(@SuppressWarnings("rawtypes") Enum errorCode, String... args) {
+ if (isWarnEnabled()) {
+ invokeErrorCodeLogger(errorLogger::warn, (EELFResolvableErrorEnum) errorCode, args);
+ }
+ }
+
+ @Override
+ public void warn(@SuppressWarnings("rawtypes") Enum arg0, LogFields arg1, String... args) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Get the method name for a calling method (from the current stack trace)
+ *
+ * @param level number of levels for the caller (not including this method)
+ * @return the class and name of the calling method in the form "class#method"
+ */
+ public static String getCallerMethodName(int level) {
+ StackTraceElement callingMethod = Thread.currentThread().getStackTrace()[level + 2];
+ return callingMethod.getClassName() + "#" + callingMethod.getMethodName();
+ }
+
+ /**
+ * Convenience method to be used only for testing purposes.
+ *
+ * @return the directory storing the log files
+ */
+ public static String getLogDirectory() {
+ ch.qos.logback.classic.Logger logger =
+ (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger("com.att.eelf");
+ AsyncAppender appender = (AsyncAppender) logger.getAppender("asyncEELF");
+ FileAppender<?> fileAppender = (FileAppender<?>) appender.getAppender("EELF");
+ return new File(fileAppender.getFile()).getParent();
+ }
+
+ private void setMdcClassName() {
+ MDC.put(MdcParameter.CLASS_NAME.value(), getCallerMethodName(3));
+ }
+
+ private void unsetMdcClassName() {
+ MDC.put(MdcParameter.CLASS_NAME.value(), null);
+ }
+
+ /**
+ * Set the Begin, End, and Elapsed time values in the MDC context.
+ *
+ * @param stopwatch
+ */
+ private void setMdcElapsedTime(final StopWatch stopwatch) {
+ long startTime = stopwatch.getStartTime();
+ long elapsedTime = stopwatch.getTime();
+
+ setContextValue(MdcParameter.BEGIN_TIMESTAMP, timestampFormat.format(startTime));
+ setContextValue(MdcParameter.END_TIMESTAMP, timestampFormat.format(startTime + elapsedTime));
+ setContextValue(MdcParameter.ELAPSED_TIME, Long.toString(elapsedTime)); // Milliseconds
+ }
+
+ /**
+ * @param logMethod the logger method to invoke
+ * @param message
+ */
+ private void invokeLogger(Consumer<String> logMethod, String message) {
+ setMdcClassName();
+ logMethod.accept(message);
+ unsetMdcClassName();
+ }
+
+ /**
+ * @param logMethod
+ * @param msg
+ * @param args
+ */
+ private void invokeLogger(BiConsumer<ApplicationMsgs, String[]> logMethod, ApplicationMsgs msg, String[] args) {
+ setMdcClassName();
+ logMethod.accept(msg, args);
+ unsetMdcClassName();
+ }
+
+ /**
+ * @param logMethod
+ * @param errorEnum
+ * @param args
+ */
+ private void invokeErrorCodeLogger(BiConsumer<EELFResolvableErrorEnum, String[]> logMethod,
+ EELFResolvableErrorEnum errorEnum, String[] args) {
+ setMdcClassName();
+ logMethod.accept(errorEnum, args);
+ unsetMdcClassName();
+ }
+
+ /**
+ * @param logMethod
+ * @param errorEnum
+ * @param t a Throwable
+ * @param args
+ */
+ private void invokeErrorCodeLogger(TriConsumer<EELFResolvableErrorEnum, Throwable, String[]> logMethod,
+ EELFResolvableErrorEnum errorEnum, Throwable t, String[] args) {
+ setMdcClassName();
+ logMethod.accept(errorEnum, t, args);
+ unsetMdcClassName();
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
new file mode 100644
index 0000000..3bccebe
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -0,0 +1,302 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.parser;
+
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
+import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
+import org.onap.aai.babel.xml.generator.model.AllotedResource;
+import org.onap.aai.babel.xml.generator.model.L3NetworkWidget;
+import org.onap.aai.babel.xml.generator.model.Model;
+import org.onap.aai.babel.xml.generator.model.ProvidingService;
+import org.onap.aai.babel.xml.generator.model.Resource;
+import org.onap.aai.babel.xml.generator.model.Service;
+import org.onap.aai.babel.xml.generator.model.TunnelXconnectWidget;
+import org.onap.aai.babel.xml.generator.model.VfModule;
+import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.cl.api.Logger;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.toscaparser.api.Group;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Property;
+
+public class ArtifactGeneratorToscaParser {
+
+ public static final String GENERATOR_AAI_ERROR_INVALID_ID =
+ "Invalid value for mandatory attribute <%s> in Artifact: <%s>";
+ private static final String ALLOTTED_RESOURCE = "Allotted Resource";
+ private static final String TUNNEL_XCONNECT = "Tunnel XConnect";
+ private static Logger log = LogHelper.INSTANCE;
+
+ private ISdcCsarHelper csarHelper;
+
+ /**
+ * Constructs using csarHelper
+ *
+ * @param csarHelper The csar helper
+ */
+ public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
+ this.csarHelper = csarHelper;
+ }
+
+ /**
+ * Returns the artifact description
+ *
+ * @param model the artifact model
+ * @return the artifact model's description
+ */
+ public static String getArtifactDescription(Model model) {
+ String artifactDesc = model.getModelDescription();
+ if (model.getModelType().equals(ModelType.SERVICE)) {
+ artifactDesc = "AAI Service Model";
+ } else if (model.getModelType().equals(ModelType.RESOURCE)) {
+ artifactDesc = "AAI Resource Model";
+ }
+ return artifactDesc;
+ }
+
+ /**
+ * Initialises the widget configuration.
+ *
+ * @throws IOException
+ */
+ public static void initWidgetConfiguration() throws IOException {
+ log.debug("Getting Widget Configuration");
+ String configLocation = System.getProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE);
+ if (configLocation != null) {
+ File file = new File(configLocation);
+ if (file.exists()) {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(file));
+ WidgetConfigurationUtil.setConfig(properties);
+ } else {
+ throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND, configLocation));
+ }
+ } else {
+ throw new IllegalArgumentException(GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
+ }
+ }
+
+ /**
+ * Generates a Resource List using input Service Node Templates
+ *
+ * @param serviceNodes input Service Node Templates
+ * @param idTypeStore ID->Type mapping
+ * @return the processed resource models
+ */
+ public List<Resource> processResourceToscas(List<NodeTemplate> serviceNodes, Map<String, String> idTypeStore) {
+ List<Resource> resources = new LinkedList<>();
+ for (NodeTemplate serviceNode : serviceNodes) {
+ List<NodeTemplate> resourceNodes = csarHelper.getNodeTemplateChildren(serviceNode);
+
+ String resourceUuId = serviceNode.getMetaData().getValue("UUID");
+ String mapValue = idTypeStore.get(resourceUuId);
+ if (mapValue != null) {
+ Model model = Model.getModelFor(idTypeStore.get(serviceNode.getMetaData().getValue("UUID")));
+
+ log.debug("Inside Resource artifact generation for resource");
+ Map<String, String> serviceMetadata = serviceNode.getMetaData().getAllProperties();
+ model.populateModelIdentificationInformation(serviceMetadata);
+
+ // Found model from the type store so removing the same
+ idTypeStore.remove(model.getModelNameVersionId());
+ processVfTosca(idTypeStore, model, resourceNodes);
+
+ // Process group information from tosca for vfModules
+ if (csarHelper.getServiceVfList() != null) {
+ processVfModules(resources, model, serviceNode);
+ }
+
+ if (hasSubCategoryTunnelXConnect(serviceMetadata) && hasAllottedResource(serviceMetadata)) {
+ model.addWidget(new TunnelXconnectWidget());
+ }
+ resources.add((Resource) model);
+ }
+ }
+ return resources;
+ }
+
+ private void processVfModules(List<Resource> resources, Model model, NodeTemplate serviceNode) {
+ // Get the customisation UUID for each VF node and use it to get its Groups
+ String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNode);
+
+ // Populate a Map of Group against NodeTemplates that are members of the Group
+ List<Group> serviceGroups = csarHelper.getVfModulesByVf(uuid);
+
+ // Process each VF Group
+ for (Group serviceGroup : serviceGroups) {
+ Model groupModel = Model.getModelFor(serviceGroup.getType());
+ if (groupModel instanceof VfModule) {
+ processVfModule(resources, model, serviceGroup, serviceNode, (VfModule) groupModel);
+ }
+ }
+
+ }
+
+ private void processVfModule(List<Resource> resources, Model model, Group groupDefinition, NodeTemplate serviceNode,
+ VfModule groupModel) {
+ // Populate group with metadata properties
+ groupModel.populateModelIdentificationInformation(groupDefinition.getMetadata().getAllProperties());
+ // Populate group with non-metadata properties
+ Map<String, Property> groupProperties = groupDefinition.getProperties();
+ Map<String, String> properties = populateStringProperties(groupProperties);
+ groupModel.populateModelIdentificationInformation(properties);
+ processVfModuleGroup(resources, model, groupDefinition, serviceNode, groupModel);
+ }
+
+ private void processVfModuleGroup(List<Resource> resources, Model model, Group groupDefinition,
+ NodeTemplate serviceNode, VfModule groupModel) {
+ // Get names of the members of the service group
+ List<NodeTemplate> members = csarHelper.getMembersOfVfModule(serviceNode, groupDefinition);
+ if (members != null && !members.isEmpty()) {
+ List<String> memberNames = members.stream().map(NodeTemplate::getName).collect(Collectors.toList());
+ groupModel.setMembers(memberNames);
+ for (NodeTemplate nodeTemplate : members) {
+ processNodeTemplate(groupModel, nodeTemplate);
+ }
+ }
+
+ model.addResource(groupModel); // Added group (VfModule) to the (VF) model
+ // Check if we have already encountered the same VfModule across all the artifacts
+ if (!resources.contains(groupModel)) {
+ resources.add(groupModel);
+ }
+ }
+
+ private static void processNodeTemplate(Model group, NodeTemplate nodeTemplate) {
+ Model resourceNode;
+ // L3-network inside vf-module to be generated as Widget a special handling.
+ if (nodeTemplate.getType().contains("org.openecomp.resource.vl")) {
+ resourceNode = new L3NetworkWidget();
+ } else {
+ resourceNode = Model.getModelFor(nodeTemplate.getType());
+ }
+ if (resourceNode != null && !(resourceNode instanceof Resource)) {
+ Widget widget = (Widget) resourceNode;
+ widget.addKey(nodeTemplate.getName());
+ // Add the widget element encountered to the Group model
+ group.addWidget(widget);
+ }
+ }
+
+ /**
+ * Process the service tosca
+ *
+ * @param service model of the service artifact
+ * @param idTypeStore ID->Type mapping
+ * @param nodeTemplates a list of service nodes
+ *
+ */
+ public void processServiceTosca(Service service, Map<String, String> idTypeStore,
+ List<NodeTemplate> nodeTemplates) {
+ log.debug("Inside Service Tosca ");
+ // Get the resource/widgets in the service according to the node-template types
+ for (NodeTemplate node : nodeTemplates) {
+ Model model = Model.getModelFor(correctNodeType(node));
+ if (model != null) {
+ model.populateModelIdentificationInformation(node.getMetaData().getAllProperties());
+ if (model instanceof Resource) {
+ // Keeping track of resource types and
+ // their uuid for identification during resource tosca processing
+ idTypeStore.put(model.getModelNameVersionId(), correctNodeType(node));
+ service.addResource((Resource) model);
+ } else {
+ service.addWidget((Widget) model);
+ }
+ }
+ }
+ }
+
+ private String correctNodeType(NodeTemplate nodeType) {
+ String correctedNodeType = nodeType.getType();
+ if (hasAllottedResource(nodeType.getMetaData().getAllProperties())) {
+ if (nodeType.getType().contains("org.openecomp.resource.vf.")) {
+ correctedNodeType = "org.openecomp.resource.vf.allottedResource";
+ }
+ if (nodeType.getType().contains("org.openecomp.resource.vfc.")) {
+ correctedNodeType = "org.openecomp.resource.vfc.AllottedResource";
+ }
+ }
+ return correctedNodeType;
+ }
+
+ private boolean hasAllottedResource(Map<String, String> metadata) {
+ return ALLOTTED_RESOURCE.equals(metadata.get(GeneratorConstants.CATEGORY));
+ }
+
+ private boolean hasSubCategoryTunnelXConnect(Map<String, String> metadata) {
+ return TUNNEL_XCONNECT.equals(metadata.get(GeneratorConstants.SUBCATEGORY));
+ }
+
+ /**
+ * Create a Map of property name against String property value from the input Map
+ *
+ * @param inputMap The input Map
+ * @return Map of property name against String property value
+ */
+ private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
+ return inputMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
+ e -> e.getValue().getValue() == null ? "" : e.getValue().getValue().toString()));
+ }
+
+ private void processVfTosca(Map<String, String> idTypeStore, Model model, List<NodeTemplate> resourceNodes) {
+ boolean flag = false;
+
+ for (NodeTemplate resourceNodeTemplate : resourceNodes) {
+ Model resourceNode = Model.getModelFor(correctNodeType(resourceNodeTemplate));
+ if (resourceNode instanceof ProvidingService) {
+ flag = true;
+ Map<String, Property> nodeProperties = resourceNodeTemplate.getProperties();
+ if (nodeProperties.get("providing_service_uuid") == null
+ || nodeProperties.get("providing_service_invariant_uuid") == null) {
+ throw new IllegalArgumentException(
+ String.format(GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, model.getModelId()));
+ }
+ Map<String, String> properties = populateStringProperties(nodeProperties);
+ properties.put(GeneratorConstants.VERSION, "1.0");
+ resourceNode.populateModelIdentificationInformation(properties);
+ model.addResource((Resource) resourceNode);
+ } else if (resourceNode instanceof Resource && !(resourceNode.getWidgetType().equals(Widget.Type.L3_NET))) {
+ idTypeStore.put(resourceNode.getModelNameVersionId(), correctNodeType(resourceNodeTemplate));
+ model.addResource((Resource) resourceNode);
+ }
+ }
+
+ if (model instanceof AllotedResource && !flag) {
+ throw new IllegalArgumentException(
+ String.format(GENERATOR_AAI_PROVIDING_SERVICE_MISSING, model.getModelId()));
+ }
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/request/RequestHeaders.java b/src/main/java/org/onap/aai/babel/request/RequestHeaders.java
new file mode 100644
index 0000000..f0d960c
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/request/RequestHeaders.java
@@ -0,0 +1,84 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.request;
+
+import java.util.Optional;
+import javax.ws.rs.core.HttpHeaders;
+
+/** Bean to represent the ECOMP request/transaction IDs required for EELF logging. */
+public class RequestHeaders {
+
+ // ECOMP request ID a.k.a. transaction ID or correlation ID
+ public static final String HEADER_REQUEST_ID = "X-ECOMP-RequestID";
+ public static final String HEADER_SERVICE_INSTANCE_ID = "X-ECOMP-ServiceInstanceID";
+ // This value should match with org.openecomp.restclient.client.Headers.TRANSACTION_ID
+ private static final String HEADER_X_TRANSACTION_ID = "X-TransactionId";
+
+ private String requestId;
+ private String instanceId;
+ private String transactionId;
+
+ public RequestHeaders(HttpHeaders headers) {
+ requestId = headers.getHeaderString(RequestHeaders.HEADER_REQUEST_ID);
+ instanceId = headers.getHeaderString(RequestHeaders.HEADER_SERVICE_INSTANCE_ID);
+ transactionId = headers.getHeaderString(RequestHeaders.HEADER_X_TRANSACTION_ID);
+ }
+
+ public String getRequestId() {
+ return requestId;
+ }
+
+ public String getInstanceId() {
+ return instanceId;
+ }
+
+ public String getTransactionId() {
+ return transactionId;
+ }
+
+ /**
+ * Get the global request ID from the HTTP headers. The value will be taken from the header "X-ECOMP-RequestID" if
+ * this is set, or else the value of "X-TransactionId" (which may be null).
+ *
+ * <p>
+ * If the correlation ID contains the symbol : then this character and any trailing characters are removed. This
+ * allows for an incrementing numeric sequence where there are multiple HTTP requests for a single transaction.
+ *
+ * @return the normalsed UUID used for correlating transactions across components, or else null (if no ID is set)
+ */
+ public String getCorrelationId() {
+ // If the request ID is missing, use the transaction ID (if present)
+ String uuid = Optional.ofNullable(getRequestId()).orElse(getTransactionId());
+
+ // Normalize the correlation ID by removing any suffix
+ if (uuid != null && uuid.contains(":")) {
+ uuid = uuid.split(":")[0];
+ }
+
+ return uuid;
+ }
+
+ @Override
+ public String toString() {
+ return "RequestHeaders [requestId=" + requestId + ", instanceId=" + instanceId + ", transactionId="
+ + transactionId + "]";
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/service/GenerateArtifactsService.java b/src/main/java/org/onap/aai/babel/service/GenerateArtifactsService.java
index bb7b721..7034149 100644
--- a/src/main/java/org/onap/aai/babel/service/GenerateArtifactsService.java
+++ b/src/main/java/org/onap/aai/babel/service/GenerateArtifactsService.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.service;
@@ -34,9 +32,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.onap.aai.auth.AAIAuthException;
-/**
- * Generate artifacts from the specified request content
- */
+/** Generate artifacts from the specified request content */
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -46,6 +42,4 @@ public interface GenerateArtifactsService {
@Path("/generateArtifacts")
Response generateArtifacts(@Context UriInfo uriInfo, @Context HttpHeaders headers,
@Context HttpServletRequest servletRequest, String request) throws AAIAuthException;
-
-
}
diff --git a/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java b/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java
index bdb45b5..eef7476 100644
--- a/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java
+++ b/src/main/java/org/onap/aai/babel/service/GenerateArtifactsServiceImpl.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,16 +17,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.service;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonSyntaxException;
+import com.att.aft.dme2.internal.gson.Gson;
+import com.att.aft.dme2.internal.gson.GsonBuilder;
+import com.att.aft.dme2.internal.gson.JsonSyntaxException;
import java.util.Base64;
import java.util.List;
+import java.util.UUID;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.HttpHeaders;
@@ -34,25 +33,26 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
-import org.onap.aai.auth.AAIAuthException;
+import org.apache.commons.lang.time.StopWatch;
import org.onap.aai.auth.AAIMicroServiceAuth;
import org.onap.aai.auth.AAIMicroServiceAuthCore;
import org.onap.aai.babel.csar.CsarConverterException;
import org.onap.aai.babel.csar.CsarToXmlConverter;
+import org.onap.aai.babel.csar.vnfcatalog.ToscaToCatalogException;
+import org.onap.aai.babel.csar.vnfcatalog.VnfVendorImageExtractor;
import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.logging.LogHelper.MdcParameter;
+import org.onap.aai.babel.logging.LogHelper.StatusCode;
+import org.onap.aai.babel.request.RequestHeaders;
import org.onap.aai.babel.service.data.BabelArtifact;
import org.onap.aai.babel.service.data.BabelRequest;
import org.onap.aai.babel.util.RequestValidationException;
import org.onap.aai.babel.util.RequestValidator;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-
-/**
- * Generate SDC Artifacts by passing in a CSAR payload, Artifact Name and Artifact version
- */
+/** Generate SDC Artifacts by passing in a CSAR payload, Artifact Name and Artifact version */
public class GenerateArtifactsServiceImpl implements GenerateArtifactsService {
- private static Logger applicationLogger = LoggerFactory.getInstance().getLogger(GenerateArtifactsServiceImpl.class);
+ private static final LogHelper applicationLogger = LogHelper.INSTANCE;
private AAIMicroServiceAuth aaiMicroServiceAuth;
@@ -66,14 +66,35 @@ public class GenerateArtifactsServiceImpl implements GenerateArtifactsService {
/*
* (non-Javadoc)
- *
+ *
* @see org.onap.aai.babel.service.GenerateArtifactsService#generateArtifacts(javax.ws.rs.core.UriInfo,
* javax.ws.rs.core.HttpHeaders, javax.servlet.http.HttpServletRequest, java.lang.String)
*/
@Override
public Response generateArtifacts(UriInfo uriInfo, HttpHeaders headers, HttpServletRequest servletRequest,
- String requestBody) throws AAIAuthException {
- applicationLogger.debug("Received request: " + requestBody);
+ String requestBody) {
+ applicationLogger.startAudit(headers, servletRequest);
+ applicationLogger.info(ApplicationMsgs.BABEL_REQUEST_PAYLOAD,
+ "Received request: " + headers.getRequestHeaders() + requestBody);
+ applicationLogger.debug(String.format(
+ "Received request. UriInfo \"%s\", HttpHeaders \"%s\", ServletRequest \"%s\", Request \"%s\"", uriInfo,
+ headers, servletRequest, requestBody));
+
+ // Additional name/value pairs according to EELF guidelines
+ applicationLogger.setContextValue("Protocol", "https");
+ applicationLogger.setContextValue("Method", "POST");
+ applicationLogger.setContextValue("Path", uriInfo.getPath());
+ applicationLogger.setContextValue("Query", uriInfo.getPathParameters().toString());
+
+ RequestHeaders requestHeaders = new RequestHeaders(headers);
+ applicationLogger.info(ApplicationMsgs.BABEL_REQUEST_PAYLOAD, requestHeaders.toString());
+
+ String requestId = requestHeaders.getCorrelationId();
+ if (requestId == null) {
+ requestId = UUID.randomUUID().toString();
+ applicationLogger.info(ApplicationMsgs.MISSING_REQUEST_ID, requestId);
+ applicationLogger.setContextValue(MdcParameter.REQUEST_ID, requestId);
+ }
Response response;
try {
@@ -82,23 +103,36 @@ public class GenerateArtifactsServiceImpl implements GenerateArtifactsService {
response = authorized ? generateArtifacts(requestBody)
: buildResponse(Status.UNAUTHORIZED, "User not authorized to perform the operation.");
- } catch (AAIAuthException e) {
+ } catch (Exception e) {
applicationLogger.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, e);
- throw e;
+ applicationLogger.logAuditError(e);
+ return buildResponse(Status.INTERNAL_SERVER_ERROR,
+ "Error while processing request. Please check the babel service logs for more details.\n");
+ }
+
+ StatusCode statusDescription;
+ int statusCode = response.getStatus();
+ if (statusCode / 100 == 2) {
+ statusDescription = StatusCode.COMPLETE;
+ } else {
+ statusDescription = StatusCode.ERROR;
}
+ applicationLogger.logAudit(statusDescription, Integer.toString(statusCode),
+ Response.Status.fromStatusCode(statusCode).getReasonPhrase(), response.getEntity().toString());
- applicationLogger.debug("Sending response: " + response.getStatus() + " " + response.getEntity().toString());
return response;
}
-
/**
* Generate XML model artifacts from request body.
- *
+ *
* @param requestBody the request body in JSON format
* @return response object containing the generated XML models
*/
protected Response generateArtifacts(String requestBody) {
+ StopWatch stopwatch = new StopWatch();
+ stopwatch.start();
+
Response response;
try {
@@ -107,42 +141,53 @@ public class GenerateArtifactsServiceImpl implements GenerateArtifactsService {
BabelRequest babelRequest = gson.fromJson(requestBody, BabelRequest.class);
RequestValidator.validateRequest(babelRequest);
byte[] csarFile = Base64.getDecoder().decode(babelRequest.getCsar());
- List<BabelArtifact> xmlArtifacts = new CsarToXmlConverter().generateXmlFromCsar(csarFile,
+
+ List<BabelArtifact> babelArtifacts = new CsarToXmlConverter().generateXmlFromCsar(csarFile,
babelRequest.getArtifactName(), babelRequest.getArtifactVersion());
- response = buildResponse(Status.OK, gson.toJson(xmlArtifacts));
+ BabelArtifact vendorImageConfiguration = new VnfVendorImageExtractor().extract(csarFile);
+ if (vendorImageConfiguration != null) {
+ babelArtifacts.add(vendorImageConfiguration);
+ }
+
+ response = buildResponse(Status.OK, gson.toJson(babelArtifacts));
} catch (JsonSyntaxException e) {
- applicationLogger.error(ApplicationMsgs.INVALID_REQUEST_JSON, e);
- response = buildResponse(Status.BAD_REQUEST, "Malformed request.");
+ response = processError(ApplicationMsgs.INVALID_REQUEST_JSON, Status.BAD_REQUEST, e, "Malformed request.");
} catch (CsarConverterException e) {
- applicationLogger.error(ApplicationMsgs.INVALID_CSAR_FILE, e);
- response = buildResponse(Status.INTERNAL_SERVER_ERROR, "Error converting CSAR artifact to XML model.");
+ response = processError(ApplicationMsgs.INVALID_CSAR_FILE, Status.INTERNAL_SERVER_ERROR, e,
+ "Error converting CSAR artifact to XML model.");
+ } catch (ToscaToCatalogException e) {
+ response = processError(ApplicationMsgs.PROCESSING_VNF_CATALOG_ERROR, Status.INTERNAL_SERVER_ERROR, e,
+ "Error converting CSAR artifact to VNF catalog.");
} catch (RequestValidationException e) {
- applicationLogger.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, e);
- response = buildResponse(Status.BAD_REQUEST, e.getLocalizedMessage());
+ response =
+ processError(ApplicationMsgs.PROCESS_REQUEST_ERROR, Status.BAD_REQUEST, e, e.getLocalizedMessage());
} catch (Exception e) {
- applicationLogger.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, e);
- response = buildResponse(Status.INTERNAL_SERVER_ERROR,
+ response = processError(ApplicationMsgs.PROCESS_REQUEST_ERROR, Status.INTERNAL_SERVER_ERROR, e,
"Error while processing request. Please check the babel service logs for more details.\n");
+ } finally {
+ applicationLogger.logMetrics(stopwatch, LogHelper.getCallerMethodName(0));
}
return response;
}
+ private Response processError(ApplicationMsgs applicationMsgs, Status responseStatus, Exception e, String message) {
+ applicationLogger.error(applicationMsgs, e);
+
+ return buildResponse(responseStatus, message);
+ }
+
/**
* Helper method to create a REST response object.
- *
+ *
* @param status response status code
* @param entity response payload
* @return
*/
private Response buildResponse(Status status, String entity) {
- //@formatter:off
- return Response
- .status(status)
- .entity(entity)
- .type(MediaType.TEXT_PLAIN)
- .build();
- //@formatter:on
+ // @formatter:off
+ return Response.status(status).entity(entity).type(MediaType.TEXT_PLAIN).build();
+ // @formatter:on
}
}
diff --git a/src/main/java/org/onap/aai/babel/service/InfoService.java b/src/main/java/org/onap/aai/babel/service/InfoService.java
new file mode 100644
index 0000000..107c6d1
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/service/InfoService.java
@@ -0,0 +1,80 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.service;
+
+import java.time.Clock;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.Temporal;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+/**
+ * Information service for the micro-service. Return status details to the caller.
+ *
+ * @exclude
+ */
+@Path("/core-service")
+public class InfoService {
+
+ private Clock clock = Clock.systemDefaultZone();
+ private LocalDateTime startTime = LocalDateTime.now(clock);
+ private long infoCount = 0L;
+
+ /**
+ * @param format is an optional setting - html requests an HTML format
+ * @return a formatted status report
+ */
+ @GET
+ @Path("/info")
+ @Produces("text/plain")
+ public String getInfo(@DefaultValue("text") @QueryParam("format") String format) {
+ return "Status: Up\n" + statusReport(clock) + "\n";
+ }
+
+ /** @return a status report showing the up time for the service */
+ public String statusReport(Clock clock) {
+ Temporal reportTime = LocalDateTime.now(clock);
+ long upTime = ChronoUnit.SECONDS.between(startTime, reportTime);
+ long upTimeDays = ChronoUnit.DAYS.between(startTime, reportTime);
+
+ StringBuilder sb = new StringBuilder("Started at ");
+ sb.append(startTime).append('\n').append("Up time ");
+ if (upTimeDays > 0) {
+ sb.append(upTimeDays).append(" day");
+ if (upTimeDays > 1) {
+ sb.append("s");
+ }
+ sb.append(" ");
+ }
+ sb.append(LocalTime.MIDNIGHT.plusSeconds(upTime).format(DateTimeFormatter.ofPattern("HH:mm:ss"))).append('\n');
+
+ sb.append('\n').append("Info Service").append('\n');
+ sb.append("total=").append(++infoCount).append('\n');
+
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java b/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java
index 986aed9..81c237e 100644
--- a/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java
+++ b/src/main/java/org/onap/aai/babel/service/data/BabelArtifact.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,21 +17,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.service.data;
-/**
- * Bean representing the return artifacts of the Babel microservice.
- */
+/** Bean representing the return artifacts of the Babel microservice. */
public class BabelArtifact {
+
+ public enum ArtifactType {
+ MODEL,
+ VNFCATALOG;
+ }
+
String name;
- String type;
- byte[] payload;
+ ArtifactType type;
+ String payload;
- public BabelArtifact(String name, String type, byte[] payload) {
- super();
+ public BabelArtifact(String name, ArtifactType type, String payload) {
this.name = name;
this.type = type;
this.payload = payload;
@@ -45,19 +46,19 @@ public class BabelArtifact {
this.name = name;
}
- public String getType() {
+ public ArtifactType getType() {
return type;
}
public void setType(String type) {
- this.type = type;
+ this.type = ArtifactType.valueOf(type);
}
- public byte[] getPayload() {
+ public String getPayload() {
return payload;
}
- public void setPayload(byte[] payload) {
+ public void setPayload(String payload) {
this.payload = payload;
}
}
diff --git a/src/main/java/org/onap/aai/babel/service/data/BabelRequest.java b/src/main/java/org/onap/aai/babel/service/data/BabelRequest.java
index 20a101f..47241b4 100644
--- a/src/main/java/org/onap/aai/babel/service/data/BabelRequest.java
+++ b/src/main/java/org/onap/aai/babel/service/data/BabelRequest.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +17,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.service.data;
public class BabelRequest {
private String csar;
- private String artifactVersion;
+ private String artifactVersion;
private String artifactName;
public String getCsar() {
@@ -34,20 +32,20 @@ public class BabelRequest {
public void setCsar(String csar) {
this.csar = csar;
}
-
+
public String getArtifactVersion() {
- return artifactVersion;
- }
+ return artifactVersion;
+ }
- public void setArtifactVersion(String artifactVersion) {
- this.artifactVersion = artifactVersion;
- }
+ public void setArtifactVersion(String artifactVersion) {
+ this.artifactVersion = artifactVersion;
+ }
- public String getArtifactName() {
- return artifactName;
- }
+ public String getArtifactName() {
+ return artifactName;
+ }
- public void setArtifactName(String artifactName) {
- this.artifactName = artifactName;
- }
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
}
diff --git a/src/main/java/org/onap/aai/babel/util/RequestValidationException.java b/src/main/java/org/onap/aai/babel/util/RequestValidationException.java
index 5e3be5e..cf5322a 100644
--- a/src/main/java/org/onap/aai/babel/util/RequestValidationException.java
+++ b/src/main/java/org/onap/aai/babel/util/RequestValidationException.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +17,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.util;
-/**
- * This exception is thrown when the request fails validation.
- */
+/** This exception is thrown when the request fails validation. */
public class RequestValidationException extends Exception {
private static final long serialVersionUID = 1L;
@@ -38,5 +34,3 @@ public class RequestValidationException extends Exception {
super(message);
}
}
-
-
diff --git a/src/main/java/org/onap/aai/babel/util/RequestValidator.java b/src/main/java/org/onap/aai/babel/util/RequestValidator.java
index ecc9d2b..499a5c8 100644
--- a/src/main/java/org/onap/aai/babel/util/RequestValidator.java
+++ b/src/main/java/org/onap/aai/babel/util/RequestValidator.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,21 +17,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.util;
import org.onap.aai.babel.service.data.BabelRequest;
+/** Utility class */
public class RequestValidator {
- private RequestValidator() {}
-
+ /** Empty constructor */
+ private RequestValidator() {
+ // Prevent instantiation
+ }
/**
* Validates that the request body contains the required attributes
- *
+ *
* @param request the request body to validate
*/
public static void validateRequest(BabelRequest request) throws RequestValidationException {
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/ArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/ArtifactGenerator.java
index 4fd51aa..46d5ea4 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/ArtifactGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/ArtifactGenerator.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,23 +17,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.xml.generator;
import java.util.List;
import org.onap.aai.babel.service.data.BabelArtifact;
-import org.openecomp.sdc.generator.data.Artifact;
+import org.onap.aai.babel.xml.generator.data.Artifact;
public interface ArtifactGenerator {
/**
* Generate a {@link List} of {@link BabelArtifact}s from the Artifacts obtained from the CSAR
- *
- * @param csarArtifacts artifacts obtained from the CSAR file
+ *
+ * @param csarArchive original CSAR file (zip format)
+ * @param csarArtifacts YAML artifacts extracted from the CSAR file
* @return generated {@link BabelArtifact}s
+ * @throws XmlArtifactGenerationException
*/
- List<BabelArtifact> generateArtifacts(List<Artifact> csarArtifacts) throws XmlArtifactGenerationException;
-
+ List<BabelArtifact> generateArtifacts(byte[] csarArchive, List<Artifact> csarArtifacts)
+ throws XmlArtifactGenerationException;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java
index c6def3d..65e0ada 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,36 +17,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.xml.generator;
+import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
import org.onap.aai.babel.service.data.BabelArtifact;
+import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
+import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator;
+import org.onap.aai.babel.xml.generator.data.AdditionalParams;
+import org.onap.aai.babel.xml.generator.data.Artifact;
+import org.onap.aai.babel.xml.generator.data.GenerationData;
+import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
+import org.onap.aai.babel.xml.generator.data.GroupType;
import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.openecomp.sdc.generator.data.AdditionalParams;
-import org.openecomp.sdc.generator.data.Artifact;
-import org.openecomp.sdc.generator.data.GenerationData;
-import org.openecomp.sdc.generator.data.GeneratorUtil;
-import org.openecomp.sdc.generator.data.GroupType;
-import org.openecomp.sdc.generator.service.ArtifactGenerationService;
/**
* This class is responsible for generating xml model artifacts from a collection of csar file artifacts
*/
public class ModelGenerator implements ArtifactGenerator {
- private static Logger logger = LoggerFactory.getInstance().getLogger(ModelGenerator.class);
+ private static final Logger logger = LogHelper.INSTANCE;
- private static final String GENERATORCONFIG = "{\"artifactTypes\": [\"AAI\"]}";
- private static final Pattern UUID_NORMATIVE_NEW_VERSION = Pattern.compile("^\\d{1,}.0");
private static final String VERSION_DELIMITER = ".";
private static final String VERSION_DELIMITER_REGEXP = "\\" + VERSION_DELIMITER;
private static final String DEFAULT_SERVICE_VERSION = "1.0";
@@ -54,12 +51,14 @@ public class ModelGenerator implements ArtifactGenerator {
/**
* Invokes the TOSCA artifact generator API with the input artifacts.
*
+ * @param csarArchive
* @param csarArtifacts the input artifacts
* @return {@link List} of output artifacts
* @throws XmlArtifactGenerationException if there is an error trying to generate xml artifacts
*/
@Override
- public List<BabelArtifact> generateArtifacts(List<Artifact> csarArtifacts) throws XmlArtifactGenerationException {
+ public List<BabelArtifact> generateArtifacts(byte[] csarArchive, List<Artifact> csarArtifacts)
+ throws XmlArtifactGenerationException {
logger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
"Generating XML for " + csarArtifacts.size() + " CSAR artifacts.");
@@ -70,19 +69,19 @@ public class ModelGenerator implements ArtifactGenerator {
String serviceVersion = getServiceVersion(toscaVersion);
logger.debug("The service version is " + serviceVersion);
Map<String, String> additionalParams = new HashMap<>();
- additionalParams.put(AdditionalParams.ServiceVersion.getName(), serviceVersion);
+ additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), serviceVersion);
// Call ArtifactGenerator API
logger.debug("Obtaining instance of ArtifactGenerationService");
- ArtifactGenerationService generationService = ArtifactGenerationService.lookup();
+ org.onap.aai.babel.xml.generator.api.ArtifactGenerator generator = new AaiArtifactGenerator();
logger.debug("About to call generationService.generateArtifact()");
- GenerationData data = generationService.generateArtifact(csarArtifacts, GENERATORCONFIG, additionalParams);
+ GenerationData data = generator.generateArtifact(csarArchive, csarArtifacts, additionalParams);
logger.debug("Call generationService.generateArtifact() has finished");
// Convert results into BabelArtifacts
if (data.getErrorData().isEmpty()) {
- return data.getResultData().stream().map(a -> new BabelArtifact(a.getName(), a.getType(), a.getPayload()))
- .collect(Collectors.toList());
+ return data.getResultData().stream().map(a -> new BabelArtifact(a.getName(), ArtifactType.MODEL,
+ new String(Base64.getDecoder().decode(a.getPayload())))).collect(Collectors.toList());
} else {
throw new XmlArtifactGenerationException(
"Error occurred during artifact generation: " + data.getErrorData().toString());
@@ -115,14 +114,10 @@ public class ModelGenerator implements ArtifactGenerator {
String serviceVersion;
try {
- if (UUID_NORMATIVE_NEW_VERSION.matcher(artifactVersion).matches()) {
- serviceVersion = artifactVersion;
- } else {
- String[] versionParts = artifactVersion.split(VERSION_DELIMITER_REGEXP);
- Integer majorVersion = Integer.parseInt(versionParts[0]);
+ String[] versionParts = artifactVersion.split(VERSION_DELIMITER_REGEXP);
+ Integer majorVersion = Integer.parseInt(versionParts[0]);
- serviceVersion = (majorVersion + 1) + VERSION_DELIMITER + "0";
- }
+ serviceVersion = majorVersion + VERSION_DELIMITER + "0";
} catch (Exception e) {
logger.warn(ApplicationMsgs.DISTRIBUTION_EVENT,
"Error generating service version from artifact version: " + artifactVersion
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/XmlArtifactGenerationException.java b/src/main/java/org/onap/aai/babel/xml/generator/XmlArtifactGenerationException.java
index bff6ab3..5e5304b 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/XmlArtifactGenerationException.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/XmlArtifactGenerationException.java
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 European Software Marketing Ltd.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +17,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.babel.xml.generator;
-/**
- * This class represents an exception encountered when generating an Artifact.
- */
+/** This class represents an exception encountered when generating an Artifact. */
public class XmlArtifactGenerationException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
new file mode 100644
index 0000000..bdcd71c
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
@@ -0,0 +1,239 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.api;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.io.FileUtils;
+import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser;
+import org.onap.aai.babel.xml.generator.data.AdditionalParams;
+import org.onap.aai.babel.xml.generator.data.Artifact;
+import org.onap.aai.babel.xml.generator.data.ArtifactType;
+import org.onap.aai.babel.xml.generator.data.GenerationData;
+import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
+import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
+import org.onap.aai.babel.xml.generator.data.GroupType;
+import org.onap.aai.babel.xml.generator.model.Model;
+import org.onap.aai.babel.xml.generator.model.Resource;
+import org.onap.aai.babel.xml.generator.model.Service;
+import org.onap.aai.cl.api.Logger;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.slf4j.MDC;
+
+public class AaiArtifactGenerator implements ArtifactGenerator {
+
+ private static final String ARTIFACT_MODEL_INFO = "ARTIFACT_MODEL_INFO";
+
+ private static Logger log = LogHelper.INSTANCE;
+
+ @Override
+ public GenerationData generateArtifact(byte[] csarArchive, List<Artifact> input,
+ Map<String, String> additionalParams) {
+ Path path = null;
+
+ try {
+ ArtifactGeneratorToscaParser.initWidgetConfiguration();
+ String serviceVersion = validateServiceVersion(additionalParams);
+ GenerationData generationData = new GenerationData();
+
+ path = createTempFile(csarArchive);
+ if (path != null) {
+ ISdcCsarHelper csarHelper =
+ SdcToscaParserFactory.getInstance().getSdcCsarHelper(path.toAbsolutePath().toString());
+
+ List<NodeTemplate> serviceNodes =
+ csarHelper.getServiceNodeTemplates();
+ Map<String, String> serviceMetaData = csarHelper.getServiceMetadataAllProperties();
+
+ if (serviceNodes == null) {
+ throw new IllegalArgumentException(GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA);
+ }
+
+ // Populate basic service model metadata
+ Service serviceModel = new Service();
+ serviceModel.populateModelIdentificationInformation(serviceMetaData);
+ serviceModel.setModelVersion(serviceVersion);
+
+ Map<String, String> idTypeStore = new HashMap<>();
+
+ ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(csarHelper);
+ if (!serviceNodes.isEmpty()) {
+ parser.processServiceTosca(serviceModel, idTypeStore, serviceNodes);
+ }
+
+ // Process the resource TOSCA files
+ List<Resource> resources = parser.processResourceToscas(serviceNodes, idTypeStore);
+
+ // Generate AAI XML service model
+ AaiModelGenerator modelGenerator = AaiModelGenerator.getInstance();
+ MDC.put(ARTIFACT_MODEL_INFO, serviceModel.getModelName() + "," + getArtifactLabel(serviceModel));
+ String aaiServiceModel = modelGenerator.generateModelFor(serviceModel);
+ generationData.add(getServiceArtifact(serviceModel, aaiServiceModel));
+
+ // Generate AAI XML resource model
+ for (Resource res : resources) {
+ MDC.put(ARTIFACT_MODEL_INFO, res.getModelName() + "," + getArtifactLabel(res));
+ String aaiResourceModel = modelGenerator.generateModelFor(res);
+ generationData.add(getResourceArtifact(res, aaiResourceModel));
+
+ }
+ }
+ return generationData;
+ } catch (Exception e) {
+ log.error(ApplicationMsgs.INVALID_CSAR_FILE, e);
+ GenerationData generationData = new GenerationData();
+ generationData.add(ArtifactType.AAI.name(), e.getMessage());
+ return generationData;
+
+ } finally {
+ if (path != null) {
+ FileUtils.deleteQuietly(path.toFile());
+ }
+ }
+ }
+
+ private Path createTempFile(byte[] bytes) {
+ Path path = null;
+ try {
+ log.debug("Creating temp file on file system for the csar");
+ path = Files.createTempFile("temp", ".csar");
+ Files.write(path, bytes);
+ } catch (IOException e) {
+ log.error(ApplicationMsgs.TEMP_FILE_ERROR, e);
+ }
+ return path;
+ }
+
+ /**
+ * Method to generate the artifact label for AAI model
+ *
+ * @param model
+ * @return the artifact label as String
+ */
+ public String getArtifactLabel(Model model) {
+ StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
+ artifactName.append("-");
+ artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append("-");
+ artifactName.append(hashCodeUuId(model.getModelNameVersionId()));
+ return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-");
+ }
+
+ /**
+ * Method to generate the artifact name for an AAI model.
+ *
+ * @param model AAI artifact model
+ * @return Model artifact name
+ */
+ private String getArtifactName(Model model) {
+ StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name());
+ artifactName.append("-");
+
+ String truncatedArtifactName = truncateName(model.getModelName());
+ artifactName.append(truncatedArtifactName);
+
+ artifactName.append("-");
+ artifactName.append(model.getModelType().name().toLowerCase());
+ artifactName.append("-");
+ artifactName.append(model.getModelVersion());
+
+ artifactName.append(".");
+ artifactName.append(GeneratorConstants.GENERATOR_AAI_GENERATED_ARTIFACT_EXTENSION);
+ return artifactName.toString();
+ }
+
+ /**
+ * Create Resource artifact model from the AAI xml model string.
+ *
+ * @param resourceModel Model of the resource artifact
+ * @param aaiResourceModel AAI model as string
+ * @return Generated {@link Artifact} model for the resource
+ */
+ private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
+ Artifact artifact = new Artifact(ArtifactType.MODEL_INVENTORY_PROFILE.name(), GroupType.DEPLOYMENT.name(),
+ GeneratorUtil.checkSum(aaiResourceModel.getBytes()), GeneratorUtil.encode(aaiResourceModel.getBytes()));
+ String resourceArtifactName = getArtifactName(resourceModel);
+ String resourceArtifactLabel = getArtifactLabel(resourceModel);
+ artifact.setName(resourceArtifactName);
+ artifact.setLabel(resourceArtifactLabel);
+ String description = ArtifactGeneratorToscaParser.getArtifactDescription(resourceModel);
+ artifact.setDescription(description);
+ return artifact;
+ }
+
+ /**
+ * Create Service artifact model from the AAI xml model string.
+ *
+ * @param serviceModel Model of the service artifact
+ * @param aaiServiceModel AAI model as string
+ * @return Generated {@link Artifact} model for the service
+ */
+ private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
+ Artifact artifact = new Artifact(ArtifactType.MODEL_INVENTORY_PROFILE.name(), GroupType.DEPLOYMENT.name(),
+ GeneratorUtil.checkSum(aaiServiceModel.getBytes()), GeneratorUtil.encode(aaiServiceModel.getBytes()));
+ String serviceArtifactName = getArtifactName(serviceModel);
+ String serviceArtifactLabel = getArtifactLabel(serviceModel);
+ artifact.setName(serviceArtifactName);
+ artifact.setLabel(serviceArtifactLabel);
+ String description = ArtifactGeneratorToscaParser.getArtifactDescription(serviceModel);
+ artifact.setDescription(description);
+ return artifact;
+ }
+
+ private int hashCodeUuId(String uuId) {
+ int hashcode = 0;
+ for (int i = 0; i < uuId.length(); i++) {
+ hashcode = 31 * hashcode + uuId.charAt(i);
+ }
+ return hashcode;
+ }
+
+ private String truncateName(String name) {
+ String truncatedName = name;
+ if (name.length() >= 200) {
+ truncatedName = name.substring(0, 199);
+ }
+ return truncatedName;
+ }
+
+ private String validateServiceVersion(Map<String, String> additionalParams) {
+ String serviceVersion;
+ serviceVersion = additionalParams.get(AdditionalParams.SERVICE_VERSION.getName());
+ if (serviceVersion == null) {
+ throw new IllegalArgumentException(GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
+ } else {
+ String versionRegex = "^[1-9]\\d*(\\.0)$";
+ if (!(serviceVersion.matches(versionRegex))) {
+ throw new IllegalArgumentException(
+ String.format(GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION));
+ }
+ }
+ return serviceVersion;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
new file mode 100644
index 0000000..f8571f3
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java
@@ -0,0 +1,64 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.api;
+
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.ERROR_CATEGORY;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.ERROR_CODE;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.ERROR_DESCRIPTION;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_ERROR_CODE;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_ERROR_SERVICE_INSTANTIATION_FAILED;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_PARTNER_NAME;
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.PARTNER_NAME;
+
+import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.logging.CategoryLogLevel;
+import org.onap.aai.babel.xml.generator.model.Resource;
+import org.onap.aai.babel.xml.generator.model.Service;
+import org.onap.aai.cl.api.Logger;
+import org.slf4j.MDC;
+
+public interface AaiModelGenerator {
+
+ /**
+ * Gets instance.
+ *
+ * @return the instance
+ */
+ public static AaiModelGenerator getInstance() {
+ Logger log = LogHelper.INSTANCE;
+ try {
+ return AaiModelGenerator.class
+ .cast(Class.forName("org.onap.aai.babel.xml.generator.api.AaiModelGeneratorImpl").newInstance());
+ } catch (Exception exception) {
+ MDC.put(PARTNER_NAME, GENERATOR_PARTNER_NAME);
+ MDC.put(ERROR_CATEGORY, CategoryLogLevel.ERROR.name());
+ MDC.put(ERROR_CODE, GENERATOR_ERROR_CODE);
+ MDC.put(ERROR_DESCRIPTION, GENERATOR_ERROR_SERVICE_INSTANTIATION_FAILED);
+ log.error(ApplicationMsgs.PROCESS_REQUEST_ERROR, exception);
+ }
+ return null;
+ }
+
+ public String generateModelFor(Service service);
+
+ public String generateModelFor(Resource resource);
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
new file mode 100644
index 0000000..488faae
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorImpl.java
@@ -0,0 +1,260 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.api;
+
+import java.io.StringWriter;
+import java.util.List;
+import java.util.Set;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import org.onap.aai.babel.logging.ApplicationMsgs;
+import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.model.Resource;
+import org.onap.aai.babel.xml.generator.model.Service;
+import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.xsd.Model;
+import org.onap.aai.babel.xml.generator.xsd.ModelElement;
+import org.onap.aai.babel.xml.generator.xsd.ModelElements;
+import org.onap.aai.babel.xml.generator.xsd.ModelVer;
+import org.onap.aai.babel.xml.generator.xsd.ModelVers;
+import org.onap.aai.babel.xml.generator.xsd.Relationship;
+import org.onap.aai.babel.xml.generator.xsd.RelationshipData;
+import org.onap.aai.babel.xml.generator.xsd.RelationshipList;
+import org.onap.aai.cl.api.Logger;
+import org.w3c.dom.DOMException;
+
+/**
+ * Implementation of the {@link AaiModelGenerator} which generates the XML models from the Service/Resource/Widget java
+ * models.
+ */
+public class AaiModelGeneratorImpl implements AaiModelGenerator {
+ private static Logger log = LogHelper.INSTANCE;
+
+ /**
+ * Method to generate the AAI model for a Service.
+ *
+ * @param service Java object model representing an AAI {@link Service} model
+ * @return XML representation of the service model in String format
+ */
+ @Override
+ public String generateModelFor(Service service) {
+ // Create a JAXB Model for AAI service model
+ Model aaiServiceModel = new Model();
+ log.debug("Generating Model for Service with ModelName: " + service.getModelName());
+ // after new model
+ aaiServiceModel.setModelInvariantId(service.getModelId());
+ aaiServiceModel.setModelVers(new ModelVers());
+ ModelVer modelVer = new ModelVer();
+ modelVer.setModelDescription(service.getModelDescription());
+ modelVer.setModelName(service.getModelName());
+ modelVer.setModelVersion(service.getModelVersion());
+ modelVer.setModelVersionId(service.getModelNameVersionId());
+ modelVer.setModelElements(new ModelElements());
+ ModelElements modelElements = modelVer.getModelElements();
+ // Populate basic model details
+ aaiServiceModel.setModelType(service.getModelType().name().toLowerCase()); // Using enum name as model type
+ List<ModelElement> modelElementList = modelElements.getModelElement();
+
+ // Add service base widget model element
+ ModelElement serviceWidgetModelRelationshipElement = createRelationshipModelElement(
+ getNewDataDelFlagValue(service.getDeleteFlag()), service.getWidgetId(), service.getWidgetInvariantId());
+ modelElementList.add(serviceWidgetModelRelationshipElement);
+
+ // Add the resource model elements
+ ModelElements serviceModelElements = serviceWidgetModelRelationshipElement.getModelElements();
+ List<ModelElement> serviceModelElementList = serviceModelElements.getModelElement();
+ Set<Resource> serviceResources = service.getResources();
+ if (serviceResources != null && !serviceResources.isEmpty()) {
+ for (Resource resourceModel : serviceResources) {
+ ModelElement aaiResourceModelElement =
+ createRelationshipModelElement(getNewDataDelFlagValue(resourceModel.getDeleteFlag()),
+ resourceModel.getModelNameVersionId(), resourceModel.getModelId());
+ serviceModelElementList.add(aaiResourceModelElement);
+ }
+ }
+
+ // Add the widget model elements
+ Set<Widget> serviceWidgets = service.getWidgets();
+ if (serviceWidgets != null && !serviceWidgets.isEmpty()) {
+ for (Widget widgetModel : serviceWidgets) {
+ ModelElement widgetModelElement =
+ createRelationshipModelElement(getNewDataDelFlagValue(widgetModel.getDeleteFlag()),
+ widgetModel.getId(), widgetModel.getWidgetId());
+ serviceModelElementList.add(widgetModelElement);
+ }
+ }
+ ModelVers modelVers = aaiServiceModel.getModelVers();
+ List<ModelVer> modelVerList = modelVers.getModelVer();
+ modelVerList.add(modelVer);
+ return getModelAsString(aaiServiceModel);
+ }
+
+ /**
+ * Method to generate the AAI model for a Resource.
+ *
+ * @param resource Java object model representing an AAI {@link Resource} model
+ * @return XML representation of the resource model in String format
+ */
+ @Override
+ public String generateModelFor(Resource resource) {
+ // Create a JAXB Model for AAI Resource model
+ Model aaiResourceModel = new Model();
+ log.debug("Generating Model for Resource with ModelName: " + resource.getModelName());
+ aaiResourceModel.setModelInvariantId(resource.getModelId());
+ aaiResourceModel.setModelVers(new ModelVers());
+ ModelVer modelVer = new ModelVer();
+ modelVer.setModelDescription(resource.getModelDescription());
+ modelVer.setModelName(resource.getModelName());
+ modelVer.setModelVersion(resource.getModelVersion());
+ modelVer.setModelVersionId(resource.getModelNameVersionId());
+ modelVer.setModelElements(new ModelElements());
+ ModelElements modelElements = modelVer.getModelElements();
+ aaiResourceModel.setModelType(resource.getModelType().name().toLowerCase()); // Using enum name as model type
+ List<ModelElement> modelElementList = modelElements.getModelElement();
+
+ // Add resource base widget model element
+ ModelElement resourceWidgetModelRelationshipElement =
+ createRelationshipModelElement(getNewDataDelFlagValue(resource.getDeleteFlag()), resource.getWidgetId(),
+ resource.getWidgetInvariantId());
+ modelElementList.add(resourceWidgetModelRelationshipElement);
+
+ // Add the child resources to the base widget model element list
+ ModelElements baseResourceWidgetModelElements = resourceWidgetModelRelationshipElement.getModelElements();
+ List<ModelElement> baseResourceWidgetModelElementList = baseResourceWidgetModelElements.getModelElement();
+ Set<Resource> childResources = resource.getResources();
+ if (childResources != null && !childResources.isEmpty()) {
+ for (Resource childResourceModel : childResources) {
+ ModelElement aaiChildResourceModelElement =
+ createRelationshipModelElement(getNewDataDelFlagValue(childResourceModel.getDeleteFlag()),
+ childResourceModel.getModelNameVersionId(), childResourceModel.getModelId());
+ baseResourceWidgetModelElementList.add(aaiChildResourceModelElement);
+ }
+ }
+ // Add resource widgets/resources to the resource widget model relationship element
+ Set<Widget> resourceWidgets = resource.getWidgets();
+ if (resourceWidgets != null && !resourceWidgets.isEmpty()) {
+ generateWidgetChildren(resourceWidgetModelRelationshipElement, resourceWidgets);
+ }
+
+ ModelVers modelVers = aaiResourceModel.getModelVers();
+ List<ModelVer> modelVerList = modelVers.getModelVer();
+ modelVerList.add(modelVer);
+ return getModelAsString(aaiResourceModel);
+ }
+
+ /**
+ * Method to create the <model-element></model-element> holding the relationship value for a resource/widget model.
+ *
+ * @param newDataDelFlag Value of the <new-data-del-flag></new-data-del-flag> attribute for a widget/resource in the
+ * model xml
+ * @param relationshipValue Value of the <relationship-value></relationship-value> attribute for the widget/resource
+ * in the model xml
+ * @return Java object representation for the <model-element></model-element> holding the relationship
+ */
+ private ModelElement createRelationshipModelElement(String newDataDelFlag, String modelVersionId,
+ String modelInvariantId) {
+ ModelElement relationshipModelElement = new ModelElement();
+ relationshipModelElement.setNewDataDelFlag(newDataDelFlag); // Set new-data-del-flag value
+ relationshipModelElement.setCardinality("unbounded");
+ RelationshipList relationShipList = new RelationshipList();
+ final List<Relationship> relationships = relationShipList.getRelationship();
+ Relationship relationship = new Relationship();
+ relationship.setRelatedTo("model-ver");
+ List<RelationshipData> relationshipDataList = relationship.getRelationshipData();
+
+ RelationshipData modelVersionRelationshipData = new RelationshipData();
+ modelVersionRelationshipData.setRelationshipKey("model-ver.model-version-id");
+ modelVersionRelationshipData.setRelationshipValue(modelVersionId); // Set the widget/resource name-version-uuid
+ // as value
+ relationshipDataList.add(modelVersionRelationshipData);
+ RelationshipData modelInvariantRelationshipData = new RelationshipData();
+ modelInvariantRelationshipData.setRelationshipKey("model.model-invariant-id");
+ modelInvariantRelationshipData.setRelationshipValue(modelInvariantId);
+ relationshipDataList.add(modelInvariantRelationshipData);
+ relationships.add(relationship);
+ relationshipModelElement.setRelationshipList(relationShipList);
+ relationshipModelElement.setModelElements(new ModelElements());
+ return relationshipModelElement;
+ }
+
+ /**
+ * Method to create the child model elements of the widget. Handles the generation of recursive child widget
+ * elements (if any)
+ *
+ * @param parent Reference to the parent widget model element
+ * @param widgetChildrenSet Set of children obtained from the tosca/widget definition
+ */
+ private void generateWidgetChildren(ModelElement parent, Set<Widget> widgetChildrenSet) {
+ for (Widget widget : widgetChildrenSet) {
+ Set<Widget> widgetSubChildren = widget.getWidgets();
+ if (widgetSubChildren != null && !widgetSubChildren.isEmpty()) {
+ ModelElement widgetChildRelationshipElement = createRelationshipModelElement(
+ getNewDataDelFlagValue(widget.getDeleteFlag()), widget.getId(), widget.getWidgetId());
+ // Recursive call for getting the children of widgets (if any)
+ generateWidgetChildren(widgetChildRelationshipElement, widgetSubChildren);
+ parent.getModelElements().getModelElement().add(widgetChildRelationshipElement);
+ } else {
+ ModelElement widgetChildRelationshipElement = createRelationshipModelElement(
+ getNewDataDelFlagValue(widget.getDeleteFlag()), widget.getId(), widget.getWidgetId());
+ parent.getModelElements().getModelElement().add(widgetChildRelationshipElement);
+ }
+ }
+ }
+
+ /**
+ * Converts the data delete flag value from boolean to String as per AAI model.
+ *
+ * @param delFlag Boolean value as true/false from the annotation
+ * @return Converted value to a flag as per AAI model
+ */
+ private String getNewDataDelFlagValue(boolean delFlag) {
+ if (delFlag) {
+ return "T";
+ } else {
+ return "F";
+ }
+ }
+
+ /**
+ * JAXB marshalling helper method to convert the Java object model to XML String.
+ *
+ * @param model Java Object model of a service/widget/resource
+ * @return XML representation of the Java model in String format
+ */
+ private String getModelAsString(Model model) {
+ JAXBContext jaxbContext;
+ StringWriter modelStringWriter = new StringWriter();
+ try {
+ jaxbContext = JAXBContext.newInstance(Model.class);
+ Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
+ jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "US-ASCII");
+ jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
+ jaxbMarshaller.marshal(model, modelStringWriter);
+ } catch (JAXBException jaxbException) {
+ log.error(ApplicationMsgs.INVALID_CSAR_FILE, jaxbException);
+ throw new DOMException(DOMException.SYNTAX_ERR, jaxbException.getMessage());
+ }
+
+ return modelStringWriter.toString();
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/ArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/ArtifactGenerator.java
new file mode 100644
index 0000000..b5c8f5b
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/ArtifactGenerator.java
@@ -0,0 +1,41 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.api;
+
+import java.util.List;
+import java.util.Map;
+import org.onap.aai.babel.xml.generator.data.Artifact;
+import org.onap.aai.babel.xml.generator.data.GenerationData;
+
+/** Artifact Generation. Note that there is only one implementation of this interface currently. */
+public interface ArtifactGenerator {
+
+ /**
+ * Implementation of the method to generate AAI artifacts.
+ *
+ * @param csarArchive original CSAR (zip format)
+ * @param input List of input tosca files
+ * @param additionalParams
+ * @return Translated/Error data as a {@link GenerationData} object
+ */
+ public GenerationData generateArtifact(byte[] csarArchive, List<Artifact> input,
+ Map<String, String> additionalParams);
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/AdditionalParams.java b/src/main/java/org/onap/aai/babel/xml/generator/data/AdditionalParams.java
new file mode 100644
index 0000000..00b276c
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/AdditionalParams.java
@@ -0,0 +1,35 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+public enum AdditionalParams {
+ SERVICE_VERSION("serviceVersion");
+
+ private String name;
+
+ AdditionalParams(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java b/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java
new file mode 100644
index 0000000..50dfc89
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/Artifact.java
@@ -0,0 +1,96 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+public class Artifact {
+
+ String name;
+ String type;
+ String groupType;
+ String description;
+ String label;
+ String version;
+ String checksum;
+ byte[] payload;
+
+ /**
+ * Instantiates a new Artifact.
+ *
+ * @param type the type
+ * @param groupType the group type
+ * @param checksum the checksum
+ * @param payload the payload
+ */
+ public Artifact(String type, String groupType, String checksum, byte[] payload) {
+ this.type = type;
+ this.groupType = groupType;
+ this.checksum = checksum;
+ this.payload = payload;
+ }
+
+ public byte[] getPayload() {
+ return payload;
+ }
+
+ public String getChecksum() {
+ return checksum;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getGroupType() {
+ return groupType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/ArtifactType.java b/src/main/java/org/onap/aai/babel/xml/generator/data/ArtifactType.java
new file mode 100644
index 0000000..572342a
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/ArtifactType.java
@@ -0,0 +1,27 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+public enum ArtifactType {
+ OTHER,
+ AAI,
+ MODEL_INVENTORY_PROFILE
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java
new file mode 100644
index 0000000..f59cb66
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GenerationData.java
@@ -0,0 +1,65 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class GenerationData {
+
+ List<Artifact> resultData = new ArrayList<>();
+ Map<String, List<String>> errorData = new HashMap<>();
+
+ public void add(List<Artifact> resultData, Map<String, List<String>> errorData) {
+ this.resultData.addAll(resultData);
+ this.errorData.putAll(errorData);
+ }
+
+ public void add(Artifact generatedArtifact) {
+ resultData.add(generatedArtifact);
+ }
+
+ /**
+ * Add the error code to the list of error codes for the given ID
+ *
+ * @param generatorId the generator id
+ * @param errorCode the error code
+ */
+ public void add(String generatorId, String errorCode) {
+ errorData.computeIfAbsent(generatorId, k -> new ArrayList<>());
+ errorData.get(generatorId).add(errorCode);
+ }
+
+ public void add(GenerationData generationData) {
+ this.resultData.addAll(generationData.resultData);
+ this.errorData.putAll(generationData.errorData);
+ }
+
+ public List<Artifact> getResultData() {
+ return resultData;
+ }
+
+ public Map<String, List<String>> getErrorData() {
+ return errorData;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java
new file mode 100644
index 0000000..40e8eb9
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorConstants.java
@@ -0,0 +1,92 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+public class GeneratorConstants {
+
+ /*
+ * Private constructor to prevent instantiation
+ */
+ private GeneratorConstants() {
+ throw new UnsupportedOperationException("This static class should not be instantiated!");
+ }
+
+ public static final String PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE = "artifactgenerator.config";
+
+ public static final String VERSION = "version";
+ public static final String CATEGORY = "category";
+ public static final String SUBCATEGORY = "subcategory";
+ public static final int ID_LENGTH = 36;
+
+ public static final String GENERATOR_AAI_GENERATED_ARTIFACT_EXTENSION = "xml";
+
+ // Error codes
+ public static final String GENERATOR_INVOCATION_ERROR_CODE = "ARTIFACT_GENERATOR_INVOCATION_ERROR";
+
+ // Error Constants
+ public static final String GENERATOR_ERROR_INVALID_CLIENT_CONFIGURATION = "Invalid Client Configuration";
+ public static final String GENERATOR_ERROR_ARTIFACT_GENERATION_FAILED =
+ "Unable to generate artifacts for the provided input";
+ public static final String GENERATOR_ERROR_SERVICE_INSTANTIATION_FAILED =
+ "Artifact Generation Service Instantiation failed";
+
+ // AAI Generator Error Messages
+ public static final String GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH = "Checksum Mismatch for file : %s";
+ public static final String GENERATOR_AAI_ERROR_INVALID_TOSCA = "Invalid format for Tosca YML : %s";
+ public static final String GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION = "Operation Not Supported for Widgets";
+ public static final String GENERATOR_AAI_ERROR_MISSING_SERVICE_TOSCA =
+ "Service tosca missing from list of input artifacts";
+ public static final String GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA =
+ "Invalid Service definition mandatory attribute version missing for resource with UUID: <%s>";
+
+ public static final String GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA =
+ "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with " + "UUID: "
+ + "<%s>";
+ public static final String GENERATOR_AAI_ERROR_MISSING_RESOURCE_TOSCA =
+ "Cannot generate artifacts. Resource Tosca missing for resource with UUID: <%s>";
+
+ public static final String GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION =
+ "Cannot generate artifacts. Service version is not specified";
+
+ public static final String GENERATOR_AAI_INVALID_SERVICE_VERSION =
+ "Cannot generate artifacts. Service version is incorrect";
+
+ // Logging constants
+ public static final String PARTNER_NAME = "userId";
+ public static final String ERROR_CATEGORY = "ErrorCategory";
+ public static final String ERROR_CODE = "ErrorCode";
+ public static final String ERROR_DESCRIPTION = "ErrorDescription";
+
+ public static final String GENERATOR_ERROR_CODE = "300F";
+ public static final String GENERATOR_PARTNER_NAME = "SDC Catalog";
+
+ // AAI Generator Error Messages for Logging
+ public static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
+ "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
+ public static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
+ "Cannot generate artifacts. artifactgenerator.config system property not configured";
+ public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
+ "Cannot generate artifacts. Widget configuration not found for %s";
+ public static final String GENERATOR_AAI_PROVIDING_SERVICE_MISSING =
+ "Cannot generate artifacts. Providing Service is missing for allotted resource %s";
+ public static final String GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING =
+ "Cannot generate artifacts. Providing Service Metadata is missing for allotted resource %s";
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java
new file mode 100644
index 0000000..905c859
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GeneratorUtil.java
@@ -0,0 +1,65 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+import java.util.Base64;
+import org.apache.commons.codec.digest.DigestUtils;
+
+/** Utility method class for artifact generation. */
+public class GeneratorUtil {
+
+ /*
+ * Private constructor to prevent instantiation
+ */
+ private GeneratorUtil() {
+ throw new UnsupportedOperationException("This static class should not be instantiated!");
+ }
+
+ /**
+ * Decodes Base64 encode byte array input.
+ *
+ * @param input Base64 encoded byte array
+ * @return Decoded byte array
+ */
+ public static byte[] decoder(byte[] input) {
+ return input != null ? Base64.getDecoder().decode(input) : new byte[0];
+ }
+
+ /**
+ * Encode a byte array input using Base64 encoding.
+ *
+ * @param input Input byte array to be encoded
+ * @return Base64 encoded byte array
+ */
+ public static byte[] encode(byte[] input) {
+ return input != null ? Base64.getEncoder().encode(input) : new byte[0];
+ }
+
+ /**
+ * Calculate the checksum for a given input.
+ *
+ * @param input Byte array for which the checksum has to be calculated
+ * @return Calculated checksum of the input byte array
+ */
+ public static String checkSum(byte[] input) {
+ return input != null ? DigestUtils.md5Hex(input).toUpperCase() : null;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GroupType.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupType.java
new file mode 100644
index 0000000..b2bc3f9
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupType.java
@@ -0,0 +1,26 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+public enum GroupType {
+ DEPLOYMENT,
+ OTHER
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
new file mode 100644
index 0000000..d36982d
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
@@ -0,0 +1,43 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.data;
+
+import java.util.Properties;
+
+public class WidgetConfigurationUtil {
+
+ private static Properties config;
+
+ /*
+ * Private constructor to prevent instantiation
+ */
+ private WidgetConfigurationUtil() {
+ throw new UnsupportedOperationException("This static class should not be instantiated!");
+ }
+
+ public static Properties getConfig() {
+ return config;
+ }
+
+ public static void setConfig(Properties config) {
+ WidgetConfigurationUtil.config = config;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/error/IllegalAccessException.java b/src/main/java/org/onap/aai/babel/xml/generator/error/IllegalAccessException.java
new file mode 100644
index 0000000..3c907cb
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/error/IllegalAccessException.java
@@ -0,0 +1,30 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.error;
+
+public class IllegalAccessException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public IllegalAccessException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java b/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java
new file mode 100644
index 0000000..b6ca2d3
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java
@@ -0,0 +1,29 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.logging;
+
+public enum CategoryLogLevel {
+ INFO,
+ WARN,
+ DEBUG,
+ ERROR,
+ FATAL
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java
new file mode 100644
index 0000000..cecf7bd
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java
@@ -0,0 +1,28 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+
+@Model(widget = Widget.Type.ALLOTTED_RESOURCE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+public class AllotedResource extends Resource {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java
new file mode 100644
index 0000000..740ca62
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResourceWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.ALLOTTED_RESOURCE,
+ cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "allotted-resource")
+public class AllotedResourceWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java
new file mode 100644
index 0000000..26dde9b
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/FlavorWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.FLAVOR, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
+@ModelWidget(type = ModelType.WIDGET, name = "flavor")
+public class FlavorWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java
new file mode 100644
index 0000000..60656b2
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/ImageWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.IMAGE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
+@ModelWidget(type = ModelType.WIDGET, name = "image")
+public class ImageWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java b/src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java
new file mode 100644
index 0000000..105c3a1
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java
@@ -0,0 +1,28 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = false)
+public class L3Network extends Resource {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java
new file mode 100644
index 0000000..f737b82
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/L3NetworkWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "l3-network")
+public class L3NetworkWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java
new file mode 100644
index 0000000..fb07ef6
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/LIntfWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.LINT, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "l-interface")
+public class LIntfWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
new file mode 100644
index 0000000..262d29a
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
@@ -0,0 +1,248 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
+import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+
+public abstract class Model {
+
+ protected Set<Resource> resources = new HashSet<>();
+ protected Set<Widget> widgets = new HashSet<>();
+ private String modelId;
+ private String modelName;
+ private String modelVersion;
+ private String modelNameVersionId;
+ private String modelDescription;
+
+ /**
+ * Gets the object (model) corresponding to the supplied TOSCA type.
+ *
+ * @param toscaType the tosca type
+ * @return the model for the type, or null
+ */
+ public static Model getModelFor(String toscaType) {
+ Model modelToBeReturned = null;
+ String typePrefix = toscaType;
+ while (modelToBeReturned == null && typePrefix != null && typePrefix.lastIndexOf('.') != -1) {
+ switch (typePrefix) {
+ case "org.openecomp.resource.vf.allottedResource":
+ modelToBeReturned = new AllotedResource();
+ break;
+ case "org.openecomp.resource.vfc.AllottedResource":
+ modelToBeReturned = new ProvidingService();
+ break;
+ case "org.openecomp.resource.vfc":
+ modelToBeReturned = new VServerWidget();
+ break;
+ case "org.openecomp.resource.cp":
+ case "org.openecomp.cp":
+ modelToBeReturned = new LIntfWidget();
+ break;
+ case "org.openecomp.resource.vl":
+ modelToBeReturned = new L3Network();
+ break;
+ case "org.openecomp.resource.vf":
+ modelToBeReturned = new VirtualFunction();
+ break;
+ case "org.openecomp.groups.vfmodule":
+ case "org.openecomp.groups.VfModule":
+ modelToBeReturned = new VfModule();
+ break;
+ case "org.openecomp.resource.vfc.nodes.heat.cinder":
+ modelToBeReturned = new VolumeWidget();
+ break;
+ default:
+ modelToBeReturned = null;
+ break;
+ }
+ typePrefix = typePrefix.substring(0, typePrefix.lastIndexOf('.'));
+ }
+
+ return modelToBeReturned;
+ }
+
+ public abstract boolean addResource(Resource resource);
+
+ public abstract boolean addWidget(Widget resource);
+
+ /**
+ * Gets widget version id.
+ *
+ * @return the widget version id
+ */
+ public String getWidgetId() {
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ return Widget.getWidget(model.widget()).getId();
+ }
+
+ /**
+ * Gets invariant id.
+ *
+ * @return the invariant id
+ */
+ public String getWidgetInvariantId() {
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ return Widget.getWidget(model.widget()).getWidgetId();
+ }
+
+ /**
+ * Gets delete flag.
+ *
+ * @return the delete flag
+ */
+ public boolean getDeleteFlag() {
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ return model.dataDeleteFlag();
+ }
+
+ /**
+ * Gets cardinality.
+ *
+ * @return the cardinality
+ */
+ public Cardinality getCardinality() {
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ return model.cardinality();
+ }
+
+ public abstract Widget.Type getWidgetType();
+
+ public String getModelId() {
+ checkSupported();
+ return modelId;
+ }
+
+ /**
+ * Gets model type.
+ *
+ * @return the model type
+ */
+ public ModelType getModelType() {
+ if (this instanceof Service) {
+ return ModelType.SERVICE;
+ } else if (this instanceof Resource) {
+ return ModelType.RESOURCE;
+ } else if (this instanceof Widget) {
+ return ModelType.WIDGET;
+ } else {
+ return null;
+ }
+ }
+
+ public String getModelName() {
+ return modelName;
+ }
+
+ public String getModelVersion() {
+ return modelVersion;
+ }
+
+ public String getModelNameVersionId() {
+ checkSupported();
+ return modelNameVersionId;
+ }
+
+ public String getModelDescription() {
+ return modelDescription;
+ }
+
+ /**
+ * Populate model identification information.
+ *
+ * @param modelIdentInfo the model ident info
+ */
+ public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
+ Iterator<String> iter = modelIdentInfo.keySet().iterator();
+ String property;
+ while (iter.hasNext()) {
+ property = iter.next();
+ switch (property) {
+ case "vfModuleModelInvariantUUID":
+ case "serviceInvariantUUID":
+ case "resourceInvariantUUID":
+ case "invariantUUID":
+ case "providing_service_invariant_uuid":
+ modelId = modelIdentInfo.get(property);
+ break;
+ case "vfModuleModelUUID":
+ case "resourceUUID":
+ case "serviceUUID":
+ case "UUID":
+ case "providing_service_uuid":
+ modelNameVersionId = modelIdentInfo.get(property);
+ break;
+ case "vfModuleModelVersion":
+ case "serviceVersion":
+ case "resourceversion":
+ case "version":
+ modelVersion = modelIdentInfo.get(property);
+ break;
+ case "vfModuleModelName":
+ case "serviceName":
+ case "resourceName":
+ case "name":
+ modelName = modelIdentInfo.get(property);
+ break;
+ case "serviceDescription":
+ case "resourceDescription":
+ case "vf_module_description":
+ case "description":
+ modelDescription = modelIdentInfo.get(property);
+ break;
+ case "providing_service_name":
+ modelName = modelIdentInfo.get(property);
+ modelDescription = modelIdentInfo.get(property);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public void setModelVersion(String modelVersion) {
+ this.modelVersion = modelVersion;
+ }
+
+ public Set<Resource> getResources() {
+ return resources;
+ }
+
+ public Set<Widget> getWidgets() {
+ return widgets;
+ }
+
+ private void checkSupported() {
+ if (this instanceof Widget) {
+ throw new IllegalAccessException(GeneratorConstants.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java b/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java
new file mode 100644
index 0000000..e9076a9
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/OamNetwork.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "oam-network")
+public class OamNetwork extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java
new file mode 100644
index 0000000..e25274e
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java
@@ -0,0 +1,28 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.ALLOTTED_RESOURCE,
+ cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
+public class ProvidingService extends Resource {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
new file mode 100644
index 0000000..9d4feab
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
@@ -0,0 +1,54 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+public class Resource extends Model {
+
+ @Override
+ public int hashCode() {
+ return getModelNameVersionId().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Resource) {
+ return getModelNameVersionId().equals(((Resource) obj).getModelNameVersionId());
+ }
+ return false;
+ }
+
+ @Override
+ public boolean addResource(Resource resource) {
+ return resources.add(resource);
+ }
+
+ @Override
+ public boolean addWidget(Widget widget) {
+ return widgets.add(widget);
+ }
+
+ @Override
+ public Widget.Type getWidgetType() {
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ return model.widget();
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java
new file mode 100644
index 0000000..a0f84c7
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/ResourceWidget.java
@@ -0,0 +1,24 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+public class ResourceWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
new file mode 100644
index 0000000..9d22e41
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
@@ -0,0 +1,43 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.SERVICE, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+public class Service extends Model {
+
+ @Override
+ public boolean addResource(Resource resource) {
+ return resources.add(resource);
+ }
+
+ @Override
+ public boolean addWidget(Widget widget) {
+ return widgets.add(widget);
+ }
+
+ @Override
+ public Widget.Type getWidgetType() {
+ return null;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java
new file mode 100644
index 0000000..7c2229d
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/ServiceWidget.java
@@ -0,0 +1,28 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@ModelWidget(type = ModelType.WIDGET, name = "service-instance")
+public class ServiceWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java
new file mode 100644
index 0000000..a0a4392
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/TenantWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.TENANT, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false)
+@ModelWidget(type = ModelType.WIDGET, name = "tenant")
+public class TenantWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java
new file mode 100644
index 0000000..548cd6f
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/TunnelXconnectWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.TUNNEL_XCONNECT, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "tunnel-xconnect")
+public class TunnelXconnectWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java
new file mode 100644
index 0000000..7de0f5b
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VServerWidget.java
@@ -0,0 +1,44 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.VSERVER, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "vserver")
+public class VServerWidget extends Widget {
+
+ /** Instantiates a new V server widget. */
+ public VServerWidget() {
+ addWidget(new FlavorWidget());
+ addWidget(new ImageWidget());
+ addWidget(new TenantWidget());
+ addWidget(new VfcWidget());
+ }
+
+ @Override
+ public boolean addWidget(Widget widget) {
+ return widgets.add(widget);
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java
new file mode 100644
index 0000000..8b8913d
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java
@@ -0,0 +1,109 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import java.util.List;
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+
+@Model(widget = Widget.Type.VFMODULE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+public class VfModule extends Resource {
+
+ Widget vserver = null;
+ boolean addlintf = false;
+ boolean addvolume = false;
+
+ List<String> members;
+
+ public void setMembers(List<String> members) {
+ this.members = members;
+ }
+
+ /**
+ * Adds Widget.
+ *
+ * @param widget the widget
+ * @return the boolean
+ */
+ @Override
+ public boolean addWidget(Widget widget) {
+ if (widget.memberOf(members)) {
+ if (vserver == null && widget.getId().equals(new VServerWidget().getId())) {
+ addVserverWidget(widget);
+ } else if (widget.getId().equals(new LIntfWidget().getId())) {
+ return addLIntfWidget(widget);
+ } else if (widget.getId().equals(new VolumeWidget().getId())) {
+ addVolumeWidget(widget);
+ return true;
+ }
+ if (widget.getId().equals(new OamNetwork().getId())) {
+ return false;
+ }
+ return widgets.add(widget);
+ }
+ return false;
+ }
+
+ private void addVolumeWidget(Widget widget) {
+ if (vserver != null) {
+ vserver.addWidget(widget);
+ } else {
+ addvolume = true;
+ }
+ }
+
+ /**
+ * @param widget
+ * @return
+ */
+ private boolean addLIntfWidget(Widget widget) {
+ if (vserver != null) {
+ vserver.addWidget(widget);
+ return true;
+ } else {
+ addlintf = true;
+ return false;
+ }
+ }
+
+ private void addVserverWidget(Widget widget) {
+ vserver = widget;
+ if (addlintf) {
+ vserver.addWidget(new LIntfWidget());
+ }
+ if (addvolume) {
+ vserver.addWidget(new VolumeWidget());
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return getModelNameVersionId().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Resource) {
+ return getModelNameVersionId().equals(((Resource) obj).getModelNameVersionId());
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java
new file mode 100644
index 0000000..cc27ca9
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModuleWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VFMODULE, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "vf-module")
+public class VfModuleWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java
new file mode 100644
index 0000000..614244e
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VfWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VF, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "generic-vnf")
+public class VfWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java
new file mode 100644
index 0000000..abfa49f
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VfcWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VFC, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "vnfc")
+public class VfcWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java
new file mode 100644
index 0000000..be75d65
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java
@@ -0,0 +1,28 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+
+@Model(widget = Widget.Type.VF, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+public class VirtualFunction extends Resource {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java
new file mode 100644
index 0000000..3a0aa37
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeGroupWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.VOLUME_GROUP, cardinality = Cardinality.UNBOUNDED,
+ dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "volume-group")
+public class VolumeGroupWidget extends Widget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java
new file mode 100644
index 0000000..d18a723
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/VolumeWidget.java
@@ -0,0 +1,31 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import org.onap.aai.babel.xml.generator.types.Cardinality;
+import org.onap.aai.babel.xml.generator.types.Model;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+@Model(widget = Widget.Type.VOLUME, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true)
+@ModelWidget(type = ModelType.WIDGET, name = "volume")
+public class VolumeWidget extends ResourceWidget {
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
new file mode 100644
index 0000000..545ad79
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
@@ -0,0 +1,211 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.model;
+
+import static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+import org.onap.aai.babel.xml.generator.data.ArtifactType;
+import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
+import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
+import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
+import org.onap.aai.babel.xml.generator.types.ModelType;
+import org.onap.aai.babel.xml.generator.types.ModelWidget;
+
+public abstract class Widget extends Model {
+
+ private Set<String> keys = new HashSet<>();
+
+ /**
+ * Gets widget.
+ *
+ * @param type the type
+ * @return the widget
+ */
+ public static Widget getWidget(Type type) {
+
+ switch (type) {
+ case SERVICE:
+ return new ServiceWidget();
+ case VF:
+ return new VfWidget();
+ case VFC:
+ return new VfcWidget();
+ case VSERVER:
+ return new VServerWidget();
+ case VOLUME:
+ return new VolumeWidget();
+ case FLAVOR:
+ return new FlavorWidget();
+ case TENANT:
+ return new TenantWidget();
+ case VOLUME_GROUP:
+ return new VolumeGroupWidget();
+ case LINT:
+ return new LIntfWidget();
+ case L3_NET:
+ return new L3NetworkWidget();
+ case VFMODULE:
+ return new VfModuleWidget();
+ case IMAGE:
+ return new ImageWidget();
+ case OAM_NETWORK:
+ return new OamNetwork();
+ case ALLOTTED_RESOURCE:
+ return new AllotedResourceWidget();
+ case TUNNEL_XCONNECT:
+ return new TunnelXconnectWidget();
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Gets id.
+ *
+ * @return the id
+ */
+ public String getId() {
+ Properties properties = WidgetConfigurationUtil.getConfig();
+ String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
+ if (id == null) {
+ throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
+ ArtifactType.AAI.name() + ".model-version-id." + getName()));
+ }
+ return id;
+ }
+
+ public ModelType getType() {
+ ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
+ return widgetModel.type();
+ }
+
+ public String getName() {
+ ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
+ return widgetModel.name();
+ }
+
+ /**
+ * Get Widget Id from properties file.
+ *
+ * @return - Widget Id
+ */
+ @Override
+ public String getWidgetId() {
+ Properties properties = WidgetConfigurationUtil.getConfig();
+ String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id." + getName());
+ if (id == null) {
+ throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
+ ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
+ }
+ return id;
+ }
+
+ @Override
+ public int hashCode() {
+ return getId().hashCode();
+ }
+
+ @Override
+ public Type getWidgetType() {
+ return null;
+ }
+
+ /**
+ * Equals.
+ *
+ * @param obj Object
+ * @return the boolean
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Widget) {
+ if (getId().equals(((Widget) obj).getId())) {
+ ((Widget) obj).keys.addAll(this.keys);
+ return true;
+ }
+ return false;
+ } else {
+ return false;
+ }
+ }
+
+ public void addKey(String key) {
+ this.keys.add(key);
+ }
+
+ /**
+ * Member of boolean.
+ *
+ * @param keys the keys
+ * @return the boolean
+ */
+ public boolean memberOf(List<String> keys) {
+ if (keys == null) {
+ return false;
+ }
+ return !Collections.disjoint(this.keys, keys);
+ }
+
+ /**
+ * All instances used boolean.
+ *
+ * @param collection the collection
+ * @return the boolean
+ */
+ public boolean allInstancesUsed(Set<String> collection) {
+ Set<String> keyCopy = new HashSet<>(keys);
+ keyCopy.removeAll(collection);
+ return keyCopy.isEmpty();
+ }
+
+ @Override
+ public boolean addResource(Resource resource) {
+ throw new IllegalAccessException(GeneratorConstants.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
+ }
+
+ @Override
+ public boolean addWidget(Widget widget) {
+ return true;
+ }
+
+ public enum Type {
+ SERVICE,
+ VF,
+ VFC,
+ VSERVER,
+ VOLUME,
+ FLAVOR,
+ TENANT,
+ VOLUME_GROUP,
+ LINT,
+ L3_NET,
+ VFMODULE,
+ IMAGE,
+ OAM_NETWORK,
+ ALLOTTED_RESOURCE,
+ TUNNEL_XCONNECT
+ }
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java b/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java
new file mode 100644
index 0000000..9cdb93b
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/types/Cardinality.java
@@ -0,0 +1,25 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.types;
+
+public enum Cardinality {
+ UNBOUNDED
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java
new file mode 100644
index 0000000..f69c3ea
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/types/Model.java
@@ -0,0 +1,53 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.onap.aai.babel.xml.generator.model.Widget;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Model {
+
+ /**
+ * Widget widget . type.
+ *
+ * @return the widget . type
+ */
+ public Widget.Type widget();
+
+ /**
+ * Data delete flag boolean.
+ *
+ * @return the boolean
+ */
+ public boolean dataDeleteFlag();
+
+ /**
+ * Cardinality cardinality.
+ *
+ * @return the cardinality
+ */
+ public Cardinality cardinality();
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/ModelType.java b/src/main/java/org/onap/aai/babel/xml/generator/types/ModelType.java
new file mode 100644
index 0000000..7dd86c6
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/types/ModelType.java
@@ -0,0 +1,27 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.types;
+
+public enum ModelType {
+ SERVICE,
+ RESOURCE,
+ WIDGET;
+}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java b/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java
new file mode 100644
index 0000000..307524e
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/types/ModelWidget.java
@@ -0,0 +1,45 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
+ * 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.onap.aai.babel.xml.generator.types;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ModelWidget {
+
+ /**
+ * Type model type.
+ *
+ * @return the model type
+ */
+ public ModelType type();
+
+ /**
+ * Name string.
+ *
+ * @return the string
+ */
+ public String name();
+}
diff --git a/src/main/resources/babel-logging-resources.properties b/src/main/resources/babel-logging-resources.properties
index 3cd23ab..dba72c8 100644
--- a/src/main/resources/babel-logging-resources.properties
+++ b/src/main/resources/babel-logging-resources.properties
@@ -46,14 +46,42 @@ DISTRIBUTION_EVENT=\
Distribution event: {0}|\
A distribution event was received from ASDC|\
+MESSAGE_AUDIT=\
+ BABEL0002I|\
+ {0}|\
+ |\
+
+MESSAGE_METRIC=\
+ BABEL0003I|\
+ {0}|\
+ |\
+
PROCESS_REQUEST_ERROR=\
- BABEL0002E|\
+ BABEL0004E|\
Error while processing REST request.|\
INVALID_REQUEST_JSON=\
- BABEL0003E|\
+ BABEL0005E|\
Error while processing JSON in request body.|\
INVALID_CSAR_FILE=\
- BABEL0004E|\
- Error while processing CSAR file.|\ \ No newline at end of file
+ BABEL0006E|\
+ Error while processing CSAR file.|\
+
+PROCESSING_VNF_CATALOG_ERROR=\
+ BABEL0007E|\
+ Error while processing VNF Catalog.|\
+
+BABEL_REQUEST_PAYLOAD=\
+ BABEL0008I|\
+ Babel request payload: {0}|\
+
+BABEL_RESPONSE_PAYLOAD=\
+ BABEL0009I|\
+ Babel response payload: {0}|\
+
+MISSING_REQUEST_ID=\
+ BABEL0010I|\
+ Missing request ID. Assigned {0}|\
+ |\
+ \ No newline at end of file