diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-23 14:46:56 +0100 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-03-23 14:46:56 +0100 |
commit | 378d05bded462b721cd04e7eb5ab06a944da452e (patch) | |
tree | 1469e4d7645cb33c5c86a8c4ecccb63593e50626 /src/main/java/org/onap | |
parent | dc90370d229c69ed6c7ce39993f72a0ea3a314e9 (diff) |
Rework the SDC test
Rework the uni tests so that SDC controller is more tested, also dcae
code has been reworked for improving sonar report
Issue-ID: CLAMP-81
Change-Id: Ia6ec272e1bf86e72d9d7294aeec0695b861f78af
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java/org/onap')
4 files changed, 85 insertions, 42 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java index c4abebdcd..d5015040c 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -30,13 +30,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
-import java.security.GeneralSecurityException;
import java.util.Date;
import java.util.List;
import javax.ws.rs.BadRequestException;
-import org.apache.commons.codec.DecoderException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -46,6 +44,7 @@ import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.DcaeEvent;
+import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;
import org.onap.clamp.clds.model.properties.Global;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.util.LoggingUtils;
@@ -61,7 +60,9 @@ public class DcaeInventoryServices { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- private static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ public static final String DCAE_TYPE_NAME = "typeName";
+ public static final String DCAE_TYPE_ID = "typeId";
@Autowired
private ClampProperties refProp;
@Autowired
@@ -74,18 +75,13 @@ public class DcaeInventoryServices { * The CldsModel
* @param userId
* The user ID
- * @throws GeneralSecurityException
- * In case of issue when decryting the DCAE password
* @throws ParseException
* In case of DCAE Json parse exception
- * @throws DecoderException
- * In case of issues with HexString decoding
*/
- public void setEventInventory(CldsModel cldsModel, String userId)
- throws GeneralSecurityException, ParseException, DecoderException {
+ public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {
String artifactName = cldsModel.getControlName();
DcaeEvent dcaeEvent = new DcaeEvent();
- String isDcaeInfoAvailable = null;
+ DcaeInventoryResponse dcaeResponse = null;
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "setEventInventory");
if (artifactName != null) {
@@ -103,7 +99,7 @@ public class DcaeInventoryServices { resourceUuid = resourceUuidList.get(0);
}
/* Inventory service url is called in this method */
- isDcaeInfoAvailable = getDcaeInformation(artifactName, invariantServiceUuid, resourceUuid);
+ dcaeResponse = getDcaeInformation(artifactName, invariantServiceUuid, resourceUuid);
/* set dcae events */
dcaeEvent.setArtifactName(artifactName);
dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
@@ -120,22 +116,21 @@ public class DcaeInventoryServices { LoggingUtils.setTimeContext(startTime, new Date());
metricsLogger.info("setEventInventory complete");
}
- /* Null whether the DCAE has items lenght or not */
- if (isDcaeInfoAvailable != null) {
- /* Inserting Event in to DB */
- logger.info(isDcaeInfoAvailable);
- JSONParser parser = new JSONParser();
- Object obj0 = parser.parse(isDcaeInfoAvailable);
- JSONObject jsonObj = (JSONObject) obj0;
+ this.analyzeAndSaveDcaeResponse(dcaeResponse, cldsModel, dcaeEvent, userId);
+ }
+
+ private void analyzeAndSaveDcaeResponse(DcaeInventoryResponse dcaeResponse, CldsModel cldsModel,
+ DcaeEvent dcaeEvent, String userId) throws ParseException {
+ if (dcaeResponse != null) {
+ logger.info("Dcae Response for query on inventory: " + dcaeResponse);
String oldTypeId = cldsModel.getTypeId();
String newTypeId = "";
- if (jsonObj.get("typeId") != null) {
- newTypeId = jsonObj.get("typeId").toString();
- cldsModel.setTypeId(jsonObj.get("typeId").toString());
+ if (dcaeResponse.getTypeId() != null) {
+ newTypeId = dcaeResponse.getTypeId();
+ cldsModel.setTypeId(dcaeResponse.getTypeId());
}
- // cldsModel.setTypeName(cldsModel.getControlName().toString()+".yml");
- if (jsonObj.get("typeName") != null) {
- cldsModel.setTypeName(jsonObj.get("typeName").toString());
+ if (dcaeResponse.getTypeName() != null) {
+ cldsModel.setTypeName(dcaeResponse.getTypeName());
}
if (oldTypeId == null || !oldTypeId.equalsIgnoreCase(newTypeId)
|| cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE)) {
@@ -157,13 +152,13 @@ public class DcaeInventoryServices { * The service UUID
* @param resourceUuid
* The resource UUID
- * @return The DCAE inventory for the artifact
+ * @return The DCAE inventory for the artifact in DcaeInventoryResponse
* @throws IOException
* In case of issues with the stream
* @throws ParseException
* In case of issues with the Json parsing
*/
- public String getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
+ public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
throws IOException, ParseException {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");
@@ -171,25 +166,23 @@ public class DcaeInventoryServices { + artifactName;
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;
logger.info("Dcae Inventory Service full url - " + fullUrl);
- String daceInventoryResponse = null;
+ String dcaeInventoryResponse = null;
String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
JSONParser parser = new JSONParser();
Object obj0 = parser.parse(responseStr);
JSONObject jsonObj = (JSONObject) obj0;
Long totalCount = (Long) jsonObj.get("totalCount");
int numServices = totalCount.intValue();
- if (numServices == 0) {
- daceInventoryResponse = null;
- } else if (numServices > 0) {
+ if (numServices > 0) {
JSONArray itemsArray = (JSONArray) jsonObj.get("items");
JSONObject dcaeServiceType0 = (JSONObject) itemsArray.get(0);
- daceInventoryResponse = dcaeServiceType0.toString();
- logger.info(daceInventoryResponse);
+ dcaeInventoryResponse = dcaeServiceType0.toString();
+ logger.info("getDcaeInformation, answer from DCAE inventory:" + dcaeInventoryResponse);
}
LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());
LoggingUtils.setTimeContext(startTime, new Date());
metricsLogger.info("getDcaeInformation complete: number services returned=" + numServices);
- return daceInventoryResponse;
+ return new ObjectMapper().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);
}
/**
diff --git a/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java new file mode 100644 index 000000000..b0a784c83 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/model/dcae/DcaeInventoryResponse.java @@ -0,0 +1,53 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.model.dcae; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** + * This class maps the DCAE inventory answer to a nice pojo. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class DcaeInventoryResponse { + + private String typeName; + private String typeId; + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getTypeId() { + return typeId; + } + + public void setTypeId(String typeId) { + this.typeId = typeId; + } +} diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java index b11385239..97ab05868 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java @@ -66,6 +66,7 @@ public class CsarHandler { private String blueprintInvariantResourceUuid; private String blueprintInvariantServiceUuid; public static final String CSAR_TYPE = "TOSCA_CSAR"; + public static final String BLUEPRINT_TYPE = "DCAE_INVENTORY_BLUEPRINT"; private INotificationData sdcNotification; public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException { @@ -114,7 +115,7 @@ public class CsarHandler { for (IResourceInstance resource : this.getSdcNotification().getResources()) { if ("VF".equals(resource.getResourceType())) { for (IArtifactInfo artifact : resource.getArtifacts()) { - if ("DCAE_INVENTORY_BLUEPRINT".equals(artifact.getArtifactType())) { + if (BLUEPRINT_TYPE.equals(artifact.getArtifactType())) { blueprintArtifactName = artifact.getArtifactName(); blueprintInvariantResourceUuid = resource.getResourceInvariantUUID(); } @@ -129,7 +130,7 @@ public class CsarHandler { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); - if (entry.getName().contains("DCAE_INVENTORY_BLUEPRINT")) { + if (entry.getName().contains(BLUEPRINT_TYPE)) { listEntries.add(entry); } } diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index cb100725b..4c6ed7fc7 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -24,8 +24,6 @@ package org.onap.clamp.clds.sdc.controller.installer; import com.att.aft.dme2.internal.apache.commons.io.IOUtils; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import java.io.IOException; import java.util.ArrayList; @@ -57,7 +55,6 @@ import org.yaml.snakeyaml.Yaml; */ public class CsarInstallerImpl implements CsarInstaller { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class); private Map<String, BlueprintParserFilesConfiguration> bpmnMapping = new HashMap<>(); public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-ClosedLoopTemplate-"; public static final String MODEL_NAME_PREFIX = "ClosedLoop-"; @@ -153,11 +150,11 @@ public class CsarInstallerImpl implements CsarInstaller { private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException { return dcaeInventoryService.getDcaeInformation(csar.getBlueprintArtifactName(), - csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid()); + csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid()).getTypeId(); } private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintParserFilesConfiguration configFiles) - throws IOException, SdcArtifactInstallerException { + throws IOException { CldsTemplate template = new CldsTemplate(); template.setBpmnId("Sdc-Generated"); template.setBpmnText( @@ -184,9 +181,8 @@ public class CsarInstallerImpl implements CsarInstaller { cldsModel.setBlueprintText(csar.getDcaeBlueprint()); cldsModel.setTemplateName(cldsTemplate.getName()); cldsModel.setTemplateId(cldsTemplate.getId()); - // cldsModel.setDocText(cldsTemplate.getPropText()); cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" - + csar.getSdcNotification().getServiceInvariantUUID() + "\"]},{\"name\":\"vf\",\"value\":[\"" + + csar.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" + csar.getBlueprintInvariantResourceUuid() + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]}]}"); cldsModel.setBpmnText(cldsTemplate.getBpmnText()); |