diff options
Diffstat (limited to 'adapters/mso-sdnc-adapter/src/main/java')
4 files changed, 133 insertions, 24 deletions
diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java index 91c7c7c65f..294dccdb90 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Constants.java @@ -40,4 +40,9 @@ public interface Constants { public static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey"; public static final String REQUEST_TUNABLES = "org.onap.so.adapters.sdnc"; + + public static final String MSO_ACTION_LCM = "lcm"; + public static final String LCM_API_VER = "2.00"; + public static final int LCM_FLAGS_TTL = 65000; + public static final String LCM_ORIGINATOR_ID = "MSO"; } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java index 880ef0a7b0..b15831ff03 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/MapRequestTunables.java @@ -45,27 +45,35 @@ public class MapRequestTunables { RequestTunables reqTunable = new RequestTunables(reqTunableOriginal); String error = null; String key; - if ("query".equals(reqTunable.getAction())) { // due to variable format for reqTunable.getOperation() eg - // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 - key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + ".." + reqTunable.getAction(); - logger.debug(GENERATED_KEY + key); - } else if ("put".equals(reqTunable.getAction()) || "restdelete".equals(reqTunable.getAction())) { // due to - // variable - // format for - // reqTunable.getOperation() - // eg - // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 - key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction(); - logger.debug(GENERATED_KEY + key); + String msoAction = reqTunable.getMsoAction(); + + if (Constants.MSO_ACTION_LCM.equals(msoAction)) { + key = Constants.REQUEST_TUNABLES + "." + msoAction + "." + reqTunable.getOperation(); } else { - key = Constants.REQUEST_TUNABLES + "." + reqTunable.getMsoAction() + "." + reqTunable.getOperation() + "." - + reqTunable.getAction(); - logger.debug(GENERATED_KEY + key); + if ("query".equals(reqTunable.getAction())) { + // due to variable format for reqTunable.getOperation(), eg + // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 + key = Constants.REQUEST_TUNABLES + "." + msoAction + ".." + reqTunable.getAction(); + } else if ("put".equals(reqTunable.getAction()) || "restdelete".equals(reqTunable.getAction())) { + // due to variable format for reqTunable.getOperation(), eg + // services/layer3-service-list/8fe4ba4f-35cf-4d9b-a04a-fd3f5d4c5cc9 + key = Constants.REQUEST_TUNABLES + "..." + reqTunable.getAction(); + } else { + key = Constants.REQUEST_TUNABLES + "." + msoAction + "." + reqTunable.getOperation() + "." + + reqTunable.getAction(); + } } + logger.debug(GENERATED_KEY + key); String value; value = env.getProperty(key, ""); + if (Constants.MSO_ACTION_LCM.equals(msoAction) && (value == null || value.length() == 0)) { + key = Constants.REQUEST_TUNABLES + "." + msoAction + ".default"; + logger.debug("Can not find key of " + reqTunable.getOperation() + ", use default: " + key); + value = env.getProperty(key, ""); + } + if (value != null && value.length() > 0) { String[] parts = value.split("\\|"); // escape pipe diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java index a8418ea901..bcd1db7929 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/SDNCRestClient.java @@ -98,19 +98,23 @@ public class SDNCRestClient { String bpelReqId = bpelRequest.getRequestHeader().getRequestId(); String callbackUrl = bpelRequest.getRequestHeader().getCallbackUrl(); + String msoAction = bpelRequest.getRequestHeader().getMsoAction(); String sdncReqBody = null; - RequestTunables rt = new RequestTunables(bpelReqId, bpelRequest.getRequestHeader().getMsoAction(), - bpelRequest.getRequestHeader().getSvcOperation(), bpelRequest.getRequestHeader().getSvcAction()); + RequestTunables rt = new RequestTunables(bpelReqId, msoAction, bpelRequest.getRequestHeader().getSvcOperation(), + bpelRequest.getRequestHeader().getSvcAction()); rt = tunablesMapper.setTunables(rt); rt.setSdncaNotificationUrl(env.getProperty(Constants.MY_URL_PROP)); - if ("POST".equals(rt.getReqMethod())) { Node node = (Node) bpelRequest.getRequestData(); Document reqDoc = node.getOwnerDocument(); - sdncReqBody = Utils.genSdncReq(reqDoc, rt); + if (Constants.MSO_ACTION_LCM.equals(msoAction)) { + sdncReqBody = Utils.genSdncLcmReq(reqDoc, rt); + } else { + sdncReqBody = Utils.genSdncReq(reqDoc, rt); + } } else if ("PUT".equals(rt.getReqMethod())) { Node node = (Node) bpelRequest.getRequestData(); Document reqDoc = node.getOwnerDocument(); @@ -317,7 +321,7 @@ public class SDNCRestClient { } - logger.debug("Invoking Bpel Callback. BpelCallbackUrl:{}", bpelUrl); + logger.debug("Invoking Bpel Callback. BpelCallbackUrl: {}", bpelUrl); cbPort.sdncAdapterCallback(cbReq); } catch (Exception e) { @@ -325,6 +329,6 @@ public class SDNCRestClient { logger.error("Error {} - {} - {}", ErrorCode.BusinessProcessError.getValue(), MessageEnum.RA_CALLBACK_BPEL_EXC.toString(), error, e); } - logger.info(MessageEnum.RA_CALLBACK_BPEL_COMPLETE.name(), CAMUNDA); + logger.info("{} : {}", MessageEnum.RA_CALLBACK_BPEL_COMPLETE.name(), CAMUNDA); } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java index f710988886..56c38f8891 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/impl/Utils.java @@ -24,6 +24,8 @@ package org.onap.so.adapters.sdnc.impl; import java.io.StringWriter; +import java.time.Instant; +import java.util.UUID; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -94,7 +96,7 @@ public class Utils { } String s = domToStr(newdoc); - logger.debug("Formatted SdncReq:\n", s); + logger.debug("Formatted SdncReq:\n{}", s); return s; } catch (Exception e) { @@ -128,7 +130,7 @@ public class Utils { } String s = domToStr(newdoc); - logger.debug("Formatted SdncPutReq:\n {}", s); + logger.debug("Formatted SdncPutReq:\n{}", s); return s; } catch (Exception e) { @@ -138,6 +140,96 @@ public class Utils { return null; } + public static Element genLcmCommonHeader(Document doc, String requestId) { + Element commonHeader = doc.createElement("common-header"); + + Element hdrChild; + + hdrChild = doc.createElement("api-ver"); + hdrChild.appendChild(doc.createTextNode(Constants.LCM_API_VER)); + commonHeader.appendChild(hdrChild); + + hdrChild = doc.createElement("flags"); + + Element flagChild; + + flagChild = doc.createElement("force"); + flagChild.appendChild(doc.createTextNode("FALSE")); + hdrChild.appendChild(flagChild); + + flagChild = doc.createElement("mode"); + flagChild.appendChild(doc.createTextNode("NORMAL")); + hdrChild.appendChild(flagChild); + + flagChild = doc.createElement("ttl"); + flagChild.appendChild(doc.createTextNode(String.valueOf(Constants.LCM_FLAGS_TTL))); + hdrChild.appendChild(flagChild); + + commonHeader.appendChild(hdrChild); + + hdrChild = doc.createElement("originator-id"); + hdrChild.appendChild(doc.createTextNode(Constants.LCM_ORIGINATOR_ID)); + commonHeader.appendChild(hdrChild); + + hdrChild = doc.createElement("request-id"); + hdrChild.appendChild(doc.createTextNode(requestId)); + commonHeader.appendChild(hdrChild); + + hdrChild = doc.createElement("sub-request-id"); + hdrChild.appendChild(doc.createTextNode(UUID.randomUUID().toString())); + commonHeader.appendChild(hdrChild); + + hdrChild = doc.createElement("timestamp"); + hdrChild.appendChild(doc.createTextNode(Instant.now().toString())); + commonHeader.appendChild(hdrChild); + + return commonHeader; + } + + public static String genSdncLcmReq(Document reqDoc, RequestTunables rt) { + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + Document newdoc = db.newDocument(); + Element root = newdoc.createElementNS(rt.getNamespace(), "input"); + newdoc.appendChild(root); + + String elemData = rt.getReqId(); + if (elemData == null || elemData.length() == 0) { + elemData = UUID.randomUUID().toString(); + } + + Element hdrChild; + hdrChild = genLcmCommonHeader(newdoc, elemData); + root.appendChild(hdrChild); + + elemData = rt.getAction(); + if (elemData != null && elemData.length() > 0) { + hdrChild = newdoc.createElement("action"); + hdrChild.appendChild(newdoc.createTextNode(elemData)); + root.appendChild(hdrChild); + } + + // RequestData + NodeList nodes = reqDoc.getDocumentElement().getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node n = nodes.item(i); + Node newNode = newdoc.importNode(n, true); + root.appendChild(newNode); + } + + String s = domToStr(newdoc); + logger.debug("Formatted SdncLcmReq:\n{}", s); + return s; + + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.RA_ERROR_CREATE_SDNC_REQUEST.toString(), "SDNC", + ErrorCode.BusinessProcessError.getValue(), "Exception in genSdncLcmReq", e); + } + return null; + } + public static String genMsoFailResp(SDNCResponse resp) { try { @@ -163,7 +255,7 @@ public class Utils { root.appendChild(elem3); String s = domToStr(newdoc); - logger.debug("Formatted SdncReq: {}", s); + logger.debug("Formatted MsoFailResp:\n{}", s); return s; } catch (Exception e) { |