diff options
author | ChrisC <cc697w@intl.att.com> | 2017-01-31 11:40:03 +0100 |
---|---|---|
committer | ChrisC <cc697w@intl.att.com> | 2017-01-31 12:59:33 +0100 |
commit | 025301d08b061482c1f046d562bf017c8cbcfe8d (patch) | |
tree | 68a2a549736c9bf0f7cd4e71c76e40ef7e2606f2 /asdc-controller/src/main/java/org/openecomp/mso/asdc/installer | |
parent | 2754ad52f833278a5c925bd788a16d1dce16a598 (diff) |
Initial OpenECOMP MSO commit
Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d
Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'asdc-controller/src/main/java/org/openecomp/mso/asdc/installer')
8 files changed, 1291 insertions, 0 deletions
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/ASDCElementInfo.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/ASDCElementInfo.java new file mode 100644 index 0000000000..5e59be526f --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/ASDCElementInfo.java @@ -0,0 +1,212 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.IResourceInstance; +import org.openecomp.sdc.api.notification.IVfModuleMetadata; +import org.openecomp.mso.asdc.client.ASDCConfiguration; + +/** + * A class representing a generic element whose information can be used for example to log artifacts, resource... data. + */ +public class ASDCElementInfo { + + /** + * A default, empty instance used in case a source element was not correctly provided. + */ + public static final ASDCElementInfo EMPTY_INSTANCE = new ASDCElementInfo(); + + /** + * Used to define the other possible ASDC Element types (usually in addition to existing artifact types, etc.).<br/> + * <br/> + * Possible types allowed:<br/> + * <ul> + * <li>{@link ASDCElementTypeEnum#VNF_RESOURCE}</li> + * <ul> + */ + public static enum ASDCElementTypeEnum { + /** + * The type VNF_RESOURCE. Represents a VNF_RESOURCE element. + */ + VNF_RESOURCE + }; + + /** + * The map of element information fields useful for logging. The complete contents of this list will be concatenated. + */ + private final Map<String, String> elementInfoMap = new HashMap<>(); + + /** + * The type of this element. + */ + private final String type; + + private ASDCElementInfo () { + // Private parameterless constructor. Not visible, only used for EMPTY_INSTANCE. + this.type = ""; + } + + /** + * Artifact-type based constructor. Requires a valid artifact type. + * @param artifactType The artifact type + */ + private ASDCElementInfo (String artifactType) { + // We need the exact type name here... + this.type = artifactType; + } + + /** + * 'Other element type'-based constructor. Requires a valid element type. + * @param elementType An ASDCElementTypeEnum entry. This will usually contain enumerated types not in the existing + */ + private ASDCElementInfo (ASDCElementTypeEnum elementType) { + // We need the exact type name here... + this.type = elementType.name(); + } + + /** + * Add an information entry (name, UUID, etc.) from an artifact/resource/..., once a at time. + * + * @param key The key (name) of the information entry (Artifact UUID, Resource Name, etc.) + * @param value The value bound to the information entry. + */ + public final void addElementInfo(String key, String value) { + if ((key != null) && (value != null)) { + this.getElementInfoMap().put(key, value); + } + } + + /** + * Returns an aggregated, formatted list of the expected details about an ASDC element. + * (non-Javadoc) + * @return An aggregated list of element information entries, comma-separated. + * @see java.lang.Object#toString() + */ + @Override + public final String toString() { + StringBuffer sb = new StringBuffer(); + List<String> aggregatedElements = new ArrayList<>(); + for (Entry<String, String> entry : this.getElementInfoMap().entrySet()) { + aggregatedElements.add(entry.getKey() + ": " + entry.getValue()); + } + sb.append(aggregatedElements.size() > 0 ? aggregatedElements.get(0) : ""); + if (aggregatedElements.size() > 1) { + for (int i = 1; i < aggregatedElements.size(); ++i) { + sb.append (", "); + sb.append(aggregatedElements.get(i)); + } + } + return sb.toString(); + } + + /** + * The type that was defined at creation time. This is typically VNF_RESOURCE, VF_MODULE_METADATA, HEAT_ENV, etc. + * @return The type of this element information type. This will usually be either an ArtifactTypeEnum entry name or an ASDCElementTypeEnum entry name. + * @see ASDCElementInfo.ASDCElementTypeEnum + */ + public String getType() { + return type; + } + + /** + * Provides the map of all element information entries for this type. + * @return A map of all element information entries which will be used by the toString() method. + * @see ASDCElementInfo#toString() + */ + protected Map<String, String> getElementInfoMap() { + return elementInfoMap; + } + + /** + * Create an ASDCElementInfo object from a VNF Resource.<br/> + * <br/> + * <b>Used information:</b><br/> + * <ul> + * <li>Resource Instance Name</li> + * <li>Resource Instance UUID</li> + * </ul> + * + * @param vfResourceStructure The VfResourceStructure to use as source of information (see {@link VfResourceStructure}). + * @return an ASDCElementInfo using the information held in the VNF Resource. + */ + public static final ASDCElementInfo createElementFromVfResourceStructure (VfResourceStructure vfResourceStructure) { + if (vfResourceStructure == null) { + return EMPTY_INSTANCE; + } + ASDCElementInfo elementInfo = new ASDCElementInfo(ASDCElementTypeEnum.VNF_RESOURCE); + IResourceInstance resourceInstance = vfResourceStructure.getResourceInstance(); + elementInfo.addElementInfo("Resource Instance Name", resourceInstance.getResourceInstanceName()); + elementInfo.addElementInfo("Resource Instance Invariant UUID", resourceInstance.getResourceInvariantUUID()); + return elementInfo; + } + + /** + * Create an ASDCElementInfo object from a VF Module.<br/> + * <br/> + * <b>Used information:</b><br/> + * <ul> + * <li>Module Model Name</li> + * <li>Module Model UUID</li> + * </ul> + * + * @param vfModuleStructure The VfModuleStructure to use as source of information (see {@link VfModuleStructure}). + * @return an ASDCElementInfo using the information held in the VF Module. + */ + public static final ASDCElementInfo createElementFromVfModuleStructure (VfModuleStructure vfModuleStructure) { + if (vfModuleStructure == null) { + return EMPTY_INSTANCE; + } + ASDCElementInfo elementInfo = new ASDCElementInfo(ASDCConfiguration.VF_MODULES_METADATA); + IVfModuleMetadata moduleMetadata = vfModuleStructure.getVfModuleMetadata(); + elementInfo.addElementInfo("Module Model Name", moduleMetadata.getVfModuleModelName()); + elementInfo.addElementInfo("Module Model Invariant UUID", moduleMetadata.getVfModuleModelInvariantUUID()); + return elementInfo; + } + + /** + * Create an ASDCElementInfo object from an IArtfiactInfo instance.<br/> + * <br/> + * <b>Used information:</b><br/> + * <ul> + * <li>IArtifactInfo Name</li> + * <li>IArtifactInfo UUID</li> + * </ul> + * + * @param artifactInfo The VfModuleStructure to use as source of information (see {@link IArtifactInfo}). + * @return an ASDCElementInfo using the information held in the IArtifactInfo instance. + */ + public static final ASDCElementInfo createElementFromVfArtifactInfo (IArtifactInfo artifactInfo) { + if (artifactInfo == null) { + return EMPTY_INSTANCE; + } + ASDCElementInfo elementInfo = new ASDCElementInfo(artifactInfo.getArtifactType()); + elementInfo.addElementInfo(elementInfo.getType() + " Name", artifactInfo.getArtifactName()); + elementInfo.addElementInfo(elementInfo.getType() + " UUID", artifactInfo.getArtifactUUID()); + return elementInfo; + } +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/BigDecimalVersion.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/BigDecimalVersion.java new file mode 100644 index 0000000000..a0932ed3b6 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/BigDecimalVersion.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + + +import java.math.BigDecimal; + +public class BigDecimalVersion { + + /** + * This method truncates and convert the version String provided in the notification. + * + * @param version The version to check + * @return A BigDecimal value checked and truncated + */ + public static BigDecimal castAndCheckNotificationVersion(String version) { + // Truncate the version if bad type + String[] splitVersion = version.split("\\."); + StringBuffer newVersion = new StringBuffer(); + if (splitVersion.length > 1) { + newVersion.append(splitVersion[0]); + newVersion.append("."); + newVersion.append(splitVersion[1]); + } else { + return new BigDecimal(splitVersion[0]); + } + + for (int i=2;i<splitVersion.length;i++) { + newVersion.append(splitVersion[i]); + } + + return new BigDecimal(newVersion.toString()); + } + + /** + * This method truncates and convert the version String provided in the notification. + * + * @param version The version to check + * @return A String value checked and truncated to Decimal format + */ + public static String castAndCheckNotificationVersionToString (String version) { + return castAndCheckNotificationVersion(version).toString(); + } +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/IArtifactOrchestrator.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/IArtifactOrchestrator.java new file mode 100644 index 0000000000..25c3b9c6a7 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/IArtifactOrchestrator.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + + + +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.mso.asdc.client.exceptions.ArtifactInstallerException; + +public interface IArtifactOrchestrator { + + void installTheArtifact (INotificationData iNotif, IResourceInstance resource, IArtifactInfo artifact, IDistributionClientDownloadResult downloadResult) throws ArtifactInstallerException; + + boolean isArtifactAlreadyDeployed (INotificationData iNotif,IResourceInstance resource,IArtifactInfo artifact) throws ArtifactInstallerException; + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/IVfResourceInstaller.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/IVfResourceInstaller.java new file mode 100644 index 0000000000..5f0f9305eb --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/IVfResourceInstaller.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + + + +import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException; + +public interface IVfResourceInstaller { + + boolean isResourceAlreadyDeployed (VfResourceStructure vfResourceStructure) throws ArtifactInstallerException; + + public void installTheResource (VfResourceStructure vfResourceStructure) throws ArtifactInstallerException; +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfModuleArtifact.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfModuleArtifact.java new file mode 100644 index 0000000000..c7f19ea1bf --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfModuleArtifact.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + + +import java.io.UnsupportedEncodingException; + +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; + +/** + * The structure that contains the artifactInfo and its associated DownloadedResult. + * + */ +public final class VfModuleArtifact { + private final IArtifactInfo artifactInfo; + private int deployedInDb=0; + private final String result; + + private Object catalogObject; + + public VfModuleArtifact(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { + artifactInfo=artifactinfo; + result = new String(clientResult.getArtifactPayload(), "UTF-8"); + + } + + public Object getCatalogObject() { + return catalogObject; + } + + public void setCatalogObject(Object catalogObject) { + this.catalogObject = catalogObject; + } + + public IArtifactInfo getArtifactInfo() { + return artifactInfo; + } + + public String getResult() { + return result; + } + + public int getDeployedInDb() { + return deployedInDb; + } + + public void incrementDeployedInDB() { + ++deployedInDb; + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfModuleStructure.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfModuleStructure.java new file mode 100644 index 0000000000..239bc8ab99 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfModuleStructure.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.openecomp.sdc.api.notification.IVfModuleMetadata; +import org.openecomp.mso.asdc.client.ASDCConfiguration; +import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException; +import org.openecomp.mso.db.catalog.beans.VfModule; + +public final class VfModuleStructure { + + private final IVfModuleMetadata vfModuleMetadata; + + private final VfResourceStructure parentVfResource; + + private VfModule catalogVfModule; + /** + * The list of artifact existing in this resource hashed by artifactType. + */ + private final Map<String, List<VfModuleArtifact>> artifactsMap; + + public VfModuleStructure(VfResourceStructure vfParentResource,IVfModuleMetadata vfmoduleMetadata) throws ArtifactInstallerException { + + vfModuleMetadata = vfmoduleMetadata; + parentVfResource = vfParentResource; + + artifactsMap = new HashMap<String, List<VfModuleArtifact>>(); + + for (String artifactUUID:this.vfModuleMetadata.getArtifacts()) { + if (vfParentResource.getArtifactsMapByUUID().containsKey(artifactUUID)) { + this.addToStructure(vfParentResource.getArtifactsMapByUUID().get(artifactUUID)); + } else { + throw new ArtifactInstallerException("Artifact (UUID:"+artifactUUID+ ") referenced in the VFModule UUID list has not been downloaded, cancelling the Resource deployment"); + } + } + } + + private void addToStructure(VfModuleArtifact vfModuleArtifact) { + + if (artifactsMap.containsKey(vfModuleArtifact.getArtifactInfo().getArtifactType())) { + artifactsMap.get(vfModuleArtifact.getArtifactInfo().getArtifactType()).add(vfModuleArtifact); + + } else { + List<VfModuleArtifact> nestedList = new LinkedList<VfModuleArtifact>(); + nestedList.add(vfModuleArtifact); + + artifactsMap.put(vfModuleArtifact.getArtifactInfo().getArtifactType(), nestedList); + } + } + + public List<VfModuleArtifact> getOrderedArtifactList() { + + List <VfModuleArtifact> artifactsList = new LinkedList <VfModuleArtifact>(); + + artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT)); + artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_ENV)); + artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL)); + + for (VfModuleArtifact artifact:(artifactsMap.get(ASDCConfiguration.HEAT_NESTED))) { + artifactsList.add(artifact); + } + + for (VfModuleArtifact artifact:(artifactsMap.get(ASDCConfiguration.HEAT_ARTIFACT))) { + artifactsList.add(artifact); + } + + artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL)); + + return null; + } + + public IVfModuleMetadata getVfModuleMetadata() { + return vfModuleMetadata; + } + + public VfResourceStructure getParentVfResource() { + return parentVfResource; + } + + public Map<String, List<VfModuleArtifact>> getArtifactsMap() { + return artifactsMap; + } + + + public VfModule getCatalogVfModule() { + return catalogVfModule; + } + + public void setCatalogVfModule(VfModule catalogVfModule) { + this.catalogVfModule = catalogVfModule; + } + + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfResourceStructure.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfResourceStructure.java new file mode 100644 index 0000000000..7be5e7010b --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/VfResourceStructure.java @@ -0,0 +1,165 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer; + + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; +import org.openecomp.sdc.api.notification.IVfModuleMetadata; +import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; +import org.openecomp.mso.asdc.client.ASDCConfiguration; +import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException; +import org.openecomp.mso.db.catalog.beans.Service; +import org.openecomp.mso.db.catalog.beans.VnfResource; + +/** + * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure). + * + * + */ +public final class VfResourceStructure { + + private boolean isDeployedSuccessfully=false; + /** + * The Raw notification data. + */ + private final INotificationData notification; + + /** + * The resource we will try to deploy. + */ + private final IResourceInstance resourceInstance; + + /** + * The list of VfModules defined for this resource. + */ + private final List<VfModuleStructure> vfModulesStructureList; + + /** + * The list of VfModulesMetadata defined for this resource. + */ + private List<IVfModuleMetadata> vfModulesMetadataList; + + private VnfResource catalogVnfResource; + + private Service catalogService; + + /** + * The list of artifacts existing in this resource hashed by UUID. + */ + private final Map<String, VfModuleArtifact> artifactsMapByUUID; + + + public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) { + notification=notificationdata; + resourceInstance=resourceinstance; + + + vfModulesStructureList = new LinkedList<VfModuleStructure>(); + artifactsMapByUUID = new HashMap<String, VfModuleArtifact>(); + } + + public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { + VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult); + + switch(artifactinfo.getArtifactType()) { + case ASDCConfiguration.HEAT: + case ASDCConfiguration.HEAT_ENV: + case ASDCConfiguration.HEAT_VOL: + case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported + case ASDCConfiguration.HEAT_ARTIFACT: + case ASDCConfiguration.HEAT_NET: + case ASDCConfiguration.OTHER: + artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact); + break; + + case ASDCConfiguration.VF_MODULES_METADATA: + vfModulesMetadataList = distributionClient.decodeVfModuleArtifact(clientResult.getArtifactPayload()); + break; + + default: + break; + + } + } + + public void createVfModuleStructures() throws ArtifactInstallerException { + + if (vfModulesMetadataList == null) { + throw new ArtifactInstallerException("VfModule Meta DATA could not be decoded properly or was not present in the notification"); + } + for (IVfModuleMetadata vfModuleMeta:vfModulesMetadataList) { + vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta)); + } + } + + public INotificationData getNotification() { + return notification; + } + + public IResourceInstance getResourceInstance() { + return resourceInstance; + } + + public List<VfModuleStructure> getVfModuleStructure() { + return vfModulesStructureList; + } + + public boolean isDeployedSuccessfully() { + return isDeployedSuccessfully; + } + + public void setSuccessfulDeployment() { + isDeployedSuccessfully = true; + } + + public Map<String, VfModuleArtifact> getArtifactsMapByUUID() { + return artifactsMapByUUID; + } + + public List<VfModuleStructure> getVfModulesStructureList() { + return vfModulesStructureList; + } + + public VnfResource getCatalogVnfResource() { + return catalogVnfResource; + } + + public void setCatalogVnfResource(VnfResource catalogVnfResource) { + this.catalogVnfResource = catalogVnfResource; + } + + public Service getCatalogService() { + return catalogService; + } + + public void setCatalogService(Service catalogService) { + this.catalogService = catalogService; + } +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/VfResourceInstaller.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/VfResourceInstaller.java new file mode 100644 index 0000000000..4cef0f1013 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/VfResourceInstaller.java @@ -0,0 +1,596 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.asdc.installer.heat; + + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.hibernate.exception.ConstraintViolationException; +import org.hibernate.exception.LockAcquisitionException; + +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.mso.asdc.client.ASDCConfiguration; +import org.openecomp.mso.asdc.client.exceptions.ArtifactInstallerException; +import org.openecomp.mso.asdc.installer.ASDCElementInfo; +import org.openecomp.mso.asdc.installer.BigDecimalVersion; +import org.openecomp.mso.asdc.installer.IVfResourceInstaller; +import org.openecomp.mso.asdc.installer.VfModuleArtifact; +import org.openecomp.mso.asdc.installer.VfModuleStructure; +import org.openecomp.mso.asdc.installer.VfResourceStructure; +import org.openecomp.mso.asdc.util.YamlEditor; +import org.openecomp.mso.db.catalog.CatalogDatabase; +import org.openecomp.mso.db.catalog.beans.HeatEnvironment; +import org.openecomp.mso.db.catalog.beans.HeatFiles; +import org.openecomp.mso.db.catalog.beans.HeatTemplate; +import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; +import org.openecomp.mso.db.catalog.beans.Service; +import org.openecomp.mso.db.catalog.beans.VfModule; +import org.openecomp.mso.db.catalog.beans.VnfResource; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; + +public class VfResourceInstaller implements IVfResourceInstaller { + + private MsoLogger logger; + + public VfResourceInstaller() { + logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.ASDC); + } + + @Override + public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStructure) + throws ArtifactInstallerException { + boolean status = false; + + try (CatalogDatabase db = new CatalogDatabase()) { + + logger.info(MessageEnum.ASDC_CHECK_HEAT_TEMPLATE, "VNFResource", + VfResourceInstaller.createVNFName(vfResourceStructure), + BigDecimalVersion.castAndCheckNotificationVersionToString( + vfResourceStructure.getNotification().getServiceVersion()), "", ""); + + VnfResource vnfResource = db.getVnfResource( + VfResourceInstaller.createVNFName(vfResourceStructure), + BigDecimalVersion.castAndCheckNotificationVersionToString( + vfResourceStructure.getNotification().getServiceVersion())); + + if (vnfResource != null) { + status = true; + + } + + if (status) { + logger.info(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED_DETAIL, + vfResourceStructure.getResourceInstance().getResourceInstanceName(), + vfResourceStructure.getResourceInstance().getResourceUUID(), + vfResourceStructure.getNotification().getServiceName(), + BigDecimalVersion.castAndCheckNotificationVersionToString( + vfResourceStructure.getNotification().getServiceVersion()), + vfResourceStructure.getNotification().getServiceUUID(), + vfResourceStructure.getResourceInstance().getResourceName(), "", ""); + } else { + logger.info(MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL, + vfResourceStructure.getResourceInstance().getResourceInstanceName(), + vfResourceStructure.getResourceInstance().getResourceUUID(), + vfResourceStructure.getNotification().getServiceName(), + BigDecimalVersion.castAndCheckNotificationVersionToString( + vfResourceStructure.getNotification().getServiceVersion()), + vfResourceStructure.getNotification().getServiceUUID(), + vfResourceStructure.getResourceInstance().getResourceName(),"", ""); + } + + return status; + + } catch (Exception e) { + logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception - isResourceAlreadyDeployed"); + throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e); + } + } + + @Override + public void installTheResource(VfResourceStructure vfResourceStructure) throws ArtifactInstallerException { + + // 1. Add the DB object list (Hashed) to be created from the HashMap + // UUID + // The DB objects will be stored in each VfModuleArtifact objects + // Those objects could be reused by different VfModule + + for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { + + switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) { + case ASDCConfiguration.HEAT: + case ASDCConfiguration.HEAT_VOL: + case ASDCConfiguration.HEAT_NESTED: + VfResourceInstaller.createHeatTemplateFromArtifact(vfResourceStructure, vfModuleArtifact); + break; + case ASDCConfiguration.HEAT_ENV: + VfResourceInstaller.createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact); + break; + case ASDCConfiguration.HEAT_ARTIFACT: + VfResourceInstaller.createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact); + break; + case ASDCConfiguration.HEAT_NET: + case ASDCConfiguration.OTHER: + logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT, vfModuleArtifact.getArtifactInfo().getArtifactType()+"(Artifact Name:"+vfModuleArtifact.getArtifactInfo().getArtifactName()+")", "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported"); + break; + default: + break; + + } + } + + // in case of deployment failure, use a string that will represent the type of artifact that failed... + List<ASDCElementInfo> artifactListForLogging = new ArrayList<>(); + + CatalogDatabase catalogDB = new CatalogDatabase(); + // 2. Create the VFModules/VNFResource objects by linking them to the + // objects created before and store them in Resource/module structure + // Opening a DB transaction, starting from here + try { + + VfResourceInstaller.createService(vfResourceStructure); + + VfResourceInstaller.createVnfResource(vfResourceStructure); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure)); + + catalogDB.saveOrUpdateVnfResource(vfResourceStructure.getCatalogVnfResource()); + catalogDB.saveService(vfResourceStructure.getCatalogService()); + + for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) { + + // Here we set the right db structure according to the Catalog + // DB + + // We expect only one MAIN HEAT per VFMODULE + // we can also obtain from it the Env ArtifactInfo, that's why + // we + // get the Main IArtifactInfo + + HeatTemplate heatMainTemplate = null; + HeatEnvironment heatEnv = null; + + HeatTemplate heatVolumeTemplate = null; + HeatEnvironment heatVolumeEnv = null; + + if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT)) { + IArtifactInfo mainEnvArtifactInfo = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) + .get(0).getArtifactInfo().getGeneratedArtifact(); + + // MAIN HEAT + heatMainTemplate = (HeatTemplate) vfModuleStructure.getArtifactsMap() + .get(ASDCConfiguration.HEAT).get(0).getCatalogObject(); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo + .createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo())); + + catalogDB.saveHeatTemplate(heatMainTemplate, heatMainTemplate.getParameters()); + // Indicate we have deployed it in the DB + vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).incrementDeployedInDB(); + + + // VOLUME HEAT + // We expect only one VOL HEAT per VFMODULE + // we can also obtain from it the Env ArtifactInfo, that's why + // we get the Volume IArtifactInfo + + if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_VOL)) { + IArtifactInfo volEnvArtifactInfo = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0) + .getArtifactInfo().getGeneratedArtifact(); + + heatVolumeTemplate = (HeatTemplate) vfModuleStructure.getArtifactsMap() + .get(ASDCConfiguration.HEAT_VOL).get(0).getCatalogObject(); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo())); + + catalogDB.saveHeatTemplate(heatVolumeTemplate, heatVolumeTemplate.getParameters()); + // Indicate we have deployed it in the DB + vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).incrementDeployedInDB(); + + if (volEnvArtifactInfo != null) { + heatVolumeEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID() + .get(volEnvArtifactInfo.getArtifactUUID()).getCatalogObject(); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(volEnvArtifactInfo)); + + catalogDB.saveHeatEnvironment(heatVolumeEnv); + // Indicate we have deployed it in the DB + vfResourceStructure.getArtifactsMapByUUID().get(volEnvArtifactInfo.getArtifactUUID()).incrementDeployedInDB(); + } + + } + + // NESTED HEAT + // Here we expect many HEAT_NESTED template to be there + // check first if we really have nested heat templates + if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_NESTED)) { + for (VfModuleArtifact heatNestedArtifact : vfModuleStructure.getArtifactsMap() + .get(ASDCConfiguration.HEAT_NESTED)) { + + // Check if this nested is well referenced by the MAIN HEAT + String parentArtifactType = VfResourceInstaller.identifyParentOfNestedTemplate(vfModuleStructure,heatNestedArtifact); + HeatTemplate heatNestedTemplate = (HeatTemplate) heatNestedArtifact.getCatalogObject(); + + if (parentArtifactType != null) { + + switch (parentArtifactType) { + case ASDCConfiguration.HEAT: + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo())); + + catalogDB.saveNestedHeatTemplate (heatMainTemplate.getId(), heatNestedTemplate, heatNestedTemplate.getTemplateName()); + // Indicate we have deployed it in the DB + heatNestedArtifact.incrementDeployedInDB(); + break; + case ASDCConfiguration.HEAT_VOL: + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo())); + catalogDB.saveNestedHeatTemplate (heatVolumeTemplate.getId(), heatNestedTemplate, heatNestedTemplate.getTemplateName()); + // Indicate we have deployed it in the DB + heatNestedArtifact.incrementDeployedInDB(); + break; + + default: + break; + + } + } else { // Assume it belongs to HEAT MAIN + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo())); + + catalogDB.saveNestedHeatTemplate (heatMainTemplate.getId(), heatNestedTemplate, heatNestedTemplate.getTemplateName()); + // Indicate we have deployed it in the DB + heatNestedArtifact.incrementDeployedInDB(); + } + } + } + + if (mainEnvArtifactInfo != null) { + heatEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID() + .get(mainEnvArtifactInfo.getArtifactUUID()).getCatalogObject(); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(mainEnvArtifactInfo)); + + catalogDB.saveHeatEnvironment(heatEnv); + // Indicate we have deployed it in the DB + vfResourceStructure.getArtifactsMapByUUID().get(mainEnvArtifactInfo.getArtifactUUID()).incrementDeployedInDB(); + } + + } + + + // here we expect one VFModule to be there + VfResourceInstaller.createVfModule(vfModuleStructure,heatMainTemplate, heatVolumeTemplate, heatEnv, heatVolumeEnv); + VfModule vfModule = vfModuleStructure.getCatalogVfModule(); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure)); + + catalogDB.saveOrUpdateVfModule(vfModule); + + // Here we expect many HEAT_TEMPLATE files to be there + if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT_ARTIFACT)) { + for (VfModuleArtifact heatArtifact : vfModuleStructure.getArtifactsMap() + .get(ASDCConfiguration.HEAT_ARTIFACT)) { + + HeatFiles heatFile = (HeatFiles) heatArtifact.getCatalogObject(); + + // Add this one for logging + artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatArtifact.getArtifactInfo())); + + + catalogDB.saveVfModuleToHeatFiles (vfModule.getId(), heatFile); + // Indicate we will deploy it in the DB + heatArtifact.incrementDeployedInDB(); + } + } + + } + + catalogDB.commit(); + vfResourceStructure.setSuccessfulDeployment(); + + } catch (Exception e) { + + Throwable dbExceptionToCapture = e; + while (!(dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) + && (dbExceptionToCapture.getCause() != null)) { + dbExceptionToCapture = dbExceptionToCapture.getCause(); + } + + if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) { + logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED, vfResourceStructure.getResourceInstance().getResourceName(), + vfResourceStructure.getNotification().getServiceVersion(), "", "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e); + } else { + String endEvent = "Exception caught during installation of the VFResource. Transaction rollback."; + String elementToLog = (artifactListForLogging.size() > 0 ? artifactListForLogging.get(artifactListForLogging.size()-1).toString() : "No element listed"); + logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError, "Exception caught during installation of the VFResource. Transaction rollback", e); + catalogDB.rollback(); + throw new ArtifactInstallerException( + "Exception caught during installation of the VFResource. Transaction rollback.", e); + } + + } finally { + catalogDB.close(); + // Debug log the whole collection... + logger.debug(artifactListForLogging.toString()); + } + + } + + private static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure,VfModuleArtifact heatNestedArtifact) { + + if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null + && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) { + for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0) + .getArtifactInfo().getRelatedArtifacts()) { + if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) { + return ASDCConfiguration.HEAT; + } + + } + } + + if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null + && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo().getRelatedArtifacts() != null) { + for (IArtifactInfo unknownArtifact:vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo().getRelatedArtifacts()) { + if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) { + return ASDCConfiguration.HEAT_VOL; + } + + } + } + + // Does not belong to anything + return null; + + } + + private static void createVnfResource(VfResourceStructure vfResourceStructure) { + VnfResource vnfResource = new VnfResource(); + + vnfResource.setAsdcUuid(vfResourceStructure.getResourceInstance().getResourceUUID()); + vnfResource.setDescription(vfResourceStructure.getNotification().getServiceDescription()); + + vnfResource.setOrchestrationMode("HEAT"); + // Set the version but Version is stored into ASDC_SERVICE_MODEL_VERSION + vnfResource.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion())); + vnfResource.setVnfType(VfResourceInstaller.createVNFName(vfResourceStructure)); + vnfResource.setModelVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfResourceStructure.getResourceInstance().getResourceVersion())); + + vnfResource.setModelInvariantUuid(vfResourceStructure.getResourceInstance().getResourceInvariantUUID()); + vnfResource.setModelCustomizationName(vfResourceStructure.getResourceInstance().getResourceInstanceName()); + vnfResource.setModelName(vfResourceStructure.getResourceInstance().getResourceName()); + vnfResource.setServiceModelInvariantUUID(vfResourceStructure.getNotification().getServiceInvariantUUID()); + + vfResourceStructure.setCatalogVnfResource(vnfResource); + } + + private static void createVfModule(VfModuleStructure vfModuleStructure,HeatTemplate heatMain, HeatTemplate heatVolume,HeatEnvironment heatEnv, HeatEnvironment heatVolumeEnv) { + VfModule vfModule = new VfModule(); + vfModule.setType(createVfModuleName(vfModuleStructure)); + vfModule.setAsdcUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelUUID()); + vfModule.setDescription(vfModuleStructure.getVfModuleMetadata().getVfModuleModelDescription()); + + if (vfModuleStructure.getVfModuleMetadata().isBase()) { + vfModule.setIsBase(1); + } else { + vfModule.setIsBase(0); + } + + vfModule.setModelInvariantUuid(vfModuleStructure.getVfModuleMetadata().getVfModuleModelInvariantUUID()); + vfModule.setModelName(vfModuleStructure.getVfModuleMetadata().getVfModuleModelName()); + + vfModule.setVersion(BigDecimalVersion.castAndCheckNotificationVersionToString(vfModuleStructure.getParentVfResource().getNotification().getServiceVersion())); + vfModule.setModelVersion(BigDecimalVersion.castAndCheckNotificationVersionToString( + vfModuleStructure.getVfModuleMetadata().getVfModuleModelVersion())); + + vfModuleStructure.setCatalogVfModule(vfModule); + + VfResourceInstaller.createVfModuleLinks(vfModule, vfModuleStructure.getParentVfResource().getCatalogVnfResource(), heatMain,heatVolume, heatEnv,heatVolumeEnv); + } + + private static void createVfModuleLinks(VfModule vfModule, VnfResource vnfResource, HeatTemplate heatMain, + HeatTemplate heatVolume, HeatEnvironment heatEnv, HeatEnvironment heatVolumeEnv) { + + if (heatMain !=null) { + vfModule.setTemplateId(heatMain.getId()); + } + if (heatEnv != null) { + vfModule.setEnvironmentId(heatEnv.getId()); + } + if (heatVolume != null) { + vfModule.setVolTemplateId(heatVolume.getId()); + } + if (heatVolumeEnv != null) { + vfModule.setVolEnvironmentId(heatVolumeEnv.getId()); + } + + vfModule.setVnfResourceId(vnfResource.getId()); + + } + + private static Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile) { + + // Scan the payload downloadResult and extract the HeatTemplate + // parameters + YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes()); + return yamlEditor.getParameterList(); + + } + + + public static String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure, List<String> listTypes) { + String newFileBody = filebody; + for (VfModuleArtifact moduleArtifact:vfResourceStructure.getArtifactsMapByUUID().values()) { + + if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) { + + newFileBody = verifyTheFilePrefixInString(newFileBody,moduleArtifact.getArtifactInfo().getArtifactName()); + } + } + return newFileBody; + } + + public static String verifyTheFilePrefixInString(final String body, final String filenameToVerify) { + + String needlePrefix = "file:///"; + String prefixedFilenameToVerify = needlePrefix+filenameToVerify; + + if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) { + return body; + } + + StringBuffer sb = new StringBuffer(body.length()); + + int currentIndex = 0; + int startIndex = 0; + + while (currentIndex != -1) { + startIndex = currentIndex; + currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex); + + if (currentIndex == -1) { + break; + } + + // We append from the startIndex up to currentIndex (start of File Name) + sb.append(body.substring(startIndex, currentIndex)); + sb.append(filenameToVerify); + + currentIndex += prefixedFilenameToVerify.length(); + } + + sb.append(body.substring(startIndex)); + + return sb.toString(); + } + + private static void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure, + VfModuleArtifact vfModuleArtifact) { + HeatTemplate heatTemplate = new HeatTemplate(); + + // TODO Set the label + heatTemplate.setAsdcLabel("label"); + // Use the ResourceName of the ASDC template because the HEAT could be + // reused + heatTemplate.setAsdcResourceName(vfResourceStructure.getResourceInstance().getResourceName()); + heatTemplate.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + List<String> typeList = new ArrayList<String>(); + typeList.add(ASDCConfiguration.HEAT_NESTED); + typeList.add(ASDCConfiguration.HEAT_ARTIFACT); + + heatTemplate.setTemplateBody(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(),vfResourceStructure,typeList)); + heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { + heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); + } else { + heatTemplate.setTimeoutMinutes(240); + } + + heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatTemplate.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + Set<HeatTemplateParam> heatParam = VfResourceInstaller + .extractHeatTemplateParameters(vfModuleArtifact.getResult()); + heatTemplate.setParameters(heatParam); + + vfModuleArtifact.setCatalogObject(heatTemplate); + } + + private static void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure, + VfModuleArtifact vfModuleArtifact) { + HeatEnvironment heatEnvironment = new HeatEnvironment(); + + heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + // TODO Set the label + heatEnvironment.setAsdcLabel("Label"); + + List<String> typeList = new ArrayList<String>(); + typeList.add(ASDCConfiguration.HEAT); + typeList.add(ASDCConfiguration.HEAT_VOL); + + heatEnvironment.setEnvironment(verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(),vfResourceStructure,typeList)); + heatEnvironment.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatEnvironment.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatEnvironment.setAsdcResourceName(VfResourceInstaller.createVNFName(vfResourceStructure)); + + vfModuleArtifact.setCatalogObject(heatEnvironment); + + } + + private static void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure, + VfModuleArtifact vfModuleArtifact) { + + HeatFiles heatFile = new HeatFiles(); + // TODO Set the label + heatFile.setAsdcLabel("Label"); + heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatFile.setFileBody(vfModuleArtifact.getResult()); + heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + heatFile.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + + heatFile.setAsdcResourceName(vfResourceStructure.getResourceInstance().getResourceName()); + vfModuleArtifact.setCatalogObject(heatFile); + + } + + private static void createService(VfResourceStructure vfResourceStructure) { + + Service service = new Service(); + service.setDescription(vfResourceStructure.getNotification().getServiceDescription()); + service.setServiceName(vfResourceStructure.getNotification().getServiceName()); + service.setServiceNameVersionId(vfResourceStructure.getNotification().getServiceUUID()); + service.setVersion(vfResourceStructure.getNotification().getServiceVersion()); + service.setModelInvariantUUID(vfResourceStructure.getNotification().getServiceInvariantUUID()); + + vfResourceStructure.setCatalogService(service); + } + + + private static String createVNFName(VfResourceStructure vfResourceStructure) { + + return vfResourceStructure.getNotification().getServiceName() + "/" + vfResourceStructure.getResourceInstance().getResourceInstanceName(); + } + + private static String createVfModuleName(VfModuleStructure vfModuleStructure) { + + return createVNFName(vfModuleStructure.getParentVfResource())+"::"+vfModuleStructure.getVfModuleMetadata().getVfModuleModelName(); + } + +} |