diff options
14 files changed, 2112 insertions, 581 deletions
diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml index cd97471b5b..66ea46fcc9 100644 --- a/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml +++ b/adapters/mso-vfc-adapter/WebContent/WEB-INF/web.xml @@ -16,7 +16,7 @@ </context-param> <context-param> <param-name>mso.configuration</param-name> - <param-value>MSO_PROP_NETWORK_ADAPTER=mso.vfc.properties,MSO_PROP_TOPOLOGY=topology.properties</param-value> + <param-value>MSO_PROP_VFC_ADAPTER=mso.vfc.properties,MSO_PROP_TOPOLOGY=topology.properties</param-value> </context-param> <context-param> <param-name>mso.cloud_config.configuration</param-name> diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java index a8189925fb..749b9f9fc3 100644 --- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java @@ -256,13 +256,9 @@ public class BpelRestClient { .build(); post.setConfig(requestConfig); - //Client 4.3+ - CloseableHttpClient client = null; - //Client 4.3+ //Execute & GetResponse - try { - client = HttpClients.createDefault(); + try(CloseableHttpClient client = HttpClients.createDefault()) { CloseableHttpResponse response = client.execute(post); if (response != null) { lastResponseCode = response.getStatusLine().getStatusCode(); @@ -277,16 +273,6 @@ public class BpelRestClient { LOGGER.error (MessageEnum.RA_SEND_VNF_NOTIF_ERR, error, "Camunda", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception - Error sending Bpel notification", e); lastResponseCode = 900; lastResponse = ""; - } finally { - try { - client.close(); - } catch (IOException e) { - // ignore - LOGGER.debug("IOException: ", e); - } catch (NullPointerException e) { - //ignore - LOGGER.debug("NullPointerException: ", e); - } } LOGGER.debug("Response code from BPEL server: "+lastResponseCode); LOGGER.debug("Response body is: "+lastResponse); 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 index 70fa7c14be..c2879a4df2 100644 --- 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 @@ -32,23 +32,21 @@ import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; - -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.NetworkResourceCustomization; import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization; +import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization; import org.openecomp.mso.db.catalog.beans.Service; import org.openecomp.mso.db.catalog.beans.ServiceToAllottedResources; import org.openecomp.mso.db.catalog.beans.ServiceToNetworks; import org.openecomp.mso.db.catalog.beans.VnfResource; - +import org.openecomp.mso.logger.MessageEnum; import org.openecomp.mso.logger.MsoLogger; +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.results.IDistributionClientDownloadResult; /** * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure). * @@ -141,8 +139,10 @@ public final class VfResourceStructure { public void createVfModuleStructures() throws ArtifactInstallerException { + //for vender tosca VNF there is no VFModule in VF if (vfModulesMetadataList == null) { - throw new ArtifactInstallerException("VfModule Meta DATA could not be decoded properly or was not present in the notification"); + LOGGER.info(MessageEnum.ASDC_GENERAL_INFO,"There is no VF mudules in the VF.", "ASDC", "createVfModuleStructures"); + return; } for (IVfModuleData vfModuleMeta:vfModulesMetadataList) { vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta)); diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java index b6dddacd7c..b998be9a69 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java @@ -197,303 +197,330 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller { List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
int outerLoop = 0;
logger.debug("**vfMondeTEmplatesList.size()=" + vfNodeTemplatesList.size());
- for (NodeTemplate nodeTemplate : vfNodeTemplatesList) {
- logger.debug("nodeTemplate outerLoop=" + outerLoop++);
- // extract VF metadata
-
- Metadata metadata = nodeTemplate.getMetaData();
+ for(NodeTemplate nodeTemplate : vfNodeTemplatesList) {
+ logger.debug("nodeTemplate outerLoop=" + outerLoop++);
+ // extract VF metadata
- String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper().getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
- logger.debug("vfCustomizationUUID=" + vfCustomizationUUID);
+ Metadata metadata = nodeTemplate.getMetaData();
-
- /* HEAT TABLE POPULATION
- * *******************************************************************************************************
- */
-
- int nextLoop = 0;
- for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
- logger.debug("vfResourceStructure.getVfMOduleStructure() loop, nextLoop = " + nextLoop++);
- logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
-
- // Here we set the right db structure according to the Catalog
- // DB
+ String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper().getMetadataPropertyValue(metadata,
+ SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
+ logger.debug("vfCustomizationUUID=" + vfCustomizationUUID);
- // 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
+ // extract VF metadata
+ createVnfResource(nodeTemplate, toscaResourceStruct);
- HeatTemplate heatMainTemplate = null;
- HeatEnvironment heatEnv;
-
- HeatTemplate heatVolumeTemplate = null;
- HeatEnvironment heatVolumeEnv;
-
-
- IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
-
-
- if (vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT)) {
-
- List<VfModuleArtifact> artifacts = vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT);
- logger.debug("there are " + artifacts.size() + " artifacts");
- IArtifactInfo mainEnvArtifactInfo = null;
- for (VfModuleArtifact vfma : artifacts) {
- logger.debug("vmfa=" + vfma.toString());
- mainEnvArtifactInfo =
- vfma.getArtifactInfo().getGeneratedArtifact();
-
- // MAIN HEAT
- heatMainTemplate = (HeatTemplate) vfma.getCatalogObject();
-
- // Set HeatTemplateArtifactUUID to use later when setting the VfModule and NetworkResource
- toscaResourceStruct.setHeatTemplateUUID(heatMainTemplate.getArtifactUuid());
+ // check for duplicate record already in the database
+ VnfResource vnfResource =
+ catalogDB.getVnfResource(toscaResourceStruct.getCatalogVnfResource().getModelName(),
+ BigDecimalVersion.castAndCheckNotificationVersionToString(
+ toscaResourceStruct.getCatalogVnfResource().getVersion()));
- // Add this one for logging
- artifactListForLogging.add(ASDCElementInfo
- .createElementFromVfArtifactInfo(vfma.getArtifactInfo()));
-
- catalogDB.saveHeatTemplate(heatMainTemplate, heatMainTemplate.getParameters());
- // Indicate we have deployed it in the DB
- vfma.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();
-
- // Set VolHeatTemplate ArtifactUUID to use later when setting the VfModule
- toscaResourceStruct.setVolHeatTemplateUUID(heatVolumeTemplate.getArtifactUuid());
-
-
- // Add this one for logging
- artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo()));
+ if(vnfResource != null) {
+ toscaResourceStruct.setVnfAlreadyInstalled(true);
+ }
- 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();
-
- // Set VolHeatTemplate ArtifactUUID to use later when setting the VfModule
- toscaResourceStruct.setVolHeatEnvTemplateUUID(heatVolumeEnv.getArtifactUuid());
-
- // 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
- // XXX FIX BY PCLO: Defect# -36643 -US666034 - 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 = ToscaResourceInstaller.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.getArtifactUuid(), 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.getArtifactUuid(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
- // Indicate we have deployed it in the DB
- heatNestedArtifact.incrementDeployedInDB();
- break;
-
- default:
- break;
+ if(!toscaResourceStruct.isVnfAlreadyInstalled()) {
- }
- } else { // Assume it belongs to HEAT MAIN
- // Add this one for logging
- artifactListForLogging.add(ASDCElementInfo.createElementFromVfArtifactInfo(heatNestedArtifact.getArtifactInfo()));
-
- catalogDB.saveNestedHeatTemplate (heatMainTemplate.getArtifactUuid(), heatNestedTemplate, heatNestedTemplate.getTemplateName());
- // Indicate we have deployed it in the DB
- heatNestedArtifact.incrementDeployedInDB();
- }
- }
- }
-
- if (mainEnvArtifactInfo != null) {
- heatEnv = (HeatEnvironment) vfResourceStructure.getArtifactsMapByUUID()
- .get(mainEnvArtifactInfo.getArtifactUUID()).getCatalogObject();
-
- // Set HeatEnvironmentArtifactUUID to use later when setting the VfModule
- toscaResourceStruct.setEnvHeatTemplateUUID(heatEnv.getArtifactUuid());
+ catalogDB.saveOrUpdateVnfResource(toscaResourceStruct.getCatalogVnfResource());
- // 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);
-
-
- // extract VF metadata
- createVnfResource(nodeTemplate, toscaResourceStruct);
-
- // check for duplicate record already in the database
- VnfResource vnfResource = catalogDB.getVnfResource(toscaResourceStruct.getCatalogVnfResource().getModelName(),
- BigDecimalVersion.castAndCheckNotificationVersionToString(
- toscaResourceStruct.getCatalogVnfResource().getVersion()));
+ boolean saveVnfCustomization = catalogDB
+ .saveVnfResourceCustomization(toscaResourceStruct.getCatalogVnfResourceCustomization());
- if (vnfResource != null) {
- toscaResourceStruct.setVnfAlreadyInstalled(true);
- }
-
-
- if(!toscaResourceStruct.isVnfAlreadyInstalled()) {
-
- catalogDB.saveOrUpdateVnfResource(toscaResourceStruct.getCatalogVnfResource());
-
- }
-
-
- boolean saveVnfCustomization = catalogDB.saveVnfResourceCustomization(toscaResourceStruct.getCatalogVnfResourceCustomization());
-
- if(saveVnfCustomization){
- catalogDB.saveServiceToResourceCustomization(toscaResourceStruct.getCatalogVfServiceToResourceCustomization());
- }
-
- List<org.openecomp.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct.getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
- logger.debug("vfGroups:" + vfGroups.toString());
-
- Collections.sort(vfGroups, new Comparator<org.openecomp.sdc.toscaparser.api.Group>() {
- @Override
- public int compare(org.openecomp.sdc.toscaparser.api.Group group1, org.openecomp.sdc.toscaparser.api.Group group2) {
-
- //Field name1Field = group1.class.getDeclaredField("name");
- //name1Field.setAccessible(true);
- String thisName = group1.getName(); //(String) name1Field.get(group1);
- String thatName = group2.getName(); // (String) name1Field.get(group2);
-
- Matcher m = lastDigit.matcher(thisName);
- Matcher m2 = lastDigit.matcher(thatName);
-
- String thisDigit = "0";
- String thatDigit = "0";
- if (m.find()) {
- thisDigit = m.group();
- } else {
- return -1;
- }
- if (m2.find()) {
- thatDigit = m2.group();
- } else {
- return 1;
- }
-
- return new Integer(thisDigit).compareTo(new Integer(thatDigit));
+ if(saveVnfCustomization) {
+ catalogDB.saveServiceToResourceCustomization(
+ toscaResourceStruct.getCatalogVfServiceToResourceCustomization());
+ }
- }
- });
-
- logger.debug("vfGroupsAfter:" + vfGroups.toString());
+ /*
+ * HEAT TABLE POPULATION
+ * *********************************************************************************
+ * **********************
+ */
-
- for(Group group : vfGroups){
-
-
- //boolean saveVFModule = createVFModule(group, nodeTemplate, toscaResourceStruct, vfMetadata);
- if (vfMetadata.getVfModuleModelCustomizationUUID() == null) {
- logger.debug("NULL 1");
- } else {
- logger.debug("vfMetadata.getMCU=" + vfMetadata.getVfModuleModelCustomizationUUID());
- }
- if (group.getMetadata() == null) {
- logger.debug("NULL 3");
- } else {
- logger.debug("group.getMetadata().getValue() = " + group.getMetadata().getValue("vfModuleModelCustomizationUUID"));
- }
- if (vfMetadata.getVfModuleModelCustomizationUUID().equals(group.getMetadata().getValue("vfModuleModelCustomizationUUID"))) {
- logger.debug("Found a match at " + vfMetadata.getVfModuleModelCustomizationUUID());
- createVFModule(group, nodeTemplate, toscaResourceStruct, vfResourceStructure, vfMetadata);
-
- catalogDB.saveOrUpdateVfModule(toscaResourceStruct.getCatalogVfModule());
-
- catalogDB.saveOrUpdateVfModuleCustomization(toscaResourceStruct.getCatalogVfModuleCustomization());
-
- catalogDB.saveVnfResourceToVfModuleCustomization(toscaResourceStruct.getCatalogVnfResourceCustomization(), toscaResourceStruct.getCatalogVfModuleCustomization());
-
+ int nextLoop = 0;
+ for(VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
+ logger.debug("vfResourceStructure.getVfMOduleStructure() loop, nextLoop = " + nextLoop++);
+ logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
- } else {
- if(toscaResourceStruct.getCatalogVfModuleCustomization() != null){
- logger.debug("No match for " + toscaResourceStruct.getCatalogVfModuleCustomization().getModelCustomizationUuid());
- } else {
- logger.debug("No match for vfModuleModelCustomizationUUID");
- }
- }
-
- }
-
- } //Commented out to process VFModules each time
-
+ // Here we set the right db structure according to the Catalog
+ // DB
-
- // 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()));
-
- if(toscaResourceStruct.getCatalogVfModule() != null && heatFile != null){
- catalogDB.saveVfModuleToHeatFiles (toscaResourceStruct.getCatalogVfModule().getModelUUID(), heatFile);
- }
- // Indicate we will deploy it in the DB
- heatArtifact.incrementDeployedInDB();
- }
- }
-
- }
+ // 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;
+
+ HeatTemplate heatVolumeTemplate = null;
+ HeatEnvironment heatVolumeEnv;
+
+ IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();
+
+ if(vfModuleStructure.getArtifactsMap().containsKey(ASDCConfiguration.HEAT)) {
+
+ List<VfModuleArtifact> artifacts =
+ vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT);
+ logger.debug("there are " + artifacts.size() + " artifacts");
+ IArtifactInfo mainEnvArtifactInfo = null;
+ for(VfModuleArtifact vfma : artifacts) {
+ logger.debug("vmfa=" + vfma.toString());
+ mainEnvArtifactInfo = vfma.getArtifactInfo().getGeneratedArtifact();
+
+ // MAIN HEAT
+ heatMainTemplate = (HeatTemplate)vfma.getCatalogObject();
+
+ // Set HeatTemplateArtifactUUID to use later when setting the VfModule
+ // and NetworkResource
+ toscaResourceStruct.setHeatTemplateUUID(heatMainTemplate.getArtifactUuid());
+
+ // Add this one for logging
+ artifactListForLogging
+ .add(ASDCElementInfo.createElementFromVfArtifactInfo(vfma.getArtifactInfo()));
+
+ catalogDB.saveHeatTemplate(heatMainTemplate, heatMainTemplate.getParameters());
+ // Indicate we have deployed it in the DB
+ vfma.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();
+
+ // Set VolHeatTemplate ArtifactUUID to use later when setting the
+ // VfModule
+ toscaResourceStruct.setVolHeatTemplateUUID(heatVolumeTemplate.getArtifactUuid());
+
+ // 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();
+
+ // Set VolHeatTemplate ArtifactUUID to use later when setting the
+ // VfModule
+ toscaResourceStruct.setVolHeatEnvTemplateUUID(heatVolumeEnv.getArtifactUuid());
+
+ // 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
+ // XXX FIX BY PCLO: Defect# -36643 -US666034 - 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 = ToscaResourceInstaller
+ .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.getArtifactUuid(),
+ 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.getArtifactUuid(),
+ 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.getArtifactUuid(),
+ heatNestedTemplate, heatNestedTemplate.getTemplateName());
+ // Indicate we have deployed it in the DB
+ heatNestedArtifact.incrementDeployedInDB();
+ }
+ }
+ }
+
+ if(mainEnvArtifactInfo != null) {
+ heatEnv = (HeatEnvironment)vfResourceStructure.getArtifactsMapByUUID()
+ .get(mainEnvArtifactInfo.getArtifactUUID()).getCatalogObject();
+
+ // Set HeatEnvironmentArtifactUUID to use later when setting the
+ // VfModule
+ toscaResourceStruct.setEnvHeatTemplateUUID(heatEnv.getArtifactUuid());
+
+ // 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);
+
+ List<org.openecomp.sdc.toscaparser.api.Group> vfGroups =
+ toscaResourceStruct.getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
+ logger.debug("vfGroups:" + vfGroups.toString());
+
+ Collections.sort(vfGroups, new Comparator<org.openecomp.sdc.toscaparser.api.Group>() {
+
+ @Override
+ public int compare(org.openecomp.sdc.toscaparser.api.Group group1,
+ org.openecomp.sdc.toscaparser.api.Group group2) {
+
+ // Field name1Field = group1.class.getDeclaredField("name");
+ // name1Field.setAccessible(true);
+ String thisName = group1.getName(); // (String)
+ // name1Field.get(group1);
+ String thatName = group2.getName(); // (String)
+ // name1Field.get(group2);
+
+ Matcher m = lastDigit.matcher(thisName);
+ Matcher m2 = lastDigit.matcher(thatName);
+
+ String thisDigit = "0";
+ String thatDigit = "0";
+ if(m.find()) {
+ thisDigit = m.group();
+ } else {
+ return -1;
+ }
+ if(m2.find()) {
+ thatDigit = m2.group();
+ } else {
+ return 1;
+ }
+
+ return new Integer(thisDigit).compareTo(new Integer(thatDigit));
+
+ }
+ });
+
+ logger.debug("vfGroupsAfter:" + vfGroups.toString());
+
+ for(Group group : vfGroups) {
+
+ // boolean saveVFModule = createVFModule(group, nodeTemplate,
+ // toscaResourceStruct, vfMetadata);
+ if(vfMetadata.getVfModuleModelCustomizationUUID() == null) {
+ logger.debug("NULL 1");
+ } else {
+ logger.debug("vfMetadata.getMCU=" + vfMetadata.getVfModuleModelCustomizationUUID());
+ }
+ if(group.getMetadata() == null) {
+ logger.debug("NULL 3");
+ } else {
+ logger.debug("group.getMetadata().getValue() = "
+ + group.getMetadata().getValue("vfModuleModelCustomizationUUID"));
+ }
+ if(vfMetadata.getVfModuleModelCustomizationUUID()
+ .equals(group.getMetadata().getValue("vfModuleModelCustomizationUUID"))) {
+ logger.debug("Found a match at " + vfMetadata.getVfModuleModelCustomizationUUID());
+ createVFModule(group, nodeTemplate, toscaResourceStruct, vfResourceStructure,
+ vfMetadata);
+
+ catalogDB.saveOrUpdateVfModule(toscaResourceStruct.getCatalogVfModule());
+
+ catalogDB.saveOrUpdateVfModuleCustomization(
+ toscaResourceStruct.getCatalogVfModuleCustomization());
+
+ catalogDB.saveVnfResourceToVfModuleCustomization(
+ toscaResourceStruct.getCatalogVnfResourceCustomization(),
+ toscaResourceStruct.getCatalogVfModuleCustomization());
+
+ } else {
+ if(toscaResourceStruct.getCatalogVfModuleCustomization() != null) {
+ logger.debug("No match for " + toscaResourceStruct.getCatalogVfModuleCustomization()
+ .getModelCustomizationUuid());
+ } else {
+ logger.debug("No match for vfModuleModelCustomizationUUID");
+ }
+ }
+
+ }
+
+ } // Commented out to process VFModules each time
+
+ // 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()));
+
+ if(toscaResourceStruct.getCatalogVfModule() != null && heatFile != null) {
+ catalogDB.saveVfModuleToHeatFiles(
+ toscaResourceStruct.getCatalogVfModule().getModelUUID(), heatFile);
+ }
+ // Indicate we will deploy it in the DB
+ heatArtifact.incrementDeployedInDB();
+ }
+ }
+
+ }
+
+ }
/* END OF HEAT TABLE POPULATION
* ***************************************************************************************************
@@ -536,7 +563,10 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller { createNetworkResource(vlNode, toscaResourceStruct, networkHeatTemplateLookup.get(0));
} else {
- throw new ArtifactInstallerException("No NetworkResourceName found in TempNetworkHeatTemplateLookup for " + networkResourceModelName);
+ logger.info(MessageEnum.ASDC_GENERAL_INFO,
+ "No NetworkResourceName found in TempNetworkHeatTemplateLookup for" + networkResourceModelName, "ASDC",
+ "createVfModuleStructures");
+ createNetworkResource(vlNode, toscaResourceStruct, null);
}
@@ -760,6 +790,7 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller { service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
//service.setVersion(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+ service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
service.setToscaCsarArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID());
//service.setCreated(getCurrentTimeStamp());
}
@@ -804,11 +835,16 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller { networkResource.setModelVersion(testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
networkResource.setAicVersionMax(testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
- networkResource.setAicVersionMin(networkHeatTemplateLookup.getAicVersionMin());
+ String aicVersionMin = networkHeatTemplateLookup != null ? networkHeatTemplateLookup.getAicVersionMin() : "2.5";
+ networkResource.setAicVersionMin(aicVersionMin);
networkResource.setToscaNodeType(networkNodeTemplate.getType());
networkResource.setDescription(testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
networkResource.setOrchestrationMode("HEAT");
- networkResource.setHeatTemplateArtifactUUID(networkHeatTemplateLookup.getHeatTemplateArtifactUuid());
+ networkResource.setCategory(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
+ networkResource.setSubCategory(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
+ //for tosca NS ,there is no heat for network VL
+ String heatTemplateArtifactUUID = networkHeatTemplateLookup != null ? networkHeatTemplateLookup.getHeatTemplateArtifactUuid() : "null";
+ networkResource.setHeatTemplateArtifactUUID(heatTemplateArtifactUUID);
toscaResourceStructure.setCatalogNetworkResource(networkResource);
@@ -992,11 +1028,12 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller { vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType()));
vnfResource.setAicVersionMax(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES).trim()));
vnfResource.setAicVersionMin(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES).trim()));
- //vnfResource.setHeatTemplateArtifactUUId(toscaResourceStructure.getHeatTemplateUUID());
-
- // vfNodeTemplate.getProperties()
- toscaResourceStructure.setCatalogVnfResource(vnfResource);
-
+ // vnfResource.setHeatTemplateArtifactUUId(toscaResourceStructure.getHeatTemplateUUID());
+ vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
+ vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
+ // vfNodeTemplate.getProperties()
+ toscaResourceStructure.setCatalogVnfResource(vnfResource);
+
VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
vnfResourceCustomization.setModelCustomizationUuid(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).trim()));
vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName());
diff --git a/common/src/main/java/org/openecomp/mso/logger/MessageEnum.java b/common/src/main/java/org/openecomp/mso/logger/MessageEnum.java index 3d181e35b4..963554191e 100644 --- a/common/src/main/java/org/openecomp/mso/logger/MessageEnum.java +++ b/common/src/main/java/org/openecomp/mso/logger/MessageEnum.java @@ -172,6 +172,7 @@ public enum MessageEnum implements EELFResolvableErrorEnum{ ASDC_GENERAL_EXCEPTION_ARG,
ASDC_GENERAL_EXCEPTION,
ASDC_GENERAL_WARNING,
+ ASDC_GENERAL_INFO,
ASDC_AUDIT_EXEC,
ASDC_GENERAL_METRICS,
ASDC_CREATE_SERVICE,
diff --git a/common/src/main/resources/ASDC.properties b/common/src/main/resources/ASDC.properties index 015ca3510e..4f3864dac2 100644 --- a/common/src/main/resources/ASDC.properties +++ b/common/src/main/resources/ASDC.properties @@ -208,3 +208,8 @@ ASDC_PROPERTIES_NOT_FOUND=\ Please verify whether properties file exist or readable|\ Please verify whether properties file exist or readable|\ Properties file not found +ASDC_GENERAL_INFO=\ + MSO-ASDC-9305I|\ + INFO: {0}|\ + No resolution needed|\ + General Info diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java index 7ac188b027..aefe0d5a8b 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java @@ -378,16 +378,16 @@ public class CatalogDatabase implements Closeable { */ public Service getService (String modelName) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get service with name " + modelName); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get service with name " + modelName); String hql = "FROM Service WHERE modelName = :MODEL_NAME"; - Query query = getSession ().createQuery (hql); - query.setParameter ("MODEL_NAME", modelName); + Query query = getSession().createQuery(hql); + query.setParameter("MODEL_NAME", modelName); Service service = null; try { - service = (Service) query.uniqueResult (); + service = (Service) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelName='" + modelName + "'"); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelName=" + modelName, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelName=" + modelName); @@ -412,8 +412,8 @@ public class CatalogDatabase implements Closeable { public Service getServiceByModelUUID (String modelUUID) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get service with Model UUID " + modelUUID); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get service with Model UUID " + modelUUID); String hql = "FROM Service WHERE modelUUID = :MODEL_UUID"; HashMap<String, String> parameters = new HashMap<>(); @@ -462,25 +462,25 @@ public class CatalogDatabase implements Closeable { LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId); String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method"; - query = getSession ().createQuery (hql); - query.setParameter ("MODEL_UUID", serviceNameVersionId); + query = getSession().createQuery(hql); + query.setParameter("MODEL_UUID", serviceNameVersionId); } else { serviceId = map.get("serviceId"); serviceVersion = map.get("serviceVersion"); - LOGGER.debug ("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion); + LOGGER.debug("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion); String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method"; - query = getSession ().createQuery (hql); - query.setParameter ("service_id", serviceId); - query.setParameter ("service_version", serviceVersion); + query = getSession().createQuery(hql); + query.setParameter("service_id", serviceId); + query.setParameter("service_version", serviceVersion); } - query.setParameter ("http_method", httpMethod); + query.setParameter("http_method", httpMethod); - long startTime = System.currentTimeMillis (); + long startTime = System.currentTimeMillis(); Service service = null; try { - service = (Service) query.uniqueResult (); + service = (Service) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'"); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for service_id=" + serviceId); @@ -511,37 +511,37 @@ public class CatalogDatabase implements Closeable { * @param modelName * @return Service object or null if none found */ - public Service getServiceByModelName (String modelName){ + public Service getServiceByModelName(String modelName){ - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get service with name " + modelName); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get service with name " + modelName); String hql = "FROM Service WHERE modelName = :MODEL_NAME"; - Query query = getSession ().createQuery (hql); - query.setParameter ("MODEL_NAME", modelName); + Query query = getSession().createQuery(hql); + query.setParameter("MODEL_NAME", modelName); @SuppressWarnings("unchecked") - List <Service> resultList = query.list (); + List <Service> resultList = query.list(); // See if something came back. - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator ()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null); + return resultList.get(0); } public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get service with modelInvariantId: " + modelInvariantId + " and modelVersion: " + modelVersion); String hql = "FROM Service WHERE modelInvariantUUID = :MODEL_INVARIANT_UUID AND version = :VERSION_STR"; - Query query = getSession ().createQuery (hql); - query.setParameter ("MODEL_INVARIANT_UUID", modelInvariantId); + Query query = getSession().createQuery(hql); + query.setParameter("MODEL_INVARIANT_UUID", modelInvariantId); query.setParameter("VERSION_STR", modelVersion); Service result = null; @@ -554,11 +554,11 @@ public class CatalogDatabase implements Closeable { } // See if something came back. if (result==null) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByVersionAndInvariantId", null); return null; } - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByVersionAndInvariantId", null); return result; } @@ -614,67 +614,67 @@ public class CatalogDatabase implements Closeable { * @param action * * @return ServiceRecipe object or null if none found */ - public ServiceRecipe getServiceRecipeByServiceModelUuid (String serviceModelUuid, String action) { + public ServiceRecipe getServiceRecipeByServiceModelUuid(String serviceModelUuid, String action) { StringBuilder hql; if(action == null){ - hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid"); + hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid"); }else { - hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action "); + hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action "); } long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid + LOGGER.debug("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid + " and action " + action ); - Query query = getSession ().createQuery (hql.toString ()); - query.setParameter ("serviceModelUuid", serviceModelUuid); + Query query = getSession().createQuery(hql.toString()); + query.setParameter("serviceModelUuid", serviceModelUuid); if(action != null){ - query.setParameter (ACTION, action); + query.setParameter(ACTION, action); } @SuppressWarnings("unchecked") - List <ServiceRecipe> resultList = query.list (); + List <ServiceRecipe> resultList = query.list(); - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null); + return resultList.get(0); } - public List<ServiceRecipe> getServiceRecipes (String serviceModelUuid) { + public List<ServiceRecipe> getServiceRecipes(String serviceModelUuid) { StringBuilder hql; - hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID"); + hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUUID = :serviceModelUUID"); - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get Service recipe with serviceModelUUID " + serviceModelUuid); - Query query = getSession ().createQuery (hql.toString ()); - query.setParameter ("serviceModelUUID", serviceModelUuid); + Query query = getSession().createQuery(hql.toString()); + query.setParameter("serviceModelUUID", serviceModelUuid); @SuppressWarnings("unchecked") - List <ServiceRecipe> resultList = query.list (); + List <ServiceRecipe> resultList = query.list(); - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipes", null); return Collections.EMPTY_LIST; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipes", null); return resultList; } @@ -733,48 +733,48 @@ public class CatalogDatabase implements Closeable { */ public VnfResource getVnfResource (String vnfType) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get vnf resource with model_name " + vnfType); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get vnf resource with model_name " + vnfType); String hql = "FROM VnfResource WHERE modelName = :vnf_name"; - Query query = getSession ().createQuery (hql); - query.setParameter ("vnf_name", vnfType); + Query query = getSession().createQuery(hql); + query.setParameter("vnf_name", vnfType); @SuppressWarnings("unchecked") - List <VnfResource> resultList = query.list (); + List <VnfResource> resultList = query.list(); // See if something came back. Name is unique, so - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF not found", "CatalogDB", "getVnfResource", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResource", null); + return resultList.get(0); } /** * Return the newest version of a specific VNF resource (queried by Name). * * @param vnfType - * @param version + * @param serviceVersion * @return VnfResource object or null if none found */ public VnfResource getVnfResource (String vnfType, String serviceVersion) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion); String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion"; - Query query = getSession ().createQuery (hql); - query.setParameter ("vnfName", vnfType); - query.setParameter ("serviceVersion", serviceVersion); + Query query = getSession().createQuery(hql); + query.setParameter("vnfName", vnfType); + query.setParameter("serviceVersion", serviceVersion); VnfResource resource = null; try { - resource = (VnfResource) query.uniqueResult (); + resource = (VnfResource) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'"); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType); @@ -807,22 +807,22 @@ public class CatalogDatabase implements Closeable { * @param modelCustomizationId * @return VnfResource object or null if none found */ - public VnfResource getVnfResourceByModelCustomizationId (String modelCustomizationId) { + public VnfResource getVnfResourceByModelCustomizationId(String modelCustomizationId) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId); String hql = "SELECT vr " + "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc " + "WHERE vrc.modelCustomizationUuid = :modelCustomizationId"; - Query query = getSession ().createQuery (hql); - query.setParameter ("modelCustomizationId", modelCustomizationId); + Query query = getSession().createQuery(hql); + query.setParameter("modelCustomizationId", modelCustomizationId); VnfResource resource = null; try { - resource = (VnfResource) query.uniqueResult (); - } catch (org.hibernate.NonUniqueResultException nure) { + resource = (VnfResource) query.uniqueResult(); + } catch(org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelCustomizationUuid='" + modelCustomizationId + "'"); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId); @@ -839,9 +839,9 @@ public class CatalogDatabase implements Closeable { throw e; } if (resource == null) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null); } else { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null); } return resource; } @@ -854,53 +854,54 @@ public class CatalogDatabase implements Closeable { */ public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationName (String modelCustomizationName, String modelVersionId) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF resource Customization with modelCustomizationName " + modelCustomizationName + " serviceModelUUID " + modelVersionId); String hql = "SELECT vrc FROM VnfResourceCustomization as vrc WHERE vrc.modelCustomizationUuid IN " + "(SELECT src.resourceModelCustomizationUUID FROM ServiceToResourceCustomization src " + "WHERE src.serviceModelUUID = :modelVersionId)" + "AND vrc.modelInstanceName = :modelCustomizationName"; - Query query = getSession ().createQuery (hql); - query.setParameter ("modelCustomizationName", modelCustomizationName); - query.setParameter ("modelVersionId", modelVersionId); + Query query = getSession().createQuery(hql); + query.setParameter("modelCustomizationName", modelCustomizationName); + query.setParameter("modelVersionId", modelVersionId); @SuppressWarnings("unchecked") - List <VnfResourceCustomization> resultList = query.list (); + List<VnfResourceCustomization> resultList = query.list(); - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VnfResourceCustomization not found", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceCustomizationByModelCustomizationName", null); + return resultList.get(0); } /** * Return the newest version of a specific VNF resource (queried by modelInvariantId). * - * @param version + * @param modelInvariantUuid model invariant ID + * @param modelVersion model version * @return VnfResource object or null if none found */ public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid); String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion"; - Query query = getSession ().createQuery (hql); - query.setParameter ("modelInvariantUuid", modelInvariantUuid); - query.setParameter ("serviceVersion", modelVersion); + Query query = getSession().createQuery(hql); + query.setParameter("modelInvariantUuid", modelInvariantUuid); + query.setParameter("serviceVersion", modelVersion); VnfResource resource = null; try { - resource = (VnfResource) query.uniqueResult (); + resource = (VnfResource) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'"); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid); @@ -957,43 +958,43 @@ public class CatalogDatabase implements Closeable { * Return the newest version of a vfModule - 1607 * */ - public VfModule getVfModuleModelName (String modelName) { + public VfModule getVfModuleModelName(String modelName) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get vfModuleModelName with name " + modelName); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get vfModuleModelName with name " + modelName); String hql = "FROM VfModule WHERE modelName = :model_name"; - Query query = getSession ().createQuery (hql); - query.setParameter ("model_name", modelName); + Query query = getSession().createQuery(hql); + query.setParameter("model_name", modelName); @SuppressWarnings("unchecked") - List <VfModule> resultList = query.list (); + List<VfModule> resultList = query.list(); // See if something came back. Name is unique, so - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VF not found", "CatalogDB", "getVfModuleModelName", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null); + return resultList.get(0); } - public VfModule getVfModuleModelName (String modelName, String model_version) { + public VfModule getVfModuleModelName(String modelName, String model_version) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'"); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'"); String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version"; - Query query = getSession ().createQuery (hql); - query.setParameter ("modelName", modelName); - query.setParameter ("model_version", model_version); + Query query = getSession().createQuery(hql); + query.setParameter("modelName", modelName); + query.setParameter("model_version", model_version); VfModule module = null; try { - module = (VfModule) query.uniqueResult (); + module = (VfModule) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: type='" + modelName + "', asdc_service_model_version='" + model_version + "'"); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName); @@ -1011,9 +1012,9 @@ public class CatalogDatabase implements Closeable { throw e; } if (module == null) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null); } else { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null); } return module; } @@ -1025,21 +1026,21 @@ public class CatalogDatabase implements Closeable { *@author cb645j * */ - public VfModuleCustomization getVfModuleCustomizationByModelName (String modelName) { + public VfModuleCustomization getVfModuleCustomizationByModelName(String modelName) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VfModuleCustomization By VfModule's ModelName: " + modelName); String hql = "SELECT VfModuleCustomization FROM VfModuleCustomization as vfmc LEFT OUTER JOIN VfModule as vfm on vfm.modelUUID = vfmc.vfModuleModelUuid where vfm.modelName = :model_name"; - Query query = getSession ().createQuery (hql); - query.setParameter ("model_name", modelName); + Query query = getSession().createQuery(hql); + query.setParameter("model_name", modelName); @SuppressWarnings("unchecked") List<VfModuleCustomization> resultList = query.list(); // See if something came back. Name is unique, so - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successful query but Vf module NOT found", "CatalogDB", "getVfModuleCustomizationByModelName", null); return null; } @@ -1054,28 +1055,28 @@ public class CatalogDatabase implements Closeable { * @param networkType * @return NetworkResource object or null if none found */ - public NetworkResource getNetworkResource (String networkType) { + public NetworkResource getNetworkResource(String networkType) { - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get network resource with type " + networkType); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get network resource with type " + networkType); String hql = "FROM NetworkResource WHERE model_name = :network_type"; - Query query = getSession ().createQuery (hql); - query.setParameter ("network_type", networkType); + Query query = getSession().createQuery(hql); + query.setParameter("network_type", networkType); @SuppressWarnings("unchecked") - List <NetworkResource> resultList = query.list (); + List <NetworkResource> resultList = query.list(); // See if something came back. Name is unique, so - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Network Resource not found", "CatalogDB", "getNetworkResource", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null); - return resultList.get (0); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getNetworkResource", null); + return resultList.get(0); } /** @@ -1086,46 +1087,46 @@ public class CatalogDatabase implements Closeable { * @param serviceType The service Name, if null or empty is provided, it won't be taken into account * @return VnfRecipe object or null if none found */ - public VnfRecipe getVnfRecipe (String vnfType, String action, String serviceType) { + public VnfRecipe getVnfRecipe(String vnfType, String action, String serviceType) { boolean withServiceType = false; - StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); + StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); // If query c - if (serviceType == null || serviceType.isEmpty ()) { - hql.append ("AND serviceType is NULL "); + if (serviceType == null || serviceType.isEmpty()) { + hql.append("AND serviceType is NULL "); } else { - hql.append ("AND serviceType = :serviceType "); + hql.append("AND serviceType = :serviceType "); withServiceType = true; } - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType + " and action " + action + " and service type " + serviceType); - Query query = getSession ().createQuery (hql.toString ()); - query.setParameter (VNF_TYPE, vnfType); - query.setParameter (ACTION, action); + Query query = getSession().createQuery(hql.toString()); + query.setParameter(VNF_TYPE, vnfType); + query.setParameter(ACTION, action); if (withServiceType) { - query.setParameter (SERVICE_TYPE, serviceType); + query.setParameter(SERVICE_TYPE, serviceType); } @SuppressWarnings("unchecked") - List <VnfRecipe> resultList = query.list (); + List <VnfRecipe> resultList = query.list(); - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null); + return resultList.get(0); } /** @@ -1135,31 +1136,31 @@ public class CatalogDatabase implements Closeable { * @param action * @return VnfRecipe object or null if none found */ - public VnfRecipe getVnfRecipe (String vnfType, String action) { - StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); + public VnfRecipe getVnfRecipe(String vnfType, String action) { + StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vnfType = :vnfType AND action = :action "); - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF recipe with name " + vnfType + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF recipe with name " + vnfType + " and action " + action); - Query query = getSession ().createQuery (hql.toString ()); - query.setParameter (VNF_TYPE, vnfType); - query.setParameter (ACTION, action); + Query query = getSession().createQuery(hql.toString()); + query.setParameter(VNF_TYPE, vnfType); + query.setParameter(ACTION, action); @SuppressWarnings("unchecked") - List <VnfRecipe> resultList = query.list (); + List <VnfRecipe> resultList = query.list(); - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe not found", "CatalogDB", "getVnfRecipe", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfRecipe", null); + return resultList.get(0); } /** @@ -1169,30 +1170,30 @@ public class CatalogDatabase implements Closeable { * @param action * @return VnfRecipe object or null if none found */ - public VnfRecipe getVnfRecipeByVfModuleId (String vnfType, String vfModuleId, String action) { + public VnfRecipe getVnfRecipeByVfModuleId(String vnfType, String vfModuleId, String action) { - StringBuilder hql = new StringBuilder ("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action "); + StringBuilder hql = new StringBuilder("FROM VnfRecipe WHERE vfModuleId = :vfModuleId and action = :action "); - long startTime = System.currentTimeMillis (); - LOGGER.debug ("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId); + long startTime = System.currentTimeMillis(); + LOGGER.debug("Catalog database - get VNF Recipe with vfModuleId " + vfModuleId); - Query query = getSession ().createQuery (hql.toString ()); - query.setParameter (VF_MODULE_MODEL_UUID, vfModuleId); - query.setParameter (ACTION, action); + Query query = getSession().createQuery(hql.toString ()); + query.setParameter(VF_MODULE_MODEL_UUID, vfModuleId); + query.setParameter(ACTION, action); @SuppressWarnings("unchecked") - List <VnfRecipe> resultList = query.list (); + List <VnfRecipe> resultList = query.list(); - if (resultList.isEmpty ()) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null); + if (resultList.isEmpty()) { + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF recipe Entry not found", "CatalogDB", "getVnfRecipeByVfModuleId", null); return null; } - Collections.sort (resultList, new MavenLikeVersioningComparator ()); - Collections.reverse (resultList); + Collections.sort(resultList, new MavenLikeVersioningComparator()); + Collections.reverse(resultList); - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null); - return resultList.get (0); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. VNF Recipe Entry found", "CatalogDB", "getVnfRecipeByVfModuleId", null); + return resultList.get(0); } public VfModule getVfModuleTypeByUuid(String modelCustomizationUuid) { @@ -1298,7 +1299,7 @@ public class CatalogDatabase implements Closeable { query.setParameter ("serviceModelInvariantUuid", serviceModelInvariantUuid); VnfResource vnfResource = null; try { - vnfResource = (VnfResource) query.uniqueResult (); + vnfResource = (VnfResource) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: serviceModelInvariantUuid='" + serviceModelInvariantUuid); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for serviceModelInvariantUuid=" + serviceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for serviceModelInvariantUuid==" + serviceModelInvariantUuid); @@ -1316,23 +1317,23 @@ public class CatalogDatabase implements Closeable { throw e; } if (vnfResource == null) { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleType", null); } else { - LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null); + LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleType", null); } return vnfResource; } public VnfResource getVnfResourceByVnfUuid(String vnfResourceModelInvariantUuid) { long startTime = System.currentTimeMillis(); - LOGGER.debug ("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid); + LOGGER.debug("Catalog database - get vfModuleType with vnfResourceModelInvariantUuid " + vnfResourceModelInvariantUuid); String hql = "FROM VnfResource WHERE vnfResourceModelInvariantUuid = :vnfResourceModelInvariantUuid"; Query query = getSession().createQuery(hql); - query.setParameter ("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid); + query.setParameter("vnfResourceModelInvariantUuid", vnfResourceModelInvariantUuid); VnfResource vnfResource = null; try { - vnfResource = (VnfResource) query.uniqueResult (); + vnfResource = (VnfResource) query.uniqueResult(); } catch (org.hibernate.NonUniqueResultException nure) { LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfResourceModelInvariantUuid='" + vnfResourceModelInvariantUuid); LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfResourceModelInvariantUuid=" + vnfResourceModelInvariantUuid, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfResourceModelInvariantUuid==" + vnfResourceModelInvariantUuid); diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java index b6151f176d..025b13b708 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/NetworkResource.java @@ -41,6 +41,8 @@ public class NetworkResource extends MavenLikeVersioning implements Serializable private String toscaNodeType; private Timestamp created; private String modelUUID; + private String category; + private String subCategory; private String heatTemplateArtifactUUID; public NetworkResource() {} @@ -123,8 +125,40 @@ public class NetworkResource extends MavenLikeVersioning implements Serializable public void setModelUUID(String modelUUID) { this.modelUUID = modelUUID; } - - public String getHeatTemplateArtifactUUID() { + + + /** + * @return Returns the category. + */ + public String getCategory() { + return category; + } + + + /** + * @param category The category to set. + */ + public void setCategory(String category) { + this.category = category; + } + + + /** + * @return Returns the subCategory. + */ + public String getSubCategory() { + return subCategory; + } + + + /** + * @param subCategory The subCategory to set. + */ + public void setSubCategory(String subCategory) { + this.subCategory = subCategory; + } + + public String getHeatTemplateArtifactUUID() { return heatTemplateArtifactUUID; } diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java index fe7b7a3b8c..beb021ac11 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/Service.java @@ -39,6 +39,7 @@ public class Service extends MavenLikeVersioning implements Serializable { private Timestamp created; private String toscaCsarArtifactUUID; private String modelVersion; + private String category; private String serviceType; private String serviceRole; private Map<String,ServiceRecipe> recipes; @@ -115,8 +116,22 @@ public class Service extends MavenLikeVersioning implements Serializable { this.modelVersion = modelVersion; } - - public String getServiceType() { + /** + * @return Returns the category. + */ + public String getCategory() { + return category; + } + + + /** + * @param category The category to set. + */ + public void setCategory(String category) { + this.category = category; + } + + public String getServiceType() { return serviceType; } diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java index 8fe8127383..0872f146ad 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/beans/VnfResource.java @@ -43,6 +43,8 @@ public class VnfResource extends MavenLikeVersioning implements Serializable { private String orchestrationMode; private String aicVersionMin; private String aicVersionMax; + private String category; + private String subCategory; private String heatTemplateArtifactUUId; private Timestamp created; private String modelVersion; @@ -108,7 +110,39 @@ public class VnfResource extends MavenLikeVersioning implements Serializable { this.aicVersionMax = aicVersionMax; } - public String getModelInvariantUuid() { + + /** + * @return Returns the category. + */ + public String getCategory() { + return category; + } + + + /** + * @param category The category to set. + */ + public void setCategory(String category) { + this.category = category; + } + + + /** + * @return Returns the subCategory. + */ + public String getSubCategory() { + return subCategory; + } + + + /** + * @param subCategory The subCategory to set. + */ + public void setSubCategory(String subCategory) { + this.subCategory = subCategory; + } + + public String getModelInvariantUuid() { return this.modelInvariantUuid; } diff --git a/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml b/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml index 1599cf5c66..41e049ad8d 100644 --- a/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml +++ b/mso-catalog-db/src/main/resources/NetworkResource.hbm.xml @@ -35,6 +35,8 @@ <property name="neutronNetworkType" column="NEUTRON_NETWORK_TYPE" type="string" length="20"/> <property name="description" column="DESCRIPTION" type="string" length="1200"/> <property name="orchestrationMode" column="ORCHESTRATION_MODE" type="string" length="20"/> + <property name="category" column="RESOURCE_CATEGORY" type="string" length="20"/> + <property name="subCategory" column="RESOURCE_SUB_CATEGORY" type="string" length="20"/> <property name="heatTemplateArtifactUUID" column="HEAT_TEMPLATE_ARTIFACT_UUID" type="string" length="200" not-null="true" /> <property name="aicVersionMin" type="string" > diff --git a/mso-catalog-db/src/main/resources/Service.hbm.xml b/mso-catalog-db/src/main/resources/Service.hbm.xml index 5bdb0f62bd..70f5731b7d 100644 --- a/mso-catalog-db/src/main/resources/Service.hbm.xml +++ b/mso-catalog-db/src/main/resources/Service.hbm.xml @@ -39,6 +39,7 @@ <property name="modelInvariantUUID" type="string"> <column name="MODEL_INVARIANT_UUID" default="'MANUAL_RECORD'" not-null="true" length="200"/> </property> + <property name="category" column="SERVICE_CATEGORY" type="string" length="20"/> <property name="serviceType" column="SERVICE_TYPE" type="string" length="20"/> <property name="serviceRole" column="SERVICE_ROLE" type="string" length="20"/> diff --git a/mso-catalog-db/src/main/resources/VnfResource.hbm.xml b/mso-catalog-db/src/main/resources/VnfResource.hbm.xml index 2647a0fcc2..03d1de544c 100644 --- a/mso-catalog-db/src/main/resources/VnfResource.hbm.xml +++ b/mso-catalog-db/src/main/resources/VnfResource.hbm.xml @@ -36,6 +36,8 @@ <property name="orchestrationMode" type="string" column="ORCHESTRATION_MODE" length="20" not-null="true"/> <property name="aicVersionMin" type="string" column="AIC_VERSION_MIN" length="20"/> <property name="aicVersionMax" type="string" column="AIC_VERSION_MAX" length="20"/> + <property name="category" type="string" column="RESOURCE_CATEGORY" length="20"/> + <property name="subCategory" type="string" column="RESOURCE_SUB_CATEGORY" length="20"/> <property name="heatTemplateArtifactUUId" type="string" column="HEAT_TEMPLATE_ARTIFACT_UUID" length="200" /> <property name="created" type="timestamp" generated="insert" update="false" insert="false" not-null="true"> <column name="CREATION_TIMESTAMP" default="CURRENT_TIMESTAMP"/> diff --git a/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java b/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java index 7d39dd6409..e9f080b1dd 100644 --- a/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java +++ b/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java @@ -53,12 +53,7 @@ import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization; import org.openecomp.mso.db.catalog.utils.RecordNotFoundException; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -615,31 +610,297 @@ public class CatalogDatabaseTest { assertEquals(null, service); } - @Test(expected = Exception.class) - public void getServiceTestException(){ - Service ht = cd.getService("123"); + @Test + public void getServiceTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return service; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getService("123"); + assertEquals("123-uuid", service.getModelUUID()); } - @Test(expected = Exception.class) - public void getServiceByModelUUIDTestException(){ - Service ht = cd.getServiceByModelUUID("123"); + @Test(expected = NonUniqueResultException.class) + public void getServiceNoUniqueResultTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getService("123"); + } + + @Test(expected = HibernateException.class) + public void getServiceHibernateExceptionTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getService("123"); } @Test(expected = Exception.class) - public void getService2TestException(){ + public void getServiceExceptionTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception("generic exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getService("123"); + } + + @Test + public void getServiceByModelUUIDTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return service; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + Service service = cd.getServiceByModelUUID("123"); + assertEquals("123-uuid", service.getModelUUID()); + } + + @Test + public void getService2Test(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return service; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + HashMap<String, String> map = new HashMap<>(); map.put("serviceNameVersionId", "v2"); - Service ht = cd.getService(map, "123"); + Service service = cd.getService(map, "123"); + + assertEquals("123-uuid", service.getModelUUID()); } - @Test(expected = Exception.class) - public void getServiceByModelNameTestException(){ - Service ht = cd.getServiceByModelName("123"); + @Test + public void getServiceByModelNameTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<Service> list() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return Arrays.asList(service); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getServiceByModelName("123"); + assertEquals("123-uuid", service.getModelUUID()); + } + + @Test + public void getServiceByModelNameEmptyTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<Service> list() throws Exception { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + Service service = cd.getServiceByModelName("123"); + assertEquals(null, service); + } + + @Test + public void getServiceByVersionAndInvariantIdTest() throws Exception{ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return service; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + Service service = cd.getServiceByVersionAndInvariantId("123","tetwe"); + assertEquals("123-uuid", service.getModelUUID()); } @Test(expected = Exception.class) - public void getServiceByVersionAndInvariantIdTestException() throws Exception{ - Service ht = cd.getServiceByVersionAndInvariantId("123","tetwe"); + public void getServiceByVersionAndInvariantIdNonUniqueResultTest() throws Exception{ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + Service service = cd.getServiceByVersionAndInvariantId("123","tetwe"); } @Test(expected = Exception.class) @@ -647,14 +908,112 @@ public class CatalogDatabaseTest { ServiceRecipe ht = cd.getServiceRecipe("123","tetwe"); } - @Test(expected = Exception.class) - public void getServiceRecipeByServiceModelUuidTestException() throws Exception{ - ServiceRecipe ht = cd.getServiceRecipeByServiceModelUuid("123","tetwe"); + @Test + public void getServiceRecipeByServiceModelUuidTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<ServiceRecipe> list() throws Exception { + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setId(1); + return Arrays.asList(serviceRecipe); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + ServiceRecipe serviceRecipe = cd.getServiceRecipeByServiceModelUuid("123","tetwe"); + assertEquals(1, serviceRecipe.getId()); } - @Test(expected = Exception.class) + @Test + public void getServiceRecipeByServiceModelUuidEmptyTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<ServiceRecipe> list() throws Exception { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + ServiceRecipe serviceRecipe = cd.getServiceRecipeByServiceModelUuid("123","tetwe"); + assertEquals(null, serviceRecipe); + } + + @Test public void getServiceRecipesTestException() throws Exception{ - List<ServiceRecipe> ht = cd.getServiceRecipes("123"); + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<ServiceRecipe> list() { + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setId(1); + return Arrays.asList(serviceRecipe); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + List<ServiceRecipe> serviceRecipes = cd.getServiceRecipes("123"); + assertEquals(1, serviceRecipes.size()); + } + + @Test + public void getServiceRecipesEmptyTest() throws Exception{ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<ServiceRecipe> list() { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + List<ServiceRecipe> serviceRecipes = cd.getServiceRecipes("123"); + assertEquals(0, serviceRecipes.size()); } @Test(expected = Exception.class) @@ -662,33 +1021,415 @@ public class CatalogDatabaseTest { VnfComponent ht = cd.getVnfComponent(123,"vnf"); } - @Test(expected = Exception.class) - public void getVnfResourceTestException() throws Exception{ - VnfResource ht = cd.getVnfResource("vnf"); + @Test + public void getVnfResourceTest() throws Exception{ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfResource> list() { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return Arrays.asList(vnfResource); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf"); + assertEquals("123-uuid", vnfResource.getModelUuid()); } - @Test(expected = Exception.class) - public void getVnfResource2TestException() throws Exception{ - VnfResource ht = cd.getVnfResource("vnf","3992"); + @Test + public void getVnfResourceEmptyTest() throws Exception{ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfResource> list() { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf"); + assertEquals(null, vnfResource); + } + + @Test + public void getVnfResourceByTypeTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf","3992"); + assertEquals("123-uuid", vnfResource.getModelUuid()); + } + + @Test(expected = NonUniqueResultException.class) + public void getVnfResourceNURExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf","3992"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceHibernateExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf","3992"); } @Test(expected = Exception.class) - public void getVnfResourceByModelCustomizationIdTestException() throws Exception{ - VnfResource ht = cd.getVnfResourceByModelCustomizationId("3992"); + public void getVnfResourceExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResource("vnf","3992"); + } + + @Test + public void getVnfResourceByModelCustomizationIdTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByModelCustomizationId("3992"); + assertEquals("123-uuid",vnfResource.getModelUuid()); } + @Test(expected = NonUniqueResultException.class) + public void getVnfResourceByModelCustomizationIdNURExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByModelCustomizationId("3992"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceByModelCustomizationIdHibernateExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByModelCustomizationId("3992"); + } + + @Test(expected = Exception.class) public void getServiceRecipeTest2Exception() throws Exception{ ServiceRecipe ht = cd.getServiceRecipe(1001,"3992"); } - @Test(expected = Exception.class) - public void getVnfResourceCustomizationByModelCustomizationNameTestException(){ + @Test + public void getVnfResourceCustomizationByModelCustomizationNameTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfResourceCustomization> list() throws Exception { + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setVnfResourceModelUUID("123-uuid"); + return Arrays.asList(vnfResourceCustomization); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResourceCustomization vnf = cd.getVnfResourceCustomizationByModelCustomizationName("test", "test234"); + assertEquals("123-uuid", vnf.getVnfResourceModelUUID()); + } + + @Test + public void getVnfResourceCustomizationByModelCustomizationNameEmptyTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfResourceCustomization> list() throws Exception { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; VnfResourceCustomization vnf = cd.getVnfResourceCustomizationByModelCustomizationName("test", "test234"); + assertEquals(null, vnf); + } + + @Test + public void getVnfResourceByModelInvariantIdTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult(){ + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + assertEquals("123-uuid", vnf.getModelUuid()); + } + + @Test(expected = NonUniqueResultException.class) + public void getVnfResourceByModelInvariantIdNURExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult(){ + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceByModelInvariantIdHibernateExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult(){ + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); } @Test(expected = Exception.class) - public void getVnfResourceByModelInvariantIdTestException(){ + public void getVnfResourceByModelInvariantIdExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); } @@ -697,39 +1438,445 @@ public class CatalogDatabaseTest { VnfResource vnf = cd.getVnfResourceById(19299); } - @Test(expected = Exception.class) - public void getVfModuleModelNameTestException(){ - VfModule vnf = cd.getVfModuleModelName("tetes"); + @Test + public void getVfModuleModelName(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VfModule> list() throws Exception { + VfModule vfModule = new VfModule(); + vfModule.setModelUUID("123-uuid"); + return Arrays.asList(vfModule); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VfModule vfModule = cd.getVfModuleModelName("vfmodule"); + assertEquals("123-uuid", vfModule.getModelUUID()); } - @Test(expected = Exception.class) - public void getVfModuleModelName2TestException(){ - VfModule vnf = cd.getVfModuleModelName("tetes","4kidsl"); + @Test + public void getVfModuleModelNameExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VfModule> list() throws Exception { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VfModule vfModule = cd.getVfModuleModelName("vfmodule"); + assertEquals(null, vfModule); } - @Test(expected = Exception.class) - public void ggetVfModuleCustomizationByModelNameTestException(){ - VfModuleCustomization vnf = cd.getVfModuleCustomizationByModelName("tetes"); + @Test + public void getVfModuleModelNameTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + VfModule vfModule = new VfModule(); + vfModule.setModelUUID("123-uuid"); + return vfModule; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl"); + assertEquals("123-uuid", vfModule.getModelUUID()); } - @Test(expected = Exception.class) - public void getNetworkResourceTestException(){ - NetworkResource vnf = cd.getNetworkResource("tetes"); + @Test(expected = NonUniqueResultException.class) + public void getVfModuleModelNameNURExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl"); } - @Test(expected = Exception.class) - public void getVnfRecipeTestException(){ - VnfRecipe vnf = cd.getVnfRecipe("tetes","ergfedrf","4993493"); + @Test(expected = HibernateException.class) + public void getVfModuleModelNameHibernateExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl"); } @Test(expected = Exception.class) - public void getVnfRecipe2TestException(){ - VnfRecipe vnf = cd.getVnfRecipe("tetes","4993493"); + public void getVfModuleModelNameGenericExceptionTest() { + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl"); } - @Test(expected = Exception.class) - public void getVnfRecipeByVfModuleIdTestException(){ - VnfRecipe vnf = cd.getVnfRecipeByVfModuleId("tetes","4993493","vnf"); + @Test + public void ggetVfModuleCustomizationByModelNameTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VfModuleCustomization> list() throws Exception { + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setVfModuleModelUuid("123-uuid"); + return Arrays.asList(vfModuleCustomization); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VfModuleCustomization vfModuleCustomization = cd.getVfModuleCustomizationByModelName("tetes"); + assertEquals("123-uuid", vfModuleCustomization.getVfModuleModelUuid()); + } + + @Test + public void ggetVfModuleCustomizationByModelNameEmptyTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VfModuleCustomization> list() throws Exception { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VfModuleCustomization vfModuleCustomization = cd.getVfModuleCustomizationByModelName("tetes"); + assertEquals(null, vfModuleCustomization); + } + + @Test + public void getNetworkResourceTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<NetworkResource> list() throws Exception { + NetworkResource networkResource = new NetworkResource(); + networkResource.setModelUUID("123-uuid"); + return Arrays.asList(networkResource); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + NetworkResource networkResource = cd.getNetworkResource("tetes"); + assertEquals("123-uuid", networkResource.getModelUUID()); + } + + @Test + public void getNetworkResourceTestEmptyException(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<NetworkResource> list() throws Exception { + return Arrays.asList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + NetworkResource networkResource = cd.getNetworkResource("tetes"); + assertEquals(null, networkResource); + } + + @Test + public void getVnfRecipeTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfRecipe> list() throws Exception { + VnfRecipe vnfRecipe = new VnfRecipe(); + vnfRecipe.setVfModuleId("123-id"); + return Arrays.asList(vnfRecipe); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","ergfedrf","4993493"); + assertEquals("123-id", vnfRecipe.getVfModuleId()); + } + + @Test + public void getVnfRecipeEmptyTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfRecipe> list() throws Exception { + return Collections.emptyList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","ergfedrf","4993493"); + assertEquals(null, vnfRecipe); + } + + @Test + public void getVnfRecipe2Test(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfRecipe> list() throws Exception { + VnfRecipe vnfRecipe = new VnfRecipe(); + vnfRecipe.setId(1); + return Arrays.asList(vnfRecipe); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","4993493"); + assertEquals(1, vnfRecipe.getId()); + } + + @Test + public void getVnfRecipe2EmptyTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfRecipe> list() throws Exception { + return Collections.emptyList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfRecipe vnfRecipe = cd.getVnfRecipe("tetes","4993493"); + assertEquals(null, vnfRecipe); + } + + @Test + public void getVnfRecipeByVfModuleIdTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfRecipe> list() throws Exception { + VnfRecipe vnfRecipe = new VnfRecipe(); + vnfRecipe.setId(1); + return Arrays.asList(vnfRecipe); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfRecipe vnfRecipe = cd.getVnfRecipeByVfModuleId("tetes","4993493","vnf"); + assertEquals(1, vnfRecipe.getId()); + } + + @Test + public void getVnfRecipeByVfModuleIdEmptyTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<VnfRecipe> list() throws Exception { + return Collections.emptyList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfRecipe vnfRecipe = cd.getVnfRecipeByVfModuleId("tetes","4993493","vnf"); + assertEquals(null, vnfRecipe); } @Test(expected = Exception.class) @@ -741,18 +1888,284 @@ public class CatalogDatabaseTest { public void getVfModuleType2TestException(){ VfModule vnf = cd.getVfModuleType("4993493","vnf"); } - @Test(expected = Exception.class) - public void getVnfResourceByServiceUuidTestException(){ - VnfResource vnf = cd.getVnfResourceByServiceUuid("4993493"); + @Test + public void getVnfResourceByServiceUuidTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResourceByServiceUuid("4993493"); + assertEquals("123-uuid", vnfResource.getModelUuid()); } + + @Test(expected = NonUniqueResultException.class) + public void getVnfResourceByServiceUuidNURExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResourceByServiceUuid("4993493"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceByServiceUuidHibernateExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResourceByServiceUuid("4993493"); + } + @Test(expected = Exception.class) - public void getVnfResourceByVnfUuidTestException(){ - VnfResource vnf = cd.getVnfResourceByVnfUuid("4993493"); + public void getVnfResourceByServiceUuidExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnfResource = cd.getVnfResourceByServiceUuid("4993493"); + } + + @Test + public void getVnfResourceByVnfUuidTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByVnfUuid("4993493"); + assertEquals("123-uuid", vnfResource.getModelUuid()); } + + @Test(expected = NonUniqueResultException.class) + public void getVnfResourceByVnfUuidNURExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new NonUniqueResultException(-1); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByVnfUuid("4993493"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceByVnfUuidHibernateExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByVnfUuid("4993493"); + } + @Test(expected = Exception.class) - public void getVfModuleByModelInvariantUuidTestException(){ - VfModule vnf = cd.getVfModuleByModelInvariantUuid("4993493"); + public void getVnfResourceByVnfUuidExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VnfResource vnfResource = cd.getVnfResourceByVnfUuid("4993493"); + } + + @Test + public void getVfModuleByModelInvariantUuidTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public List<VfModule> list() throws Exception { + VfModule vfModule = new VfModule(); + vfModule.setModelUUID("123-uuid"); + return Arrays.asList(vfModule); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VfModule vfModule = cd.getVfModuleByModelInvariantUuid("4993493"); + assertEquals("123-uuid", vfModule.getModelUUID()); } + + @Test + public void getVfModuleByModelInvariantUuidEmptyTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public List<VfModule> list() throws Exception { + return Collections.emptyList(); + } + }; + + MockUp<Session> mockedSession = new MockUp<Session>() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp<CatalogDatabase>() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + VfModule vfModule = cd.getVfModuleByModelInvariantUuid("4993493"); + assertEquals(null, vfModule); + } + @Test(expected = Exception.class) public void getVfModuleByModelCustomizationUuidTestException(){ VfModuleCustomization vnf = cd.getVfModuleByModelCustomizationUuid("4993493"); |