diff options
author | Blimkie, Steven (sb787e) <steven.blimkie@amdocs.com> | 2017-06-27 21:08:37 +0300 |
---|---|---|
committer | Blimkie, Steven (sb787e) <steven.blimkie@amdocs.com> | 2017-06-27 21:10:57 +0300 |
commit | fe17f093d5c61207949eebef95b83baf5139be50 (patch) | |
tree | 776be9df8cd4cf8e5a69bde1f0ed741e78ab08fb | |
parent | faa407b9cd0430c1e6b8b668392fe5e33f792432 (diff) |
Allow handling of legact model artifacts
Change-Id: I3d4c5e51140d4d05b3fd871d58c2590421c0e9db
Signed-off-by: Blimkie, Steven (sb787e) <steven.blimkie@amdocs.com>
40 files changed, 3248 insertions, 2874 deletions
@@ -16,32 +16,115 @@ The Model Loader: ## Compiling Model Loader Model Loader can be compiled by running `mvn clean install` +A Model Loader docker image can be created by running `docker build -t openecomp/model-loader target` ## Running Model Loader -### Create a config file with the following key/values: +### Deploying The Micro Service -``` -DISTR_CLIENT_ASDC_ADDRESS=<SDC_ADDRESS> -DISTR_CLIENT_CONSUMER_GROUP=<UEB_CONSUMER_GROUP> ;; Uniquely identiy this group of model loaders. -DISTR_CLIENT_CONSUMER_ID=<UEB_CONSUMER_GROUP_ID> ;; Uniquely identiythis model loader. -DISTR_CLIENT_ENVIRONMENT_NAME=<ENVIRONMENT_NAME> ;; Environment name configured on the SDC -DISTR_CLIENT_PASSWORD=<DISTR_PASSWORD> ;; Password to connect to SDC -DISTR_CLIENT_USER=<USER_ID> ;; User name to connect to SDC - -APP_SERVER_BASE_URL=https://<aai-address>:8443 ;; AAI Address (URL) -APP_SERVER_AUTH_USER=<USER_ID> ;; User name to connect to AAI -APP_SERVER_AUTH_PASSWORD=<PASSWORD> ;; Password to connect to AAi +Push the Docker image that you have built to your Docker repository and pull it down to the location that you will be running the search service from. -``` +**Create the following directories on the host machine:** -### Docker + ./logs + ./opt/app/model-loader/appconfig + ./opt/app/model-loader/appconfig/auth + +You will be mounting these as data volumes when you start the Docker container. For examples of the files required in these directories, see the aai/test/config repository (https://gerrit.onap.org/r/#/admin/projects/aai/test-config) -#### Build your own Model Loader docker image and create docker containers -1. mvn clean package docker:build ;; Build a docker image of Model Loader -2. sudo docker images ;; list docker images and check if the image you build is listed. -3. sudo docker run --env-file <config-filename> <model-loader-image> /opt/jetty/jetty*/bin/startup.sh +**Populate these directories as follows:** +##### Contents of /opt/app/model-loader/appconfig -#### Retrieve logs from stopped container -* docker cp <container-id>:/opt/jetty/jetty-distribution-9.3.9.v20160517/logs/AAI-ML/error.log /tmp/ +The following file must be present in this directory on the host machine: + +_model-loader.properties_ + # Always false. TLS Auth currently not supported + ml.distribution.ACTIVE_SERVER_TLS_AUTH=false + + # Address/port of the SDC + ml.distribution.ASDC_ADDRESS=<SDC-Hostname>:8443 + + # DMaaP consumer group. + ml.distribution.CONSUMER_GROUP=aai-ml-group + + # DMaaP consumer ID + ml.distribution.CONSUMER_ID=aai-ml + + # SDC Environment Name. This must match the environment name configured on the SDC + ml.distribution.ENVIRONMENT_NAME=<Environment Name> + + # Currently not used + ml.distribution.KEYSTORE_PASSWORD= + + # Currently not used + ml.distribution.KEYSTORE_FILE= + + # Obfuscated password to connect to the SDC. To obtain this value, use the following Jetty library to + # obfuscate the cleartext password: http://www.eclipse.org/jetty/documentation/9.4.x/configuring-security-secure-passwords.html + ml.distribution.PASSWORD=OBF:<password> + + # How often (in seconds) to poll the DMaaP cluster for new model events + ml.distribution.POLLING_INTERVAL=<integer> + + # Timeout value (in seconds) when polling DMaaP for new model events + ml.distribution.POLLING_TIMEOUT=<integer> + + # Username to use when connecting to the SDC + ml.distribution.USER=<username> + + # Artifact type we want to download from the SDC (the values below will typically suffice) + ml.distribution.ARTIFACT_TYPES=MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG + + # URL of the A&AI + ml.aai.BASE_URL=https://<AAI-Hostname>:8443 + + # A&AI endpoint to post models + ml.aai.MODEL_URL=/aai/v*/service-design-and-creation/models/model/ + + # A&AI endpoint to post named queries + ml.aai.NAMED_QUERY_URL=/aai/v*/service-design-and-creation/named-queries/named-query/ + + # A&AI endpoint to post vnf images + ml.aai.VNF_IMAGE_URL=/aai/v8/service-design-and-creation/vnf-images + + # Name of certificate to use in connecting to the A&AI + ml.aai.KEYSTORE_FILE=aai-os-cert.p12 + + # Obfuscated keystore password to connect to the A&AI. This is only required if using 2-way SSL (not basic auth). + # To obtain this value, use the following Jetty library to obfuscate the cleartext password: + # http://www.eclipse.org/jetty/documentation/9.4.x/configuring-security-secure-passwords.html + ml.aai.KEYSTORE_PASSWORD=OBF:<password> + + # Name of user to use when connecting to the A&AI. This is only required if using basic auth (not 2-way SSL). + ml.aai.AUTH_USER=<username> + + # Obfuscated password to connect to the A&AI. This is only required if using basic auth (not 2-way SSL). + # To obtain this value, use the following Jetty library to obfuscate the cleartext password: + # http://www.eclipse.org/jetty/documentation/9.4.x/configuring-security-secure-passwords.html + ml.aai.AUTH_PASSWORD=OBF:<password> + + + +##### Contents of the /opt/app/model-loader/app-config/auth Directory + +The following files must be present in this directory on the host machine: + +_aai-os-cert.p12_ + +The certificate used to connected to the A&AI + +**Start the service:** + +You can now start the Docker container for the _Search Data Service_, in the following manner: + + docker run -d \ + -e CONFIG_HOME=/opt/app/model-loader/config/ \ + -v /logs:/logs \ + -v /opt/app/model-loader/appconfig:/opt/app/model-loader/config \ + --name model-loader \ + {{your docker repo}}/model-loader + +Where, + + {{your docker repo}} = The Docker repository you have published your image to. diff --git a/src/main/java/org/openecomp/modelloader/entity/Artifact.java b/src/main/java/org/openecomp/modelloader/entity/Artifact.java index 30709ae..88c75eb 100644 --- a/src/main/java/org/openecomp/modelloader/entity/Artifact.java +++ b/src/main/java/org/openecomp/modelloader/entity/Artifact.java @@ -1,46 +1,46 @@ -/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.entity;
-
-public abstract class Artifact {
-
- private String payload;
- private ArtifactType type;
-
- public ArtifactType getType() {
- return type;
- }
-
- public void setType(ArtifactType type) {
- this.type = type;
- }
-
- public String getPayload() {
- return payload;
- }
-
- public void setPayload(String payload) {
- this.payload = payload;
- }
-
-}
+/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity; + +public abstract class Artifact { + + private String payload; + private ArtifactType type; + + public Artifact(ArtifactType type) { + this.type = type; + } + + public ArtifactType getType() { + return type; + } + + public String getPayload() { + return payload; + } + + public void setPayload(String payload) { + this.payload = payload; + } + +} diff --git a/src/main/java/org/openecomp/modelloader/entity/ArtifactType.java b/src/main/java/org/openecomp/modelloader/entity/ArtifactType.java index ae556bc..381733b 100644 --- a/src/main/java/org/openecomp/modelloader/entity/ArtifactType.java +++ b/src/main/java/org/openecomp/modelloader/entity/ArtifactType.java @@ -1,27 +1,30 @@ -/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.entity;
-
-public enum ArtifactType {
- MODEL, NAMED_QUERY, VNF_CATALOG;
-}
+/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity; + +public enum ArtifactType { + MODEL, + MODEL_V8, + NAMED_QUERY, + VNF_CATALOG; +} diff --git a/src/main/java/org/openecomp/modelloader/entity/catalog/VnfCatalogArtifact.java b/src/main/java/org/openecomp/modelloader/entity/catalog/VnfCatalogArtifact.java index a15ed3c..9b4c587 100644 --- a/src/main/java/org/openecomp/modelloader/entity/catalog/VnfCatalogArtifact.java +++ b/src/main/java/org/openecomp/modelloader/entity/catalog/VnfCatalogArtifact.java @@ -1,33 +1,33 @@ -/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.entity.catalog;
-
-import org.openecomp.modelloader.entity.Artifact;
-import org.openecomp.modelloader.entity.ArtifactType;
-
-public class VnfCatalogArtifact extends Artifact {
- public VnfCatalogArtifact(String payload) {
- setPayload(payload);
- setType(ArtifactType.VNF_CATALOG);
- }
-}
+/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.catalog; + +import org.openecomp.modelloader.entity.Artifact; +import org.openecomp.modelloader.entity.ArtifactType; + +public class VnfCatalogArtifact extends Artifact { + public VnfCatalogArtifact(String payload) { + super(ArtifactType.VNF_CATALOG); + setPayload(payload); + } +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/AbstractModelArtifact.java b/src/main/java/org/openecomp/modelloader/entity/model/AbstractModelArtifact.java new file mode 100644 index 0000000..2add53e --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/AbstractModelArtifact.java @@ -0,0 +1,85 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.openecomp.modelloader.config.ModelLoaderConfig; +import org.openecomp.modelloader.entity.Artifact; +import org.openecomp.modelloader.entity.ArtifactType; +import org.openecomp.modelloader.restclient.AaiRestClient; + +public abstract class AbstractModelArtifact extends Artifact { + + private String modelNamespace; + private String modelNamespaceVersion; + private Set<String> referencedModelIds = new HashSet<String>(); + + public AbstractModelArtifact(ArtifactType type) { + super(type); + } + + public Set<String> getDependentModelIds() { + return referencedModelIds; + } + + public void addDependentModelId(String dependentModelId) { + this.referencedModelIds.add(dependentModelId); + } + + public String getModelNamespace() { + return modelNamespace; + } + + public void setModelNamespace(String modelNamespace) { + this.modelNamespace = modelNamespace; + + // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9') + String[] parts = modelNamespace.split("/"); + modelNamespaceVersion = parts[parts.length-1].trim(); + } + + public String getModelNamespaceVersion() { + return modelNamespaceVersion; + } + + public abstract String getUniqueIdentifier(); + + public abstract boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<AbstractModelArtifact> addedModels); + + public abstract void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId); + + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("\nType=" + getType().toString() +"\nId=" + getUniqueIdentifier() +"\nVersion=" + getModelNamespaceVersion() + "\nDependant models: "); + for (String dep : referencedModelIds) { + sb.append(dep + " "); + } + + return sb.toString(); + } + + +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/IModelParser.java b/src/main/java/org/openecomp/modelloader/entity/model/IModelParser.java new file mode 100644 index 0000000..3a31756 --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/IModelParser.java @@ -0,0 +1,31 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import java.util.List; + +import org.openecomp.modelloader.entity.Artifact; + +public interface IModelParser { + public List<Artifact> parse(byte[] artifactPayload, String artifactName); +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifact.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifact.java index 432e442..f316e28 100644 --- a/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifact.java +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifact.java @@ -22,94 +22,44 @@ */ package org.openecomp.modelloader.entity.model; -import org.openecomp.modelloader.entity.Artifact; -import org.w3c.dom.Node; +import java.io.StringWriter; +import java.util.List; -import java.util.HashSet; -import java.util.Set; - -public class ModelArtifact extends Artifact { - - String modelVerId; - String modelInvariantId; - String nameVersionId; - String modelVerModelVersionId; - String modelModelInvariantId; - String modelNamespace; - String modelNamespaceVersion; - Set<String> referencedModelIds = new HashSet<String>(); - Node modelVer; - boolean isV9Artifact = true; - - public boolean isV9Artifact() { - return isV9Artifact; - } - - public void setV9Artifact(boolean isV9Artifact) { - this.isV9Artifact = isV9Artifact; - } +import javax.ws.rs.core.Response; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; - public String getModelVerModelVersionId() { - return modelVerModelVersionId; - } - - public void setModelVerModelVersionId(String modelVerModelVersionId) { - this.modelVerModelVersionId = modelVerModelVersionId; - } - - public String getModelModelInvariantId() { - return modelModelInvariantId; - } - - public void setModelModelInvariantId(String modelModelInvariantId) { - this.modelModelInvariantId = modelModelInvariantId; - } - - public String getNameVersionId() { - return nameVersionId; - } - - public void setNameVersionId(String nameVersionId) { - this.nameVersionId = nameVersionId; - } - - public String getModelNamespace() { - return modelNamespace; - } - - public void setModelNamespace(String modelNamespace) { - this.modelNamespace = modelNamespace; - - // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9') - String[] parts = modelNamespace.split("/"); - modelNamespaceVersion = parts[parts.length-1].trim(); - } - - public String getModelNamespaceVersion() { - return modelNamespaceVersion; - } +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.modelloader.config.ModelLoaderConfig; +import org.openecomp.modelloader.entity.ArtifactType; +import org.openecomp.modelloader.restclient.AaiRestClient; +import org.openecomp.modelloader.service.ModelLoaderMsgs; +import org.w3c.dom.Node; - public Set<String> getDependentModelIds() { - return referencedModelIds; - } +import com.sun.jersey.api.client.ClientResponse; - public void addDependentModelId(String dependentModelId) { - this.referencedModelIds.add(dependentModelId); - } +public class ModelArtifact extends AbstractModelArtifact { - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("ModelInvariantId=" + modelInvariantId + "(" + getType().toString() + ") ==> "); - for (String dep : referencedModelIds) { - sb.append(dep + " "); - } + private static final String AAI_MODEL_VER_SUB_URL = "/model-vers/model-ver"; + + private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifact.class.getName()); + + private String modelVerId; + private String modelInvariantId; + private Node modelVer; + private boolean firstVersionOfModel = false; - return sb.toString(); + public ModelArtifact() { + super(ArtifactType.MODEL); } public String getModelVerId() { - return modelVerId; + return modelVerId; } public void setModelVerId(String modelVerId) { @@ -131,11 +81,130 @@ public class ModelArtifact extends Artifact { public void setModelVer(Node modelVer) { this.modelVer = modelVer; } - - public String getModelModelVerCombinedKey() { - if ( (getModelInvariantId() == null) && (getModelVerId() == null) ) { - return getNameVersionId(); - } - return getModelInvariantId() + "|" + getModelVerId(); - } + + @Override + public String getUniqueIdentifier() { + return getModelInvariantId() + "|" + getModelVerId(); + } + + @Override + public boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<AbstractModelArtifact> addedModels) { + ClientResponse getResponse = aaiClient.getResource(getModelUrl(config), distId, AaiRestClient.MimeType.XML); + if ( (getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode()) ) { + // Only attempt the PUT if the model doesn't already exist + ClientResponse putResponse = aaiClient.putResource(getModelUrl(config), getPayload(), distId, AaiRestClient.MimeType.XML); + if ( (putResponse != null) && (putResponse.getStatus() == Response.Status.CREATED.getStatusCode()) ) { + addedModels.add(this); + + // Flag this as the first version of the model that has been added. + firstVersionOfModel = true; + + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getUniqueIdentifier() + " successfully ingested."); + } + else { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + getType().toString() + " " + getUniqueIdentifier() + + ". Rolling back distribution."); + return false; + } + } + else { + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getModelInvariantId() + " already exists. Skipping ingestion."); + getResponse = aaiClient.getResource(getModelVerUrl(config), distId, AaiRestClient.MimeType.XML); + if ( (getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode()) ) { + // Only attempt the PUT if the model-ver doesn't already exist + ClientResponse putResponse = null; + + try { + putResponse = aaiClient.putResource(getModelVerUrl(config), nodeToString(getModelVer()), distId, AaiRestClient.MimeType.XML); + } catch (TransformerException e) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + getType().toString() + " " + getUniqueIdentifier() + + ": " + e.getMessage() + ". Rolling back distribution."); + return false; + } + if ( (putResponse != null) && (putResponse.getStatus() == Response.Status.CREATED.getStatusCode()) ) { + addedModels.add(this); + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getUniqueIdentifier() + " successfully ingested."); + } + else { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + getType().toString() + " " + + getUniqueIdentifier() + ". Rolling back distribution."); + return false; + } + } + else { + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getUniqueIdentifier() + " already exists. Skipping ingestion."); + } + } + + return true; + } + + @Override + public void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId) { + String url = getModelVerUrl(config); + if (firstVersionOfModel) { + // If this was the first version of the model which was added, we want to remove the entire + // model rather than just the version. + url = getModelUrl(config); + } + + // Best effort to delete. Nothing we can do in the event this fails. + aaiClient.getAndDeleteResource(url, distId); + } + + private String getModelUrl(ModelLoaderConfig config) { + String baseURL = config.getAaiBaseUrl().trim(); + String subURL = null; + String instance = null; + + subURL = config.getAaiModelUrl(getModelNamespaceVersion()).trim(); + instance = getModelInvariantId(); + + if ( (!baseURL.endsWith("/")) && (!subURL.startsWith("/")) ) { + baseURL = baseURL + "/"; + } + + if ( baseURL.endsWith("/") && subURL.startsWith("/") ) { + baseURL = baseURL.substring(0, baseURL.length()-1); + } + + if (!subURL.endsWith("/")) { + subURL = subURL + "/"; + } + + String url = baseURL + subURL + instance; + return url; + } + + private String getModelVerUrl(ModelLoaderConfig config) { + String baseURL = config.getAaiBaseUrl().trim(); + String subURL = null; + String instance = null; + + subURL = config.getAaiModelUrl(getModelNamespaceVersion()).trim() + getModelInvariantId() + AAI_MODEL_VER_SUB_URL; + instance = getModelVerId(); + + if ( (!baseURL.endsWith("/")) && (!subURL.startsWith("/")) ) { + baseURL = baseURL + "/"; + } + + if ( baseURL.endsWith("/") && subURL.startsWith("/") ) { + baseURL = baseURL.substring(0, baseURL.length()-1); + } + + if (!subURL.endsWith("/")) { + subURL = subURL + "/"; + } + + String url = baseURL + subURL + instance; + return url; + } + + private String nodeToString(Node node) throws TransformerException { + StringWriter sw = new StringWriter(); + Transformer t = TransformerFactory.newInstance().newTransformer(); + t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + t.transform(new DOMSource(node), new StreamResult(sw)); + return sw.toString(); + } } diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactHandler.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactHandler.java index 19b69cf..13ef1b1 100644 --- a/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactHandler.java +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactHandler.java @@ -22,38 +22,22 @@ */ package org.openecomp.modelloader.entity.model; -import com.sun.jersey.api.client.ClientResponse; - import org.openecomp.cl.api.Logger; import org.openecomp.cl.eelf.LoggerFactory; import org.openecomp.modelloader.config.ModelLoaderConfig; import org.openecomp.modelloader.entity.Artifact; import org.openecomp.modelloader.entity.ArtifactHandler; -import org.openecomp.modelloader.entity.ArtifactType; import org.openecomp.modelloader.restclient.AaiRestClient; import org.openecomp.modelloader.service.ModelLoaderMsgs; -import org.w3c.dom.Node; - -import java.io.StringWriter; import java.util.ArrayList; import java.util.List; -import javax.ws.rs.core.Response; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - public class ModelArtifactHandler extends ArtifactHandler { - private static final String AAI_MODEL_VER = "/model-vers/model-ver"; - private static Logger logger = LoggerFactory.getInstance().getLogger(ArtifactHandler.class.getName()); - - + private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifactHandler.class.getName()); + public ModelArtifactHandler(ModelLoaderConfig config) { super(config); } @@ -61,166 +45,34 @@ public class ModelArtifactHandler extends ArtifactHandler { @Override public boolean pushArtifacts(List<Artifact> artifacts, String distributionID) { ModelSorter modelSorter = new ModelSorter(); - List<Artifact> sortedModelArtifacts = modelSorter.sort(artifacts); - + List<Artifact> sortedModelArtifacts; + try { + sortedModelArtifacts = modelSorter.sort(artifacts); + } + catch (RuntimeException ex) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve models: " + ex.getMessage()); + return false; + } + // Push the ordered list of model artifacts to A&AI. If one fails, we need to roll back // the changes. - List<ModelArtifact> completedModels = new ArrayList<ModelArtifact>(); + List<AbstractModelArtifact> completedModels = new ArrayList<AbstractModelArtifact>(); AaiRestClient aaiClient = new AaiRestClient(config); for (Artifact art : sortedModelArtifacts) { - ModelArtifact model = (ModelArtifact)art; - - boolean version = model.isV9Artifact(); - //Non - V9 version for models - if(version == false){ - ClientResponse getResponse = aaiClient.getResource(getModelVerURL(model), distributionID, AaiRestClient.MimeType.XML); - if ( (getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode()) ) { - logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, " Artifact format not valid for " + - model.getType().toString() + "- model-invariant-id[model-id]: " + - model.getModelInvariantId() + " and model-version-id[model-name-version-id]: "+ - model.getModelVerId()+ " . Rolling back distribution."); - return false; + AbstractModelArtifact model = (AbstractModelArtifact)art; + if (model.push(aaiClient, config, distributionID, completedModels) != true) { + for (AbstractModelArtifact modelToDelete : completedModels) { + modelToDelete.rollbackModel(aaiClient, config, distributionID); } - else{ - completedModels.add(model); - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, model.getType().toString() + - " " + model.getModelInvariantId() + " successfully ingested."); - } - } - else - { - ClientResponse getResponse = aaiClient.getResource(getURL(model), distributionID, AaiRestClient.MimeType.XML); - if ( (getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode()) ) { - // Only attempt the PUT if the model doesn't already exist - ClientResponse putResponse = aaiClient.putResource(getURL(model), model.getPayload(), distributionID, AaiRestClient.MimeType.XML); - if ( (putResponse != null) && (putResponse.getStatus() == Response.Status.CREATED.getStatusCode()) ) { - completedModels.add(model); - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, model.getType().toString() + - " " + model.getModelInvariantId() + " successfully ingested."); - } - else { - logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + - model.getType().toString() + " " + model.getModelInvariantId() + ". Rolling back distribution."); - for (ModelArtifact modelToDelete : completedModels) { - // Best effort to delete. Nothing we can do in the event this fails. - aaiClient.getAndDeleteResource(getURL(modelToDelete), distributionID); - } - - return false; - } - } - else { - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, model.getType().toString() + " " + model.getModelInvariantId() + - " already exists. Skipping ingestion."); - getResponse = aaiClient.getResource(getModelVerURL(model), distributionID, AaiRestClient.MimeType.XML); - if ( (getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode()) ) { - // Only attempt the PUT if the model-ver doesn't already exist - ClientResponse putResponse = null; - - try { - putResponse = aaiClient.putResource(getModelVerURL(model), nodeToString(model.getModelVer()), distributionID, AaiRestClient.MimeType.XML); - } catch (TransformerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - if ( (putResponse != null) && (putResponse.getStatus() == Response.Status.CREATED.getStatusCode()) ) { - completedModels.add(model); - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, model.getType().toString() + " " + - model.getNameVersionId() + " successfully ingested."); - } - else { - logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + - model.getType().toString() + " " + model.getNameVersionId() + ". Rolling back distribution."); - - for (ModelArtifact modelToDelete : completedModels) { - // Best effort to delete. Nothing we can do in the event this fails. - aaiClient.getAndDeleteResource(getModelVerURL(modelToDelete), distributionID); - } - - return false; - } - } - else { - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, model.getType().toString() + " " + - model.getModelInvariantId() + " already exists. Skipping ingestion."); - } - } + return false; } } return true; } - - private String nodeToString(Node node) throws TransformerException { - StringWriter sw = new StringWriter(); - Transformer t = TransformerFactory.newInstance().newTransformer(); - t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - t.transform(new DOMSource(node), new StreamResult(sw)); - System.out.println(sw.toString()); - return sw.toString(); - } - - private String getURL(ModelArtifact model) { - String baseURL = config.getAaiBaseUrl().trim(); - String subURL = null; - String instance = null; - if (model.getType().equals(ArtifactType.MODEL)) { - subURL = config.getAaiModelUrl(model.getModelNamespaceVersion()).trim(); - instance = model.getModelInvariantId(); - } - else { - subURL = config.getAaiNamedQueryUrl(model.getModelNamespaceVersion()).trim(); - instance = model.getNameVersionId(); - } - - if ( (!baseURL.endsWith("/")) && (!subURL.startsWith("/")) ) { - baseURL = baseURL + "/"; - } - - if ( baseURL.endsWith("/") && subURL.startsWith("/") ) { - baseURL = baseURL.substring(0, baseURL.length()-1); - } - - if (!subURL.endsWith("/")) { - subURL = subURL + "/"; - } - - String url = baseURL + subURL + instance; - return url; - } - - private String getModelVerURL(ModelArtifact model) { - String baseURL = config.getAaiBaseUrl().trim(); - String subURL = null; - String instance = null; - if (model.getType().equals(ArtifactType.MODEL)) { - subURL = config.getAaiModelUrl(model.getModelNamespaceVersion()).trim() + model.getModelInvariantId() + AAI_MODEL_VER; - instance = model.getModelVerId(); - } - else { - subURL = config.getAaiNamedQueryUrl(model.getModelNamespaceVersion()).trim(); - instance = model.getNameVersionId(); - } - - if ( (!baseURL.endsWith("/")) && (!subURL.startsWith("/")) ) { - baseURL = baseURL + "/"; - } - - if ( baseURL.endsWith("/") && subURL.startsWith("/") ) { - baseURL = baseURL.substring(0, baseURL.length()-1); - } - - if (!subURL.endsWith("/")) { - subURL = subURL + "/"; - } - - String url = baseURL + subURL + instance; - return url; - } - // This method is used for the test REST interface to load models without an ASDC public void loadModelTest(byte[] payload) { List<Artifact> modelArtifacts = new ArrayList<Artifact>(); diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactParser.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactParser.java index 1bd77c8..d81539c 100644 --- a/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactParser.java +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelArtifactParser.java @@ -25,9 +25,7 @@ package org.openecomp.modelloader.entity.model; import org.openecomp.cl.api.Logger; import org.openecomp.cl.eelf.LoggerFactory; import org.openecomp.modelloader.entity.Artifact; -import org.openecomp.modelloader.entity.ArtifactType; import org.openecomp.modelloader.service.ModelLoaderMsgs; -import org.openecomp.modelloader.util.JsonXmlConverter; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -36,32 +34,20 @@ import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import java.io.StringReader; -import java.io.StringWriter; import java.util.ArrayList; import java.util.List; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -public class ModelArtifactParser { +public class ModelArtifactParser implements IModelParser { - private static String MODELS_ELEMENT = "models"; - private static String MODEL_ELEMENT = "model"; - private static String NAMED_QUERIES_ELEMENT = "named-queries"; - private static String NAMED_QUERY_ELEMENT = "named-query"; - private static String MODEL_NAME_VERSION_ID = "model-name-version-id"; private static String MODEL_VER = "model-ver"; private static String MODEL_VERSION_ID = "model-version-id"; private static String MODEL_INVARIANT_ID = "model-invariant-id"; - private static String NAMED_QUERY_VERSION_ID = "named-query-uuid"; + private static String RELATIONSHIP = "relationship"; private static String RELATIONSHIP_DATA = "relationship-data"; private static String RELATIONSHIP_KEY = "relationship-key"; private static String RELATIONSHIP_VALUE = "relationship-value"; @@ -75,54 +61,22 @@ public class ModelArtifactParser { List<Artifact> modelList = new ArrayList<Artifact>(); try { - // Artifact could be JSON or XML - if (JsonXmlConverter.isValidJson(payload)) { - payload = JsonXmlConverter.convertJsonToXml(payload); - } - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(payload)); Document doc = builder.parse(is); - if ( (doc.getDocumentElement().getNodeName().equalsIgnoreCase(MODEL_ELEMENT)) || - (doc.getDocumentElement().getNodeName().equalsIgnoreCase(NAMED_QUERY_ELEMENT)) ) { - - ModelArtifact model = parseModel(doc.getDocumentElement(), payload); + ModelArtifact model = parseModel(doc.getDocumentElement(), payload); - if (model != null) { - if ( ArtifactType.MODEL.equals(model.getType())) { - logger.info( ModelLoaderMsgs.DISTRIBUTION_EVENT, "Model parsed =====>>>> " - + "Model-invariant-Id: "+ model.getModelInvariantId() - + " Model-Version-Id: "+ model.getModelVerId()); - } - modelList.add(model); - } - else { - logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse artifact " + artifactName); - return null; - } + if (model != null) { + logger.info( ModelLoaderMsgs.DISTRIBUTION_EVENT, "Model parsed =====>>>> " + + "Model-invariant-Id: "+ model.getModelInvariantId() + + " Model-Version-Id: "+ model.getModelVerId()); + modelList.add(model); } - else if ( (doc.getDocumentElement().getNodeName().equalsIgnoreCase(MODELS_ELEMENT)) || - (doc.getDocumentElement().getNodeName().equalsIgnoreCase(NAMED_QUERIES_ELEMENT)) ) { - // The complete set of models/named-queries were contained in this artifact - NodeList nodeList = doc.getDocumentElement().getChildNodes(); - for (int i = 0; i < nodeList.getLength(); i++) { - Node childNode = nodeList.item(i); - if ( (childNode.getNodeName().equalsIgnoreCase(MODEL_ELEMENT)) || - (childNode.getNodeName().equalsIgnoreCase(NAMED_QUERY_ELEMENT)) ) { - String modelPayload = nodeToString(childNode); - ModelArtifact model = parseModel(childNode, modelPayload); - if (model != null) { - modelList.add(model); - } - else { - logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse artifact " + artifactName); - modelList.clear(); - break; - } - } - } + else { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse artifact " + artifactName); + return null; } } catch (Exception ex) { @@ -132,28 +86,16 @@ public class ModelArtifactParser { return modelList; } - private void printDetails(Node modelVer) throws TransformerException { - logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, nodeToString(modelVer)); - } - private ModelArtifact parseModel(Node modelNode, String payload) { ModelArtifact model = new ModelArtifact(); model.setPayload(payload); - if (modelNode.getNodeName().equalsIgnoreCase(MODEL_ELEMENT)) { - //compare with Model-ver - model.setType(ArtifactType.MODEL); - } - else { - model.setType(ArtifactType.NAMED_QUERY); - } - Element e = (Element)modelNode; model.setModelNamespace(e.getAttribute("xmlns")); parseNode(modelNode, model); - if (model.getModelInvariantId() == null && model.getNameVersionId() == null) { + if ( (model.getModelInvariantId() == null) || (model.getModelVerId() == null) ){ return null; } @@ -161,36 +103,19 @@ public class ModelArtifactParser { } private void parseNode(Node node, ModelArtifact model) { - - if(node.getNodeName().equalsIgnoreCase(MODEL_NAME_VERSION_ID)){ - model.setModelVerId(node.getTextContent().trim()); - model.setV9Artifact(false); - } - else if(node.getNodeName().equalsIgnoreCase("model-id")){ - model.setModelInvariantId(node.getTextContent().trim()); - model.setV9Artifact(false); - } - - else if (node.getNodeName().equalsIgnoreCase(MODEL_INVARIANT_ID)) { + if (node.getNodeName().equalsIgnoreCase(MODEL_INVARIANT_ID)) { model.setModelInvariantId(node.getTextContent().trim()); } else if (node.getNodeName().equalsIgnoreCase(MODEL_VERSION_ID)) { model.setModelVerId(node.getTextContent().trim()); - //Change to Model Invariant Id - } - else if (node.getNodeName().equalsIgnoreCase(NAMED_QUERY_VERSION_ID)) { - model.setNameVersionId(node.getTextContent().trim()); } - else if (node.getNodeName().equalsIgnoreCase(RELATIONSHIP_DATA)) { - parseRelationshipNode(node, model); - if(model.getModelModelInvariantId()!=null && model.getModelVerModelVersionId()!=null && !model.getModelModelInvariantId().isEmpty() && !model.getModelVerModelVersionId().isEmpty()){ - model.addDependentModelId(model.getModelModelInvariantId() + "|" + model.getModelVerModelVersionId()); - model.setModelModelInvariantId(""); - model.setModelVerModelVersionId(""); + else if (node.getNodeName().equalsIgnoreCase(RELATIONSHIP)) { + String dependentModelKey = parseRelationshipNode(node, model); + if (dependentModelKey != null) { + model.addDependentModelId(dependentModelKey); } } else { - if (node.getNodeName().equalsIgnoreCase(MODEL_VER)) { model.setModelVer(node); if ( (model.getModelNamespace() != null) && (!model.getModelNamespace().isEmpty()) ) { @@ -208,57 +133,62 @@ public class ModelArtifactParser { } } - private void parseRelationshipNode(Node node, ModelArtifact model) { - - //invariant-id comes before model-version-id .. create a list of values - String key = null; - String value = null; - String modelVersionIdKey=null; - String modelInvariantIdIdKey=null; - String modelVersionIdValue=null; - String modelInvariantIdIdValue=null; + private String parseRelationshipNode(Node node, ModelArtifact model) { + String currentKey = null; + String currentValue = null; + String modelVersionIdValue = null; + String modelInvariantIdValue = null; NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); - - - if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_KEY)) { - key = childNode.getTextContent().trim(); - if(key.equalsIgnoreCase(MODEL_VER_ELEMENT_RELATIONSHIP_KEY)){ - modelVersionIdKey = key; - } - else if(key.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY)){ - modelInvariantIdIdKey = key; - } - } - else if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_VALUE)) { - value = childNode.getTextContent().trim(); - if(modelVersionIdKey!=null){ - modelVersionIdValue = value; - model.setModelVerModelVersionId(modelVersionIdValue); + + if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_DATA)) { + NodeList relDataChildList = childNode.getChildNodes(); + + for (int j = 0; j < relDataChildList.getLength(); j++) { + Node relDataChildNode = relDataChildList.item(j); + + if (relDataChildNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_KEY)) { + currentKey = relDataChildNode.getTextContent().trim(); + + if (currentValue != null) { + if (currentKey.equalsIgnoreCase(MODEL_VER_ELEMENT_RELATIONSHIP_KEY)) { + modelVersionIdValue = currentValue; + } + else if (currentKey.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY)) { + modelInvariantIdValue = currentValue; + } + + currentKey = null; + currentValue = null; + } + } + else if (relDataChildNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_VALUE)) { + currentValue = relDataChildNode.getTextContent().trim(); + + if (currentKey != null) { + if (currentKey.equalsIgnoreCase(MODEL_VER_ELEMENT_RELATIONSHIP_KEY)) { + modelVersionIdValue = currentValue; + } + else if (currentKey.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY)) { + modelInvariantIdValue = currentValue; + } + + currentKey = null; + currentValue = null; + } + } } - else if(modelInvariantIdIdKey!=null){ - modelInvariantIdIdValue = value; - model.setModelModelInvariantId(modelInvariantIdIdValue); - } - } } - - if ( (key != null) && (key.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY )) && - (model.isV9Artifact == false ||ArtifactType.NAMED_QUERY.equals(model.getType())) ) { - if (value != null) { - model.addDependentModelId(value); - } + + if ( (modelVersionIdValue != null) && (modelInvariantIdValue != null) ) { + return modelInvariantIdValue + "|" + modelVersionIdValue; } - } + + return null; - private String nodeToString(Node node) throws TransformerException { - StringWriter sw = new StringWriter(); - Transformer t = TransformerFactory.newInstance().newTransformer(); - t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - t.transform(new DOMSource(node), new StreamResult(sw)); - return sw.toString(); } + } diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelParserFactory.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelParserFactory.java new file mode 100644 index 0000000..aa3283f --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelParserFactory.java @@ -0,0 +1,87 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.modelloader.service.ModelLoaderMsgs; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; + +public class ModelParserFactory { + private static Logger logger = LoggerFactory.getInstance().getLogger(ModelParserFactory.class.getName()); + + private static String MODEL_ELEMENT = "model"; + private static String NAMED_QUERY_ELEMENT = "named-query"; + + public static IModelParser createModelParser(byte[] artifactPayload, String artifactName) { + Document doc = null; + + try { + String payload = new String(artifactPayload); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder; + builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(payload)); + doc = builder.parse(is); + } catch (Exception e) { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse artifact " + artifactName); + return null; + } + + if (doc.getDocumentElement().getNodeName().equalsIgnoreCase(NAMED_QUERY_ELEMENT)) { + return new NamedQueryArtifactParser(); + } + + if (!doc.getDocumentElement().getNodeName().equalsIgnoreCase(MODEL_ELEMENT)) { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse artifact " + artifactName + + ": Invalid root element: " + doc.getDocumentElement().getNodeName()); + return null; + } + + Element e = doc.getDocumentElement(); + String ns = e.getAttribute("xmlns"); + String[] parts = ns.split("/"); + + if (parts.length < 1) { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse artifact " + artifactName + + ": Could not parse namespace version"); + return null; + } + + String modelNamespaceVersion = parts[parts.length-1].trim().replace("v", ""); + int version = Integer.parseInt(modelNamespaceVersion); + + if (version > 8) { + return new ModelArtifactParser(); + } + + return new ModelV8ArtifactParser(); + } +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java index 7f99414..274b18f 100644 --- a/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java @@ -44,11 +44,11 @@ public class ModelSorter { * Wraps a Model object to form dependencies other Models using Edges. */ static class Node { - private final ModelArtifact model; + private final AbstractModelArtifact model; private final HashSet<Edge> inEdges; private final HashSet<Edge> outEdges; - public Node(ModelArtifact model) { + public Node(AbstractModelArtifact model) { this.model = model; inEdges = new HashSet<Edge>(); outEdges = new HashSet<Edge>(); @@ -63,36 +63,18 @@ public class ModelSorter { @Override public String toString() { - if (model.getModelInvariantId() == null) { - return model.getNameVersionId(); - } - - return model.getModelInvariantId(); + return model.getUniqueIdentifier(); } @Override public boolean equals(Object other) { - ModelArtifact otherModel = ((Node) other).model; - String modelId1 = this.model.getModelInvariantId(); - if (modelId1 == null) { - modelId1 = this.model.getNameVersionId(); - } - - String modelId2 = otherModel.getModelInvariantId(); - if (modelId2 == null) { - modelId2 = otherModel.getNameVersionId(); - } - - return modelId1.equals(modelId2); + AbstractModelArtifact otherModel = ((Node) other).model; + return this.model.getUniqueIdentifier().equals(otherModel.getUniqueIdentifier()); } @Override public int hashCode() { - if (this.model.getModelInvariantId() == null) { - return this.model.getNameVersionId().hashCode(); - } - - return this.model.getModelInvariantId().hashCode(); + return this.model.getUniqueIdentifier().hashCode(); } } @@ -150,24 +132,24 @@ public class ModelSorter { // load list of models into a map, so we can later replace referenceIds with // real Models - HashMap<String, ModelArtifact> versionIdToModelMap = new HashMap<String, ModelArtifact>(); + HashMap<String, AbstractModelArtifact> versionIdToModelMap = new HashMap<String, AbstractModelArtifact>(); for (Artifact art : models) { - ModelArtifact ma = (ModelArtifact) art; - versionIdToModelMap.put(ma.getModelModelVerCombinedKey(), ma); + AbstractModelArtifact ma = (AbstractModelArtifact) art; + versionIdToModelMap.put(ma.getUniqueIdentifier(), ma); } HashMap<String, Node> nodes = new HashMap<String, Node>(); // create a node for each model and its referenced models for (Artifact art : models) { - ModelArtifact model = (ModelArtifact) art; + AbstractModelArtifact model = (AbstractModelArtifact) art; // node might have been created by another model referencing it - Node node = nodes.get(model.getModelModelVerCombinedKey()); + Node node = nodes.get(model.getUniqueIdentifier()); if (null == node) { node = new Node(model); - nodes.put(model.getModelModelVerCombinedKey(), node); + nodes.put(model.getUniqueIdentifier(), node); } for (String referencedModelId : model.getDependentModelIds()) { @@ -176,7 +158,7 @@ public class ModelSorter { if (null == referencedNode) { // create node - ModelArtifact referencedModel = versionIdToModelMap.get(referencedModelId); + AbstractModelArtifact referencedModel = versionIdToModelMap.get(referencedModelId); if (referencedModel == null) { Log.debug("ignoring " + referencedModelId); continue; // referenced model not supplied, no need to sort it diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelV8Artifact.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelV8Artifact.java new file mode 100644 index 0000000..847f880 --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelV8Artifact.java @@ -0,0 +1,122 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.modelloader.config.ModelLoaderConfig; +import org.openecomp.modelloader.entity.Artifact; +import org.openecomp.modelloader.entity.ArtifactType; +import org.openecomp.modelloader.restclient.AaiRestClient; +import org.openecomp.modelloader.service.ModelLoaderMsgs; + +import com.sun.jersey.api.client.ClientResponse; + +public class ModelV8Artifact extends AbstractModelArtifact { + private static String AAI_CONVERSION_URL = "/aai/tools/modeltransform"; + + private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifact.class.getName()); + + private String modelNameVersionId; + private ModelArtifact translatedModel; + + public ModelV8Artifact() { + super(ArtifactType.MODEL_V8); + } + + public String getModelNameVersionId() { + return modelNameVersionId; + } + + public void setModelNameVersionId(String modelNameVersionId) { + this.modelNameVersionId = modelNameVersionId; + } + + @Override + public String getUniqueIdentifier() { + return getModelNameVersionId(); + } + + @Override + public boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<AbstractModelArtifact> addedModels) { + // For a legacy model (version <= v8), we need to call out to an A&AI endpoint to convert to the proper format + ClientResponse response = aaiClient.postResource(getConversionUrl(config), constructTransformPayload(), distId, AaiRestClient.MimeType.XML); + if ( (response == null) || (response.getStatus() != Response.Status.OK.getStatusCode()) ) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + + getType().toString() + " " + getModelNameVersionId() + ". Unable to convert model. Rolling back distribution."); + return false; + } + + String translatedPayload = response.getEntity(String.class); + + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Translated artifact payload:\n" + translatedPayload); + + ModelArtifactParser parser = new ModelArtifactParser(); + + List<Artifact> parsedArtifacts = parser.parse(translatedPayload.getBytes(), "translated-payload"); + if (parsedArtifacts == null || parsedArtifacts.isEmpty()) { + return false; + } + + translatedModel = (ModelArtifact)parsedArtifacts.get(0); + return translatedModel.push(aaiClient, config, distId, addedModels); + } + + @Override + public void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId) { + if (translatedModel != null) { + translatedModel.rollbackModel(aaiClient, config, distId); + } + } + + + private String constructTransformPayload() { + // A&AI requires that to transform a legacy model, we need to use the v8 namespace (even + // if the version < 8) + return getPayload().replaceFirst("aai.inventory/v.", "aai.inventory/v8"); + } + + private String getConversionUrl(ModelLoaderConfig config) { + String baseUrl = config.getAaiBaseUrl().trim(); + String subUrl = AAI_CONVERSION_URL; + + if ( (!baseUrl.endsWith("/")) && (!subUrl.startsWith("/")) ) { + baseUrl = baseUrl + "/"; + } + + if ( baseUrl.endsWith("/") && subUrl.startsWith("/") ) { + baseUrl = baseUrl.substring(0, baseUrl.length()-1); + } + + if (!subUrl.endsWith("/")) { + subUrl = subUrl + "/"; + } + + String url = baseUrl + subUrl; + return url; + } +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelV8ArtifactParser.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelV8ArtifactParser.java new file mode 100644 index 0000000..f5ecb2b --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelV8ArtifactParser.java @@ -0,0 +1,136 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.modelloader.entity.Artifact; +import org.openecomp.modelloader.service.ModelLoaderMsgs; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + + +public class ModelV8ArtifactParser implements IModelParser { + + private static String MODEL_NAME_VERSION_ID = "model-name-version-id"; + private static String RELATIONSHIP_DATA = "relationship-data"; + private static String RELATIONSHIP_KEY = "relationship-key"; + private static String RELATIONSHIP_VALUE = "relationship-value"; + private static String MODEL_ELEMENT_RELATIONSHIP_KEY = "model.model-name-version-id"; + + + private static Logger logger = LoggerFactory.getInstance().getLogger(ModelV8ArtifactParser.class.getName()); + + public List<Artifact> parse(byte[] artifactPayload, String artifactName) { + String payload = new String(artifactPayload); + List<Artifact> modelList = new ArrayList<Artifact>(); + + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(payload)); + Document doc = builder.parse(is); + + ModelV8Artifact model = parseModel(doc.getDocumentElement(), payload); + + if (model != null) { + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Model parsed =====>>>> " + "Model-Named-Version-Id: "+ model.getModelNameVersionId()); + modelList.add(model); + } + else { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse legacy model artifact " + artifactName); + return null; + } + } + catch (Exception ex) { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse legacy model artifact " + artifactName + ": " + ex.getLocalizedMessage()); + } + + return modelList; + } + + private ModelV8Artifact parseModel(Node modelNode, String payload) { + ModelV8Artifact model = new ModelV8Artifact(); + model.setPayload(payload); + + Element e = (Element)modelNode; + model.setModelNamespace(e.getAttribute("xmlns")); + + parseNode(modelNode, model); + + if (model.getModelNameVersionId() == null) { + return null; + } + + return model; + } + + private void parseNode(Node node, ModelV8Artifact model) { + if (node.getNodeName().equalsIgnoreCase(MODEL_NAME_VERSION_ID)) { + model.setModelNameVersionId(node.getTextContent().trim()); + } + else if (node.getNodeName().equalsIgnoreCase(RELATIONSHIP_DATA)) { + parseRelationshipNode(node, model); + } + else { + NodeList nodeList = node.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + parseNode(childNode, model); + } + } + } + + private void parseRelationshipNode(Node node, ModelV8Artifact model) { + String key = null; + String value = null; + + NodeList nodeList = node.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_KEY)) { + key = childNode.getTextContent().trim(); + } + else if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_VALUE)) { + value = childNode.getTextContent().trim(); + } + } + + if ( (key != null) && (key.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY )) ) { + if (value != null) { + model.addDependentModelId(value); + } + } + } +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/NamedQueryArtifact.java b/src/main/java/org/openecomp/modelloader/entity/model/NamedQueryArtifact.java new file mode 100644 index 0000000..1a4ceaa --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/NamedQueryArtifact.java @@ -0,0 +1,113 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import java.util.List; + +import javax.ws.rs.core.Response; + +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.modelloader.config.ModelLoaderConfig; +import org.openecomp.modelloader.entity.ArtifactType; +import org.openecomp.modelloader.restclient.AaiRestClient; +import org.openecomp.modelloader.service.ModelLoaderMsgs; + +import com.sun.jersey.api.client.ClientResponse; + +public class NamedQueryArtifact extends AbstractModelArtifact { + + private Logger logger = LoggerFactory.getInstance().getLogger(NamedQueryArtifact.class.getName()); + + private String namedQueryUuid; + + public NamedQueryArtifact() { + super(ArtifactType.NAMED_QUERY); + } + + public String getNamedQueryUuid() { + return namedQueryUuid; + } + + public void setNamedQueryUuid(String namedQueryUuid) { + this.namedQueryUuid = namedQueryUuid; + } + + @Override + public String getUniqueIdentifier() { + return getNamedQueryUuid(); + } + + @Override + public boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<AbstractModelArtifact> addedModels) { + ClientResponse getResponse = aaiClient.getResource(getNamedQueryUrl(config), distId, AaiRestClient.MimeType.XML); + if ( (getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode()) ) { + // Only attempt the PUT if the model doesn't already exist + ClientResponse putResponse = aaiClient.putResource(getNamedQueryUrl(config), getPayload(), distId, AaiRestClient.MimeType.XML); + if ( (putResponse != null) && (putResponse.getStatus() == Response.Status.CREATED.getStatusCode()) ) { + addedModels.add(this); + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getUniqueIdentifier() + " successfully ingested."); + } + else { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Ingestion failed for " + getType().toString() + " " + getUniqueIdentifier() + + ". Rolling back distribution."); + return false; + } + } + else { + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, getType().toString() + " " + getUniqueIdentifier() + " already exists. Skipping ingestion."); + } + + return true; + } + + @Override + public void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId) { + // Best effort to delete. Nothing we can do in the event this fails. + aaiClient.getAndDeleteResource(getNamedQueryUrl(config), distId); + } + + private String getNamedQueryUrl(ModelLoaderConfig config) { + String baseURL = config.getAaiBaseUrl().trim(); + String subURL = null; + String instance = null; + + subURL = config.getAaiNamedQueryUrl(getModelNamespaceVersion()).trim(); + instance = this.getNamedQueryUuid(); + + if ( (!baseURL.endsWith("/")) && (!subURL.startsWith("/")) ) { + baseURL = baseURL + "/"; + } + + if ( baseURL.endsWith("/") && subURL.startsWith("/") ) { + baseURL = baseURL.substring(0, baseURL.length()-1); + } + + if (!subURL.endsWith("/")) { + subURL = subURL + "/"; + } + + String url = baseURL + subURL + instance; + return url; + } +} diff --git a/src/main/java/org/openecomp/modelloader/entity/model/NamedQueryArtifactParser.java b/src/main/java/org/openecomp/modelloader/entity/model/NamedQueryArtifactParser.java new file mode 100644 index 0000000..3643f18 --- /dev/null +++ b/src/main/java/org/openecomp/modelloader/entity/model/NamedQueryArtifactParser.java @@ -0,0 +1,136 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.modelloader.entity.Artifact; +import org.openecomp.modelloader.service.ModelLoaderMsgs; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +import java.io.StringReader; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + + +public class NamedQueryArtifactParser implements IModelParser { + + private static String NAMED_QUERY_VERSION_ID = "named-query-uuid"; + private static String RELATIONSHIP_DATA = "relationship-data"; + private static String RELATIONSHIP_KEY = "relationship-key"; + private static String RELATIONSHIP_VALUE = "relationship-value"; + private static String MODEL_ELEMENT_RELATIONSHIP_KEY = "model.model-invariant-id"; + + + private static Logger logger = LoggerFactory.getInstance().getLogger(NamedQueryArtifactParser.class.getName()); + + public List<Artifact> parse(byte[] artifactPayload, String artifactName) { + String payload = new String(artifactPayload); + List<Artifact> modelList = new ArrayList<Artifact>(); + + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(payload)); + Document doc = builder.parse(is); + + NamedQueryArtifact model = parseModel(doc.getDocumentElement(), payload); + + if (model != null) { + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Named-Query parsed =====>>>> " + "Named-Query-UUID: "+ model.getNamedQueryUuid()); + modelList.add(model); + } + else { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse named-query artifact " + artifactName); + return null; + } + } + catch (Exception ex) { + logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse named-query artifact " + artifactName + ": " + ex.getLocalizedMessage()); + } + + return modelList; + } + + private NamedQueryArtifact parseModel(Node modelNode, String payload) { + NamedQueryArtifact model = new NamedQueryArtifact(); + model.setPayload(payload); + + Element e = (Element)modelNode; + model.setModelNamespace(e.getAttribute("xmlns")); + + parseNode(modelNode, model); + + if (model.getNamedQueryUuid() == null) { + return null; + } + + return model; + } + + private void parseNode(Node node, NamedQueryArtifact model) { + if (node.getNodeName().equalsIgnoreCase(NAMED_QUERY_VERSION_ID)) { + model.setNamedQueryUuid(node.getTextContent().trim()); + } + else if (node.getNodeName().equalsIgnoreCase(RELATIONSHIP_DATA)) { + parseRelationshipNode(node, model); + } + else { + NodeList nodeList = node.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + parseNode(childNode, model); + } + } + } + + private void parseRelationshipNode(Node node, NamedQueryArtifact model) { + String key = null; + String value = null; + + NodeList nodeList = node.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node childNode = nodeList.item(i); + if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_KEY)) { + key = childNode.getTextContent().trim(); + } + else if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_VALUE)) { + value = childNode.getTextContent().trim(); + } + } + + if ( (key != null) && (key.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY )) ) { + if (value != null) { + model.addDependentModelId(value); + } + } + } +} diff --git a/src/main/java/org/openecomp/modelloader/notification/EventCallback.java b/src/main/java/org/openecomp/modelloader/notification/EventCallback.java index 8634741..059964e 100644 --- a/src/main/java/org/openecomp/modelloader/notification/EventCallback.java +++ b/src/main/java/org/openecomp/modelloader/notification/EventCallback.java @@ -1,294 +1,293 @@ -/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.notification;
-
-import org.openecomp.sdc.api.IDistributionClient;
-import org.openecomp.sdc.api.consumer.IDistributionStatusMessage;
-import org.openecomp.sdc.api.consumer.INotificationCallback;
-import org.openecomp.sdc.api.notification.IArtifactInfo;
-import org.openecomp.sdc.api.notification.INotificationData;
-import org.openecomp.sdc.api.notification.IResourceInstance;
-import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
-import org.openecomp.sdc.api.results.IDistributionClientResult;
-import org.openecomp.sdc.utils.ArtifactTypeEnum;
-import org.openecomp.sdc.utils.DistributionActionResultEnum;
-import org.openecomp.sdc.utils.DistributionStatusEnum;
-
-import org.openecomp.cl.api.Logger;
-import org.openecomp.cl.eelf.LoggerFactory;
-import org.openecomp.cl.mdc.MdcContext;
-import org.openecomp.cl.mdc.MdcOverride;
-import org.openecomp.modelloader.config.ModelLoaderConfig;
-import org.openecomp.modelloader.entity.Artifact;
-import org.openecomp.modelloader.entity.catalog.VnfCatalogArtifact;
-import org.openecomp.modelloader.entity.catalog.VnfCatalogArtifactHandler;
-import org.openecomp.modelloader.entity.model.ModelArtifactHandler;
-import org.openecomp.modelloader.entity.model.ModelArtifactParser;
-import org.openecomp.modelloader.service.ModelLoaderMsgs;
-import org.slf4j.MDC;
-
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.List;
-
-public class EventCallback implements INotificationCallback {
-
- private IDistributionClient client;
- private ModelLoaderConfig config;
- private static Logger logger = LoggerFactory.getInstance()
- .getLogger(EventCallback.class.getName());
- private static Logger auditLogger = LoggerFactory.getInstance()
- .getAuditLogger(EventCallback.class.getName());
- private static Logger metricsLogger = LoggerFactory.getInstance()
- .getMetricsLogger(EventCallback.class.getName());
-
- private static SimpleDateFormat dateFormatter = new SimpleDateFormat(
- "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
-
- public EventCallback(IDistributionClient client, ModelLoaderConfig config) {
- this.client = client;
- this.config = config;
- }
-
- @Override
- public void activateCallback(INotificationData data) {
- // Init MDC
- MdcContext.initialize(data.getDistributionID(), "ModelLoader", "", "Event-Bus", "");
-
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
- "Received distribution " + data.getDistributionID());
-
- boolean success = true;
- List<IArtifactInfo> artifacts = getArtifacts(data);
- List<Artifact> modelArtifacts = new ArrayList<Artifact>();
- List<Artifact> catalogArtifacts = new ArrayList<Artifact>();
- ModelArtifactParser modelArtParser = new ModelArtifactParser();
-
- for (IArtifactInfo artifact : artifacts) {
- // Grab the current time so we can measure the download time for the
- // metrics log
- long startTimeInMs = System.currentTimeMillis();
- MdcOverride override = new MdcOverride();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- // Download Artifact
- IDistributionClientDownloadResult downloadResult = client.download(artifact);
-
- // Generate metrics log
- metricsLogger.info(ModelLoaderMsgs.DOWNLOAD_COMPLETE, null, override,
- artifact.getArtifactName(), downloadResult.getDistributionActionResult().toString());
-
- if (downloadResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- publishDownloadFailure(data, artifact, downloadResult.getDistributionMessageResult());
- success = false;
- break;
- }
-
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
- "Downloaded artifact: " + artifact.getArtifactName() + " Payload:\n" + new String(downloadResult.getArtifactPayload()));
-
- publishDownloadSuccess(data, artifact, downloadResult);
-
- if ((artifact.getArtifactType()
- .compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()) == 0)
- || (artifact.getArtifactType()
- .compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()) == 0)) {
- List<Artifact> parsedArtifacts = modelArtParser.parse(downloadResult.getArtifactPayload(), downloadResult.getArtifactName());
- if (parsedArtifacts != null && !parsedArtifacts.isEmpty()) {
- modelArtifacts.addAll(parsedArtifacts);
- } else {
- success = false;
- publishDeployFailure(data, artifact);
- break;
- }
- } else if (artifact.getArtifactType()
- .compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()) == 0) {
- catalogArtifacts
- .add(new VnfCatalogArtifact(new String(downloadResult.getArtifactPayload())));
- }
- }
-
- String statusString = "SUCCESS";
- if (success) {
- ModelArtifactHandler modelHandler = new ModelArtifactHandler(config);
- boolean modelDeploySuccess = modelHandler.pushArtifacts(modelArtifacts,
- data.getDistributionID());
-
- VnfCatalogArtifactHandler catalogHandler = new VnfCatalogArtifactHandler(config);
- boolean catalogDeploySuccess = catalogHandler.pushArtifacts(catalogArtifacts,
- data.getDistributionID());
-
- for (IArtifactInfo artifact : artifacts) {
- if ((artifact.getArtifactType()
- .compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()) == 0)
- || (artifact.getArtifactType()
- .compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()) == 0)) {
- if (modelDeploySuccess) {
- publishDeploySuccess(data, artifact);
- } else {
- publishDeployFailure(data, artifact);
- statusString = "FAILURE";
- }
- } else if (artifact.getArtifactType()
- .compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()) == 0) {
- if (catalogDeploySuccess) {
- publishDeploySuccess(data, artifact);
- } else {
- publishDeployFailure(data, artifact);
- statusString = "FAILURE";
- }
- }
- }
- } else {
- statusString = "FAILURE";
- }
-
- auditLogger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
- "Processed distribution " + data.getDistributionID() + " (" + statusString + ")");
- MDC.clear();
- }
-
- private List<IArtifactInfo> getArtifacts(INotificationData data) {
- List<IArtifactInfo> artifacts = new ArrayList<IArtifactInfo>();
- List<IResourceInstance> resources = data.getResources();
-
- if (data.getServiceArtifacts() != null) {
- artifacts.addAll(data.getServiceArtifacts());
- }
-
- if (resources != null) {
- for (IResourceInstance resource : resources) {
- if (resource.getArtifacts() != null) {
- artifacts.addAll(resource.getArtifacts());
- }
- }
- }
-
- return artifacts;
- }
-
- private void publishDownloadFailure(INotificationData data, IArtifactInfo artifact,
- String errorMessage) {
- // Grab the current time so we can measure the download time for the metrics
- // log
- long startTimeInMs = System.currentTimeMillis();
- MdcOverride override = new MdcOverride();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- IDistributionClientResult sendDownloadStatus = client.sendDownloadStatus(
- buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_ERROR));
- metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "download failure",
- artifact.getArtifactName(), sendDownloadStatus.getDistributionActionResult().toString());
-
- if (sendDownloadStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR,
- "Failed to publish download failure status: "
- + sendDownloadStatus.getDistributionMessageResult());
- }
-
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR,
- "Failed to download artifact " + artifact.getArtifactName() + ": " + errorMessage);
- }
-
- private void publishDownloadSuccess(INotificationData data, IArtifactInfo artifact,
- IDistributionClientDownloadResult downloadResult) {
- // Grab the current time so we can measure the download time for the metrics
- // log
- long startTimeInMs = System.currentTimeMillis();
- MdcOverride override = new MdcOverride();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- IDistributionClientResult sendDownloadStatus = client.sendDownloadStatus(
- buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK));
- metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "download success",
- artifact.getArtifactName(), sendDownloadStatus.getDistributionActionResult().toString());
-
- if (sendDownloadStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR,
- "Failed to publish download success status: "
- + sendDownloadStatus.getDistributionMessageResult());
- }
-
- if (logger.isDebugEnabled()) {
- StringBuilder sb = new StringBuilder();
- sb.append("Downloaded artifact:\n");
- sb.append("ArtInfo_Art_Name: " + artifact.getArtifactName());
- sb.append("\nArtInfo_Art_description: " + artifact.getArtifactDescription());
- sb.append("\nArtInfo_Art_CheckSum: " + artifact.getArtifactChecksum());
- sb.append("\nArtInfo_Art_Url: " + artifact.getArtifactURL());
- sb.append("\nArtInfo_Art_Type: " + artifact.getArtifactType());
- sb.append("\nArtInfo_Serv_description: " + data.getServiceDescription());
- sb.append("\nArtInfo_Serv_Name: " + data.getServiceName());
- sb.append("\nGet_serviceVersion: " + data.getServiceVersion());
- sb.append("\nGet_Service_UUID: " + data.getServiceUUID());
- sb.append("\nArtInfo_DistributionId: " + data.getDistributionID());
- logger.debug(sb.toString());
- }
- }
-
- private void publishDeployFailure(INotificationData data, IArtifactInfo artifact) {
- // Grab the current time so we can measure the download time for the metrics
- // log
- long startTimeInMs = System.currentTimeMillis();
- MdcOverride override = new MdcOverride();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- IDistributionClientResult sendStatus = client.sendDeploymentStatus(
- buildStatusMessage(client, data, artifact, DistributionStatusEnum.DEPLOY_ERROR));
- metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "deploy failure",
- artifact.getArtifactName(), sendStatus.getDistributionActionResult().toString());
-
- if (sendStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR,
- "Failed to publish deploy failure status: " + sendStatus.getDistributionMessageResult());
- }
- }
-
- private void publishDeploySuccess(INotificationData data, IArtifactInfo artifact) {
- // Grab the current time so we can measure the download time for the metrics
- // log
- long startTimeInMs = System.currentTimeMillis();
- MdcOverride override = new MdcOverride();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- IDistributionClientResult sendStatus = client.sendDownloadStatus(
- buildStatusMessage(client, data, artifact, DistributionStatusEnum.DEPLOY_OK));
- metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "deploy success",
- artifact.getArtifactName(), sendStatus.getDistributionActionResult().toString());
-
- if (sendStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
- logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR,
- "Failed to publish deploy success status: " + sendStatus.getDistributionMessageResult());
- }
- }
-
- private IDistributionStatusMessage buildStatusMessage(IDistributionClient client,
- INotificationData data, IArtifactInfo artifact, DistributionStatusEnum status) {
- IDistributionStatusMessage statusMessage = new DistributionStatusMsg(status,
- data.getDistributionID(), client.getConfiguration().getConsumerID(),
- artifact.getArtifactURL());
-
- return statusMessage;
- }
-
-}
+/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.notification; + +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; +import org.openecomp.sdc.api.consumer.INotificationCallback; +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; +import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.utils.ArtifactTypeEnum; +import org.openecomp.sdc.utils.DistributionActionResultEnum; +import org.openecomp.sdc.utils.DistributionStatusEnum; + +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.cl.mdc.MdcContext; +import org.openecomp.cl.mdc.MdcOverride; +import org.openecomp.modelloader.config.ModelLoaderConfig; +import org.openecomp.modelloader.entity.Artifact; +import org.openecomp.modelloader.entity.catalog.VnfCatalogArtifact; +import org.openecomp.modelloader.entity.catalog.VnfCatalogArtifactHandler; +import org.openecomp.modelloader.entity.model.IModelParser; +import org.openecomp.modelloader.entity.model.ModelArtifactHandler; +import org.openecomp.modelloader.entity.model.ModelParserFactory; +import org.openecomp.modelloader.service.ModelLoaderMsgs; +import org.slf4j.MDC; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +public class EventCallback implements INotificationCallback { + + private IDistributionClient client; + private ModelLoaderConfig config; + private static Logger logger = LoggerFactory.getInstance() + .getLogger(EventCallback.class.getName()); + private static Logger auditLogger = LoggerFactory.getInstance() + .getAuditLogger(EventCallback.class.getName()); + private static Logger metricsLogger = LoggerFactory.getInstance() + .getMetricsLogger(EventCallback.class.getName()); + + private static SimpleDateFormat dateFormatter = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + public EventCallback(IDistributionClient client, ModelLoaderConfig config) { + this.client = client; + this.config = config; + } + + @Override + public void activateCallback(INotificationData data) { + // Init MDC + MdcContext.initialize(data.getDistributionID(), "ModelLoader", "", "Event-Bus", ""); + + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, + "Received distribution " + data.getDistributionID()); + + boolean success = true; + List<IArtifactInfo> artifacts = getArtifacts(data); + List<Artifact> modelArtifacts = new ArrayList<Artifact>(); + List<Artifact> catalogArtifacts = new ArrayList<Artifact>(); + + for (IArtifactInfo artifact : artifacts) { + // Grab the current time so we can measure the download time for the + // metrics log + long startTimeInMs = System.currentTimeMillis(); + MdcOverride override = new MdcOverride(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + // Download Artifact + IDistributionClientDownloadResult downloadResult = client.download(artifact); + + // Generate metrics log + metricsLogger.info(ModelLoaderMsgs.DOWNLOAD_COMPLETE, null, override, + artifact.getArtifactName(), downloadResult.getDistributionActionResult().toString()); + + if (downloadResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + publishDownloadFailure(data, artifact, downloadResult.getDistributionMessageResult()); + success = false; + break; + } + + logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, + "Downloaded artifact: " + artifact.getArtifactName() + " Payload:\n" + new String(downloadResult.getArtifactPayload())); + + publishDownloadSuccess(data, artifact, downloadResult); + + if ((artifact.getArtifactType().compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()) == 0) + || (artifact.getArtifactType().compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()) == 0)) { + IModelParser parser = ModelParserFactory.createModelParser(downloadResult.getArtifactPayload(), downloadResult.getArtifactName()); + List<Artifact> parsedArtifacts = parser.parse(downloadResult.getArtifactPayload(), downloadResult.getArtifactName()); + if (parsedArtifacts != null && !parsedArtifacts.isEmpty()) { + modelArtifacts.addAll(parsedArtifacts); + } else { + success = false; + publishDeployFailure(data, artifact); + break; + } + } else if (artifact.getArtifactType() + .compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()) == 0) { + catalogArtifacts + .add(new VnfCatalogArtifact(new String(downloadResult.getArtifactPayload()))); + } + } + + String statusString = "SUCCESS"; + if (success) { + ModelArtifactHandler modelHandler = new ModelArtifactHandler(config); + boolean modelDeploySuccess = modelHandler.pushArtifacts(modelArtifacts, + data.getDistributionID()); + + VnfCatalogArtifactHandler catalogHandler = new VnfCatalogArtifactHandler(config); + boolean catalogDeploySuccess = catalogHandler.pushArtifacts(catalogArtifacts, + data.getDistributionID()); + + for (IArtifactInfo artifact : artifacts) { + if ((artifact.getArtifactType() + .compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()) == 0) + || (artifact.getArtifactType() + .compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()) == 0)) { + if (modelDeploySuccess) { + publishDeploySuccess(data, artifact); + } else { + publishDeployFailure(data, artifact); + statusString = "FAILURE"; + } + } else if (artifact.getArtifactType() + .compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()) == 0) { + if (catalogDeploySuccess) { + publishDeploySuccess(data, artifact); + } else { + publishDeployFailure(data, artifact); + statusString = "FAILURE"; + } + } + } + } else { + statusString = "FAILURE"; + } + + auditLogger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, + "Processed distribution " + data.getDistributionID() + " (" + statusString + ")"); + MDC.clear(); + } + + private List<IArtifactInfo> getArtifacts(INotificationData data) { + List<IArtifactInfo> artifacts = new ArrayList<IArtifactInfo>(); + List<IResourceInstance> resources = data.getResources(); + + if (data.getServiceArtifacts() != null) { + artifacts.addAll(data.getServiceArtifacts()); + } + + if (resources != null) { + for (IResourceInstance resource : resources) { + if (resource.getArtifacts() != null) { + artifacts.addAll(resource.getArtifacts()); + } + } + } + + return artifacts; + } + + private void publishDownloadFailure(INotificationData data, IArtifactInfo artifact, + String errorMessage) { + // Grab the current time so we can measure the download time for the metrics + // log + long startTimeInMs = System.currentTimeMillis(); + MdcOverride override = new MdcOverride(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + IDistributionClientResult sendDownloadStatus = client.sendDownloadStatus( + buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_ERROR)); + metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "download failure", + artifact.getArtifactName(), sendDownloadStatus.getDistributionActionResult().toString()); + + if (sendDownloadStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, + "Failed to publish download failure status: " + + sendDownloadStatus.getDistributionMessageResult()); + } + + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, + "Failed to download artifact " + artifact.getArtifactName() + ": " + errorMessage); + } + + private void publishDownloadSuccess(INotificationData data, IArtifactInfo artifact, + IDistributionClientDownloadResult downloadResult) { + // Grab the current time so we can measure the download time for the metrics + // log + long startTimeInMs = System.currentTimeMillis(); + MdcOverride override = new MdcOverride(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + IDistributionClientResult sendDownloadStatus = client.sendDownloadStatus( + buildStatusMessage(client, data, artifact, DistributionStatusEnum.DOWNLOAD_OK)); + metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "download success", + artifact.getArtifactName(), sendDownloadStatus.getDistributionActionResult().toString()); + + if (sendDownloadStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, + "Failed to publish download success status: " + + sendDownloadStatus.getDistributionMessageResult()); + } + + if (logger.isDebugEnabled()) { + StringBuilder sb = new StringBuilder(); + sb.append("Downloaded artifact:\n"); + sb.append("ArtInfo_Art_Name: " + artifact.getArtifactName()); + sb.append("\nArtInfo_Art_description: " + artifact.getArtifactDescription()); + sb.append("\nArtInfo_Art_CheckSum: " + artifact.getArtifactChecksum()); + sb.append("\nArtInfo_Art_Url: " + artifact.getArtifactURL()); + sb.append("\nArtInfo_Art_Type: " + artifact.getArtifactType()); + sb.append("\nArtInfo_Serv_description: " + data.getServiceDescription()); + sb.append("\nArtInfo_Serv_Name: " + data.getServiceName()); + sb.append("\nGet_serviceVersion: " + data.getServiceVersion()); + sb.append("\nGet_Service_UUID: " + data.getServiceUUID()); + sb.append("\nArtInfo_DistributionId: " + data.getDistributionID()); + logger.debug(sb.toString()); + } + } + + private void publishDeployFailure(INotificationData data, IArtifactInfo artifact) { + // Grab the current time so we can measure the download time for the metrics + // log + long startTimeInMs = System.currentTimeMillis(); + MdcOverride override = new MdcOverride(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + IDistributionClientResult sendStatus = client.sendDeploymentStatus( + buildStatusMessage(client, data, artifact, DistributionStatusEnum.DEPLOY_ERROR)); + metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "deploy failure", + artifact.getArtifactName(), sendStatus.getDistributionActionResult().toString()); + + if (sendStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, + "Failed to publish deploy failure status: " + sendStatus.getDistributionMessageResult()); + } + } + + private void publishDeploySuccess(INotificationData data, IArtifactInfo artifact) { + // Grab the current time so we can measure the download time for the metrics + // log + long startTimeInMs = System.currentTimeMillis(); + MdcOverride override = new MdcOverride(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + IDistributionClientResult sendStatus = client.sendDownloadStatus( + buildStatusMessage(client, data, artifact, DistributionStatusEnum.DEPLOY_OK)); + metricsLogger.info(ModelLoaderMsgs.EVENT_PUBLISHED, null, override, "deploy success", + artifact.getArtifactName(), sendStatus.getDistributionActionResult().toString()); + + if (sendStatus.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) { + logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, + "Failed to publish deploy success status: " + sendStatus.getDistributionMessageResult()); + } + } + + private IDistributionStatusMessage buildStatusMessage(IDistributionClient client, + INotificationData data, IArtifactInfo artifact, DistributionStatusEnum status) { + IDistributionStatusMessage statusMessage = new DistributionStatusMsg(status, + data.getDistributionID(), client.getConfiguration().getConsumerID(), + artifact.getArtifactURL()); + + return statusMessage; + } + +} diff --git a/src/main/java/org/openecomp/modelloader/restclient/AaiRestClient.java b/src/main/java/org/openecomp/modelloader/restclient/AaiRestClient.java index d4ee738..4d5e487 100644 --- a/src/main/java/org/openecomp/modelloader/restclient/AaiRestClient.java +++ b/src/main/java/org/openecomp/modelloader/restclient/AaiRestClient.java @@ -1,402 +1,480 @@ -/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.restclient;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.client.filter.LoggingFilter;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
-import org.openecomp.cl.api.LogFields;
-import org.openecomp.cl.api.LogLine;
-import org.openecomp.cl.api.Logger;
-import org.openecomp.cl.eelf.LoggerFactory;
-import org.openecomp.cl.mdc.MdcContext;
-import org.openecomp.cl.mdc.MdcOverride;
-import org.openecomp.modelloader.config.ModelLoaderConfig;
-import org.openecomp.modelloader.service.ModelLoaderMsgs;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.StringReader;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.cert.X509Certificate;
-import java.text.SimpleDateFormat;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-import javax.ws.rs.core.Response;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-public class AaiRestClient {
- public enum MimeType {
- XML("application/xml"), JSON("application/json");
-
- private String httpType;
-
- MimeType(String httpType) {
- this.httpType = httpType;
- }
-
- String getHttpHeaderType() {
- return httpType;
- }
- }
-
- private static String HEADER_TRANS_ID = "X-TransactionId";
- private static String HEADER_FROM_APP_ID = "X-FromAppId";
- private static String HEADER_AUTHORIZATION = "Authorization";
- private static String ML_APP_NAME = "ModelLoader";
- private static String RESOURCE_VERSION_PARAM = "resource-version";
-
- private static SimpleDateFormat dateFormatter = new SimpleDateFormat(
- "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
-
- private static Logger logger = LoggerFactory.getInstance()
- .getLogger(AaiRestClient.class.getName());
- private static Logger metricsLogger = LoggerFactory.getInstance()
- .getMetricsLogger(AaiRestClient.class.getName());
-
- private ModelLoaderConfig config = null;
-
- public AaiRestClient(ModelLoaderConfig config) {
- this.config = config;
- }
-
- /**
- * Send a PUT request to the A&AI.
- *
- * @param url
- * - the url
- * @param transId
- * - transaction ID
- * @param payload
- * - the XML or JSON payload for the request
- * @param mimeType
- * - the content type (XML or JSON)
- * @return ClientResponse
- */
- public ClientResponse putResource(String url, String payload, String transId, MimeType mimeType) {
- ClientResponse result = null;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- long startTimeInMs = 0;
- MdcOverride override = new MdcOverride();
-
- try {
- Client client = setupClient();
-
- baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- if (logger.isDebugEnabled()) {
- client.addFilter(new LoggingFilter(ps));
- }
-
- // Grab the current time so that we can use it for metrics purposes later.
- startTimeInMs = System.currentTimeMillis();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- if (useBasicAuth()) {
- result = client.resource(url).header(HEADER_TRANS_ID, transId)
- .header(HEADER_FROM_APP_ID, ML_APP_NAME)
- .header(HEADER_AUTHORIZATION, getAuthenticationCredentials())
- .type(mimeType.getHttpHeaderType()).put(ClientResponse.class, payload);
- } else {
- result = client.resource(url).header(HEADER_TRANS_ID, transId)
- .header(HEADER_FROM_APP_ID, ML_APP_NAME).type(mimeType.getHttpHeaderType())
- .put(ClientResponse.class, payload);
- }
- } catch (Exception ex) {
- logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "PUT", url, ex.getLocalizedMessage());
- return null;
- } finally {
- if (logger.isDebugEnabled()) {
- logger.debug(baos.toString());
- }
- }
-
- if ((result != null) && ((result.getStatus() == Response.Status.CREATED.getStatusCode())
- || (result.getStatus() == Response.Status.OK.getStatusCode()))) {
- logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "PUT", url,
- Integer.toString(result.getStatus()));
- metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS,
- new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus())
- .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION,
- result.getResponseStatus().toString()),
- override, "PUT", url, Integer.toString(result.getStatus()));
- } else {
- // If response is not 200 OK, then additionally log the reason
- String respMsg = result.getEntity(String.class);
- if (respMsg == null) {
- respMsg = result.getStatusInfo().getReasonPhrase();
- }
- logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_UNSUCCESSFUL, "PUT", url,
- Integer.toString(result.getStatus()), respMsg);
- metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_UNSUCCESSFUL,
- new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus())
- .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION,
- result.getResponseStatus().toString()),
- override, "PUT", url, Integer.toString(result.getStatus()), respMsg);
- }
-
- return result;
- }
-
- /**
- * Send a DELETE request to the A&AI.
- *
- * @param url
- * - the url
- * @param resourceVersion
- * - the resource-version of the model to delete
- * @param transId
- * - transaction ID
- * @return ClientResponse
- */
- public ClientResponse deleteResource(String url, String resourceVersion, String transId) {
- ClientResponse result = null;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- long startTimeInMs = 0;
- MdcOverride override = new MdcOverride();
-
- try {
- Client client = setupClient();
-
- baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- if (logger.isDebugEnabled()) {
- client.addFilter(new LoggingFilter(ps));
- }
-
- // Grab the current time so that we can use it for metrics purposes later.
- startTimeInMs = System.currentTimeMillis();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- if (useBasicAuth()) {
- result = client.resource(url).queryParam(RESOURCE_VERSION_PARAM, resourceVersion)
- .header(HEADER_TRANS_ID, transId).header(HEADER_FROM_APP_ID, ML_APP_NAME)
- .header(HEADER_AUTHORIZATION, getAuthenticationCredentials())
- .delete(ClientResponse.class);
- } else {
- result = client.resource(url).queryParam(RESOURCE_VERSION_PARAM, resourceVersion)
- .header(HEADER_TRANS_ID, transId).header(HEADER_FROM_APP_ID, ML_APP_NAME)
- .delete(ClientResponse.class);
- }
- } catch (Exception ex) {
- logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "DELETE", url, ex.getLocalizedMessage());
- return null;
- } finally {
- if (logger.isDebugEnabled()) {
- logger.debug(baos.toString());
- }
- }
-
- logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "DELETE", url,
- Integer.toString(result.getStatus()));
- metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS,
- new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()).setField(
- LogLine.DefinedFields.RESPONSE_DESCRIPTION, result.getResponseStatus().toString()),
- override, "DELETE", url, Integer.toString(result.getStatus()));
-
- return result;
- }
-
- /**
- * Send a GET request to the A&AI for a resource.
- *
- * @param url
- * - the url to use
- * @param transId
- * - transaction ID
- * @return ClientResponse
- */
- public ClientResponse getResource(String url, String transId, MimeType mimeType) {
- ClientResponse result = null;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- long startTimeInMs = 0;
- MdcOverride override = new MdcOverride();
-
- try {
- Client client = setupClient();
-
- baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- if (logger.isDebugEnabled()) {
- client.addFilter(new LoggingFilter(ps));
- }
-
- // Grab the current time so that we can use it for metrics purposes later.
- startTimeInMs = System.currentTimeMillis();
- override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs));
-
- if (useBasicAuth()) {
- result = client.resource(url).header(HEADER_TRANS_ID, transId)
- .header(HEADER_FROM_APP_ID, ML_APP_NAME).accept(mimeType.getHttpHeaderType())
- .header(HEADER_AUTHORIZATION, getAuthenticationCredentials()).get(ClientResponse.class);
- } else {
- result = client.resource(url).header(HEADER_TRANS_ID, transId)
- .header(HEADER_FROM_APP_ID, ML_APP_NAME).accept(mimeType.getHttpHeaderType())
- .get(ClientResponse.class);
-
- }
- } catch (Exception ex) {
- logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "GET", url, ex.getLocalizedMessage());
- return null;
- } finally {
- if (logger.isDebugEnabled()) {
- logger.debug(baos.toString());
- }
- }
-
- logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "GET", url,
- Integer.toString(result.getStatus()));
- metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS,
- new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()).setField(
- LogLine.DefinedFields.RESPONSE_DESCRIPTION, result.getResponseStatus().toString()),
- override, "GET", url, Integer.toString(result.getStatus()));
-
- return result;
- }
-
- /**
- * Does a GET on a resource to retrieve the resource version, and then DELETE
- * that version.
- *
- * @param url
- * - the url
- * @param transId
- * - transaction ID
- * @return ClientResponse
- */
- public ClientResponse getAndDeleteResource(String url, String transId) {
- // First, GET the model
- ClientResponse getResponse = getResource(url, transId, MimeType.XML);
- if ((getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode())) {
- return getResponse;
- }
-
- // Delete the model using the resource version in the response
- String resVersion = null;
- try {
- resVersion = getResourceVersion(getResponse);
- } catch (Exception e) {
- logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "GET", url, e.getLocalizedMessage());
- return null;
- }
-
- return deleteResource(url, resVersion, transId);
- }
-
- private Client setupClient() throws IOException, GeneralSecurityException {
- ClientConfig clientConfig = new DefaultClientConfig();
-
- HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
- @Override
- public boolean verify(String string, SSLSession ssls) {
- return true;
- }
- });
-
- // Create a trust manager that does not validate certificate chains
- TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
-
- @Override
- public void checkClientTrusted(X509Certificate[] certs, String authType) {}
-
- @Override
- public void checkServerTrusted(X509Certificate[] certs, String authType) {}
- } };
-
- SSLContext ctx = SSLContext.getInstance("TLS");
- KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
- FileInputStream fin = new FileInputStream(config.getAaiKeyStorePath());
- KeyStore ks = KeyStore.getInstance("PKCS12");
- char[] pwd = config.getAaiKeyStorePassword().toCharArray();
- ks.load(fin, pwd);
- kmf.init(ks, pwd);
-
- ctx.init(kmf.getKeyManagers(), trustAllCerts, null);
- clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(new HostnameVerifier() {
- @Override
- public boolean verify(String theString, SSLSession sslSession) {
- return true;
- }
- }, ctx));
-
- Client client = Client.create(clientConfig);
-
- return client;
- }
-
- private String getResourceVersion(ClientResponse response)
- throws ParserConfigurationException, SAXException, IOException {
- String respData = response.getEntity(String.class);
-
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- InputSource is = new InputSource(new StringReader(respData));
- Document doc = builder.parse(is);
-
- NodeList nodeList = doc.getDocumentElement().getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node currentNode = nodeList.item(i);
- if (currentNode.getNodeName().equals(RESOURCE_VERSION_PARAM)) {
- return currentNode.getTextContent();
- }
- }
-
- return null;
- }
-
- private String getAuthenticationCredentials() {
-
- String usernameAndPassword = config.getAaiAuthenticationUser() + ":"
- + config.getAaiAuthenticationPassword();
- return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes());
- }
-
- public boolean useBasicAuth() {
- return (config.getAaiAuthenticationUser() != null)
- && (config.getAaiAuthenticationPassword() != null);
- }
-}
+/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.restclient; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.LoggingFilter; +import com.sun.jersey.client.urlconnection.HTTPSProperties; +import org.openecomp.cl.api.LogFields; +import org.openecomp.cl.api.LogLine; +import org.openecomp.cl.api.Logger; +import org.openecomp.cl.eelf.LoggerFactory; +import org.openecomp.cl.mdc.MdcContext; +import org.openecomp.cl.mdc.MdcOverride; +import org.openecomp.modelloader.config.ModelLoaderConfig; +import org.openecomp.modelloader.service.ModelLoaderMsgs; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.io.StringReader; +import java.security.GeneralSecurityException; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.text.SimpleDateFormat; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.ws.rs.core.Response; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +public class AaiRestClient { + public enum MimeType { + XML("application/xml"), JSON("application/json"); + + private String httpType; + + MimeType(String httpType) { + this.httpType = httpType; + } + + String getHttpHeaderType() { + return httpType; + } + } + + private static String HEADER_TRANS_ID = "X-TransactionId"; + private static String HEADER_FROM_APP_ID = "X-FromAppId"; + private static String HEADER_AUTHORIZATION = "Authorization"; + private static String ML_APP_NAME = "ModelLoader"; + private static String RESOURCE_VERSION_PARAM = "resource-version"; + + private static SimpleDateFormat dateFormatter = new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + private static Logger logger = LoggerFactory.getInstance() + .getLogger(AaiRestClient.class.getName()); + private static Logger metricsLogger = LoggerFactory.getInstance() + .getMetricsLogger(AaiRestClient.class.getName()); + + private ModelLoaderConfig config = null; + + public AaiRestClient(ModelLoaderConfig config) { + this.config = config; + } + + /** + * Send a PUT request to the A&AI. + * + * @param url + * - the url + * @param transId + * - transaction ID + * @param payload + * - the XML or JSON payload for the request + * @param mimeType + * - the content type (XML or JSON) + * @return ClientResponse + */ + public ClientResponse putResource(String url, String payload, String transId, MimeType mimeType) { + ClientResponse result = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + long startTimeInMs = 0; + MdcOverride override = new MdcOverride(); + + try { + Client client = setupClient(); + + baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + if (logger.isDebugEnabled()) { + client.addFilter(new LoggingFilter(ps)); + } + + // Grab the current time so that we can use it for metrics purposes later. + startTimeInMs = System.currentTimeMillis(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + if (useBasicAuth()) { + result = client.resource(url).header(HEADER_TRANS_ID, transId) + .header(HEADER_FROM_APP_ID, ML_APP_NAME) + .header(HEADER_AUTHORIZATION, getAuthenticationCredentials()) + .type(mimeType.getHttpHeaderType()).put(ClientResponse.class, payload); + } else { + result = client.resource(url).header(HEADER_TRANS_ID, transId) + .header(HEADER_FROM_APP_ID, ML_APP_NAME).type(mimeType.getHttpHeaderType()) + .put(ClientResponse.class, payload); + } + } catch (Exception ex) { + logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "PUT", url, ex.getLocalizedMessage()); + return null; + } finally { + if (logger.isDebugEnabled()) { + logger.debug(baos.toString()); + } + } + + if ((result != null) && ((result.getStatus() == Response.Status.CREATED.getStatusCode()) + || (result.getStatus() == Response.Status.OK.getStatusCode()))) { + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "PUT", url, + Integer.toString(result.getStatus())); + metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, + new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()) + .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, + result.getResponseStatus().toString()), + override, "PUT", url, Integer.toString(result.getStatus())); + } else { + // If response is not 200 OK, then additionally log the reason + String respMsg = result.getEntity(String.class); + if (respMsg == null) { + respMsg = result.getStatusInfo().getReasonPhrase(); + } + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_UNSUCCESSFUL, "PUT", url, + Integer.toString(result.getStatus()), respMsg); + metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_UNSUCCESSFUL, + new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()) + .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, + result.getResponseStatus().toString()), + override, "PUT", url, Integer.toString(result.getStatus()), respMsg); + } + + return result; + } + + /** + * Send a DELETE request to the A&AI. + * + * @param url + * - the url + * @param resourceVersion + * - the resource-version of the model to delete + * @param transId + * - transaction ID + * @return ClientResponse + */ + public ClientResponse deleteResource(String url, String resourceVersion, String transId) { + ClientResponse result = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + long startTimeInMs = 0; + MdcOverride override = new MdcOverride(); + + try { + Client client = setupClient(); + + baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + if (logger.isDebugEnabled()) { + client.addFilter(new LoggingFilter(ps)); + } + + // Grab the current time so that we can use it for metrics purposes later. + startTimeInMs = System.currentTimeMillis(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + if (useBasicAuth()) { + result = client.resource(url).queryParam(RESOURCE_VERSION_PARAM, resourceVersion) + .header(HEADER_TRANS_ID, transId).header(HEADER_FROM_APP_ID, ML_APP_NAME) + .header(HEADER_AUTHORIZATION, getAuthenticationCredentials()) + .delete(ClientResponse.class); + } else { + result = client.resource(url).queryParam(RESOURCE_VERSION_PARAM, resourceVersion) + .header(HEADER_TRANS_ID, transId).header(HEADER_FROM_APP_ID, ML_APP_NAME) + .delete(ClientResponse.class); + } + } catch (Exception ex) { + logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "DELETE", url, ex.getLocalizedMessage()); + return null; + } finally { + if (logger.isDebugEnabled()) { + logger.debug(baos.toString()); + } + } + + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "DELETE", url, + Integer.toString(result.getStatus())); + metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, + new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()).setField( + LogLine.DefinedFields.RESPONSE_DESCRIPTION, result.getResponseStatus().toString()), + override, "DELETE", url, Integer.toString(result.getStatus())); + + return result; + } + + /** + * Send a GET request to the A&AI for a resource. + * + * @param url + * - the url to use + * @param transId + * - transaction ID + * @return ClientResponse + */ + public ClientResponse getResource(String url, String transId, MimeType mimeType) { + ClientResponse result = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + long startTimeInMs = 0; + MdcOverride override = new MdcOverride(); + + try { + Client client = setupClient(); + + baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + if (logger.isDebugEnabled()) { + client.addFilter(new LoggingFilter(ps)); + } + + // Grab the current time so that we can use it for metrics purposes later. + startTimeInMs = System.currentTimeMillis(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + if (useBasicAuth()) { + result = client.resource(url).header(HEADER_TRANS_ID, transId) + .header(HEADER_FROM_APP_ID, ML_APP_NAME).accept(mimeType.getHttpHeaderType()) + .header(HEADER_AUTHORIZATION, getAuthenticationCredentials()).get(ClientResponse.class); + } else { + result = client.resource(url).header(HEADER_TRANS_ID, transId) + .header(HEADER_FROM_APP_ID, ML_APP_NAME).accept(mimeType.getHttpHeaderType()) + .get(ClientResponse.class); + + } + } catch (Exception ex) { + logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "GET", url, ex.getLocalizedMessage()); + return null; + } finally { + if (logger.isDebugEnabled()) { + logger.debug(baos.toString()); + } + } + + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "GET", url, + Integer.toString(result.getStatus())); + metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, + new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()).setField( + LogLine.DefinedFields.RESPONSE_DESCRIPTION, result.getResponseStatus().toString()), + override, "GET", url, Integer.toString(result.getStatus())); + + return result; + } + + /** + * Send a POST request to the A&AI. + * + * @param url + * - the url + * @param transId + * - transaction ID + * @param payload + * - the XML or JSON payload for the request + * @param mimeType + * - the content type (XML or JSON) + * @return ClientResponse + */ + public ClientResponse postResource(String url, String payload, String transId, MimeType mimeType) { + ClientResponse result = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + long startTimeInMs = 0; + MdcOverride override = new MdcOverride(); + + try { + Client client = setupClient(); + + baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + if (logger.isDebugEnabled()) { + client.addFilter(new LoggingFilter(ps)); + } + + // Grab the current time so that we can use it for metrics purposes later. + startTimeInMs = System.currentTimeMillis(); + override.addAttribute(MdcContext.MDC_START_TIME, dateFormatter.format(startTimeInMs)); + + if (useBasicAuth()) { + result = client.resource(url).header(HEADER_TRANS_ID, transId) + .header(HEADER_FROM_APP_ID, ML_APP_NAME) + .header(HEADER_AUTHORIZATION, getAuthenticationCredentials()) + .type(mimeType.getHttpHeaderType()).post(ClientResponse.class, payload); + } else { + result = client.resource(url).header(HEADER_TRANS_ID, transId) + .header(HEADER_FROM_APP_ID, ML_APP_NAME).type(mimeType.getHttpHeaderType()) + .post(ClientResponse.class, payload); + } + } catch (Exception ex) { + logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "POST", url, ex.getLocalizedMessage()); + return null; + } finally { + if (logger.isDebugEnabled()) { + logger.debug(baos.toString()); + } + } + + if ((result != null) && ((result.getStatus() == Response.Status.CREATED.getStatusCode()) + || (result.getStatus() == Response.Status.OK.getStatusCode()))) { + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, "POST", url, + Integer.toString(result.getStatus())); + metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_SUCCESS, + new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()) + .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, + result.getResponseStatus().toString()), + override, "POST", url, Integer.toString(result.getStatus())); + } else { + // If response is not 200 OK, then additionally log the reason + String respMsg = result.getEntity(String.class); + if (respMsg == null) { + respMsg = result.getStatusInfo().getReasonPhrase(); + } + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_UNSUCCESSFUL, "POST", url, + Integer.toString(result.getStatus()), respMsg); + metricsLogger.info(ModelLoaderMsgs.AAI_REST_REQUEST_UNSUCCESSFUL, + new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, result.getStatus()) + .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, + result.getResponseStatus().toString()), + override, "POST", url, Integer.toString(result.getStatus()), respMsg); + } + + return result; + } + + /** + * Does a GET on a resource to retrieve the resource version, and then DELETE + * that version. + * + * @param url + * - the url + * @param transId + * - transaction ID + * @return ClientResponse + */ + public ClientResponse getAndDeleteResource(String url, String transId) { + // First, GET the model + ClientResponse getResponse = getResource(url, transId, MimeType.XML); + if ((getResponse == null) || (getResponse.getStatus() != Response.Status.OK.getStatusCode())) { + return getResponse; + } + + // Delete the model using the resource version in the response + String resVersion = null; + try { + resVersion = getResourceVersion(getResponse); + } catch (Exception e) { + logger.error(ModelLoaderMsgs.AAI_REST_REQUEST_ERROR, "GET", url, e.getLocalizedMessage()); + return null; + } + + return deleteResource(url, resVersion, transId); + } + + private Client setupClient() throws IOException, GeneralSecurityException { + ClientConfig clientConfig = new DefaultClientConfig(); + + HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { + @Override + public boolean verify(String string, SSLSession ssls) { + return true; + } + }); + + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) {} + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) {} + } }; + + SSLContext ctx = SSLContext.getInstance("TLS"); + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + FileInputStream fin = new FileInputStream(config.getAaiKeyStorePath()); + KeyStore ks = KeyStore.getInstance("PKCS12"); + char[] pwd = config.getAaiKeyStorePassword().toCharArray(); + ks.load(fin, pwd); + kmf.init(ks, pwd); + + ctx.init(kmf.getKeyManagers(), trustAllCerts, null); + clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, + new HTTPSProperties(new HostnameVerifier() { + @Override + public boolean verify(String theString, SSLSession sslSession) { + return true; + } + }, ctx)); + + Client client = Client.create(clientConfig); + + return client; + } + + private String getResourceVersion(ClientResponse response) + throws ParserConfigurationException, SAXException, IOException { + String respData = response.getEntity(String.class); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource is = new InputSource(new StringReader(respData)); + Document doc = builder.parse(is); + + NodeList nodeList = doc.getDocumentElement().getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentNode = nodeList.item(i); + if (currentNode.getNodeName().equals(RESOURCE_VERSION_PARAM)) { + return currentNode.getTextContent(); + } + } + + return null; + } + + private String getAuthenticationCredentials() { + + String usernameAndPassword = config.getAaiAuthenticationUser() + ":" + + config.getAaiAuthenticationPassword(); + return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes()); + } + + public boolean useBasicAuth() { + return (config.getAaiAuthenticationUser() != null) + && (config.getAaiAuthenticationPassword() != null); + } +} diff --git a/src/test/java/org/openecomp/modelloader/entity/model/ModelArtifactParserTest.java b/src/test/java/org/openecomp/modelloader/entity/model/ModelArtifactParserTest.java index 994c4db..ac32f58 100644 --- a/src/test/java/org/openecomp/modelloader/entity/model/ModelArtifactParserTest.java +++ b/src/test/java/org/openecomp/modelloader/entity/model/ModelArtifactParserTest.java @@ -1,205 +1,125 @@ -/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.entity.model;
-
-import static org.junit.Assert.assertTrue;
-
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.List;
-
-import org.junit.Test;
-import org.openecomp.modelloader.entity.Artifact;
-
-public class ModelArtifactParserTest {
-
- @Test
- public void testParseModelFileNoDeps() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- assertTrue(modelList.size() == 1);
-
- ModelArtifact model = (ModelArtifact) modelList.get(0);
- System.out.println(model.toString());
-
- assertTrue(model.getModelInvariantId().equalsIgnoreCase("3d560d81-57d0-438b-a2a1-5334dba0651a"));
- assertTrue(model.getType().toString().equalsIgnoreCase("MODEL"));
- System.out.println(model.getDependentModelIds().size());
- assertTrue(model.getDependentModelIds().size() == 0);
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
- @Test
- public void testParseModelFileDeps() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/AAI-stellService-service-1.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- assertTrue(modelList.size() == 1);
-
- ModelArtifact model = (ModelArtifact) modelList.get(0);
- System.out.println(model.toString());
-
- assertTrue(model.getModelInvariantId().equalsIgnoreCase("fedf9da3-6a74-4813-8fa2-221a98b0e7ad"));
- assertTrue(model.getModelVerId().equalsIgnoreCase("e0373537-7f66-4094-9939-e2f5de6ff5f6"));
- assertTrue(model.getType().toString().equalsIgnoreCase("MODEL"));
- assertTrue(model.getDependentModelIds().size() == 3);
- assertTrue(model.getDependentModelIds().contains("5c12984d-db0f-4300-a0e0-9791775cc40f|88bdbadf-db8a-490f-881e-c8effcbc3f66"));
- assertTrue(model.getDependentModelIds().contains("959b7c09-9f34-4e5f-8b63-505381db176e|374d0899-bbc2-4403-9320-fe9bebef75c6"));
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
- @Test
- public void testParseCompleteModel() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/complete-model.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- for (Artifact art : modelList) {
- ModelArtifact model = (ModelArtifact) art;
- System.out.println(model.toString());
- }
-
- assertTrue(modelList.size() == 5);
-
- ModelArtifact model1 = (ModelArtifact)modelList.get(0);
- assertTrue(model1.getModelVerId().equalsIgnoreCase("88bdbadf-db8a-490f-881e-c8effcbc3f66"));
- assertTrue(model1.getType().toString().equalsIgnoreCase("MODEL"));
- assertTrue(model1.getDependentModelIds().size() == 1);
- assertTrue(model1.getDependentModelIds().contains("3d560d81-57d0-438b-a2a1-5334dba0651a|9111f20f-e680-4001-b83f-19a2fc23bfc1"));
-
- ModelArtifact model4 = (ModelArtifact)modelList.get(4);
- assertTrue(model4.getModelInvariantId().equalsIgnoreCase("fedf9da3-6a74-4813-8fa2-221a98b0e7ad"));
- assertTrue(model4.getType().toString().equalsIgnoreCase("MODEL"));
- assertTrue(model4.getDependentModelIds().size() == 3);
- assertTrue(model4.getDependentModelIds().contains("5c12984d-db0f-4300-a0e0-9791775cc40f|88bdbadf-db8a-490f-881e-c8effcbc3f66"));
- assertTrue(model4.getDependentModelIds().contains("82194af1-3c2c-485a-8f44-420e22a9eaa4|46b92144-923a-4d20-b85a-3cbd847668a9"));
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
- @Test
- public void testParseNamedQuery() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/named-query-wan-connector.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- assertTrue(modelList.size() == 1);
-
- ModelArtifact model = (ModelArtifact) modelList.get(0);
- System.out.println(model.toString());
-
- assertTrue(model.getNameVersionId().equalsIgnoreCase("94cac189-8d88-4d63-a194-f44214e080ff"));
- assertTrue(model.getType().toString().equalsIgnoreCase("NAMED_QUERY"));
- assertTrue(model.getDependentModelIds().size() == 4);
- assertTrue(model.getDependentModelIds().contains("d09dd9da-0148-46cd-a947-591afc844d24"));
- assertTrue(model.getDependentModelIds().contains("997fc7-fca1-451f-b953-9a1e6197b4d6"));
- assertTrue(model.getDependentModelIds().contains("897df7ea-8938-42b0-bc57-46e913a4d93b"));
- assertTrue(model.getDependentModelIds().contains("f2b24d95-c582-48d5-b2d6-c5b3a94ce812"));
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
- @Test
- public void testParseModelFileInvalidArtifact() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/invalid-model.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- assertTrue(modelList == null || modelList.isEmpty());
- }
- catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
- @Test
- public void testParseModelFileIncompleteArtifact() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- assertTrue(modelList == null || modelList.isEmpty());
- }
- catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
- @Test
- public void testParseModelFileIncompleteArtifacts() throws Exception {
- final String MODEL_FILE = "src/test/resources/models/incomplete-models.xml";
-
- try {
- byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
-
- ModelArtifactParser parser = new ModelArtifactParser();
- List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
-
- assertTrue(modelList == null || modelList.isEmpty());
- }
- catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-
-}
+/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import org.junit.Test; +import org.openecomp.modelloader.entity.Artifact; + +public class ModelArtifactParserTest { + + @Test + public void testParseModelFileNoDeps() throws Exception { + final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelArtifactParser parser = new ModelArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList.size() == 1); + + ModelArtifact model = (ModelArtifact) modelList.get(0); + System.out.println(model.toString()); + + assertTrue(model.getModelInvariantId().equalsIgnoreCase("3d560d81-57d0-438b-a2a1-5334dba0651a")); + assertTrue(model.getModelNamespace().equalsIgnoreCase("http://org.openecomp.aai.inventory/v9")); + assertTrue(model.getModelNamespaceVersion().equalsIgnoreCase("v9")); + assertTrue(model.getType().toString().equalsIgnoreCase("MODEL")); + System.out.println(model.getDependentModelIds().size()); + assertTrue(model.getDependentModelIds().size() == 0); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testParseModelFileDeps() throws Exception { + final String MODEL_FILE = "src/test/resources/models/AAI-stellService-service-1.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelArtifactParser parser = new ModelArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList.size() == 1); + + ModelArtifact model = (ModelArtifact) modelList.get(0); + System.out.println(model.toString()); + + assertTrue(model.getModelInvariantId().equalsIgnoreCase("fedf9da3-6a74-4813-8fa2-221a98b0e7ad")); + assertTrue(model.getModelVerId().equalsIgnoreCase("e0373537-7f66-4094-9939-e2f5de6ff5f6")); + assertTrue(model.getType().toString().equalsIgnoreCase("MODEL")); + assertTrue(model.getDependentModelIds().size() == 3); + assertTrue(model.getDependentModelIds().contains("5c12984d-db0f-4300-a0e0-9791775cc40f|88bdbadf-db8a-490f-881e-c8effcbc3f66")); + assertTrue(model.getDependentModelIds().contains("959b7c09-9f34-4e5f-8b63-505381db176e|374d0899-bbc2-4403-9320-fe9bebef75c6")); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testParseModelFileInvalidArtifact() throws Exception { + final String MODEL_FILE = "src/test/resources/models/invalid-model.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelArtifactParser parser = new ModelArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList == null || modelList.isEmpty()); + } + catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testParseModelFileIncompleteArtifact() throws Exception { + final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelArtifactParser parser = new ModelArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList == null || modelList.isEmpty()); + } + catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } +} diff --git a/src/test/java/org/openecomp/modelloader/entity/model/ModelParserFactoryTest.java b/src/test/java/org/openecomp/modelloader/entity/model/ModelParserFactoryTest.java new file mode 100644 index 0000000..46db11a --- /dev/null +++ b/src/test/java/org/openecomp/modelloader/entity/model/ModelParserFactoryTest.java @@ -0,0 +1,58 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.Test; + +public class ModelParserFactoryTest { + + @Test + public void testParserFactory() throws Exception { + final String MODEL_FILE_V8 = "src/test/resources/models/v8-wan-connector-model.xml"; + final String MODEL_FILE_V9 = "src/test/resources/models/AAI-VL-resource-1.xml"; + final String MODEL_FILE_NAMED_QUERY = "src/test/resources/models/named-query-wan-connector.xml"; + + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE_V8)); + IModelParser parser = ModelParserFactory.createModelParser(xmlBytes, "v8-wan-connector-model.xml"); + assertTrue(parser instanceof ModelV8ArtifactParser); + + xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE_V9)); + parser = ModelParserFactory.createModelParser(xmlBytes, "AAI-VL-resource-1.xml"); + assertTrue(parser instanceof ModelArtifactParser); + + xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE_NAMED_QUERY)); + parser = ModelParserFactory.createModelParser(xmlBytes, "named-query-wan-connector.xml"); + assertTrue(parser instanceof NamedQueryArtifactParser); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } +} diff --git a/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java b/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java index 03eaa39..fdc81da 100644 --- a/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java +++ b/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java @@ -54,8 +54,9 @@ public class ModelSorterTest { List<Artifact> modelList = new ArrayList<Artifact>(); ModelArtifact model = new ModelArtifact(); - model.setNameVersionId("aaaaa"); - model.addDependentModelId("xyz"); + model.setModelInvariantId("aaa"); + model.setModelVerId("111"); + model.addDependentModelId("xyz|123"); modelList.add(model); ModelSorter sorter = new ModelSorter(); @@ -82,17 +83,17 @@ public class ModelSorterTest { ModelArtifact aaaa = new ModelArtifact(); aaaa.setModelInvariantId("aaaa"); - aaaa.setModelVerId("mvaaaa"); - aaaa.addDependentModelId("cccc|mvcccc"); + aaaa.setModelVerId("mvaaaa"); + aaaa.addDependentModelId("cccc|mvcccc"); ModelArtifact bbbb = new ModelArtifact(); bbbb.setModelInvariantId("bbbb"); - bbbb.setModelVerId("mvbbbb"); - bbbb.addDependentModelId("aaaa|mvaaaa"); + bbbb.setModelVerId("mvbbbb"); + bbbb.addDependentModelId("aaaa|mvaaaa"); ModelArtifact cccc = new ModelArtifact(); cccc.setModelInvariantId("cccc"); - cccc.setModelVerId("mvcccc"); + cccc.setModelVerId("mvcccc"); modelList.add(aaaa); modelList.add(bbbb); @@ -109,19 +110,89 @@ public class ModelSorterTest { assertEquals(aaaa, sortedList.get(1)); assertEquals(bbbb, sortedList.get(2)); } + + @Test + public void multipleModelsV8() { + + List<Artifact> modelList = new ArrayList<Artifact>(); + + ModelV8Artifact aaaa = new ModelV8Artifact(); + aaaa.setModelNameVersionId("aaaa"); + aaaa.addDependentModelId("cccc"); + + ModelV8Artifact bbbb = new ModelV8Artifact(); + bbbb.setModelNameVersionId("bbbb"); + bbbb.addDependentModelId("aaaa"); + + ModelV8Artifact cccc = new ModelV8Artifact(); + cccc.setModelNameVersionId("cccc"); + + modelList.add(aaaa); + modelList.add(bbbb); + modelList.add(cccc); + ModelSorter sorter = new ModelSorter(); + sorter = new ModelSorter(); + + List<Artifact> 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)); + } + + @Test + public void multipleModelsAndNamedQueries() { + + List<Artifact> modelList = new ArrayList<Artifact>(); + + 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<Artifact> sortedList = sorter.sort(modelList); + assertNotNull(sortedList); + assertEquals(3, sortedList.size()); + + 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(expected = RuntimeException.class) public void circularDependency() { List<Artifact> modelList = new ArrayList<Artifact>(); ModelArtifact aaaa = new ModelArtifact(); - aaaa.setNameVersionId("aaaa"); - aaaa.addDependentModelId("bbbb"); + aaaa.setModelInvariantId("aaaa"); + aaaa.setModelVerId("1111"); + aaaa.addDependentModelId("bbbb|1111"); ModelArtifact bbbb = new ModelArtifact(); - bbbb.setNameVersionId("bbbb"); - bbbb.addDependentModelId("aaaa"); + bbbb.setModelInvariantId("bbbb"); + bbbb.setModelVerId("1111"); + bbbb.addDependentModelId("aaaa|1111"); modelList.add(aaaa); modelList.add(bbbb); diff --git a/src/test/java/org/openecomp/modelloader/entity/model/ModelV8ArtifactParserTest.java b/src/test/java/org/openecomp/modelloader/entity/model/ModelV8ArtifactParserTest.java new file mode 100644 index 0000000..098bc8c --- /dev/null +++ b/src/test/java/org/openecomp/modelloader/entity/model/ModelV8ArtifactParserTest.java @@ -0,0 +1,104 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import org.junit.Test; +import org.openecomp.modelloader.entity.Artifact; + +public class ModelV8ArtifactParserTest { + + @Test + public void testParseModelFile() throws Exception { + final String MODEL_FILE = "src/test/resources/models/v8-wan-connector-model.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelV8ArtifactParser parser = new ModelV8ArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList.size() == 1); + + ModelV8Artifact model = (ModelV8Artifact) modelList.get(0); + System.out.println(model.toString()); + + assertTrue(model.getModelNameVersionId().equalsIgnoreCase("93d9d45d-7eec-4371-9083-675e4c353de3")); + assertTrue(model.getModelNamespace().equalsIgnoreCase("http://com.att.aai.inventory/v7")); + assertTrue(model.getModelNamespaceVersion().equalsIgnoreCase("v7")); + assertTrue(model.getType().toString().equalsIgnoreCase("MODEL_V8")); + assertTrue(model.getDependentModelIds().size() == 7); + assertTrue(model.getDependentModelIds().contains("d09dd9da-0148-46cd-a947-591afc844d24")); + assertTrue(model.getDependentModelIds().contains("997fc7-fca1-451f-b953-9a1e6197b4d6")); + assertTrue(model.getDependentModelIds().contains("ae16244f-4d29-4801-a559-e25f2db2a4c3")); + assertTrue(model.getDependentModelIds().contains("759dbd4a-2473-46f3-a932-48d987c9b4a1")); + assertTrue(model.getDependentModelIds().contains("a6d9de88-4046-4b78-a59e-5691243d292a")); + assertTrue(model.getDependentModelIds().contains("35be1acf-1298-48c6-a128-66850083b8bd")); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testParseModelFileInvalidArtifact() throws Exception { + final String MODEL_FILE = "src/test/resources/models/invalid-model.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelV8ArtifactParser parser = new ModelV8ArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList == null || modelList.isEmpty()); + } + catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + + @Test + public void testParseModelFileIncompleteArtifact() throws Exception { + final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + ModelV8ArtifactParser parser = new ModelV8ArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList == null || modelList.isEmpty()); + } + catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + +} diff --git a/src/test/java/org/openecomp/modelloader/entity/model/NamedQueryArtifactParserTest.java b/src/test/java/org/openecomp/modelloader/entity/model/NamedQueryArtifactParserTest.java new file mode 100644 index 0000000..cc9d615 --- /dev/null +++ b/src/test/java/org/openecomp/modelloader/entity/model/NamedQueryArtifactParserTest.java @@ -0,0 +1,64 @@ +/** + * ============LICENSE_START======================================================= + * Model Loader + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. + */ +package org.openecomp.modelloader.entity.model; + +import static org.junit.Assert.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +import org.junit.Test; +import org.openecomp.modelloader.entity.Artifact; + +public class NamedQueryArtifactParserTest { + + @Test + public void testParseNamedQuery() throws Exception { + final String MODEL_FILE = "src/test/resources/models/named-query-wan-connector.xml"; + + try { + byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE)); + + NamedQueryArtifactParser parser = new NamedQueryArtifactParser(); + List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact"); + + assertTrue(modelList.size() == 1); + + NamedQueryArtifact model = (NamedQueryArtifact) modelList.get(0); + System.out.println(model.toString()); + + assertTrue(model.getNamedQueryUuid().equalsIgnoreCase("94cac189-8d88-4d63-a194-f44214e080ff")); + assertTrue(model.getType().toString().equalsIgnoreCase("NAMED_QUERY")); + assertTrue(model.getDependentModelIds().size() == 4); + assertTrue(model.getDependentModelIds().contains("d09dd9da-0148-46cd-a947-591afc844d24")); + assertTrue(model.getDependentModelIds().contains("997fc7-fca1-451f-b953-9a1e6197b4d6")); + assertTrue(model.getDependentModelIds().contains("897df7ea-8938-42b0-bc57-46e913a4d93b")); + assertTrue(model.getDependentModelIds().contains("f2b24d95-c582-48d5-b2d6-c5b3a94ce812")); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } + +} diff --git a/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java b/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java index 5d9edc9..08a429a 100644 --- a/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java +++ b/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java @@ -115,7 +115,7 @@ public class AaiRestClientTest { subURL = subURL + "/"; } - String url = baseURL + subURL + model.getNameVersionId(); + String url = baseURL + subURL + model.getUniqueIdentifier(); return url; } } diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index 3f0fb7a..aef38e6 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -1,37 +1,17 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<configuration debug="false">
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <!-- encoders are by default assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
- </encoder>
- </appender>
-
- <logger name="com.att.eelf" level="DEBUG" additivity="false">
- <appender-ref ref="STDOUT" />
- </logger>
-
- <root level="debug">
- <appender-ref ref="STDOUT" />
- </root>
-</configuration>
+<configuration debug="false"> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <!-- encoders are by default assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder --> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <logger name="com.att.eelf" level="DEBUG" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <root level="debug"> + <appender-ref ref="STDOUT" /> + </root> +</configuration> diff --git a/src/test/resources/model-loader-empty-auth-password.properties b/src/test/resources/model-loader-empty-auth-password.properties index 34432a4..91fd527 100644 --- a/src/test/resources/model-loader-empty-auth-password.properties +++ b/src/test/resources/model-loader-empty-auth-password.properties @@ -1,43 +1,23 @@ -###
-# ============LICENSE_START======================================================= -# MODEL LOADER SERVICE -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License. -# ============LICENSE_END=========================================================
-###
-
-# Model Loader Distribution Client Configuration
-ml.distribution.ACTIVE_SERVER_TLS_AUTH=false
-ml.distribution.ASDC_ADDRESS=
-ml.distribution.CONSUMER_GROUP=aai-ml-group-test
-ml.distribution.CONSUMER_ID=aai-ml-id-test
-ml.distribution.ENVIRONMENT_NAME=
-ml.distribution.KEYSTORE_PASSWORD=
-ml.distribution.KEYSTORE_FILE=asdc-client.jks
-ml.distribution.PASSWORD=
-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
-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.KEYSTORE_FILE=aai-client-cert.p12
-ml.aai.KEYSTORE_PASSWORD=
-ml.aai.AUTH_USER=ModelLoader
-ml.aai.AUTH_PASSWORD=
+# Model Loader Distribution Client Configuration +ml.distribution.ACTIVE_SERVER_TLS_AUTH=false +ml.distribution.ASDC_ADDRESS= +ml.distribution.CONSUMER_GROUP=aai-ml-group-test +ml.distribution.CONSUMER_ID=aai-ml-id-test +ml.distribution.ENVIRONMENT_NAME= +ml.distribution.KEYSTORE_PASSWORD= +ml.distribution.KEYSTORE_FILE=asdc-client.jks +ml.distribution.PASSWORD= +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 +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.KEYSTORE_FILE=aai-client-cert.p12 +ml.aai.KEYSTORE_PASSWORD= +ml.aai.AUTH_USER=ModelLoader +ml.aai.AUTH_PASSWORD= diff --git a/src/test/resources/model-loader-no-auth-password.properties b/src/test/resources/model-loader-no-auth-password.properties index 035d3e8..2f36934 100644 --- a/src/test/resources/model-loader-no-auth-password.properties +++ b/src/test/resources/model-loader-no-auth-password.properties @@ -1,41 +1,21 @@ -###
-# ============LICENSE_START======================================================= -# MODEL LOADER SERVICE -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License. -# ============LICENSE_END=========================================================
-###
-
-# Model Loader Distribution Client Configuration
-ml.distribution.ACTIVE_SERVER_TLS_AUTH=false
-ml.distribution.ASDC_ADDRESS=
-ml.distribution.CONSUMER_GROUP=aai-ml-group-test
-ml.distribution.CONSUMER_ID=aai-ml-id-test
-ml.distribution.ENVIRONMENT_NAME=
-ml.distribution.KEYSTORE_PASSWORD=
-ml.distribution.KEYSTORE_FILE=asdc-client.jks
-ml.distribution.PASSWORD=
-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
-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.KEYSTORE_FILE=aai-client-cert.p12
-ml.aai.KEYSTORE_PASSWORD=
+# Model Loader Distribution Client Configuration +ml.distribution.ACTIVE_SERVER_TLS_AUTH=false +ml.distribution.ASDC_ADDRESS= +ml.distribution.CONSUMER_GROUP=aai-ml-group-test +ml.distribution.CONSUMER_ID=aai-ml-id-test +ml.distribution.ENVIRONMENT_NAME= +ml.distribution.KEYSTORE_PASSWORD= +ml.distribution.KEYSTORE_FILE=asdc-client.jks +ml.distribution.PASSWORD= +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 +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.KEYSTORE_FILE=aai-client-cert.p12 +ml.aai.KEYSTORE_PASSWORD= diff --git a/src/test/resources/model-loader.properties b/src/test/resources/model-loader.properties index 34432a4..91fd527 100644 --- a/src/test/resources/model-loader.properties +++ b/src/test/resources/model-loader.properties @@ -1,43 +1,23 @@ -###
-# ============LICENSE_START======================================================= -# MODEL LOADER SERVICE -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License. -# ============LICENSE_END=========================================================
-###
-
-# Model Loader Distribution Client Configuration
-ml.distribution.ACTIVE_SERVER_TLS_AUTH=false
-ml.distribution.ASDC_ADDRESS=
-ml.distribution.CONSUMER_GROUP=aai-ml-group-test
-ml.distribution.CONSUMER_ID=aai-ml-id-test
-ml.distribution.ENVIRONMENT_NAME=
-ml.distribution.KEYSTORE_PASSWORD=
-ml.distribution.KEYSTORE_FILE=asdc-client.jks
-ml.distribution.PASSWORD=
-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
-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.KEYSTORE_FILE=aai-client-cert.p12
-ml.aai.KEYSTORE_PASSWORD=
-ml.aai.AUTH_USER=ModelLoader
-ml.aai.AUTH_PASSWORD=
+# Model Loader Distribution Client Configuration +ml.distribution.ACTIVE_SERVER_TLS_AUTH=false +ml.distribution.ASDC_ADDRESS= +ml.distribution.CONSUMER_GROUP=aai-ml-group-test +ml.distribution.CONSUMER_ID=aai-ml-id-test +ml.distribution.ENVIRONMENT_NAME= +ml.distribution.KEYSTORE_PASSWORD= +ml.distribution.KEYSTORE_FILE=asdc-client.jks +ml.distribution.PASSWORD= +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 +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.KEYSTORE_FILE=aai-client-cert.p12 +ml.aai.KEYSTORE_PASSWORD= +ml.aai.AUTH_USER=ModelLoader +ml.aai.AUTH_PASSWORD= diff --git a/src/test/resources/models/AAI-Testvsp..vmme_cinder..module-1-resource-1.xml b/src/test/resources/models/AAI-Testvsp..vmme_cinder..module-1-resource-1.xml index 7bd1073..6ec4fb3 100644 --- a/src/test/resources/models/AAI-Testvsp..vmme_cinder..module-1-resource-1.xml +++ b/src/test/resources/models/AAI-Testvsp..vmme_cinder..module-1-resource-1.xml @@ -1,52 +1,32 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>5a2aac99-ffe8-415f-9242-420ed10da23e</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>29d3fc43-4ff2-4e5c-acd0-7370f5b2715a</model-version-id>
- <model-name>Testvsp..vmme_cinder..module-1</model-name>
- <model-version>1</model-version>
- <model-description></model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>5a2aac99-ffe8-415f-9242-420ed10da23e</model-invariant-id> + <model-type>resource</model-type> + <model-vers> + <model-ver> + <model-version-id>29d3fc43-4ff2-4e5c-acd0-7370f5b2715a</model-version-id> + <model-name>Testvsp..vmme_cinder..module-1</model-name> + <model-version>1</model-version> + <model-description></model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/AAI-Testvsp..vmme_small_ecomp..module-0-resource-1.xml b/src/test/resources/models/AAI-Testvsp..vmme_small_ecomp..module-0-resource-1.xml index 8fe5319..ee436ba 100644 --- a/src/test/resources/models/AAI-Testvsp..vmme_small_ecomp..module-0-resource-1.xml +++ b/src/test/resources/models/AAI-Testvsp..vmme_small_ecomp..module-0-resource-1.xml @@ -1,180 +1,160 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>1e8fdfc0-03cf-4742-b060-dab818954d67</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>da6769f0-aa58-4e90-b2c9-664c2630d131</model-version-id>
- <model-name>Testvsp..vmme_small_ecomp..module-0</model-name>
- <model-version>1</model-version>
- <model-description></model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>f6a038c2-820c-42ba-8c2b-375e24e8f932</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3f4c7204-739b-4bbb-87a7-8a6856439c90</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>abcc54bc-bb74-49dc-9043-7f7171707545</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>97c26c99-6870-44c1-8a07-1d900d3f4ce6</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>36200fb5-f251-4f5d-a520-7c5ad5c2cd4b</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>bace8d1c-a261-4041-9e37-823117415d0f</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>a32613fd-18b9-459e-aab8-fffb3912966a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>cea0a982-8d55-4093-921e-418fbccf7060</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>5761e0a7-c6df-4d8a-9ebd-b8f445054dec</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>96129eb9-f0de-4e05-8af2-73146473f766</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>8ecb2c5d-7176-4317-a255-26274edfdd53</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>ff69d4e0-a8e8-4108-bdb0-dd63217e63c7</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>1e8fdfc0-03cf-4742-b060-dab818954d67</model-invariant-id> + <model-type>resource</model-type> + <model-vers> + <model-ver> + <model-version-id>da6769f0-aa58-4e90-b2c9-664c2630d131</model-version-id> + <model-name>Testvsp..vmme_small_ecomp..module-0</model-name> + <model-version>1</model-version> + <model-description></model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>f6a038c2-820c-42ba-8c2b-375e24e8f932</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>3f4c7204-739b-4bbb-87a7-8a6856439c90</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>abcc54bc-bb74-49dc-9043-7f7171707545</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>97c26c99-6870-44c1-8a07-1d900d3f4ce6</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>36200fb5-f251-4f5d-a520-7c5ad5c2cd4b</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>bace8d1c-a261-4041-9e37-823117415d0f</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>a32613fd-18b9-459e-aab8-fffb3912966a</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>cea0a982-8d55-4093-921e-418fbccf7060</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>5761e0a7-c6df-4d8a-9ebd-b8f445054dec</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>96129eb9-f0de-4e05-8af2-73146473f766</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>8ecb2c5d-7176-4317-a255-26274edfdd53</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>ff69d4e0-a8e8-4108-bdb0-dd63217e63c7</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/AAI-VL-resource-1.xml b/src/test/resources/models/AAI-VL-resource-1.xml index 98941ad..e80d4f3 100644 --- a/src/test/resources/models/AAI-VL-resource-1.xml +++ b/src/test/resources/models/AAI-VL-resource-1.xml @@ -1,52 +1,32 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>5c12984d-db0f-4300-a0e0-9791775cc40f</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>88bdbadf-db8a-490f-881e-c8effcbc3f66</model-version-id>
- <model-name>VL</model-name>
- <model-version>1</model-version>
- <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>5c12984d-db0f-4300-a0e0-9791775cc40f</model-invariant-id> + <model-type>resource</model-type> + <model-vers> + <model-ver> + <model-version-id>88bdbadf-db8a-490f-881e-c8effcbc3f66</model-version-id> + <model-name>VL</model-name> + <model-version>1</model-version> + <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/AAI-stellService-service-1.xml b/src/test/resources/models/AAI-stellService-service-1.xml index 378b09e..20cfd11 100644 --- a/src/test/resources/models/AAI-stellService-service-1.xml +++ b/src/test/resources/models/AAI-stellService-service-1.xml @@ -1,89 +1,69 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>fedf9da3-6a74-4813-8fa2-221a98b0e7ad</model-invariant-id>
- <model-type>service</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>e0373537-7f66-4094-9939-e2f5de6ff5f6</model-version-id>
- <model-name>stellService</model-name>
- <model-version>1</model-version>
- <model-description>fd</model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>88bdbadf-db8a-490f-881e-c8effcbc3f66</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>5c12984d-db0f-4300-a0e0-9791775cc40f</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>374d0899-bbc2-4403-9320-fe9bebef75c6</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>959b7c09-9f34-4e5f-8b63-505381db176e</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>46b92144-923a-4d20-b85a-3cbd847668a9</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>82194af1-3c2c-485a-8f44-420e22a9eaa4</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>fedf9da3-6a74-4813-8fa2-221a98b0e7ad</model-invariant-id> + <model-type>service</model-type> + <model-vers> + <model-ver> + <model-version-id>e0373537-7f66-4094-9939-e2f5de6ff5f6</model-version-id> + <model-name>stellService</model-name> + <model-version>1</model-version> + <model-description>fd</model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>88bdbadf-db8a-490f-881e-c8effcbc3f66</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>5c12984d-db0f-4300-a0e0-9791775cc40f</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>374d0899-bbc2-4403-9320-fe9bebef75c6</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>959b7c09-9f34-4e5f-8b63-505381db176e</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>46b92144-923a-4d20-b85a-3cbd847668a9</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>82194af1-3c2c-485a-8f44-420e22a9eaa4</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/AAI-testvsp-resource-1.xml b/src/test/resources/models/AAI-testvsp-resource-1.xml index c9a70ff..bafecfb 100644 --- a/src/test/resources/models/AAI-testvsp-resource-1.xml +++ b/src/test/resources/models/AAI-testvsp-resource-1.xml @@ -1,89 +1,69 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>959b7c09-9f34-4e5f-8b63-505381db176e</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>374d0899-bbc2-4403-9320-fe9bebef75c6</model-version-id>
- <model-name>testvsp</model-name>
- <model-version>1</model-version>
- <model-description>nkjlkl</model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>da6769f0-aa58-4e90-b2c9-664c2630d131</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>1e8fdfc0-03cf-4742-b060-dab818954d67</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>29d3fc43-4ff2-4e5c-acd0-7370f5b2715a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>5a2aac99-ffe8-415f-9242-420ed10da23e</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>93a6166f-b3d5-4f06-b4ba-aed48d009ad9</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>acc6edd8-a8d4-4b93-afaa-0994068be14c</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>959b7c09-9f34-4e5f-8b63-505381db176e</model-invariant-id> + <model-type>resource</model-type> + <model-vers> + <model-ver> + <model-version-id>374d0899-bbc2-4403-9320-fe9bebef75c6</model-version-id> + <model-name>testvsp</model-name> + <model-version>1</model-version> + <model-description>nkjlkl</model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>da6769f0-aa58-4e90-b2c9-664c2630d131</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>1e8fdfc0-03cf-4742-b060-dab818954d67</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>29d3fc43-4ff2-4e5c-acd0-7370f5b2715a</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>5a2aac99-ffe8-415f-9242-420ed10da23e</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>93a6166f-b3d5-4f06-b4ba-aed48d009ad9</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>acc6edd8-a8d4-4b93-afaa-0994068be14c</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/complete-model.xml b/src/test/resources/models/complete-model.xml deleted file mode 100644 index 394c073..0000000 --- a/src/test/resources/models/complete-model.xml +++ /dev/null @@ -1,384 +0,0 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<models xmlns="http://org.openecomp.aai.inventory/v9">
- <model>
- <model-invariant-id>5c12984d-db0f-4300-a0e0-9791775cc40f</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>88bdbadf-db8a-490f-881e-c8effcbc3f66</model-version-id>
- <model-name>VL</model-name>
- <model-version>1</model-version>
- <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
-<model>
- <model-invariant-id>1e8fdfc0-03cf-4742-b060-dab818954d67</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>da6769f0-aa58-4e90-b2c9-664c2630d131</model-version-id>
- <model-name>Testvsp..vmme_small_ecomp..module-0</model-name>
- <model-version>1</model-version>
- <model-description></model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>f6a038c2-820c-42ba-8c2b-375e24e8f932</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3f4c7204-739b-4bbb-87a7-8a6856439c90</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>abcc54bc-bb74-49dc-9043-7f7171707545</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>97c26c99-6870-44c1-8a07-1d900d3f4ce6</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>36200fb5-f251-4f5d-a520-7c5ad5c2cd4b</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>bace8d1c-a261-4041-9e37-823117415d0f</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>a32613fd-18b9-459e-aab8-fffb3912966a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>cea0a982-8d55-4093-921e-418fbccf7060</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>5761e0a7-c6df-4d8a-9ebd-b8f445054dec</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>96129eb9-f0de-4e05-8af2-73146473f766</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>8ecb2c5d-7176-4317-a255-26274edfdd53</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>ff69d4e0-a8e8-4108-bdb0-dd63217e63c7</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
-<model>
- <model-invariant-id>5a2aac99-ffe8-415f-9242-420ed10da23e</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>29d3fc43-4ff2-4e5c-acd0-7370f5b2715a</model-version-id>
- <model-name>Testvsp..vmme_cinder..module-1</model-name>
- <model-version>1</model-version>
- <model-description></model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>c00563ae-812b-4e62-8330-7c4d0f47088a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>ef86f9c5-2165-44f3-8fc3-96018b609ea5</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
-<model>
- <model-invariant-id>959b7c09-9f34-4e5f-8b63-505381db176e</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>374d0899-bbc2-4403-9320-fe9bebef75c6</model-version-id>
- <model-name>testvsp</model-name>
- <model-version>1</model-version>
- <model-description>nkjlkl</model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>da6769f0-aa58-4e90-b2c9-664c2630d131</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>1e8fdfc0-03cf-4742-b060-dab818954d67</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>29d3fc43-4ff2-4e5c-acd0-7370f5b2715a</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>5a2aac99-ffe8-415f-9242-420ed10da23e</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>93a6166f-b3d5-4f06-b4ba-aed48d009ad9</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>acc6edd8-a8d4-4b93-afaa-0994068be14c</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
-<model>
- <model-invariant-id>fedf9da3-6a74-4813-8fa2-221a98b0e7ad</model-invariant-id>
- <model-type>service</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>e0373537-7f66-4094-9939-e2f5de6ff5f6</model-version-id>
- <model-name>stellService</model-name>
- <model-version>1</model-version>
- <model-description>fd</model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>88bdbadf-db8a-490f-881e-c8effcbc3f66</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>5c12984d-db0f-4300-a0e0-9791775cc40f</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>374d0899-bbc2-4403-9320-fe9bebef75c6</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>959b7c09-9f34-4e5f-8b63-505381db176e</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>46b92144-923a-4d20-b85a-3cbd847668a9</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>82194af1-3c2c-485a-8f44-420e22a9eaa4</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
- </model>
-</models>
diff --git a/src/test/resources/models/incomplete-model.xml b/src/test/resources/models/incomplete-model.xml index b30d4d7..5bc0581 100644 --- a/src/test/resources/models/incomplete-model.xml +++ b/src/test/resources/models/incomplete-model.xml @@ -1,37 +1,17 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-name>VL</model-name>
- <model-version>1</model-version>
- <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-type>resource</model-type> + <model-vers> + <model-ver> + <model-name>VL</model-name> + <model-version>1</model-version> + <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + </model-element> + </model-elements> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/incomplete-models.xml b/src/test/resources/models/incomplete-models.xml deleted file mode 100644 index 56b10de..0000000 --- a/src/test/resources/models/incomplete-models.xml +++ /dev/null @@ -1,50 +0,0 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<models xmlns="http://org.openecomp.aai.inventory/v9">
-<model>
- <model-invariant-id>3d560d81-57d0-438b-a2a1-5334dba0651a</model-invariant-id>
- <model-type>widget</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>9111f20f-e680-4001-b83f-19a2fc23bfc1</model-version-id>
- <model-version>1.0</model-version>
- <model-name>l3-network</model-name>
- </model-ver>
- </model-vers>
-</model>
-<model>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-name>VL</model-name>
- <model-version>1</model-version>
- <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
-</model>
-</models>
diff --git a/src/test/resources/models/invalid-model.xml b/src/test/resources/models/invalid-model.xml index 906cd21..865f5d3 100644 --- a/src/test/resources/models/invalid-model.xml +++ b/src/test/resources/models/invalid-model.xml @@ -1,51 +1,31 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>5c12984d-db0f-4300-a0e0-9791775cc40f</model-invariant-id>
- <model-type>resource</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>88bdbadf-db8a-490f-881e-c8effcbc3f66</model-version-id>
- <model-name>VL</model-name>
- <model-version>1</model-version>
- <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description>
- <model-elements>
- <model-element>
- <new-data-del-flag>F</new-data-del-flag>
- <cardinality>unbounded</cardinality>
- <model-elements/>
- <relationship-list>
- <relationship>
- <related-to>model-ver</related-to>
- <relationship-data>
- <relationship-key>model-ver.model-version-id</relationship-key>
- <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value>
- </relationship-data>
- <relationship-data>
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </model-element>
- </model-elements>
- </model-ver>
- </model-vers>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>5c12984d-db0f-4300-a0e0-9791775cc40f</model-invariant-id> + <model-type>resource</model-type> + <model-vers> + <model-ver> + <model-version-id>88bdbadf-db8a-490f-881e-c8effcbc3f66</model-version-id> + <model-name>VL</model-name> + <model-version>1</model-version> + <model-description> Virtual link (VL) describes the basic topology of the connectivity as well as other required parameters (e.g. bandwidth and QoS class). </model-description> + <model-elements> + <model-element> + <new-data-del-flag>F</new-data-del-flag> + <cardinality>unbounded</cardinality> + <model-elements/> + <relationship-list> + <relationship> + <related-to>model-ver</related-to> + <relationship-data> + <relationship-key>model-ver.model-version-id</relationship-key> + <relationship-value>9111f20f-e680-4001-b83f-19a2fc23bfc1</relationship-value> + </relationship-data> + <relationship-data> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>3d560d81-57d0-438b-a2a1-5334dba0651a</relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </model-ver> + </model-vers> diff --git a/src/test/resources/models/l3-network-widget.xml b/src/test/resources/models/l3-network-widget.xml index 1e50300..1d0240b 100644 --- a/src/test/resources/models/l3-network-widget.xml +++ b/src/test/resources/models/l3-network-widget.xml @@ -1,31 +1,11 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<model xmlns="http://org.openecomp.aai.inventory/v9">
- <model-invariant-id>3d560d81-57d0-438b-a2a1-5334dba0651a</model-invariant-id>
- <model-type>widget</model-type>
- <model-vers>
- <model-ver>
- <model-version-id>9111f20f-e680-4001-b83f-19a2fc23bfc1</model-version-id>
- <model-version>1.0</model-version>
- <model-name>l3-network</model-name>
- </model-ver>
- </model-vers>
-</model>
+<model xmlns="http://org.openecomp.aai.inventory/v9"> + <model-invariant-id>3d560d81-57d0-438b-a2a1-5334dba0651a</model-invariant-id> + <model-type>widget</model-type> + <model-vers> + <model-ver> + <model-version-id>9111f20f-e680-4001-b83f-19a2fc23bfc1</model-version-id> + <model-version>1.0</model-version> + <model-name>l3-network</model-name> + </model-ver> + </model-vers> +</model>
\ No newline at end of file diff --git a/src/test/resources/models/named-query-wan-connector.xml b/src/test/resources/models/named-query-wan-connector.xml index 51047df..55d8fda 100644 --- a/src/test/resources/models/named-query-wan-connector.xml +++ b/src/test/resources/models/named-query-wan-connector.xml @@ -1,90 +1,70 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<named-query xmlns="http://org.openecomp.aai.inventory/v7">
- <named-query-uuid>94cac189-8d88-4d63-a194-f44214e080ff
- </named-query-uuid>
- <named-query-name>wan-connector</named-query-name>
- <named-query-version>v1.0</named-query-version>
- <description>Named Query - Wan Connector</description>
- <named-query-elements>
- <named-query-element>
- <relationship-list>
- <relationship>
- <related-to>model</related-to>
- <relationship-data>
- <!-- connector -->
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>d09dd9da-0148-46cd-a947-591afc844d24
- </relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- <named-query-elements>
- <named-query-element>
- <relationship-list>
- <relationship>
- <related-to>model</related-to>
- <relationship-data>
- <!-- vdc -->
- <relationship-key>model.model-invariant-id</relationship-key>
- <relationship-value>997fc7-fca1-451f-b953-9a1e6197b4d6
- </relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- <named-query-elements>
- <named-query-element>
- <relationship-list>
- <relationship>
- <related-to>model</related-to>
- <relationship-data>
- <!-- logical-link -->
- <relationship-key>model.model-invariant-id
- </relationship-key>
- <relationship-value>897df7ea-8938-42b0-bc57-46e913a4d93b
- </relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- <named-query-elements>
- <named-query-element>
- <relationship-list>
- <relationship>
- <related-to>model</related-to>
- <relationship-data>
- <!-- pserver -->
- <relationship-key>model.model-invariant-id
- </relationship-key>
- <relationship-value>f2b24d95-c582-48d5-b2d6-c5b3a94ce812
- </relationship-value>
- </relationship-data>
- </relationship>
- </relationship-list>
- </named-query-element>
- </named-query-elements>
- </named-query-element>
- </named-query-elements>
- </named-query-element>
- </named-query-elements>
- </named-query-element>
- </named-query-elements>
-</named-query>
-
+<named-query xmlns="http://org.openecomp.aai.inventory/v7"> + <named-query-uuid>94cac189-8d88-4d63-a194-f44214e080ff + </named-query-uuid> + <named-query-name>wan-connector</named-query-name> + <named-query-version>v1.0</named-query-version> + <description>Named Query - Wan Connector</description> + <named-query-elements> + <named-query-element> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- connector --> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>d09dd9da-0148-46cd-a947-591afc844d24 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <named-query-elements> + <named-query-element> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- vdc --> + <relationship-key>model.model-invariant-id</relationship-key> + <relationship-value>997fc7-fca1-451f-b953-9a1e6197b4d6 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <named-query-elements> + <named-query-element> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- logical-link --> + <relationship-key>model.model-invariant-id + </relationship-key> + <relationship-value>897df7ea-8938-42b0-bc57-46e913a4d93b + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <named-query-elements> + <named-query-element> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- pserver --> + <relationship-key>model.model-invariant-id + </relationship-key> + <relationship-value>f2b24d95-c582-48d5-b2d6-c5b3a94ce812 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </named-query-element> + </named-query-elements> + </named-query-element> + </named-query-elements> + </named-query-element> + </named-query-elements> + </named-query-element> + </named-query-elements> +</named-query> + diff --git a/src/test/resources/models/v8-wan-connector-model.xml b/src/test/resources/models/v8-wan-connector-model.xml new file mode 100644 index 0000000..09f1933 --- /dev/null +++ b/src/test/resources/models/v8-wan-connector-model.xml @@ -0,0 +1,165 @@ +<model xmlns="http://com.att.aai.inventory/v7"> + <model-id>e4a9901b-6c94-4e07-b8d8-b877d3df554c</model-id> + <model-type>service</model-type> + <model-name>wan-connector</model-name> + <model-version>v1.0</model-version> + <model-name-version-id>93d9d45d-7eec-4371-9083-675e4c353de3 + </model-name-version-id> + <model-description>Connects a customer vpn to the border elements of an + AT&T product</model-description> + <metadata> + <metadatum> + <metaname>a</metaname> + <metaval>vpn-id</metaval> + </metadatum> + <metadatum> + <metaname>b</metaname> + <metaval>product</metaval> + </metadatum> + </metadata> + <model-elements> + <model-element> + <new-data-del-flag>true</new-data-del-flag> + <cardinality>unbounded</cardinality> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- connector --> + <relationship-key>model.model-name-version-id</relationship-key> + <relationship-value>d09dd9da-0148-46cd-a947-591afc844d24 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <model-elements> + <model-element> + <new-data-del-flag>true</new-data-del-flag> + <cardinality>unbounded</cardinality> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- vdc --> + <relationship-key>model.model-name-version-id</relationship-key> + <relationship-value>997fc7-fca1-451f-b953-9a1e6197b4d6 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <model-elements> + <model-element> + <new-data-del-flag>true</new-data-del-flag> + <cardinality>unbounded</cardinality> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- l2-bridge-for-wan-connector --> + <relationship-key>model.model-name-version-id + </relationship-key> + <relationship-value>ae16244f-4d29-4801-a559-e25f2db2a4c3 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <model-constraint> + <constrained-element-sets> + <constrained-element-set> + <path>logical-link</path> + <constrained-element-set-uuid>999 + </constrained-element-set-uuid> + <constraint-type>combination</constraint-type> + <check-type>AND</check-type> + <element-choice-sets> + <element-choice-set> + <element-choice-set-name>A</element-choice-set-name> + <cardinality>1</cardinality> + <model-elements> + <model-element> + <cardinality>unbounded</cardinality> + <new-data-del-flag>false</new-data-del-flag> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- ipe --> + <relationship-key>model.model-name-version-id + </relationship-key> + <relationship-value>759dbd4a-2473-46f3-a932-48d987c9b4a1 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + <linkage-points> + <linkage-point>l-interface|p-interface|pserver + </linkage-point> + </linkage-points> + </model-element> + </model-elements> + </element-choice-set> + <element-choice-set> + <element-choice-set-name>B</element-choice-set-name> + <cardinality>1</cardinality> + <model-elements> + <model-element> + <cardinality>unbounded</cardinality> + <new-data-del-flag>false</new-data-del-flag> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- vDbe --> + <relationship-key>model.model-name-version-id + </relationship-key> + <relationship-value>8da97b81-e0e9-4157-a4cd-af3ba52871d6 + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <cardinality>unbounded</cardinality> + <new-data-del-flag>false</new-data-del-flag> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- vSbg --> + <relationship-key>model.model-name-version-id + </relationship-key> + <relationship-value>a6d9de88-4046-4b78-a59e-5691243d292a + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + <model-element> + <cardinality>unbounded</cardinality> + <new-data-del-flag>false</new-data-del-flag> + <relationship-list> + <relationship> + <related-to>model</related-to> + <relationship-data> + <!-- pBgf --> + <relationship-key>model.model-name-version-id + </relationship-key> + <relationship-value>35be1acf-1298-48c6-a128-66850083b8bd + </relationship-value> + </relationship-data> + </relationship> + </relationship-list> + </model-element> + </model-elements> + </element-choice-set> + </element-choice-sets> + </constrained-element-set> + </constrained-element-sets> + </model-constraint> + </model-element> + </model-elements> + </model-element> + </model-elements> + </model-element> + </model-elements> +</model> diff --git a/src/test/resources/vnfcatalogexample.xml b/src/test/resources/vnfcatalogexample.xml index 0348f71..c38b411 100644 --- a/src/test/resources/vnfcatalogexample.xml +++ b/src/test/resources/vnfcatalogexample.xml @@ -1,149 +1,129 @@ -<!--
- ============LICENSE_START======================================================= - MODEL LOADER SERVICE - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. - ============LICENSE_END=========================================================
- -->
-
-<vnf-catalog>
- <part-number-list>
- <part-number>FortiGate-VM00</part-number>
- <vnf-type>FW</vnf-type>
- <vendor-info>
- <vendor-name>FORTINET</vendor-name>
- <vendor-part-number>FortiGate-VM00</vendor-part-number>
- <vendor-model>VM00</vendor-model>
- </vendor-info>
- <vcpu>
- <vcpu-default>1</vcpu-default>
- <vcpu-min>1</vcpu-min>
- <vcpu-max>1</vcpu-max>
- </vcpu>
- <vmemory>
- <vmemory-default>1</vmemory-default>
- <vmemory-units>GB</vmemory-units>
- <vmemory-min>1</vmemory-min>
- <vmemory-max>1</vmemory-max>
- </vmemory>
- <vdisk>
- <vdisk-default>2</vdisk-default>
- <vdisk-units>GB</vdisk-units>
- <vdisk-min>2</vdisk-min>
- <vdisk-max>32</vdisk-max>
- </vdisk>
- <software-version-list>
- <software-version>5.2.7</software-version>
- <software-version-state>0</software-version-state>
- <software-filetype>IMAGE</software-filetype>
- <file-md5-value>1c59a521885c465004456f74d003726c</file-md5-value>
- <software-filename>test3</software-filename>
- </software-version-list>
- <software-version-list>
- <software-version>5.2.5</software-version>
- <software-version-state>1</software-version-state>
- <software-filetype>IMAGE</software-filetype>
- <file-md5-value>C4D2CBE51669796E48623E006782F7DC</file-md5-value>
- <software-filename>test2</software-filename>
- </software-version-list>
- <software-version-list>
- <software-version>5.2.4</software-version>
- <software-version-state>2</software-version-state>
- <software-filetype>IMAGE</software-filetype>
- <file-md5-value>4987E1E743FD641C879E1D3C5D50BCE0</file-md5-value>
- <software-filename>test1</software-filename>
- </software-version-list>
- <vnf-features-list>
- <vnf-feature>APPID</vnf-feature>
- </vnf-features-list>
- <vnf-features-list>
- <vnf-feature>IPS-IDS</vnf-feature>
- </vnf-features-list>
- <vnf-features-list>
- <vnf-feature>URLF</vnf-feature>
- </vnf-features-list>
- <vnf-features-list>
- <vnf-feature>Anti-Virus</vnf-feature>
- </vnf-features-list>
- <license-list>
- <license-assignment-group>FortiGate-VM00</license-assignment-group>
- <license-required>FALSE</license-required>
- </license-list>
- </part-number-list>
- <part-number-list>
- <part-number>FortiGate-VM01</part-number>
- <vnf-type>FW</vnf-type>
- <vendor-info>
- <vendor-name>FORTINET</vendor-name>
- <vendor-part-number>FortiGate-VM01</vendor-part-number>
- <vendor-model>VM01</vendor-model>
- </vendor-info>
- <vcpu>
- <vcpu-default>1</vcpu-default>
- <vcpu-min>1</vcpu-min>
- <vcpu-max>1</vcpu-max>
- </vcpu>
- <vmemory>
- <vmemory-default>2</vmemory-default>
- <vmemory-units>GB</vmemory-units>
- <vmemory-min>1</vmemory-min>
- <vmemory-max>2</vmemory-max>
- </vmemory>
- <vdisk>
- <vdisk-default>2</vdisk-default>
- <vdisk-units>GB</vdisk-units>
- <vdisk-min>2</vdisk-min>
- <vdisk-max>32</vdisk-max>
- </vdisk>
- <software-version-list>
- <software-version>5.2.7</software-version>
- <software-version-state>0</software-version-state>
- <software-filetype>IMAGE</software-filetype>
- <file-md5-value>1c59a521885c465004456f74d003726c</file-md5-value>
- <software-filename>software file name 3</software-filename>
- </software-version-list>
- <software-version-list>
- <software-version>5.2.5</software-version>
- <software-version-state>1</software-version-state>
- <software-filetype>IMAGE</software-filetype>
- <file-md5-value>C4D2CBE51669796E48623E006782F7DC</file-md5-value>
- <software-filename>software file name 2</software-filename>
- </software-version-list>
- <software-version-list>
- <software-version>5.2.4</software-version>
- <software-version-state>2</software-version-state>
- <software-filetype>IMAGE</software-filetype>
- <file-md5-value>4987E1E743FD641C879E1D3C5D50BCE0</file-md5-value>
- <software-filename>software file name</software-filename>
- </software-version-list>
- <vnf-features-list>
- <vnf-feature>APPID</vnf-feature>
- </vnf-features-list>
- <vnf-features-list>
- <vnf-feature>IPS-IDS</vnf-feature>
- </vnf-features-list>
- <vnf-features-list>
- <vnf-feature>URLF</vnf-feature>
- </vnf-features-list>
- <vnf-features-list>
- <vnf-feature>Anti-Virus</vnf-feature>
- </vnf-features-list>
- <license-list>
- <license-assignment-group>license group</license-assignment-group>
- <license-required>FALSE</license-required>
- </license-list>
- </part-number-list>
-
-</vnf-catalog>
+<vnf-catalog> + <part-number-list> + <part-number>FortiGate-VM00</part-number> + <vnf-type>FW</vnf-type> + <vendor-info> + <vendor-name>FORTINET</vendor-name> + <vendor-part-number>FortiGate-VM00</vendor-part-number> + <vendor-model>VM00</vendor-model> + </vendor-info> + <vcpu> + <vcpu-default>1</vcpu-default> + <vcpu-min>1</vcpu-min> + <vcpu-max>1</vcpu-max> + </vcpu> + <vmemory> + <vmemory-default>1</vmemory-default> + <vmemory-units>GB</vmemory-units> + <vmemory-min>1</vmemory-min> + <vmemory-max>1</vmemory-max> + </vmemory> + <vdisk> + <vdisk-default>2</vdisk-default> + <vdisk-units>GB</vdisk-units> + <vdisk-min>2</vdisk-min> + <vdisk-max>32</vdisk-max> + </vdisk> + <software-version-list> + <software-version>5.2.7</software-version> + <software-version-state>0</software-version-state> + <software-filetype>IMAGE</software-filetype> + <file-md5-value>1c59a521885c465004456f74d003726c</file-md5-value> + <software-filename>test3</software-filename> + </software-version-list> + <software-version-list> + <software-version>5.2.5</software-version> + <software-version-state>1</software-version-state> + <software-filetype>IMAGE</software-filetype> + <file-md5-value>C4D2CBE51669796E48623E006782F7DC</file-md5-value> + <software-filename>test2</software-filename> + </software-version-list> + <software-version-list> + <software-version>5.2.4</software-version> + <software-version-state>2</software-version-state> + <software-filetype>IMAGE</software-filetype> + <file-md5-value>4987E1E743FD641C879E1D3C5D50BCE0</file-md5-value> + <software-filename>test1</software-filename> + </software-version-list> + <vnf-features-list> + <vnf-feature>APPID</vnf-feature> + </vnf-features-list> + <vnf-features-list> + <vnf-feature>IPS-IDS</vnf-feature> + </vnf-features-list> + <vnf-features-list> + <vnf-feature>URLF</vnf-feature> + </vnf-features-list> + <vnf-features-list> + <vnf-feature>Anti-Virus</vnf-feature> + </vnf-features-list> + <license-list> + <license-assignment-group>FortiGate-VM00</license-assignment-group> + <license-required>FALSE</license-required> + </license-list> + </part-number-list> + <part-number-list> + <part-number>FortiGate-VM01</part-number> + <vnf-type>FW</vnf-type> + <vendor-info> + <vendor-name>FORTINET</vendor-name> + <vendor-part-number>FortiGate-VM01</vendor-part-number> + <vendor-model>VM01</vendor-model> + </vendor-info> + <vcpu> + <vcpu-default>1</vcpu-default> + <vcpu-min>1</vcpu-min> + <vcpu-max>1</vcpu-max> + </vcpu> + <vmemory> + <vmemory-default>2</vmemory-default> + <vmemory-units>GB</vmemory-units> + <vmemory-min>1</vmemory-min> + <vmemory-max>2</vmemory-max> + </vmemory> + <vdisk> + <vdisk-default>2</vdisk-default> + <vdisk-units>GB</vdisk-units> + <vdisk-min>2</vdisk-min> + <vdisk-max>32</vdisk-max> + </vdisk> + <software-version-list> + <software-version>5.2.7</software-version> + <software-version-state>0</software-version-state> + <software-filetype>IMAGE</software-filetype> + <file-md5-value>1c59a521885c465004456f74d003726c</file-md5-value> + <software-filename>software file name 3</software-filename> + </software-version-list> + <software-version-list> + <software-version>5.2.5</software-version> + <software-version-state>1</software-version-state> + <software-filetype>IMAGE</software-filetype> + <file-md5-value>C4D2CBE51669796E48623E006782F7DC</file-md5-value> + <software-filename>software file name 2</software-filename> + </software-version-list> + <software-version-list> + <software-version>5.2.4</software-version> + <software-version-state>2</software-version-state> + <software-filetype>IMAGE</software-filetype> + <file-md5-value>4987E1E743FD641C879E1D3C5D50BCE0</file-md5-value> + <software-filename>software file name</software-filename> + </software-version-list> + <vnf-features-list> + <vnf-feature>APPID</vnf-feature> + </vnf-features-list> + <vnf-features-list> + <vnf-feature>IPS-IDS</vnf-feature> + </vnf-features-list> + <vnf-features-list> + <vnf-feature>URLF</vnf-feature> + </vnf-features-list> + <vnf-features-list> + <vnf-feature>Anti-Virus</vnf-feature> + </vnf-features-list> + <license-list> + <license-assignment-group>license group</license-assignment-group> + <license-required>FALSE</license-required> + </license-list> + </part-number-list> + +</vnf-catalog> |