From 6e4f04afea4c2d07fdd9c15eda38438c7baeb308 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Thu, 26 Apr 2018 16:53:12 +0100 Subject: Convert project from AJSC to Spring Boot Remove all AJSC configuration and dependencies. Update the pom.xml to use oparent and to depend on Spring Boot. Refactor the main class to introduce a minimal set of Spring annotations. Note that the license text was corrected in this change. Issue-ID: AAI-1039 Change-Id: I16385db3216ec39bfd2881f2278e340ec3795199 Signed-off-by: mark.j.leonard --- src/main/bin/start.sh | 42 +- src/main/docker/Dockerfile | 8 +- .../aai/modelloader/config/ModelLoaderConfig.java | 555 +++++++++++---------- .../org/onap/aai/modelloader/entity/Artifact.java | 12 +- .../aai/modelloader/entity/ArtifactHandler.java | 20 +- .../onap/aai/modelloader/entity/ArtifactType.java | 12 +- .../entity/catalog/VnfCatalogArtifact.java | 12 +- .../entity/catalog/VnfCatalogArtifactHandler.java | 12 +- .../entity/catalog/VnfImageException.java | 14 +- .../entity/model/AbstractModelArtifact.java | 13 +- .../entity/model/AbstractModelArtifactParser.java | 15 +- .../model/BabelArtifactParsingException.java | 13 +- .../modelloader/entity/model/IModelArtifact.java | 13 +- .../aai/modelloader/entity/model/IModelId.java | 17 +- .../aai/modelloader/entity/model/IModelParser.java | 13 +- .../modelloader/entity/model/ModelArtifact.java | 20 +- .../entity/model/ModelArtifactHandler.java | 19 +- .../entity/model/ModelArtifactParser.java | 18 +- .../aai/modelloader/entity/model/ModelSorter.java | 28 +- .../entity/model/NamedQueryArtifact.java | 23 +- .../entity/model/NamedQueryArtifactParser.java | 26 +- .../onap/aai/modelloader/entity/model/Pair.java | 13 +- .../extraction/ArtifactInfoExtractor.java | 18 +- .../extraction/InvalidArchiveException.java | 12 +- .../notification/ArtifactDeploymentManager.java | 18 +- .../notification/ArtifactDownloadManager.java | 24 +- .../notification/BabelArtifactConverter.java | 12 +- .../modelloader/notification/BasicStatusMsg.java | 57 +++ .../notification/CompDoneStatusMessageBuilder.java | 27 +- .../notification/CompDoneStatusMsg.java | 49 +- .../DistributionStatusMessageBuilder.java | 30 +- .../notification/DistributionStatusMsg.java | 123 ++--- .../notification/DownloadFailureException.java | 12 +- .../modelloader/notification/EventCallback.java | 21 +- .../notification/NotificationPublisher.java | 34 +- .../ProcessToscaArtifactsException.java | 12 +- .../aai/modelloader/restclient/AaiRestClient.java | 12 +- .../modelloader/restclient/BabelServiceClient.java | 15 +- .../restclient/BabelServiceClientFactory.java | 12 +- .../aai/modelloader/service/ArtifactInfoImpl.java | 25 +- .../service/ModelLoaderApplication.java | 37 ++ .../modelloader/service/ModelLoaderInterface.java | 94 ++-- .../aai/modelloader/service/ModelLoaderMsgs.java | 14 +- .../modelloader/service/ModelLoaderService.java | 138 +++-- .../modelloader/service/NotificationDataImpl.java | 18 +- .../aai/modelloader/service/SdcConnectionJob.java | 18 +- .../aai/modelloader/util/JsonXmlConverter.java | 12 +- src/main/resources/application.properties | 20 + src/main/resources/logback.xml | 151 ++++++ .../modelloader/service/ModelLoaderMsgs.properties | 2 +- .../modelloader/config/ModelLoaderConfigTest.java | 385 +++++++------- .../entity/catalog/TestVnfImageException.java | 49 ++ .../catalog/VnfCatalogArtifactHandlerTest.java | 12 +- .../entity/model/ModelArtifactParserTest.java | 12 +- .../modelloader/entity/model/ModelSorterTest.java | 213 ++++---- .../entity/model/NamedQueryArtifactParserTest.java | 12 +- .../entity/model/TestModelArtifactHandler.java | 124 +++++ .../extraction/ArtifactInfoExtractorTest.java | 17 +- .../modelloader/fixture/ArtifactInfoBuilder.java | 15 +- .../fixture/NotificationDataFixtureBuilder.java | 22 +- .../fixture/ResourceInstanceBuilder.java | 16 +- .../fixture/TestNotificationDataImpl.java | 21 +- .../fixture/TestResourceInstanceImpl.java | 16 +- .../ArtifactDeploymentManagerTest.java | 20 +- .../notification/ArtifactDownloadManagerTest.java | 24 +- .../notification/BabelArtifactConverterTest.java | 22 +- .../notification/EventCallbackTest.java | 232 ++++----- .../notification/TestNotificationPublisher.java | 86 ++++ .../restclient/TestAaiServiceClient.java | 106 ++++ .../restclient/TestBabelServiceClient.java | 97 +++- .../modelloader/service/TestArtifactInfoImpl.java | 123 +++++ .../service/TestModelLoaderApplication.java | 41 ++ .../service/TestNotificationDataImpl.java | 83 +++ .../aai/modelloader/util/ArtifactTestUtils.java | 12 +- .../aai/modelloader/util/JsonXmlConverterTest.java | 157 +++--- src/test/resources/model-loader.properties | 21 +- 76 files changed, 2349 insertions(+), 1524 deletions(-) create mode 100644 src/main/java/org/onap/aai/modelloader/notification/BasicStatusMsg.java create mode 100644 src/main/java/org/onap/aai/modelloader/service/ModelLoaderApplication.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/logback.xml create mode 100644 src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.java create mode 100644 src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java create mode 100644 src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java create mode 100644 src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java create mode 100644 src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java create mode 100644 src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.java create mode 100644 src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java (limited to 'src') diff --git a/src/main/bin/start.sh b/src/main/bin/start.sh index f7b20c4..038f4df 100644 --- a/src/main/bin/start.sh +++ b/src/main/bin/start.sh @@ -4,7 +4,7 @@ # org.onap.aai # =================================================================== # Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. -# Copyright © 2017-2018 Amdocs +# 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. @@ -20,27 +20,37 @@ # ============LICENSE_END============================================ #******************************************************************************* -BASEDIR="/opt/app/model-loader/" -AJSC_HOME="$BASEDIR" +# AJSC_HOME is required for EELF logging. +# This path is referenced in the file logback.xml. +AJSC_HOME="${AJSC_HOME-/opt/app/model-loader}" if [ -z "$CONFIG_HOME" ]; then - echo "CONFIG_HOME must be set in order to start up process" - exit 1 + echo "CONFIG_HOME must be set in order to start up the process" + echo "The expected value is a folder containing the model-loader.properties file" + exit 1 fi -CLASSPATH="$AJSC_HOME/lib/*" -CLASSPATH="$CLASSPATH:$AJSC_HOME/extJars/" -CLASSPATH="$CLASSPATH:$AJSC_HOME/etc/" +JARFILE="$AJSC_HOME/model-loader.jar" + +# Some properties are repeated here for debugging purposes. PROPS="-DAJSC_HOME=$AJSC_HOME" -PROPS="$PROPS -DAJSC_CONF_HOME=$BASEDIR/bundleconfig/" -PROPS="$PROPS -Dlogback.configurationFile=$BASEDIR/bundleconfig/etc/logback.xml" -PROPS="$PROPS -DAJSC_SHARED_CONFIG=$AJSC_CONF_HOME" -PROPS="$PROPS -DAJSC_SERVICE_NAMESPACE=model-loader" -PROPS="$PROPS -DAJSC_SERVICE_VERSION=v1" -PROPS="$PROPS -Dserver.port=9500" PROPS="$PROPS -DCONFIG_HOME=$CONFIG_HOME" +PROPS="$PROPS -Dcom.att.eelf.logging.path=$AJSC_HOME" +PROPS="$PROPS -Dcom.att.eelf.logging.file=logback.xml" +PROPS="$PROPS -Dlogback.configurationFile=$AJSC_HOME/logback.xml" +PROPS="$PROPS -Dserver.port=9500" JVM_MAX_HEAP=${MAX_HEAP:-1024} -echo $CLASSPATH +if [ -z "${java_runtime_arguments}" ]; then + java_runtime_arguments="-Xms75m -Xmx${JVM_MAX_HEAP}m \ + -Dcom.sun.management.jmxremote \ + -Dcom.sun.management.jmxremote.authenticate=false \ + -Dcom.sun.management.jmxremote.ssl=false \ + -Dcom.sun.management.jmxremote.local.only=false \ + -Dcom.sun.management.jmxremote.port=1099 \ + -Dcom.sun.management.jmxremote.rmi.port=1099 \ + -Djava.rmi.server.hostname=127.0.0.1" +fi -exec java -Xmx${JVM_MAX_HEAP}m $PROPS -classpath $CLASSPATH com.att.ajsc.runner.Runner context=// port=9500 +echo "java $java_runtime_arguments $PROPS -jar $JARFILE" +java $java_runtime_arguments $PROPS -jar $JARFILE diff --git a/src/main/docker/Dockerfile b/src/main/docker/Dockerfile index 9aafdda..db67dd9 100644 --- a/src/main/docker/Dockerfile +++ b/src/main/docker/Dockerfile @@ -2,20 +2,22 @@ FROM ubuntu:14.04 ARG MICRO_HOME=/opt/app/model-loader ARG BIN_HOME=$MICRO_HOME/bin +ARG JAR_FILE=model-loader.jar RUN apt-get update # Install and setup java8 RUN apt-get update && apt-get install -y software-properties-common -## sudo -E is required to preserve the environment. If you remove that line, it will most like freeze at this step +## sudo -E is required to preserve the environment. If you remove that line, it will most likely freeze at this step RUN sudo -E add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk -## Setup JAVA_HOME, this is useful for docker commandline +## Set up JAVA_HOME for docker command-line ENV JAVA_HOME usr/lib/jvm/java-8-openjdk-amd64 RUN export JAVA_HOME # Build up the deployment folder structure RUN mkdir -p $MICRO_HOME -ADD swm/package/nix/dist_files/appl/model-loader/* $MICRO_HOME/ +COPY ${JAR_FILE} $MICRO_HOME/ +COPY classes/logback.xml $MICRO_HOME/ RUN mkdir -p $BIN_HOME COPY *.sh $BIN_HOME RUN chmod 755 $BIN_HOME/* diff --git a/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java b/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java index 692f412..3f03bb5 100644 --- a/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java +++ b/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.config; @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; import org.eclipse.jetty.util.security.Password; -import org.openecomp.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.consumer.IConfiguration; /** * Properties for the Model Loader @@ -33,267 +33,286 @@ import org.openecomp.sdc.api.consumer.IConfiguration; */ public class ModelLoaderConfig implements IConfiguration { - // Configuration file structure - public static final String PREFIX_MODEL_LOADER_CONFIG = "ml"; - public static final String PREFIX_DISTRIBUTION_CLIENT = PREFIX_MODEL_LOADER_CONFIG + ".distribution."; - public static final String PREFIX_AAI = PREFIX_MODEL_LOADER_CONFIG + ".aai."; - public static final String PREFIX_BABEL = PREFIX_MODEL_LOADER_CONFIG + ".babel."; - public static final String PREFIX_DEBUG = PREFIX_MODEL_LOADER_CONFIG + ".debug."; - - private static final String SUFFIX_KEYSTORE_FILE = "KEYSTORE_FILE"; - private static final String SUFFIX_KEYSTORE_PASS = "KEYSTORE_PASSWORD"; - - // Configuration file properties - protected static final String PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH = - PREFIX_DISTRIBUTION_CLIENT + "ACTIVE_SERVER_TLS_AUTH"; - protected static final String PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED = PREFIX_DISTRIBUTION_CLIENT + "ASDC_CONNECTION_DISABLE"; - protected static final String PROP_ML_DISTRIBUTION_ASDC_ADDRESS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_ADDRESS"; - protected static final String PROP_ML_DISTRIBUTION_CONSUMER_GROUP = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_GROUP"; - protected static final String PROP_ML_DISTRIBUTION_CONSUMER_ID = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_ID"; - protected static final String PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME = - PREFIX_DISTRIBUTION_CLIENT + "ENVIRONMENT_NAME"; - protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD = - PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_PASS; - protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_FILE = - PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_FILE; - protected static final String PROP_ML_DISTRIBUTION_PASSWORD = PREFIX_DISTRIBUTION_CLIENT + "PASSWORD"; - protected static final String PROP_ML_DISTRIBUTION_POLLING_INTERVAL = - PREFIX_DISTRIBUTION_CLIENT + "POLLING_INTERVAL"; - protected static final String PROP_ML_DISTRIBUTION_POLLING_TIMEOUT = PREFIX_DISTRIBUTION_CLIENT + "POLLING_TIMEOUT"; - protected static final String PROP_ML_DISTRIBUTION_USER = PREFIX_DISTRIBUTION_CLIENT + "USER"; - protected static final String PROP_ML_DISTRIBUTION_ARTIFACT_TYPES = PREFIX_DISTRIBUTION_CLIENT + "ARTIFACT_TYPES"; - protected static final String PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES = PREFIX_DISTRIBUTION_CLIENT + "MSG_BUS_ADDRESSES"; - protected static final String PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP = - PREFIX_DISTRIBUTION_CLIENT + "USE_HTTPS_WITH_DMAAP"; - - protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL"; - protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + SUFFIX_KEYSTORE_FILE; - protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + SUFFIX_KEYSTORE_PASS; - protected static final String PROP_AAI_MODEL_RESOURCE_URL = PREFIX_AAI + "MODEL_URL"; - protected static final String PROP_AAI_NAMED_QUERY_RESOURCE_URL = PREFIX_AAI + "NAMED_QUERY_URL"; - protected static final String PROP_AAI_VNF_IMAGE_RESOURCE_URL = PREFIX_AAI + "VNF_IMAGE_URL"; - protected static final String PROP_AAI_AUTHENTICATION_USER = PREFIX_AAI + "AUTH_USER"; - protected static final String PROP_AAI_AUTHENTICATION_PASSWORD = PREFIX_AAI + "AUTH_PASSWORD"; - - protected static final String PROP_BABEL_BASE_URL = PREFIX_BABEL + "BASE_URL"; - protected static final String PROP_BABEL_KEYSTORE_FILE = PREFIX_BABEL + SUFFIX_KEYSTORE_FILE; - protected static final String PROP_BABEL_KEYSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_KEYSTORE_PASS; - protected static final String PROP_BABEL_GENERATE_RESOURCE_URL = PREFIX_BABEL + "GENERATE_ARTIFACTS_URL"; - - protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR"; - - private Properties modelLoaderProperties = null; - - private String certLocation = "."; - - private List artifactTypes = null; - - private List msgBusAddrs = null; - - private String modelVersion = null; - - - /** - * This is the class constructor. - * - * @param modelLoaderProperties properties needed to be configured for the model loader - * @param certLocation location of the certificate - */ - public ModelLoaderConfig(Properties modelLoaderProperties, String certLocation) { - this.modelLoaderProperties = modelLoaderProperties; - this.certLocation = certLocation; - - // Get list of artifacts - artifactTypes = new ArrayList<>(); - if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES) != null) { - String[] artTypeList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES).split(","); - for (String artType : artTypeList) { - artifactTypes.add(artType); - } - } - - // Get list of message bus addresses - msgBusAddrs = new ArrayList<>(); - if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES) != null) { - String[] msgBusList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES).split(","); - for (String addr : msgBusList) { - msgBusAddrs.add(addr); - } - } - } - - @Override - public boolean activateServerTLSAuth() { - String value = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH); - return value == null ? false : Boolean.parseBoolean(value); - } - - @Override - public String getAsdcAddress() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_ADDRESS); - } - - @Override - public String getConsumerGroup() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_GROUP); - } - - @Override - public String getConsumerID() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_ID); - } - - @Override - public String getEnvironmentName() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME); - } - - @Override - public String getKeyStorePassword() { - return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD)); - } - - @Override - public String getKeyStorePath() { - return certLocation + modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_FILE); - } - - @Override - public String getPassword() { - return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_PASSWORD)); - } - - @Override - public int getPollingInterval() { - return Integer.parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_INTERVAL)); - } - - @Override - public int getPollingTimeout() { - return Integer.parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT)); - } - - @Override - public List getRelevantArtifactTypes() { - return artifactTypes; - } - - @Override - public String getUser() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_USER); - } - - @Override - public boolean isFilterInEmptyResources() { - return false; - } - - @Override - public Boolean isUseHttpsWithDmaap() { - String useHTTPS = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP); - return useHTTPS == null ? false : Boolean.valueOf(useHTTPS); - } - - @Override - public List getMsgBusAddress() { - return msgBusAddrs; - } - - public String getAaiKeyStorePath() { - return certLocation + File.separator + modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_FILE); - } - - public String getBabelKeyStorePath() { - return certLocation + File.separator + modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_FILE); - } - - public String getAaiKeyStorePassword() { - return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_PASSWORD)); - } - - public String getBabelKeyStorePassword() { - return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_PASSWORD)); - } - - public String getAaiBaseUrl() { - return modelLoaderProperties.getProperty(PROP_AAI_BASE_URL); - } - - public String getBabelBaseUrl() { - return modelLoaderProperties.getProperty(PROP_BABEL_BASE_URL); - } - - public String getBabelGenerateArtifactsUrl() { - return modelLoaderProperties.getProperty(PROP_BABEL_GENERATE_RESOURCE_URL); - } - - public String getAaiModelUrl(String version) { - setModelVersion(version); - return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_MODEL_RESOURCE_URL, version); - } - - public String getAaiNamedQueryUrl(String version) { - return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_NAMED_QUERY_RESOURCE_URL, version); - } - - public String getAaiVnfImageUrl() { - return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_VNF_IMAGE_RESOURCE_URL, getModelVersion()); - } - - public String getAaiAuthenticationUser() { - return modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_USER); - } - - public String getModelVersion() { - return modelVersion; - } - - public void setModelVersion(String modelVersion) { - this.modelVersion = modelVersion; - } - - /** - * @return password for AAI authentication that has been reverse-engineered from its obfuscated form. - */ - public String getAaiAuthenticationPassword() { - String password = Password.deobfuscate(modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_PASSWORD)); - - if (password != null && password.isEmpty()) { - password = null; - } - - return password; - } - - /** - * @return a boolean value indicating whether the simulator is enabled. - */ - public boolean getIngestSimulatorEnabled() { - String propValue = modelLoaderProperties.getProperty(PROP_DEBUG_INGEST_SIMULATOR); - return propValue != null && "enabled".equalsIgnoreCase(propValue); - } - - /** - * @return a String value of the defined property with the oxm version - */ - private String updatePropertyOXMVersion(Properties modelLoaderProperties, String propertyName, String version) { - if (version != null) - return modelLoaderProperties.getProperty(propertyName).replace("v*", version); - else - return modelLoaderProperties.getProperty(propertyName); - } - - - - - /** - * @return a boolean value indicating whether model loader is connected to ASDC. - */ - public boolean getASDCConnectionDisabled(){ - String propValue = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED); - return propValue != null && "true".equalsIgnoreCase(propValue); - - } + // Configuration file structure + public static final String PREFIX_MODEL_LOADER_CONFIG = "ml"; + public static final String PREFIX_DISTRIBUTION_CLIENT = PREFIX_MODEL_LOADER_CONFIG + ".distribution."; + public static final String PREFIX_AAI = PREFIX_MODEL_LOADER_CONFIG + ".aai."; + public static final String PREFIX_BABEL = PREFIX_MODEL_LOADER_CONFIG + ".babel."; + public static final String PREFIX_DEBUG = PREFIX_MODEL_LOADER_CONFIG + ".debug."; + + private static final String SUFFIX_KEYSTORE_FILE = "KEYSTORE_FILE"; + private static final String SUFFIX_KEYSTORE_PASS = "KEYSTORE_PASSWORD"; + + // Configuration file properties + protected static final String PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH = + PREFIX_DISTRIBUTION_CLIENT + "ACTIVE_SERVER_TLS_AUTH"; + protected static final String PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED = + PREFIX_DISTRIBUTION_CLIENT + "ASDC_CONNECTION_DISABLE"; + protected static final String PROP_ML_DISTRIBUTION_ASDC_ADDRESS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_ADDRESS"; + protected static final String PROP_ML_DISTRIBUTION_CONSUMER_GROUP = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_GROUP"; + protected static final String PROP_ML_DISTRIBUTION_CONSUMER_ID = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_ID"; + protected static final String PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME = + PREFIX_DISTRIBUTION_CLIENT + "ENVIRONMENT_NAME"; + protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD = + PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_PASS; + protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_FILE = + PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_FILE; + protected static final String PROP_ML_DISTRIBUTION_PASSWORD = PREFIX_DISTRIBUTION_CLIENT + "PASSWORD"; + protected static final String PROP_ML_DISTRIBUTION_POLLING_INTERVAL = + PREFIX_DISTRIBUTION_CLIENT + "POLLING_INTERVAL"; + protected static final String PROP_ML_DISTRIBUTION_POLLING_TIMEOUT = PREFIX_DISTRIBUTION_CLIENT + "POLLING_TIMEOUT"; + protected static final String PROP_ML_DISTRIBUTION_USER = PREFIX_DISTRIBUTION_CLIENT + "USER"; + protected static final String PROP_ML_DISTRIBUTION_ARTIFACT_TYPES = PREFIX_DISTRIBUTION_CLIENT + "ARTIFACT_TYPES"; + protected static final String PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES = + PREFIX_DISTRIBUTION_CLIENT + "MSG_BUS_ADDRESSES"; + protected static final String PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP = + PREFIX_DISTRIBUTION_CLIENT + "USE_HTTPS_WITH_DMAAP"; + + protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL"; + protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + SUFFIX_KEYSTORE_FILE; + protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + SUFFIX_KEYSTORE_PASS; + protected static final String PROP_AAI_MODEL_RESOURCE_URL = PREFIX_AAI + "MODEL_URL"; + protected static final String PROP_AAI_NAMED_QUERY_RESOURCE_URL = PREFIX_AAI + "NAMED_QUERY_URL"; + protected static final String PROP_AAI_VNF_IMAGE_RESOURCE_URL = PREFIX_AAI + "VNF_IMAGE_URL"; + protected static final String PROP_AAI_AUTHENTICATION_USER = PREFIX_AAI + "AUTH_USER"; + protected static final String PROP_AAI_AUTHENTICATION_PASSWORD = PREFIX_AAI + "AUTH_PASSWORD"; + + protected static final String PROP_BABEL_BASE_URL = PREFIX_BABEL + "BASE_URL"; + protected static final String PROP_BABEL_KEYSTORE_FILE = PREFIX_BABEL + SUFFIX_KEYSTORE_FILE; + protected static final String PROP_BABEL_KEYSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_KEYSTORE_PASS; + protected static final String PROP_BABEL_GENERATE_RESOURCE_URL = PREFIX_BABEL + "GENERATE_ARTIFACTS_URL"; + + protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR"; + private static String configHome; + + private Properties modelLoaderProperties = null; + + private String certLocation = "."; + + private List artifactTypes = null; + + private List msgBusAddrs = null; + + private String modelVersion = null; + + protected static final String FILESEP = + (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); + + public static void setConfigHome(String configHome) { + ModelLoaderConfig.configHome = configHome; + } + + public static String propertiesFile() { + return configHome + FILESEP + "model-loader.properties"; + } + + public ModelLoaderConfig(Properties configProperties) { + this(configProperties, ModelLoaderConfig.configHome + FILESEP + "auth" + FILESEP); + } + + /** + * Original constructor + * + * @param modelLoaderProperties properties needed to be configured for the model loader + * @param certLocation location of the certificate + */ + public ModelLoaderConfig(Properties modelLoaderProperties, String certLocation) { + this.modelLoaderProperties = modelLoaderProperties; + this.certLocation = certLocation; + + // Get list of artifacts + artifactTypes = new ArrayList<>(); + if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES) != null) { + String[] artTypeList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES).split(","); + for (String artType : artTypeList) { + artifactTypes.add(artType); + } + } + + // Get list of message bus addresses + msgBusAddrs = new ArrayList<>(); + if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES) != null) { + String[] msgBusList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES).split(","); + for (String addr : msgBusList) { + msgBusAddrs.add(addr); + } + } + } + + + @Override + public boolean activateServerTLSAuth() { + String value = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH); + return value == null ? false : Boolean.parseBoolean(value); + } + + @Override + public String getAsdcAddress() { + return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_ADDRESS); + } + + @Override + public String getConsumerGroup() { + return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_GROUP); + } + + @Override + public String getConsumerID() { + return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_ID); + } + + @Override + public String getEnvironmentName() { + return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME); + } + + @Override + public String getKeyStorePassword() { + return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD)); + } + + @Override + public String getKeyStorePath() { + return certLocation + modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_FILE); + } + + @Override + public String getPassword() { + return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_PASSWORD)); + } + + @Override + public int getPollingInterval() { + return Integer.parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_INTERVAL)); + } + + @Override + public int getPollingTimeout() { + return Integer.parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT)); + } + + @Override + public List getRelevantArtifactTypes() { + return artifactTypes; + } + + @Override + public String getUser() { + return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_USER); + } + + @Override + public boolean isFilterInEmptyResources() { + return false; + } + + @Override + public Boolean isUseHttpsWithDmaap() { + String useHTTPS = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP); + return useHTTPS == null ? false : Boolean.valueOf(useHTTPS); + } + + @Override + public List getMsgBusAddress() { + return msgBusAddrs; + } + + public String getAaiKeyStorePath() { + return certLocation + File.separator + modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_FILE); + } + + public String getBabelKeyStorePath() { + String filename = modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_FILE); + if (filename == null) { + return null; + } else { + return certLocation + File.separator + filename; + } + } + + public String getAaiKeyStorePassword() { + return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_PASSWORD)); + } + + public String getBabelKeyStorePassword() { + return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_PASSWORD)); + } + + public String getAaiBaseUrl() { + return modelLoaderProperties.getProperty(PROP_AAI_BASE_URL); + } + + public String getBabelBaseUrl() { + return modelLoaderProperties.getProperty(PROP_BABEL_BASE_URL); + } + + public String getBabelGenerateArtifactsUrl() { + return modelLoaderProperties.getProperty(PROP_BABEL_GENERATE_RESOURCE_URL); + } + + public String getAaiModelUrl(String version) { + setModelVersion(version); + return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_MODEL_RESOURCE_URL, version); + } + + public String getAaiNamedQueryUrl(String version) { + return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_NAMED_QUERY_RESOURCE_URL, version); + } + public String getAaiVnfImageUrl() { + return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_VNF_IMAGE_RESOURCE_URL, getModelVersion()); + } + + public String getAaiAuthenticationUser() { + return modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_USER); + } + + public String getModelVersion() { + return modelVersion; + } + + public void setModelVersion(String modelVersion) { + this.modelVersion = modelVersion; + } + + /** + * @return password for AAI authentication that has been reverse-engineered from its obfuscated form. + */ + public String getAaiAuthenticationPassword() { + String password = Password.deobfuscate(modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_PASSWORD)); + + if (password != null && password.isEmpty()) { + password = null; + } + + return password; + } + + /** + * @return a boolean value indicating whether the simulator is enabled. + */ + public boolean getIngestSimulatorEnabled() { + String propValue = modelLoaderProperties.getProperty(PROP_DEBUG_INGEST_SIMULATOR); + return propValue != null && "enabled".equalsIgnoreCase(propValue); + } + + /** + * @return a String value of the defined property with the oxm version + */ + private String updatePropertyOXMVersion(Properties modelLoaderProperties, String propertyName, String version) { + if (version != null) + return modelLoaderProperties.getProperty(propertyName).replace("v*", version); + else + return modelLoaderProperties.getProperty(propertyName); + } + + /** + * @return a boolean value indicating whether model loader is connected to ASDC. + */ + public boolean getASDCConnectionDisabled() { + String propValue = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED); + return propValue != null && "true".equalsIgnoreCase(propValue); + + } } diff --git a/src/main/java/org/onap/aai/modelloader/entity/Artifact.java b/src/main/java/org/onap/aai/modelloader/entity/Artifact.java index 4c0e0f1..f576e24 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/Artifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/Artifact.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity; diff --git a/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java b/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java index 9e80e05..b1fed03 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java +++ b/src/main/java/org/onap/aai/modelloader/entity/ArtifactHandler.java @@ -1,27 +1,26 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity; import java.util.List; - import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.restclient.AaiRestClient; @@ -33,9 +32,8 @@ public abstract class ArtifactHandler { this.config = config; } - public abstract boolean pushArtifacts(List artifacts, String distributionId, List completedArtifacts, - AaiRestClient restClient); + public abstract boolean pushArtifacts(List artifacts, String distributionId, + List completedArtifacts, AaiRestClient restClient); - public abstract void rollback(List completedArtifacts, String distributionId, - AaiRestClient aaiClient); + public abstract void rollback(List completedArtifacts, String distributionId, AaiRestClient aaiClient); } diff --git a/src/main/java/org/onap/aai/modelloader/entity/ArtifactType.java b/src/main/java/org/onap/aai/modelloader/entity/ArtifactType.java index 6959936..a58c874 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/ArtifactType.java +++ b/src/main/java/org/onap/aai/modelloader/entity/ArtifactType.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity; diff --git a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifact.java b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifact.java index 3219625..a8f4e60 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifact.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.catalog; diff --git a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java index b224407..85be50b 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java +++ b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.catalog; diff --git a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfImageException.java b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfImageException.java index 9459c49..c116abe 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfImageException.java +++ b/src/main/java/org/onap/aai/modelloader/entity/catalog/VnfImageException.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.catalog; @@ -55,4 +55,4 @@ class VnfImageException extends Exception { return resultCode; } -} \ No newline at end of file +} diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java b/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java index 3c1152f..35c672a 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java @@ -1,29 +1,28 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; import java.util.HashSet; import java.util.List; import java.util.Set; - import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.ArtifactType; diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifactParser.java b/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifactParser.java index fd6af31..35405e6 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifactParser.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifactParser.java @@ -1,24 +1,23 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ - package org.onap.aai.modelloader.entity.model; import java.io.StringReader; @@ -30,12 +29,10 @@ import java.util.stream.Collector; import java.util.stream.IntStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; - import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.service.ModelLoaderMsgs; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/BabelArtifactParsingException.java b/src/main/java/org/onap/aai/modelloader/entity/model/BabelArtifactParsingException.java index 1426e82..a3f14ba 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/BabelArtifactParsingException.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/BabelArtifactParsingException.java @@ -1,24 +1,23 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ - package org.onap.aai.modelloader.entity.model; /** diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/IModelArtifact.java b/src/main/java/org/onap/aai/modelloader/entity/model/IModelArtifact.java index 5978b99..a3b0737 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/IModelArtifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/IModelArtifact.java @@ -1,24 +1,23 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ - package org.onap.aai.modelloader.entity.model; /** diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/IModelId.java b/src/main/java/org/onap/aai/modelloader/entity/model/IModelId.java index 9b635bf..41ac94b 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/IModelId.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/IModelId.java @@ -1,35 +1,34 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ - package org.onap.aai.modelloader.entity.model; /** - * Defines methods for c + * Defines methods for Model Id */ public interface IModelId { /** * This method is responsible for using the values in the supplied Pair to set the id of the model. * - * The definition of what the relationship will be is defined by the implementation. Some model ids would have + * The definition of what the relationship will be is defined by the implementation. Some model ids would have * single key/value pairs, others would have a composite key. * * Where the id of the model is a composite key multiple calls to this method will be required to successfully set diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/IModelParser.java b/src/main/java/org/onap/aai/modelloader/entity/model/IModelParser.java index 758a882..7287142 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/IModelParser.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/IModelParser.java @@ -1,27 +1,26 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; import java.util.List; - import org.onap.aai.modelloader.entity.Artifact; @FunctionalInterface diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifact.java b/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifact.java index 896167a..154cda1 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifact.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; @@ -31,16 +31,14 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; - +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.restclient.AaiRestClient; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.restclient.client.OperationResult; - import org.w3c.dom.Node; public class ModelArtifact extends AbstractModelArtifact { diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactHandler.java b/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactHandler.java index 157ac8d..626ca49 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactHandler.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactHandler.java @@ -1,34 +1,33 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; import java.util.List; - +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.ArtifactHandler; import org.onap.aai.modelloader.restclient.AaiRestClient; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; public class ModelArtifactHandler extends ArtifactHandler { @@ -45,7 +44,7 @@ public class ModelArtifactHandler extends ArtifactHandler { List sortedModelArtifacts; try { sortedModelArtifacts = modelSorter.sort(artifacts); - } catch (RuntimeException ex) { + } catch (BabelArtifactParsingException ex) { logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve models: " + ex.getMessage()); return false; } diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactParser.java b/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactParser.java index 17bdd87..e687be0 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactParser.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/ModelArtifactParser.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; @@ -25,12 +25,10 @@ import java.util.Objects; import java.util.stream.Collector; import java.util.stream.IntStream; import javax.xml.XMLConstants; - -import org.onap.aai.modelloader.entity.Artifact; -import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; - +import org.onap.aai.modelloader.entity.Artifact; +import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/ModelSorter.java b/src/main/java/org/onap/aai/modelloader/entity/model/ModelSorter.java index e8fcf3f..4c39975 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/ModelSorter.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/ModelSorter.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import jline.internal.Log; - import org.onap.aai.modelloader.entity.Artifact; /** @@ -115,15 +114,14 @@ public class ModelSorter { * * @param originalList the list that needs to be sorted * @return a list of sorted models + * @throws BabelArtifactParsingException */ - public List sort(List originalList) { - - if (originalList.size() <= 1) { + public List sort(List originalList) throws BabelArtifactParsingException { + if (originalList == null || originalList.size() <= 1) { return originalList; } - Collection nodes = createNodes(originalList); - Collection sortedNodes = sortNodes(nodes); + Collection sortedNodes = sortNodes(createNodes(originalList)); List sortedModelsList = new ArrayList<>(sortedNodes.size()); for (Node node : sortedNodes) { @@ -188,8 +186,9 @@ public class ModelSorter { * * @param unsortedNodes the collection of nodes to be sorted * @return a sorted collection of the given nodes + * @throws BabelArtifactParsingException */ - private Collection sortNodes(Collection unsortedNodes) { + private Collection sortNodes(Collection unsortedNodes) throws BabelArtifactParsingException { // L <- Empty list that will contain the sorted elements List nodeList = new ArrayList<>(); @@ -233,7 +232,8 @@ public class ModelSorter { } } if (cycle) { - throw new RuntimeException("Circular dependency present between models, topological sort not possible"); + throw new BabelArtifactParsingException( + "Circular dependency present between models, topological sort not possible"); } return nodeList; diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifact.java b/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifact.java index 668a751..4df9879 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifact.java @@ -1,37 +1,35 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.restclient.AaiRestClient; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; - -import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.restclient.client.OperationResult; public class NamedQueryArtifact extends AbstractModelArtifact { @@ -58,7 +56,8 @@ public class NamedQueryArtifact extends AbstractModelArtifact { } @Override - public boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List completedArtifacts) { + public boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, + List completedArtifacts) { OperationResult getResponse = aaiClient.getResource(getNamedQueryUrl(config), distId, MediaType.APPLICATION_XML_TYPE); if ((getResponse == null) || (getResponse.getResultCode() != Response.Status.OK.getStatusCode())) { diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java b/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java index 5b9488e..3a0eada 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java @@ -1,32 +1,30 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; import java.util.List; - -import org.onap.aai.modelloader.entity.Artifact; -import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; - +import org.onap.aai.modelloader.entity.Artifact; +import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.w3c.dom.Node; public class NamedQueryArtifactParser extends AbstractModelArtifactParser { @@ -44,15 +42,13 @@ public class NamedQueryArtifactParser extends AbstractModelArtifactParser { boolean valid = false; if (model != null) { - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, - "Named-Query parsed =====>>>> " + "Named-Query-UUID: " + ((NamedQueryArtifact) model) - .getNamedQueryUuid()); + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Named-Query parsed =====>>>> " + "Named-Query-UUID: " + + ((NamedQueryArtifact) model).getNamedQueryUuid()); modelList.add((NamedQueryArtifact) model); valid = true; } else { - logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, - "Unable to parse named-query artifact " + artifactName); + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse named-query artifact " + artifactName); } return valid; diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/Pair.java b/src/main/java/org/onap/aai/modelloader/entity/model/Pair.java index ede60eb..e6382b1 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/Pair.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/Pair.java @@ -1,24 +1,23 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ - package org.onap.aai.modelloader.entity.model; /** diff --git a/src/main/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractor.java b/src/main/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractor.java index 7dbc34f..0fde55c 100644 --- a/src/main/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractor.java +++ b/src/main/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractor.java @@ -1,30 +1,30 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.extraction; import java.util.ArrayList; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is responsible for extracting implementations of IArtifactInto from an implementation of diff --git a/src/main/java/org/onap/aai/modelloader/extraction/InvalidArchiveException.java b/src/main/java/org/onap/aai/modelloader/extraction/InvalidArchiveException.java index 5e6353f..36581df 100644 --- a/src/main/java/org/onap/aai/modelloader/extraction/InvalidArchiveException.java +++ b/src/main/java/org/onap/aai/modelloader/extraction/InvalidArchiveException.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.extraction; diff --git a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManager.java b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManager.java index 6d75306..ca17261 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManager.java +++ b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManager.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -27,9 +27,9 @@ import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler; import org.onap.aai.modelloader.entity.model.ModelArtifactHandler; import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; /** * This class is responsible for deploying model and catalog artifacts. diff --git a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java index 3fa0b40..9dbe397 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java +++ b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -41,12 +41,12 @@ import org.onap.aai.modelloader.extraction.InvalidArchiveException; import org.onap.aai.modelloader.restclient.BabelServiceClient; import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.utils.ArtifactTypeEnum; -import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.utils.ArtifactTypeEnum; +import org.onap.sdc.utils.DistributionActionResultEnum; /** * This class is responsible for downloading the artifacts from the ASDC. diff --git a/src/main/java/org/onap/aai/modelloader/notification/BabelArtifactConverter.java b/src/main/java/org/onap/aai/modelloader/notification/BabelArtifactConverter.java index 7eb562a..ad4eb7d 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/BabelArtifactConverter.java +++ b/src/main/java/org/onap/aai/modelloader/notification/BabelArtifactConverter.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; diff --git a/src/main/java/org/onap/aai/modelloader/notification/BasicStatusMsg.java b/src/main/java/org/onap/aai/modelloader/notification/BasicStatusMsg.java new file mode 100644 index 0000000..03f521e --- /dev/null +++ b/src/main/java/org/onap/aai/modelloader/notification/BasicStatusMsg.java @@ -0,0 +1,57 @@ +/** + * ============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.modelloader.notification; + +import org.onap.sdc.api.consumer.IDistributionStatusMessageBasic; +import org.onap.sdc.utils.DistributionStatusEnum; + +public class BasicStatusMsg implements IDistributionStatusMessageBasic { + + private static final String COMPONENT_NAME = "AAI"; + protected DistributionStatusEnum status; + protected String distributionId; + protected String consumerId; + + @Override + public long getTimestamp() { + return System.currentTimeMillis(); + } + + @Override + public DistributionStatusEnum getStatus() { + return status; + } + + @Override + public String getDistributionID() { + return distributionId; + } + + @Override + public String getConsumerID() { + return consumerId; + } + + public String getComponentName() { + return COMPONENT_NAME; + } + +} diff --git a/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMessageBuilder.java b/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMessageBuilder.java index 5660ad0..c389945 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMessageBuilder.java +++ b/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMessageBuilder.java @@ -1,29 +1,29 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IComponentDoneStatusMessage; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.utils.DistributionStatusEnum; /** * This class is responsible for building an instance of {@link DistributionStatusMsg}. @@ -33,15 +33,16 @@ public class CompDoneStatusMessageBuilder { private CompDoneStatusMessageBuilder() {} /** - * Builds an instance of {@link CompDoneStatusMsg} from the given parameters about the status of the - * distribution of the given artifact. + * Builds an instance of {@link CompDoneStatusMsg} from the given parameters about the status of the distribution of + * the given artifact. * * @param client the distribution client this message pertains to * @param data data about the notification that resulted in this message being created * @param status the status of the distribution of the artifact to be reported * @return IComponentDoneStatusMessage implementation of IComponentDoneStatusMessage from the given parameters */ - public static IComponentDoneStatusMessage build(IDistributionClient client, INotificationData data, DistributionStatusEnum status) { + public static IComponentDoneStatusMessage build(IDistributionClient client, INotificationData data, + DistributionStatusEnum status) { return new CompDoneStatusMsg(status, data.getDistributionID(), client.getConfiguration().getConsumerID()); } } diff --git a/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMsg.java b/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMsg.java index db358f3..422052a 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMsg.java +++ b/src/main/java/org/onap/aai/modelloader/notification/CompDoneStatusMsg.java @@ -1,36 +1,32 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; -import org.openecomp.sdc.api.consumer.IComponentDoneStatusMessage; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; +import org.onap.sdc.utils.DistributionStatusEnum; -public class CompDoneStatusMsg implements IComponentDoneStatusMessage { - - private DistributionStatusEnum status; - private String distributionId; - private String consumerId; +public class CompDoneStatusMsg extends BasicStatusMsg implements IComponentDoneStatusMessage { /** - * Creates a new DistributionStatusMsg instance. + * Creates a new Component Done Status Message instance. * * @param status - The distribution status to be reported. * @param distributionId - The identifier of the distribution who's status is being rported on. @@ -41,29 +37,4 @@ public class CompDoneStatusMsg implements IComponentDoneStatusMessage { this.distributionId = distributionId; this.consumerId = consumerId; } - - @Override - public long getTimestamp() { - return System.currentTimeMillis(); - } - - @Override - public DistributionStatusEnum getStatus() { - return status; - } - - @Override - public String getDistributionID() { - return distributionId; - } - - @Override - public String getConsumerID() { - return consumerId; - } - - @Override - public String getComponentName() { - return "AAI"; - } } diff --git a/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMessageBuilder.java b/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMessageBuilder.java index fcfd81c..91cd3de 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMessageBuilder.java +++ b/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMessageBuilder.java @@ -1,30 +1,30 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.utils.DistributionStatusEnum; /** * This class is responsible for building an instance of {@link DistributionStatusMsg}. @@ -58,9 +58,9 @@ public class DistributionStatusMessageBuilder { * @param status the status of the distribution of the artifact to be reported * @return IDistributionStatusMessage implementation of IDistributionStatusMsg from the given parameters */ - public static IDistributionStatusMessage build(IDistributionClient client, - INotificationData data, DistributionStatusEnum status) { - return new DistributionStatusMsg(status, data.getDistributionID(), - client.getConfiguration().getConsumerID(), ""); + public static IDistributionStatusMessage build(IDistributionClient client, INotificationData data, + DistributionStatusEnum status) { + return new DistributionStatusMsg(status, data.getDistributionID(), client.getConfiguration().getConsumerID(), + ""); } } diff --git a/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMsg.java b/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMsg.java index cc9fb0b..0a2d6a9 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMsg.java +++ b/src/main/java/org/onap/aai/modelloader/notification/DistributionStatusMsg.java @@ -1,73 +1,50 @@ -/** - * ============LICENSE_START========================================== - * org.onap.aai - * =================================================================== - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== - * 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.modelloader.notification; - -import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; -import org.openecomp.sdc.utils.DistributionStatusEnum; - -public class DistributionStatusMsg implements IDistributionStatusMessage { - - private DistributionStatusEnum status; - private String distributionId; - private String consumerId; - private String artifactUrl; - - /** - * Creates a new DistributionStatusMsg instance. - * - * @param status - The distribution status to be reported. - * @param distributionId - The identifier of the distribution who's status is being rported on. - * @param consumerId - Identifier of the consumer associated with the distribution. - * @param artifactUrl - Resource identifier for the artifact. - */ - public DistributionStatusMsg(DistributionStatusEnum status, String distributionId, String consumerId, - String artifactUrl) { - this.status = status; - this.distributionId = distributionId; - this.consumerId = consumerId; - this.artifactUrl = artifactUrl; - } - - @Override - public long getTimestamp() { - return System.currentTimeMillis(); - } - - @Override - public DistributionStatusEnum getStatus() { - return status; - } - - @Override - public String getDistributionID() { - return distributionId; - } - - @Override - public String getConsumerID() { - return consumerId; - } - - @Override - public String getArtifactURL() { - return artifactUrl; - } -} +/** + * ============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.modelloader.notification; + +import org.onap.sdc.api.consumer.IDistributionStatusMessage; +import org.onap.sdc.utils.DistributionStatusEnum; + +public class DistributionStatusMsg extends BasicStatusMsg implements IDistributionStatusMessage { + + private String artifactUrl; + + /** + * Creates a new Distribution Status Message instance. + * + * @param status - The distribution status to be reported. + * @param distributionId - The identifier of the distribution who's status is being rported on. + * @param consumerId - Identifier of the consumer associated with the distribution. + * @param artifactUrl - Resource identifier for the artifact. + */ + public DistributionStatusMsg(DistributionStatusEnum status, String distributionId, String consumerId, + String artifactUrl) { + this.status = status; + this.distributionId = distributionId; + this.consumerId = consumerId; + this.artifactUrl = artifactUrl; + } + + @Override + public String getArtifactURL() { + return artifactUrl; + } +} diff --git a/src/main/java/org/onap/aai/modelloader/notification/DownloadFailureException.java b/src/main/java/org/onap/aai/modelloader/notification/DownloadFailureException.java index 73a191a..d39330f 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/DownloadFailureException.java +++ b/src/main/java/org/onap/aai/modelloader/notification/DownloadFailureException.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; diff --git a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java index fe6bf7b..2baa217 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java +++ b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -30,10 +30,10 @@ import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor; import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.consumer.INotificationCallback; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.INotificationCallback; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; import org.slf4j.MDC; public class EventCallback implements INotificationCallback { @@ -76,6 +76,7 @@ public class EventCallback implements INotificationCallback { if (artifactDeploymentManager == null) { artifactDeploymentManager = new ArtifactDeploymentManager(client, config); } + return artifactDeploymentManager; } diff --git a/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java b/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java index 447e817..967a290 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java +++ b/src/main/java/org/onap/aai/modelloader/notification/NotificationPublisher.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -31,12 +31,12 @@ import org.onap.aai.cl.mdc.MdcContext; import org.onap.aai.cl.mdc.MdcOverride; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.service.ModelLoaderMsgs; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.utils.DistributionActionResultEnum; -import org.openecomp.sdc.utils.DistributionStatusEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.utils.DistributionStatusEnum; /** * This class is responsible for publishing the status of actions performed working with artifacts. @@ -46,24 +46,18 @@ class NotificationPublisher { private static Logger logger = LoggerFactory.getInstance().getLogger(NotificationPublisher.class); private static Logger metricsLogger = LoggerFactory.getInstance().getMetricsLogger(NotificationPublisher.class); - protected static final String FILESEP = - (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); - protected static final String CONFIG_DIR = System.getProperty("CONFIG_HOME") + FILESEP; - protected static final String CONFIG_AUTH_LOCATION = CONFIG_DIR + "auth" + FILESEP; - protected static final String CONFIG_FILE = CONFIG_DIR + "model-loader.properties"; - private boolean publishingEnabled; public NotificationPublisher() { Properties configProperties = new Properties(); try { - configProperties.load(new FileInputStream(CONFIG_FILE)); + configProperties.load(new FileInputStream(ModelLoaderConfig.propertiesFile())); } catch (IOException e) { String errorMsg = "Failed to load configuration: " + e.getMessage(); logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, e, errorMsg); } - ModelLoaderConfig config = new ModelLoaderConfig(configProperties, CONFIG_AUTH_LOCATION); + ModelLoaderConfig config = new ModelLoaderConfig(configProperties); publishingEnabled = !config.getASDCConnectionDisabled(); } diff --git a/src/main/java/org/onap/aai/modelloader/notification/ProcessToscaArtifactsException.java b/src/main/java/org/onap/aai/modelloader/notification/ProcessToscaArtifactsException.java index 6678af6..0d082c1 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/ProcessToscaArtifactsException.java +++ b/src/main/java/org/onap/aai/modelloader/notification/ProcessToscaArtifactsException.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; diff --git a/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java b/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java index 28cd671..5576ea9 100644 --- a/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java +++ b/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.restclient; diff --git a/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClient.java b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClient.java index a861580..fa677a9 100644 --- a/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClient.java +++ b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClient.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.restclient; @@ -173,7 +173,8 @@ public class BabelServiceClient { .post(ClientResponse.class, obj.toString()); String sanitizedJson = JsonSanitizer.sanitize(response.getEntity(String.class)); - logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Babel response " + response.getStatus() + " " + sanitizedJson); + logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, + "Babel response " + response.getStatus() + " " + sanitizedJson); if (response.getStatus() != Response.Status.OK.getStatusCode()) { throw new BabelServiceException(sanitizedJson); diff --git a/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java index 6ce4a60..4354710 100644 --- a/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java +++ b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.restclient; diff --git a/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java b/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java index e32d92c..9af92be 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java +++ b/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java @@ -1,37 +1,38 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.service; import java.util.Collections; -import org.openecomp.sdc.api.notification.IArtifactInfo; +import java.util.List; +import org.onap.sdc.api.notification.IArtifactInfo; /** * This class is an implementation of IArtifactInfo for test purposes. */ public class ArtifactInfoImpl implements IArtifactInfo { - private java.lang.String artifactName; - private java.lang.String artifactType; - private java.lang.String artifactDescription; - private java.lang.String artifactVersion; + private String artifactName; + private String artifactType; + private String artifactDescription; + private String artifactVersion; @Override public String getArtifactName() { @@ -95,7 +96,7 @@ public class ArtifactInfoImpl implements IArtifactInfo { } @Override - public java.util.List getRelatedArtifacts() { + public List getRelatedArtifacts() { return Collections.emptyList(); } diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderApplication.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderApplication.java new file mode 100644 index 0000000..c0eb5f2 --- /dev/null +++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderApplication.java @@ -0,0 +1,37 @@ +/** + * ============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.modelloader.service; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Model Loader Spring Boot Application. + */ + +@SpringBootApplication +public class ModelLoaderApplication { + + public static void main(String[] args) { + SpringApplication.run(ModelLoaderApplication.class, args); + } + +} diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java index 1b466c8..6796090 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java +++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderInterface.java @@ -1,49 +1,45 @@ -/** - * ============LICENSE_START========================================== - * org.onap.aai - * =================================================================== - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== - * 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.modelloader.service; - -import java.io.IOException; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; - -public interface ModelLoaderInterface { - - @GET - @Path("/loadModel/{modelid}") - public Response loadModel(@PathParam("modelid") String modelid); - - @PUT - @Path("/saveModel/{modelid}/{modelname}") - public Response saveModel(@PathParam("modelid") String modelid, @PathParam("modelname") String modelname); - - @POST - @Consumes("text/plain") - @Produces("application/xml") - @Path("/ingestModel/{modelName}/{modelVersion}") - public Response ingestModel(@PathParam("modelName") String modelid, @PathParam("modelVersion") String modelVersion, - String payload) throws IOException; -} +/** + * ============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.modelloader.service; + +import java.io.IOException; +import javax.ws.rs.core.Response; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +public interface ModelLoaderInterface { + + @RequestMapping(value = "/loadModel/{modelid}", // + method = RequestMethod.GET, produces = "application/json") + @ResponseBody + public Response loadModel(String modelid); + + @RequestMapping(value = "/saveModel/{modelid}/{modelname}", // + method = RequestMethod.PUT, produces = "application/json") + @ResponseBody + public Response saveModel(String modelid, String modelname); + + @RequestMapping(value = "/ingestModel/{modelName}/{modelVersion}", // + method = RequestMethod.POST, produces = "application/json") + @ResponseBody + public Response ingestModel(String modelid, String modelVersion, String payload) throws IOException; +} diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java index c5f00c0..fd39a9a 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java +++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderMsgs.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.service; @@ -74,7 +74,7 @@ public enum ModelLoaderMsgs implements LogMessageEnum { * Arguments: {0} = request type. {1} = endpoint. {2} = error message. */ BABEL_REST_REQUEST_ERROR, - + /** * Arguments: {0} = info request payload. **/ diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java index a4cc5d1..06d6e30 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java +++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.service; @@ -29,9 +29,8 @@ import java.util.List; import java.util.Properties; import java.util.Timer; import java.util.TimerTask; - +import javax.annotation.PostConstruct; import javax.ws.rs.core.Response; - import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; @@ -40,53 +39,54 @@ import org.onap.aai.modelloader.notification.ArtifactDeploymentManager; import org.onap.aai.modelloader.notification.ArtifactDownloadManager; import org.onap.aai.modelloader.notification.EventCallback; import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.impl.DistributionClientFactory; -import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.impl.DistributionClientFactory; +import org.onap.sdc.utils.DistributionActionResultEnum; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * Service class in charge of managing the negotiating model loading capabilities between AAI and an ASDC. */ +@RestController +@RequestMapping("/services/model-loader/v1/model-service") public class ModelLoaderService implements ModelLoaderInterface { + static Logger logger = LoggerFactory.getInstance().getLogger(ModelLoaderService.class.getName()); + protected static final String FILESEP = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); - protected static final String CONFIG_DIR = System.getProperty("CONFIG_HOME") + FILESEP; - protected static final String CONFIG_AUTH_LOCATION = CONFIG_DIR + "auth" + FILESEP; - protected static final String CONFIG_FILE = CONFIG_DIR + "model-loader.properties"; - + @Value("${CONFIG_HOME}") + private String configDir; private IDistributionClient client; private ModelLoaderConfig config; - static Logger logger = LoggerFactory.getInstance().getLogger(ModelLoaderService.class.getName()); - /** * Responsible for loading configuration files and calling initialization. */ - public ModelLoaderService() { - start(); - } - + @PostConstruct protected void start() { // Load model loader system configuration logger.info(ModelLoaderMsgs.LOADING_CONFIGURATION); + ModelLoaderConfig.setConfigHome(configDir); Properties configProperties = new Properties(); try { - configProperties.load(new FileInputStream(CONFIG_FILE)); + configProperties.load(new FileInputStream(configDir + FILESEP + "model-loader.properties")); + config = new ModelLoaderConfig(configProperties); + if (!config.getASDCConnectionDisabled()) { + initSdcClient(); + } } catch (IOException e) { String errorMsg = "Failed to load configuration: " + e.getMessage(); logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg); - shutdown(); } - - config = new ModelLoaderConfig(configProperties, CONFIG_AUTH_LOCATION); - init(); - - Runtime.getRuntime().addShutdownHook(new Thread(this::preShutdownOperations)); } /** @@ -102,18 +102,28 @@ public class ModelLoaderService implements ModelLoaderInterface { /** * Responsible for loading configuration files, initializing model distribution clients, and starting them. */ - protected void init() { - if (!config.getASDCConnectionDisabled()) { - // Initialize distribution client - logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client..."); - client = DistributionClientFactory.createDistributionClient(); - EventCallback callback = new EventCallback(client, config); - - IDistributionClientResult initResult = client.init(config, callback); - - if (initResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { - String errorMsg = - "Failed to initialize distribution client: " + initResult.getDistributionMessageResult(); + protected void initSdcClient() { + // Initialize distribution client + logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client..."); + client = DistributionClientFactory.createDistributionClient(); + EventCallback callback = new EventCallback(client, config); + + IDistributionClientResult initResult = client.init(config, callback); + + if (initResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + String errorMsg = "Failed to initialize distribution client: " + initResult.getDistributionMessageResult(); + logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg); + + // Kick off a timer to retry the SDC connection + Timer timer = new Timer(); + TimerTask task = new SdcConnectionJob(client, config, callback, timer); + timer.schedule(task, new Date(), 60000); + } else { + // Start distribution client + logger.debug(ModelLoaderMsgs.INITIALIZING, "Starting distribution client..."); + IDistributionClientResult startResult = client.start(); + if (startResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + String errorMsg = "Failed to start distribution client: " + startResult.getDistributionMessageResult(); logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg); // Kick off a timer to retry the SDC connection @@ -121,41 +131,10 @@ public class ModelLoaderService implements ModelLoaderInterface { TimerTask task = new SdcConnectionJob(client, config, callback, timer); timer.schedule(task, new Date(), 60000); } else { - // Start distribution client - logger.debug(ModelLoaderMsgs.INITIALIZING, "Starting distribution client..."); - IDistributionClientResult startResult = client.start(); - if (startResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { - String errorMsg = - "Failed to start distribution client: " + startResult.getDistributionMessageResult(); - logger.error(ModelLoaderMsgs.ASDC_CONNECTION_ERROR, errorMsg); - - // Kick off a timer to retry the SDC connection - Timer timer = new Timer(); - TimerTask task = new SdcConnectionJob(client, config, callback, timer); - timer.schedule(task, new Date(), 60000); - } else { - logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established"); - } + logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established"); } } - } - - /** - * Shut down the process. - */ - private void shutdown() { - preShutdownOperations(); - - // TODO: Find a better way to shut down the model loader. - try { - // Give logs time to write to file - Thread.sleep(2000); - } catch (InterruptedException e) { // NOSONAR - // Nothing we can do at this point - logger.debug(e.getMessage()); - } - - Runtime.getRuntime().halt(1); + Runtime.getRuntime().addShutdownHook(new Thread(this::preShutdownOperations)); } /** @@ -164,7 +143,7 @@ public class ModelLoaderService implements ModelLoaderInterface { * @see org.onap.aai.modelloader.service.ModelLoaderInterface#loadModel(java.lang.String) */ @Override - public Response loadModel(String modelid) { + public Response loadModel(@PathVariable String modelid) { return Response.ok("{\"model_loaded\":\"" + modelid + "\"}").build(); } @@ -174,12 +153,13 @@ public class ModelLoaderService implements ModelLoaderInterface { * @see org.onap.aai.modelloader.service.ModelLoaderInterface#saveModel(java.lang.String, java.lang.String) */ @Override - public Response saveModel(String modelid, String modelname) { + public Response saveModel(@PathVariable String modelid, @PathVariable String modelname) { return Response.ok("{\"model_saved\":\"" + modelid + "-" + modelname + "\"}").build(); } @Override - public Response ingestModel(String modelName, String modelVersion, String payload) throws IOException { + public Response ingestModel(@PathVariable String modelName, @PathVariable String modelVersion, + @RequestBody String payload) throws IOException { boolean success; if (config.getIngestSimulatorEnabled()) { diff --git a/src/main/java/org/onap/aai/modelloader/service/NotificationDataImpl.java b/src/main/java/org/onap/aai/modelloader/service/NotificationDataImpl.java index 28611ff..536aa4a 100644 --- a/src/main/java/org/onap/aai/modelloader/service/NotificationDataImpl.java +++ b/src/main/java/org/onap/aai/modelloader/service/NotificationDataImpl.java @@ -1,30 +1,30 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.service; import java.util.Collections; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; public class NotificationDataImpl implements INotificationData { diff --git a/src/main/java/org/onap/aai/modelloader/service/SdcConnectionJob.java b/src/main/java/org/onap/aai/modelloader/service/SdcConnectionJob.java index d30e6dd..82e0bc6 100644 --- a/src/main/java/org/onap/aai/modelloader/service/SdcConnectionJob.java +++ b/src/main/java/org/onap/aai/modelloader/service/SdcConnectionJob.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.service; @@ -26,9 +26,9 @@ import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.notification.EventCallback; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.results.IDistributionClientResult; -import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; public class SdcConnectionJob extends TimerTask { static Logger logger = LoggerFactory.getInstance().getLogger(SdcConnectionJob.class.getName()); diff --git a/src/main/java/org/onap/aai/modelloader/util/JsonXmlConverter.java b/src/main/java/org/onap/aai/modelloader/util/JsonXmlConverter.java index a5a7bc5..48a33b5 100644 --- a/src/main/java/org/onap/aai/modelloader/util/JsonXmlConverter.java +++ b/src/main/java/org/onap/aai/modelloader/util/JsonXmlConverter.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.util; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..4ea6f0a --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,20 @@ +# Note that the start.sh script sets the following System Properties +# We provide default values here for testing purposes +AJSC_HOME=. +CONFIG_HOME=appconfig-local +com.att.eelf.logging.path=src/main/resources +com.att.eelf.logging.file=logback.xml +logback.configurationFile=${com.att.eelf.logging.path}/${com.att.eelf.logging.file} + +server.port=9500 +#server.ssl.key-store= +#server.ssl.key-store-password= +#server.ssl.keyStoreType= +#server.ssl.keyAlias= + +server.tomcat.max-threads=200 +# The minimum number of threads always kept alive +server.tomcat.min-spare-threads=25 + +# Spring Boot logging +logging.config=${logback.configurationFile} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..6b7c2c1 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + ${defaultPattern} + + + + + + + + + + + ${logDirectory}/${generalLogName}.log + + ${logDirectory}/${generalLogName}.%d{yyyy-MM-dd}.log.zip + 60 + + + ${errorLogPattern} + + + + + + INFO + + 256 + + + + + ${logDirectory}/${auditLogName}.log + + ${logDirectory}/${auditLogName}.%d{yyyy-MM-dd}.log.zip + 60 + + + ${auditMetricPattern} + + + + 256 + + + + + ${logDirectory}/${metricsLogName}.log + + ${logDirectory}/${metricsLogName}.%d{yyyy-MM-dd}.log.zip + 60 + + + ${auditMetricPattern} + + + + 256 + + + + + ${logDirectory}/${debugLogName}.log + + ${logDirectory}/${debugLogName}.%d{yyyy-MM-dd}.log.zip + 60 + + + ${errorLogPattern} + + + + 256 + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties b/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties index 112b48c..1e5658c 100644 --- a/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties +++ b/src/main/resources/org/onap/aai/modelloader/service/ModelLoaderMsgs.properties @@ -3,7 +3,7 @@ # org.onap.aai # =================================================================== # Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. -# Copyright © 2017-2018 Amdocs +# 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. diff --git a/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java b/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java index 1b6b847..e8060e2 100644 --- a/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java +++ b/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java @@ -1,193 +1,192 @@ -/** - * ============LICENSE_START========================================== - * org.onap.aai - * =================================================================== - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== - * 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.modelloader.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.List; -import java.util.Properties; - -import org.eclipse.jetty.util.security.Password; -import org.junit.Test; -import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.openecomp.sdc.utils.ArtifactTypeEnum; - -/** - * Tests for ModelLoaderConfig class - * - */ -public class ModelLoaderConfigTest { - - @Test - public void testYangModelArtifactType() { - Properties props = new Properties(); - props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG"); - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - - List types = config.getRelevantArtifactTypes(); - - System.out.println("ArtifactType: " + types.get(0)); - assertEquals(0, types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString())); - - System.out.println("ArtifactType: " + types.get(1)); - assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString())); - - System.out.println("ArtifactType: " + types.get(2)); - assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString())); - - assertEquals(3, types.size()); - } - - @Test - public void testMsgBusAddrs() { - Properties props = new Properties(); - props.setProperty("ml.distribution.MSG_BUS_ADDRESSES", "host1.onap.com:3904,host2.onap.com:3904"); - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - - List addrs = config.getMsgBusAddress(); - - assertEquals(2, addrs.size()); - assertEquals(0, addrs.get(0).compareToIgnoreCase("host1.onap.com:3904")); - assertEquals(0, addrs.get(1).compareToIgnoreCase("host2.onap.com:3904")); - } - - @Test - public void testDecryptPassword() { - String password = "youshallnotpass"; - ModelLoaderConfig config = - createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password); - assertEquals(password, config.getPassword()); - } - - @Test - public void testDecryptKeystorePassword() { - String password = "youshallnotpass"; - ModelLoaderConfig config = - createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password); - assertEquals(password, config.getKeyStorePassword()); - } - - @Test - public void testDecryptAAIAuthenticationPassword() { - String password = "myvoiceismypassword"; - ModelLoaderConfig config = - createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password); - assertEquals(password, config.getAaiAuthenticationPassword()); - } - - @Test - public void testDecryptAAIKeystorePassword() { - String password = "myvoiceismypassword"; - ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password); - assertEquals(password, config.getAaiKeyStorePassword()); - } - - @Test - public void testAaiBaseUrl() { - String url = "http://localhost:1234/"; - Properties props = new Properties(); - props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url); - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - assertEquals(url, config.getAaiBaseUrl()); - } - - @Test - public void testDecryptBabelKeystorePassword() { - String password = "babelpassword"; - ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password); - assertEquals(password, config.getBabelKeyStorePassword()); - } - - @Test - public void testBabelKeystorePath() { - String root = "path_to_keystore"; - String path = "relative_keystore_path"; - Properties props = new Properties(); - props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path); - ModelLoaderConfig config = new ModelLoaderConfig(props, root); - assertEquals(root + File.separator + path, config.getBabelKeyStorePath()); - } - - @Test - public void testBabelBaseUrl() { - String url = "http://localhost/"; - Properties props = new Properties(); - props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url); - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - assertEquals(url, config.getBabelBaseUrl()); - } - - @Test - public void testBabelGenerateArtifactsUrl() { - String url = "/path/to/the/resource"; - Properties props = new Properties(); - props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url); - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - assertEquals(url, config.getBabelGenerateArtifactsUrl()); - } - - @Test - public void testNoAAIAuth() throws IOException { - - Properties props = new Properties(); - props.load(new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties")); - - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - AaiRestClient aaiClient = new AaiRestClient(config); - - assertFalse("Empty AAI Password should result in no basic authentication", aaiClient.useBasicAuth()); - - props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties")); - config = new ModelLoaderConfig(props, null); - aaiClient = new AaiRestClient(config); - - assertFalse("No AAI Password should result in no basic authentication", aaiClient.useBasicAuth()); - } - - @Test - public void testGetUrls() { - Properties props = new Properties(); - props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/"); - props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL, - "/aai/v*/service-design-and-creation/named-queries/named-query/"); - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - - assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9")); - assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/", - config.getAaiNamedQueryUrl("v10")); - } - - - /** - * @param propertyName - * @param propertyValue - * @return a new ModelLoaderConfig object containing a single obfuscated property value - */ - private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) { - Properties props = new Properties(); - props.put(propertyName, Password.obfuscate(propertyValue)); - return new ModelLoaderConfig(props, null); - } -} +/** + * ============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.modelloader.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Properties; +import org.eclipse.jetty.util.security.Password; +import org.junit.Test; +import org.onap.aai.modelloader.restclient.AaiRestClient; +import org.onap.sdc.utils.ArtifactTypeEnum; + +/** + * Tests for ModelLoaderConfig class + * + */ +public class ModelLoaderConfigTest { + + @Test + public void testYangModelArtifactType() { + Properties props = new Properties(); + props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG"); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + + List types = config.getRelevantArtifactTypes(); + + System.out.println("ArtifactType: " + types.get(0)); + assertEquals(0, types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString())); + + System.out.println("ArtifactType: " + types.get(1)); + assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString())); + + System.out.println("ArtifactType: " + types.get(2)); + assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString())); + + assertEquals(3, types.size()); + } + + @Test + public void testMsgBusAddrs() { + Properties props = new Properties(); + props.setProperty("ml.distribution.MSG_BUS_ADDRESSES", "host1.onap.com:3904,host2.onap.com:3904"); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + + List addrs = config.getMsgBusAddress(); + + assertEquals(2, addrs.size()); + assertEquals(0, addrs.get(0).compareToIgnoreCase("host1.onap.com:3904")); + assertEquals(0, addrs.get(1).compareToIgnoreCase("host2.onap.com:3904")); + } + + @Test + public void testDecryptPassword() { + String password = "youshallnotpass"; + ModelLoaderConfig config = + createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password); + assertEquals(password, config.getPassword()); + } + + @Test + public void testDecryptKeystorePassword() { + String password = "youshallnotpass"; + ModelLoaderConfig config = + createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password); + assertEquals(password, config.getKeyStorePassword()); + } + + @Test + public void testDecryptAAIAuthenticationPassword() { + String password = "myvoiceismypassword"; + ModelLoaderConfig config = + createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password); + assertEquals(password, config.getAaiAuthenticationPassword()); + } + + @Test + public void testDecryptAAIKeystorePassword() { + String password = "myvoiceismypassword"; + ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password); + assertEquals(password, config.getAaiKeyStorePassword()); + } + + @Test + public void testAaiBaseUrl() { + String url = "http://localhost:1234/"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + assertEquals(url, config.getAaiBaseUrl()); + } + + @Test + public void testDecryptBabelKeystorePassword() { + String password = "babelpassword"; + ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password); + assertEquals(password, config.getBabelKeyStorePassword()); + } + + @Test + public void testBabelKeystorePath() { + String root = "path_to_keystore"; + String path = "relative_keystore_path"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path); + ModelLoaderConfig config = new ModelLoaderConfig(props, root); + assertEquals(root + File.separator + path, config.getBabelKeyStorePath()); + } + + @Test + public void testBabelBaseUrl() { + String url = "http://localhost/"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + assertEquals(url, config.getBabelBaseUrl()); + } + + @Test + public void testBabelGenerateArtifactsUrl() { + String url = "/path/to/the/resource"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + assertEquals(url, config.getBabelGenerateArtifactsUrl()); + } + + @Test + public void testNoAAIAuth() throws IOException { + + Properties props = new Properties(); + props.load(new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties")); + + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + AaiRestClient aaiClient = new AaiRestClient(config); + + assertFalse("Empty AAI Password should result in no basic authentication", aaiClient.useBasicAuth()); + + props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties")); + config = new ModelLoaderConfig(props, null); + aaiClient = new AaiRestClient(config); + + assertFalse("No AAI Password should result in no basic authentication", aaiClient.useBasicAuth()); + } + + @Test + public void testGetUrls() { + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/"); + props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL, + "/aai/v*/service-design-and-creation/named-queries/named-query/"); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + + assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9")); + assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/", + config.getAaiNamedQueryUrl("v10")); + } + + + /** + * @param propertyName + * @param propertyValue + * @return a new ModelLoaderConfig object containing a single obfuscated property value + */ + private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) { + Properties props = new Properties(); + props.put(propertyName, Password.obfuscate(propertyValue)); + return new ModelLoaderConfig(props, null); + } +} diff --git a/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.java b/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.java new file mode 100644 index 0000000..a41ddf9 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.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.modelloader.entity.catalog; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Tests for NotificationDataImpl class + * + */ +public class TestVnfImageException { + + @Test + public void testConstructors() { + VnfImageException exception = new VnfImageException("id"); + assertThat(exception.getImageId(), is(equalTo("id"))); + + exception = new VnfImageException("id2", 1); + assertThat(exception.getImageId(), is(equalTo("id2"))); + assertThat(exception.getResultCode().get(), is(equalTo(1))); + + Exception e = new Exception("message"); + exception = new VnfImageException(e); + assertThat(exception.getImageId(), is(equalTo("message"))); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java b/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java index aa75cd2..b6d4564 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.catalog; diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java index ec24acb..84a4313 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java index d59ddf7..d1d54b7 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java @@ -1,29 +1,33 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Test; @@ -32,140 +36,101 @@ import org.onap.aai.modelloader.entity.Artifact; public class ModelSorterTest { @Test - public void noModels() { - - List emptyList = Collections.emptyList(); - - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); - - List sortedList = sorter.sort(emptyList); - assertNotNull(sortedList); - assertEquals(0, sortedList.size()); - + public void edgeEquality() throws BabelArtifactParsingException { + ModelArtifact model = buildTestModel(); + ModelSorter.Node nodeA = new ModelSorter.Node(model); + ModelSorter.Node nodeB = new ModelSorter.Node(model); + ModelSorter.Node nodeC = new ModelSorter.Node(model); + + ModelSorter.Edge edgeA = new ModelSorter.Edge(nodeA, nodeB); + ModelSorter.Edge edgeB = new ModelSorter.Edge(nodeA, nodeB); + ModelSorter.Edge edgeC = new ModelSorter.Edge(nodeB, nodeA); + ModelSorter.Edge edgeD = new ModelSorter.Edge(nodeA, nodeC); + + assertThat(edgeA, is(equalTo(edgeA))); + assertThat(edgeA, is(not(equalTo(null)))); + assertThat(edgeA, is(not(equalTo(model)))); + + assertThat(edgeA, is(equalTo(edgeB))); + assertThat(edgeA, is(not(equalTo(edgeC)))); + assertThat(edgeA, is(not(equalTo(edgeD)))); } @Test - public void singleModel() { - - List modelList = new ArrayList(); - - ModelArtifact model = new ModelArtifact(); - model.setModelInvariantId("aaa"); - model.setModelVerId("111"); - model.addDependentModelId("xyz|123"); - modelList.add(model); - - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); - - List sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(1, sortedList.size()); - + public void nodeEquality() throws BabelArtifactParsingException { + ModelArtifact model = buildTestModel(); + ModelSorter.Node nodeA = new ModelSorter.Node(model); + ModelSorter.Node nodeB = new ModelSorter.Node(model); + + assertThat(nodeA, is(equalTo(nodeA))); + assertThat(nodeA, is(not(equalTo(null)))); + assertThat(nodeA, is(not(equalTo(model)))); + + assertThat(nodeA, is(equalTo(nodeB))); + assertThat(nodeA.toString(), is(equalTo(nodeB.toString()))); + assertThat(nodeA, is(not(equalTo(new ModelSorter.Node(new ModelArtifact()))))); } - /** - * depends on depends on B ------> A -------> C - * - * - * Input list = a, b, c Sorted list = c, a, b - */ @Test - public void multipleModels() { - - List modelList = new ArrayList(); - - ModelArtifact aaaa = new ModelArtifact(); - aaaa.setModelInvariantId("aaaa"); - aaaa.setModelVerId("mvaaaa"); - aaaa.addDependentModelId("cccc|mvcccc"); - - ModelArtifact bbbb = new ModelArtifact(); - bbbb.setModelInvariantId("bbbb"); - bbbb.setModelVerId("mvbbbb"); - bbbb.addDependentModelId("aaaa|mvaaaa"); - - ModelArtifact cccc = new ModelArtifact(); - cccc.setModelInvariantId("cccc"); - cccc.setModelVerId("mvcccc"); - - modelList.add(aaaa); - modelList.add(bbbb); - modelList.add(cccc); - - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); - - List sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(3, sortedList.size()); - - assertEquals(cccc, sortedList.get(0)); - assertEquals(aaaa, sortedList.get(1)); - assertEquals(bbbb, sortedList.get(2)); + public void noModels() throws BabelArtifactParsingException { + assertThat(new ModelSorter().sort(null), is(nullValue())); + assertThat(new ModelSorter().sort(Collections.emptyList()).size(), is(0)); } @Test - public void multipleModelsAndNamedQueries() { - - List modelList = new ArrayList(); - - ModelArtifact aaaa = new ModelArtifact(); - aaaa.setModelInvariantId("aaaa"); - aaaa.setModelVerId("1111"); - aaaa.addDependentModelId("cccc|2222"); - - NamedQueryArtifact nq1 = new NamedQueryArtifact(); - nq1.setNamedQueryUuid("nq1"); - nq1.addDependentModelId("aaaa|1111"); - - NamedQueryArtifact nq2 = new NamedQueryArtifact(); - nq2.setNamedQueryUuid("nq2"); - nq2.addDependentModelId("existing-model"); - - modelList.add(nq1); - modelList.add(nq2); - modelList.add(aaaa); - - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); - - List sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(3, sortedList.size()); + public void singleModel() throws BabelArtifactParsingException { + assertThat(new ModelSorter().sort(Arrays.asList(buildTestModel())).size(), is(1)); + } - System.out.println(sortedList.get(0) + "-" + sortedList.get(1) + "-" + sortedList.get(2)); - assertEquals(aaaa, sortedList.get(0)); - assertEquals(nq2, sortedList.get(1)); - assertEquals(nq1, sortedList.get(2)); + @Test + public void multipleModels() throws BabelArtifactParsingException { + Artifact a = buildTestModel("aaaa", "mvaaaa", "cccc|mvcccc"); + Artifact b = buildTestModel("bbbb", "mvbbbb", "aaaa|mvaaaa"); + Artifact c = buildTestModel("cccc", "mvcccc"); + List expected = Arrays.asList(c, a, b); + assertThat(new ModelSorter().sort(Arrays.asList(a, b, c)), is(expected)); } - @Test(expected = RuntimeException.class) - public void circularDependency() { + @Test + public void multipleModelsAndNamedQueries() throws BabelArtifactParsingException { + Artifact a = buildTestModel("aaaa", "1111", "cccc|2222"); + Artifact nq1 = buildTestNamedQuery("nq1", "aaaa|1111"); + Artifact nq2 = buildTestNamedQuery("nqw", "existing-model"); + List expected = Arrays.asList(a, nq2, nq1); + assertThat(new ModelSorter().sort(Arrays.asList(nq1, nq2, a)), is(expected)); + } + @Test(expected = BabelArtifactParsingException.class) + public void circularDependency() throws BabelArtifactParsingException { List modelList = new ArrayList(); + modelList.add(buildTestModel("aaaa", "1111", "bbbb|1111")); + modelList.add(buildTestModel("bbbb", "1111", "aaaa|1111")); + new ModelSorter().sort(modelList); + } - ModelArtifact aaaa = new ModelArtifact(); - aaaa.setModelInvariantId("aaaa"); - aaaa.setModelVerId("1111"); - aaaa.addDependentModelId("bbbb|1111"); - - ModelArtifact bbbb = new ModelArtifact(); - bbbb.setModelInvariantId("bbbb"); - bbbb.setModelVerId("1111"); - bbbb.addDependentModelId("aaaa|1111"); - - modelList.add(aaaa); - modelList.add(bbbb); + private ModelArtifact buildTestModel() { + return buildTestModel("aaa", "111", "xyz|123"); + } - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); + private ModelArtifact buildTestModel(String id, String version) { + return buildTestModel(id, version, null); + } - List sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(2, sortedList.size()); + private ModelArtifact buildTestModel(String id, String version, String dependentModel) { + ModelArtifact modelArtifact = new ModelArtifact(); + modelArtifact.setModelInvariantId(id); + modelArtifact.setModelVerId(version); + if (dependentModel != null) { + modelArtifact.addDependentModelId(dependentModel); + } + return modelArtifact; + } + private NamedQueryArtifact buildTestNamedQuery(String uuid, String modelId) { + NamedQueryArtifact nq = new NamedQueryArtifact(); + nq.setNamedQueryUuid(uuid); + nq.addDependentModelId(modelId); + return nq; } } diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java index 4fd6d1e..fa2d2d7 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java new file mode 100644 index 0000000..82990de --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java @@ -0,0 +1,124 @@ +/** + * ============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.modelloader.entity.model; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.ws.rs.core.Response; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.entity.Artifact; +import org.onap.aai.modelloader.restclient.AaiRestClient; +import org.onap.aai.restclient.client.OperationResult; + +/** + * Test the Model Artifact Handler using Mocks + * + */ +public class TestModelArtifactHandler { + + @Mock + private ModelLoaderConfig config; + + @Mock + private AaiRestClient aaiClient; + + @Before + public void setupMocks() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testEmptyLists() { + ModelArtifactHandler handler = new ModelArtifactHandler(config); + handler.pushArtifacts(Collections.emptyList(), "", Collections.emptyList(), aaiClient); + handler.rollback(Collections.emptyList(), "", aaiClient); + } + + @Test + public void testSingleItemList() { + when(config.getAaiBaseUrl()).thenReturn(""); + when(config.getAaiModelUrl(any())).thenReturn(""); + + ModelArtifactHandler handler = new ModelArtifactHandler(config); + List artifacts = Collections.singletonList(new ModelArtifact()); + handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); + handler.rollback(Collections.emptyList(), "", aaiClient); + } + + @Test + public void testPushExistingModelsWithRollback() { + when(config.getAaiBaseUrl()).thenReturn(""); + when(config.getAaiModelUrl(any())).thenReturn(""); + + OperationResult operationResult = mock(OperationResult.class); + when(aaiClient.getResource(any(), any(), any())).thenReturn(operationResult); + when(operationResult.getResultCode()).thenReturn(Response.Status.OK.getStatusCode()); + + List artifacts = new ArrayList<>(); + Artifact artifact = new ModelArtifact(); + artifacts.add(artifact); + + ModelArtifactHandler handler = new ModelArtifactHandler(config); + boolean pushed = handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); + assertThat(pushed, is(true)); + handler.rollback(artifacts, "", aaiClient); + } + + @Test + public void testPushNewModelsWithRollback() { + when(config.getAaiBaseUrl()).thenReturn(""); + when(config.getAaiModelUrl(any())).thenReturn(""); + when(config.getAaiNamedQueryUrl(any())).thenReturn(""); + + OperationResult getResult = mock(OperationResult.class); + when(aaiClient.getResource(any(), any(), any())).thenReturn(getResult); + when(getResult.getResultCode()).thenReturn(Response.Status.NOT_FOUND.getStatusCode()); + + OperationResult putResult = mock(OperationResult.class); + when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode()); + + List artifacts = new ArrayList<>(); + artifacts.add(new ModelArtifact()); + NamedQueryArtifact namedQueryArtifact = new NamedQueryArtifact(); + namedQueryArtifact.setNamedQueryUuid("fred"); + namedQueryArtifact.setModelNamespace("http://org.onap.aai.inventory/v13"); + artifacts.add(namedQueryArtifact); + + List completedArtifacts = new ArrayList<>(); + ModelArtifactHandler handler = new ModelArtifactHandler(config); + boolean pushed = handler.pushArtifacts(artifacts, "", completedArtifacts, aaiClient); + assertThat(pushed, is(true)); + handler.rollback(artifacts, "", aaiClient); + } +} + diff --git a/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java b/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java index 6de0945..8ae2c7e 100644 --- a/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java +++ b/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.extraction; @@ -32,11 +32,10 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor; import org.onap.aai.modelloader.fixture.ArtifactInfoBuilder; import org.onap.aai.modelloader.fixture.TestNotificationDataImpl; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; /** * Tests {@link ArtifactInfoExtractor} diff --git a/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java b/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java index 2540865..aa475f3 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java @@ -1,30 +1,29 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.ArrayList; import java.util.List; - import org.onap.aai.modelloader.service.ArtifactInfoImpl; -import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IArtifactInfo; /** * This class builds an instance of IArtifactInfo for test purposes. diff --git a/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java b/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java index f51a941..44f59a3 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java @@ -1,30 +1,30 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.ArrayList; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is responsible for building NotificationData for use in test classes. @@ -84,7 +84,7 @@ public class NotificationDataFixtureBuilder { private static void buildWithInvalidType() { buildService(INVALID_TYPE, NOTIFICATION_DATA_WITH_INVALID_TYPE); } - + private static void buildwithOneOfEach() { buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_OF_EACH); @@ -139,7 +139,7 @@ public class NotificationDataFixtureBuilder { public static INotificationData getNotificationDataWithInvalidType() { return NOTIFICATION_DATA_WITH_INVALID_TYPE; } - + public static INotificationData getNotificationDataWithOneOfEach() { return NOTIFICATION_DATA_WITH_ONE_OF_EACH; } diff --git a/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java b/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java index b62519d..01e00f8 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java @@ -1,28 +1,28 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class builds an instance of IArtifactInfo for test purposes. diff --git a/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java b/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java index b26b0e3..a7defdf 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java @@ -1,29 +1,29 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is an implementation of INotificationData for test purposes. @@ -97,6 +97,5 @@ public class TestNotificationDataImpl implements INotificationData { } @Override - public void setWorkloadContext(String arg0) { - } + public void setWorkloadContext(String arg0) {} } diff --git a/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java b/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java index 9b5fb19..7eaebb5 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java @@ -1,28 +1,28 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is an implementation of IResourceInstance for test purposes. diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java index 0dcff32..9d6f3c4 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -46,9 +46,8 @@ import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; import org.onap.aai.modelloader.entity.model.ModelArtifactHandler; import org.onap.aai.modelloader.extraction.InvalidArchiveException; import org.onap.aai.modelloader.util.ArtifactTestUtils; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.INotificationData; /** * Tests {@link ArtifactDeploymentManager } @@ -94,10 +93,9 @@ public class ArtifactDeploymentManagerTest { manager = null; } - private List setupTest(byte[] xml, INotificationData data) throws IOException { List toscaArtifacts = new ArrayList<>(); - IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); + org.onap.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); BabelArtifact xmlArtifact = new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml)); diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java index 71cd8af..2c02487 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -53,12 +53,12 @@ import org.onap.aai.modelloader.restclient.BabelServiceClient; import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException; import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; import org.onap.aai.modelloader.util.ArtifactTestUtils; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.impl.DistributionClientDownloadResultImpl; -import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.impl.DistributionClientDownloadResultImpl; +import org.onap.sdc.utils.DistributionActionResultEnum; /** * Tests {@link ArtifactDownloadManager} diff --git a/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java b/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java index 533a37b..e9e6059 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java @@ -1,26 +1,25 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -29,12 +28,10 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.onap.aai.babel.service.data.BabelArtifact; -import org.onap.aai.modelloader.entity.Artifact; -import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; -import org.onap.aai.modelloader.util.ArtifactTestUtils; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; /** * Tests {@link BabelArtifactConverter} @@ -69,7 +66,7 @@ public class BabelArtifactConverterTest { private List setupTest(byte[] xml, INotificationData data) throws IOException { List toscaArtifacts = new ArrayList<>(); - org.openecomp.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); + IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); BabelArtifact xmlArtifact = new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml)); @@ -77,5 +74,4 @@ public class BabelArtifactConverterTest { return toscaArtifacts; } - } diff --git a/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java b/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java index bc88c85..57a4c09 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java @@ -1,116 +1,116 @@ -/** - * ============LICENSE_START========================================== - * org.onap.aai - * =================================================================== - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== - * 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.modelloader.notification; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.List; -import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; -import org.onap.aai.modelloader.config.ModelLoaderConfig; -import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; -import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.INotificationData; - -/** - * Tests {@link EventCallback} - */ -public class EventCallbackTest { - - private static final String CONFIG_FILE = "model-loader.properties"; - - private ModelLoaderConfig config; - private Properties configProperties; - private EventCallback eventCallback; - - private ArtifactDeploymentManager mockArtifactDeploymentManager; - private ArtifactDownloadManager mockArtifactDownloadManager; - private IDistributionClient mockDistributionClient; - - @Before - public void setup() throws IOException { - configProperties = new Properties(); - configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)); - config = new ModelLoaderConfig(configProperties, null); - - mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class); - mockArtifactDownloadManager = mock(ArtifactDownloadManager.class); - mockDistributionClient = mock(IDistributionClient.class); - - eventCallback = new EventCallback(mockDistributionClient, config); - - Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager); - Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager); - } - - @After - public void tearDown() { - config = null; - configProperties = null; - eventCallback = null; - mockArtifactDeploymentManager = null; - mockArtifactDownloadManager = null; - mockDistributionClient = null; - } - - @Test - @SuppressWarnings("unchecked") - public void activateCallback_downloadFails() { - INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); - - when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class), - any(List.class), any(List.class))).thenReturn(false); - - eventCallback.activateCallback(data); - - verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class), - any(List.class), any(List.class)); - Mockito.verifyZeroInteractions(mockArtifactDeploymentManager); - } - - @SuppressWarnings("unchecked") - @Test - public void activateCallback() throws BabelArtifactParsingException { - INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); - - when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class), - any(List.class), any(List.class))).thenReturn(true); - - when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class), - any(List.class))).thenReturn(true); - - eventCallback.activateCallback(data); - - verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class), - any(List.class), any(List.class)); - verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class), - any(List.class)); - } -} +/** + * ============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.modelloader.notification; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.Properties; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; +import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.INotificationData; + +/** + * Tests {@link EventCallback} + */ +public class EventCallbackTest { + + private static final String CONFIG_FILE = "model-loader.properties"; + + private ModelLoaderConfig config; + private Properties configProperties; + private EventCallback eventCallback; + + private ArtifactDeploymentManager mockArtifactDeploymentManager; + private ArtifactDownloadManager mockArtifactDownloadManager; + private IDistributionClient mockDistributionClient; + + @Before + public void setup() throws IOException { + configProperties = new Properties(); + configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)); + config = new ModelLoaderConfig(configProperties, null); + + mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class); + mockArtifactDownloadManager = mock(ArtifactDownloadManager.class); + mockDistributionClient = mock(IDistributionClient.class); + + eventCallback = new EventCallback(mockDistributionClient, config); + + Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager); + Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager); + } + + @After + public void tearDown() { + config = null; + configProperties = null; + eventCallback = null; + mockArtifactDeploymentManager = null; + mockArtifactDownloadManager = null; + mockDistributionClient = null; + } + + @Test + @SuppressWarnings("unchecked") + public void activateCallback_downloadFails() { + INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); + + when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class))).thenReturn(false); + + eventCallback.activateCallback(data); + + verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class)); + Mockito.verifyZeroInteractions(mockArtifactDeploymentManager); + } + + @SuppressWarnings("unchecked") + @Test + public void activateCallback() throws BabelArtifactParsingException { + INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); + + when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class))).thenReturn(true); + + when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class), + any(List.class))).thenReturn(true); + + eventCallback.activateCallback(data); + + verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class)); + verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class), + any(List.class)); + } +} diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java b/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java new file mode 100644 index 0000000..bc91b2f --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java @@ -0,0 +1,86 @@ +/** + * ============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.modelloader.notification; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; + +/** + * Test the Notification Publisher using Mocks + * + */ +public class TestNotificationPublisher { + + @Mock + private IDistributionClient client; + + @Mock + private INotificationData data; + + @Mock + private IArtifactInfo artifact; + + @Mock + private IConfiguration config; + + @Mock + private IDistributionClientResult clientResult; + + static { + System.setProperty("CONFIG_HOME", "src/test/resources"); + } + + @Before + public void setupMocks() { + MockitoAnnotations.initMocks(this); + when(client.getConfiguration()).thenReturn(config); + when(client.sendDownloadStatus(any())).thenReturn(clientResult); + when(client.sendComponentDoneStatus(any())).thenReturn(clientResult); + when(client.sendComponentDoneStatus(any(), anyString())).thenReturn(clientResult); + when(client.sendDeploymentStatus(any())).thenReturn(clientResult); + when(clientResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); + } + + @Test + public void testPublisher() { + NotificationPublisher publisher = new NotificationPublisher(); + publisher.publishDownloadSuccess(client, data, artifact); + publisher.publishDownloadFailure(client, data, artifact, ""); + publisher.publishComponentSuccess(client, data); + publisher.publishComponentFailure(client, data, ""); + publisher.publishDeploySuccess(client, data, artifact); + publisher.publishDeployFailure(client, data, artifact); + } + +} + diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java new file mode 100644 index 0000000..96620ee --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java @@ -0,0 +1,106 @@ +/** + * ============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.modelloader.restclient; + +import static javax.servlet.http.HttpServletResponse.SC_OK; +import static org.apache.commons.io.IOUtils.write; + +import java.io.IOException; +import java.util.Properties; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.MediaType; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.modelloader.config.ModelLoaderConfig; + +/** + * Local testing of the Babel service + * + */ +public class TestAaiServiceClient { + + private Server server; + private AaiRestClient aaiClient; + + @Before + public void startJetty() throws Exception { + server = new Server(8080); + server.setHandler(getMockHandler()); + server.start(); + + Properties props = new Properties(); + props.put("ml.aai.KEYSTORE_PASSWORD", "2244"); + ModelLoaderConfig config = new ModelLoaderConfig(props, "."); + aaiClient = new AaiRestClient(config); + } + + @After + public void stopJetty() throws Exception { + server.stop(); + } + + @Test + public void testBuildAaiRestClient() { + Properties props = new Properties(); + ModelLoaderConfig config = new ModelLoaderConfig(props, "."); + new AaiRestClient(config); + } + + @Test + public void testOperations() { + String url = "http://localhost"; + String transId = ""; + MediaType mediaType = MediaType.APPLICATION_JSON_TYPE; + aaiClient.getResource(url, "", mediaType); + aaiClient.deleteResource("http://localhost", transId, ""); + aaiClient.getAndDeleteResource(url, transId); + aaiClient.postResource(url, "", transId, mediaType); + aaiClient.putResource(url, "", transId, mediaType); + } + + + /** + * Creates an {@link AbstractHandler handler} returning an arbitrary String as a response. + * + * @return never null. + */ + private Handler getMockHandler() { + Handler handler = new AbstractHandler() { + @Override + public void handle(String target, Request request, HttpServletRequest servletRequest, + HttpServletResponse response) throws IOException, ServletException { + response.setStatus(SC_OK); + response.setContentType("text/json;charset=utf-8"); + write("", response.getOutputStream()); + request.setHandled(true); + } + }; + return handler; + } +} + diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java index 974c034..b42fee4 100644 --- a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java +++ b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java @@ -1,40 +1,57 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.restclient; +import static javax.servlet.http.HttpServletResponse.SC_OK; +import static org.apache.commons.io.IOUtils.write; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import com.google.gson.Gson; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.junit.Ignore; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.onap.aai.babel.service.data.BabelArtifact; import org.onap.aai.modelloader.config.ModelLoaderConfig; -import org.onap.aai.modelloader.restclient.BabelServiceClient; +import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException; /** * Local testing of the Babel service @@ -42,27 +59,65 @@ import org.onap.aai.modelloader.restclient.BabelServiceClient; */ public class TestBabelServiceClient { - // Load properties from src/test/resources - protected static String CONFIG_FILE = "model-loader.properties"; + private Server server; + private String responseBody; - // This test requires a running Babel system. To test locally, annotate with org.junit.Test - @Ignore - public void testRestClient() throws Exception { // NOSONAR + { + List response = new ArrayList<>(); + response.add(new BabelArtifact("", null, "")); + response.add(new BabelArtifact("", null, "")); + response.add(new BabelArtifact("", null, "")); + responseBody = new Gson().toJson(response); + } + + @Before + public void startJetty() throws Exception { + server = new Server(8080); + server.setHandler(getMockHandler()); + server.start(); + } + + @After + public void stopJetty() throws Exception { + server.stop(); + } + + @Test + public void testRestClient() throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, + KeyStoreException, CertificateException, IOException, BabelServiceException, URISyntaxException { Properties configProperties = new Properties(); - try { - configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)); - } catch (IOException e) { - fail(); - } - BabelServiceClient client = new BabelServiceClient(new ModelLoaderConfig(configProperties, ".")); + configProperties.put("ml.babel.KEYSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0"); + configProperties.put("ml.babel.BASE_URL", "http://localhost:8080/"); + configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate"); + BabelServiceClient client = + new BabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, ".")); List result = client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"), "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient"); - assertThat(result.size(), is(equalTo(3))); } private byte[] readBytesFromFile(String resourceFile) throws IOException, URISyntaxException { return Files.readAllBytes(Paths.get(ClassLoader.getSystemResource(resourceFile).toURI())); } + + /** + * Creates an {@link AbstractHandler handler} returning an arbitrary String as a response. + * + * @return never null. + */ + private Handler getMockHandler() { + Handler handler = new AbstractHandler() { + @Override + public void handle(String target, Request request, HttpServletRequest servletRequest, + HttpServletResponse response) throws IOException, ServletException { + response.setStatus(SC_OK); + response.setContentType("text/xml;charset=utf-8"); + write(responseBody, response.getOutputStream()); + request.setHandled(true); + } + }; + return handler; + } } + diff --git a/src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java b/src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java new file mode 100644 index 0000000..366d5a5 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java @@ -0,0 +1,123 @@ +/** + * ============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.modelloader.service; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Tests for NotificationDataImpl class + * + */ +public class TestArtifactInfoImpl { + + @Test + public void testGettersAndSetters() { + ArtifactInfoImpl info = new ArtifactInfoImpl(); + String artifactName = "testname"; + String artifactType = "test-type"; + String artifactVersion = "v1"; + String artifactDescription = "test description"; + + info.setArtifactName(artifactName); + assertThat(info.getArtifactName(), is(equalTo(artifactName))); + + info.setArtifactType(artifactType); + assertThat(info.getArtifactType(), is(equalTo(artifactType))); + + info.setArtifactVersion(artifactVersion); + assertThat(info.getArtifactVersion(), is(equalTo(artifactVersion))); + + info.setArtifactDescription(artifactDescription); + assertThat(info.getArtifactDescription(), is(equalTo(artifactDescription))); + + assertThat(info.getArtifactChecksum(), is(nullValue())); + assertThat(info.getArtifactTimeout(), is(nullValue())); + assertThat(info.getArtifactURL(), is(nullValue())); + assertThat(info.getArtifactUUID(), is(nullValue())); + assertThat(info.getGeneratedArtifact(), is(nullValue())); + assertThat(info.getRelatedArtifacts(), is(empty())); + } + + + @Test + public void testEquality() { + ArtifactInfoImpl info = new ArtifactInfoImpl(); + assertThat(info, is(not(equalTo(null)))); + assertThat(info, is(not(equalTo("")))); // NOSONAR + assertThat(info, is(equalTo(info))); + + ArtifactInfoImpl other = new ArtifactInfoImpl(); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Name + other.setArtifactName(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactName("1234"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactName("1234"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Type + other.setArtifactType(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactType("type"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactType("type"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Description + other.setArtifactDescription(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactDescription("type"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactDescription("type"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Version + other.setArtifactVersion(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactVersion("v1"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactVersion("v1"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.java b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.java new file mode 100644 index 0000000..0f3ed45 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.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.modelloader.service; + +import org.junit.Test; + +/** + * Tests for ModelLoaderApplication class + * + */ +public class TestModelLoaderApplication { + + static { + System.setProperty("CONFIG_HOME", "src/test/resources"); + } + + @Test + public void testServiceStarts() { + // The SDC Distribution Client is expected to fail to initialise. + ModelLoaderApplication.main(new String[0]); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java b/src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java new file mode 100644 index 0000000..395b1f3 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java @@ -0,0 +1,83 @@ +/** + * ============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.modelloader.service; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Tests for NotificationDataImpl class + * + */ +public class TestNotificationDataImpl { + + @Test + public void testGettersAndSetters() { + NotificationDataImpl data = new NotificationDataImpl(); + String distributionId = "testid"; + String context = "testcontext"; + + data.setDistributionID(distributionId); + assertThat(data.getDistributionID(), is(equalTo(distributionId))); + + // Getters return empty data + assertThat(data.getArtifactMetadataByUUID(null), is(equalTo(null))); + assertThat(data.getServiceDescription(), is(equalTo(null))); + assertThat(data.getServiceInvariantUUID(), is(equalTo(null))); + assertThat(data.getServiceName(), is(equalTo(null))); + assertThat(data.getServiceUUID(), is(equalTo(null))); + assertThat(data.getServiceVersion(), is(equalTo(null))); + assertThat(data.getResources().size(), is(0)); + assertThat(data.getServiceArtifacts().size(), is(0)); + + // Unsupported method! + data.setWorkloadContext(context); + assertThat(data.getWorkloadContext(), is(equalTo(null))); + } + + + @Test + public void testEquality() { + NotificationDataImpl data = new NotificationDataImpl(); + assertThat(data, is(not(equalTo(null)))); + assertThat(data, is(not(equalTo("")))); // NOSONAR + assertThat(data, is(equalTo(data))); + + NotificationDataImpl other = new NotificationDataImpl(); + assertThat(data, is(equalTo(other))); + assertThat(data.hashCode(), is(equalTo(other.hashCode()))); + + other.setDistributionID(""); + assertThat(data, is(not(equalTo(other)))); + + data.setDistributionID("1234"); + assertThat(data, is(not(equalTo(other)))); + + other.setDistributionID("1234"); + assertThat(data, is(equalTo(other))); + assertThat(data.hashCode(), is(equalTo(other.hashCode()))); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java b/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java index c7a1506..9b6ea06 100644 --- a/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java +++ b/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.util; diff --git a/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java b/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java index 7a42edf..2271c57 100644 --- a/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java +++ b/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java @@ -1,79 +1,78 @@ -/** - * ============LICENSE_START========================================== - * org.onap.aai - * =================================================================== - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== - * 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.modelloader.util; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import org.junit.Test; -import org.onap.aai.modelloader.util.JsonXmlConverter; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class JsonXmlConverterTest { - - @Test - public void testConversion() throws Exception { - final String XML_MODEL_FILE = "src/test/resources/models/l3-network-widget.xml"; - final String JSON_MODEL_FILE = "src/test/resources/models/l3-network-widget.json"; - - try { - byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE)); - String originalXML = new String(encoded); - - assertFalse(JsonXmlConverter.isValidJson(originalXML)); - - encoded = Files.readAllBytes(Paths.get(JSON_MODEL_FILE)); - String originalJSON = new String(encoded); - - assertTrue(JsonXmlConverter.isValidJson(originalJSON)); - - String xmlFromJson = JsonXmlConverter.convertJsonToXml(originalJSON); - - // Spot check one of the attributes - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.parse(new ByteArrayInputStream(xmlFromJson.getBytes())); - NodeList nodeList = doc.getDocumentElement().getChildNodes(); - - String modelVid = "notFound"; - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentNode = nodeList.item(i); - if (currentNode.getNodeName().equals("model-invariant-id")) { - modelVid = currentNode.getTextContent(); - break; - } - } - - assertTrue(modelVid.equals("3d560d81-57d0-438b-a2a1-5334dba0651a")); - } catch (Exception e) { - e.printStackTrace(); - assertTrue(false); - } - } -} +/** + * ============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.modelloader.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class JsonXmlConverterTest { + + @Test + public void testConversion() throws Exception { + final String XML_MODEL_FILE = "src/test/resources/models/l3-network-widget.xml"; + final String JSON_MODEL_FILE = "src/test/resources/models/l3-network-widget.json"; + + try { + byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE)); + String originalXML = new String(encoded); + + assertFalse(JsonXmlConverter.isValidJson(originalXML)); + + encoded = Files.readAllBytes(Paths.get(JSON_MODEL_FILE)); + String originalJSON = new String(encoded); + + assertTrue(JsonXmlConverter.isValidJson(originalJSON)); + + String xmlFromJson = JsonXmlConverter.convertJsonToXml(originalJSON); + + // Spot check one of the attributes + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(new ByteArrayInputStream(xmlFromJson.getBytes())); + NodeList nodeList = doc.getDocumentElement().getChildNodes(); + + String modelVid = "notFound"; + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentNode = nodeList.item(i); + if (currentNode.getNodeName().equals("model-invariant-id")) { + modelVid = currentNode.getTextContent(); + break; + } + } + + assertTrue(modelVid.equals("3d560d81-57d0-438b-a2a1-5334dba0651a")); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } +} diff --git a/src/test/resources/model-loader.properties b/src/test/resources/model-loader.properties index 91fd527..9f3226a 100644 --- a/src/test/resources/model-loader.properties +++ b/src/test/resources/model-loader.properties @@ -1,23 +1,30 @@ # Model Loader Distribution Client Configuration ml.distribution.ACTIVE_SERVER_TLS_AUTH=false -ml.distribution.ASDC_ADDRESS= +ml.distribution.ASDC_ADDRESS=localhost +ml.distribution.MSG_BUS_ADDRESSES=localhost ml.distribution.CONSUMER_GROUP=aai-ml-group-test ml.distribution.CONSUMER_ID=aai-ml-id-test -ml.distribution.ENVIRONMENT_NAME= +ml.distribution.ENVIRONMENT_NAME=env ml.distribution.KEYSTORE_PASSWORD= ml.distribution.KEYSTORE_FILE=asdc-client.jks -ml.distribution.PASSWORD= +ml.distribution.PASSWORD=Aa123456 ml.distribution.POLLING_INTERVAL=30 ml.distribution.POLLING_TIMEOUT=20 ml.distribution.USER=ci ml.distribution.ARTIFACT_TYPES=MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG -# Model Loader AAI REST Client Configuration +# Model Loader Client Configuration for the A&AI REST interface ml.aai.BASE_URL= -ml.aai.MODEL_URL=/aai/v8/service-design-and-creation/models/model/ -ml.aai.NAMED_QUERY_URL=/aai/v8/service-design-and-creation/named-queries/named-query/ -ml.aai.VNF_IMAGE_URL=/aai/v8/service-design-and-creation/vnf-images +ml.aai.MODEL_URL=/aai/v*/service-design-and-creation/models/model/ +ml.aai.NAMED_QUERY_URL=/aai/v*/service-design-and-creation/named-queries/named-query/ +ml.aai.VNF_IMAGE_URL=/aai/v*/service-design-and-creation/vnf-images ml.aai.KEYSTORE_FILE=aai-client-cert.p12 ml.aai.KEYSTORE_PASSWORD= ml.aai.AUTH_USER=ModelLoader ml.aai.AUTH_PASSWORD= + +# Model Loader Client Configuration for the Babel Service +ml.babel.BASE_URL= +ml.babel.GENERATE_ARTIFACTS_URL=/services/babel-service/v1/app/generateArtifacts +ml.babel.KEYSTORE_FILE=aai-client-cert.p12 +ml.babel.KEYSTORE_PASSWORD= -- cgit 1.2.3-korg