diff options
author | 2018-07-06 12:25:32 -0400 | |
---|---|---|
committer | 2018-07-10 13:08:54 +0000 | |
commit | 72dbb19dd424ef559422bd0243d6a3179e01c382 (patch) | |
tree | 3dd546cdfe7a3035f947423ed6221c14c23212d9 /appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org | |
parent | da8d16cb974f9b203a59fb350e2179bf19ac3bce (diff) |
Added seq generator changes for vnf level actions
Issue-ID: APPC-921
Change-Id: I43c2cb044783ce4cd74f9685a333b52e4c7ad1fe
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org')
8 files changed, 235 insertions, 13 deletions
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java index 974a8ea63..9006e85eb 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/SequenceGenerator.java @@ -40,5 +40,5 @@ public interface SequenceGenerator { * @return returns runtime sequence for LCM operation execution * @throws APPCException */ - List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException; + List<Transaction> generateSequence(SequenceGeneratorInput input) throws Exception; } diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dbservices/SequenceGeneratorDBServices.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dbservices/SequenceGeneratorDBServices.java new file mode 100644 index 000000000..8411c2b81 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dbservices/SequenceGeneratorDBServices.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * 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========================================================= + */ + +package org.onap.appc.seqgen.dbservices; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class SequenceGeneratorDBServices { + + private static final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorDBServices.class); + private static SequenceGeneratorDBServices dgGeneralDBService = null; + private final SvcLogicResource serviceLogic; + + public static SequenceGeneratorDBServices initialise() { + if (dgGeneralDBService == null) { + dgGeneralDBService = new SequenceGeneratorDBServices(); + } + return dgGeneralDBService; + } + + public SequenceGeneratorDBServices() { + serviceLogic = new SqlResource(); + } + + public String getOutputPayloadTemplate(SvcLogicContext localContext) throws SvcLogicException { + String fn = "DBService.getPayloadOutput"; + log.info("Entering getOutputPayloadTemplate()"); + QueryStatus status = null; + if (localContext == null) return null; + localContext.setAttribute("file_category", "output_payload"); + String queryString = "select max(internal_version) as maxInternalVersion, artifact_name as artifactName from " + + "asdc_artifacts" + " where artifact_name in (select artifact_name from " + "asdc_artifacts" + + " where file_category = '" + "payload" + "' )"; + + log.info(fn + "Query String : " + queryString); + status = serviceLogic.query("SQL", false, null, queryString, null, null, localContext); + + if (status == QueryStatus.FAILURE) + throw new SvcLogicException("Error - while getting output payload template"); + + String queryString1 = "select artifact_content from " + "asdc_artifacts" + + " where artifact_name = $artifactName and internal_version = $maxInternalVersion "; + + log.debug(fn + "Query String : " + queryString1); + status = serviceLogic.query("SQL", false, null, queryString1, null, null, localContext); + if (status == QueryStatus.FAILURE) + throw new SvcLogicException("Error - while getting output payload template"); + log.debug("Template for the payload data:" + localContext.getAttribute("artifact-content")); + return localContext != null ? localContext.getAttribute("artifact-content") : null; + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java index b804574e9..a53c408e8 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java @@ -96,7 +96,7 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { return sequenceGeneratorInput; } - private List<Transaction> generateSequence(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException { + private List<Transaction> generateSequence(SequenceGeneratorInput sequenceGeneratorInput) throws Exception { if (sequenceGeneratorInput.getRequestInfo() == null) { throw new APPCException("Request info is not provided in the input"); } @@ -262,9 +262,12 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { String vnfId = vnfInfo.get("vnf-id").asText(); String vnfType = vnfInfo.get("vnf-type").asText(); + String identityUrl = vnfInfo.get("identity-url").asText(); Vnf vnf =new Vnf(); vnf.setVnfId(vnfId); vnf.setVnfType(vnfType); + vnf.setIdentityUrl(identityUrl); + logger.debug("IdentityUrl in SeqGen:" + identityUrl); Map<Vnfc, List<Vserver>> vfcs = new HashMap<>(); JsonNode vms = vnfInfo.get("vm"); if(vms.size()<1){ @@ -275,8 +278,10 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { throw new APPCException("vserver-id not found "); } String vserverId = vm.get("vserver-id").asText(); + String vmId =vm.get("vm-id").asText(); Vserver vserver = new Vserver(); vserver.setId(vserverId); + vserver.setUrl(vmId); if (vm.get("vnfc")!=null&& vm.get("vnfc").get("vnfc-name") != null && vm.get("vnfc").get("vnfc-type")!= null) { Vnfc vfc = new Vnfc(); vfc.setVnfcType(vm.get("vnfc").get("vnfc-type").asText()); diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/PayloadGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/PayloadGenerator.java new file mode 100644 index 000000000..a7eb8593c --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/PayloadGenerator.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * 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========================================================= + */ + +package org.onap.appc.seqgen.impl; + +import java.io.InputStream; +import java.io.StringReader; +import java.io.StringWriter; +import org.onap.appc.seqgen.dbservices.SequenceGeneratorDBServices; +import org.onap.appc.seqgen.objects.SequenceGeneratorInput; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import org.apache.velocity.*; +import org.apache.velocity.runtime.RuntimeServices; +import org.apache.velocity.runtime.RuntimeSingleton; +import org.apache.velocity.runtime.parser.ParseException; +import org.apache.velocity.runtime.parser.node.SimpleNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.apache.commons.io.IOUtils; + + +public class PayloadGenerator { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(PayloadGenerator.class); + private SequenceGeneratorDBServices dbService; + + public String getPayload(SequenceGeneratorInput input, String vmId, String url)throws Exception { + SequenceGeneratorDBServices services = new SequenceGeneratorDBServices(); + SvcLogicContext ctx = new SvcLogicContext(); + String payload = null; + String payloadTemplate = null; + InputStream data = getClass().getClassLoader().getResourceAsStream("payload.json"); + String payloadTemplatefromRes = IOUtils.toString(data); + System.out.println("Input template data: " + payloadTemplatefromRes); + logger.debug("Input template data: " + payloadTemplatefromRes); + payloadTemplate=payloadTemplatefromRes; + + if (payloadTemplate != null) { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + + JsonNode payloadModel = mapper.readTree(payloadTemplate).get("output_payload-model"); + logger.debug("Payload template:"+payloadModel.toString()); + + JsonNode modelName = payloadModel.get("sequence-generator"); + logger.debug("Payload Model Name:" + modelName); + + JsonNode action = payloadModel.path("action-list"); + if (action.isArray()) { + for (JsonNode nodes : action) { + String actionName = nodes.path("action").asText(); + JsonNode payloadValues = nodes.path("payload-fields"); + logger.debug("Action Name: " + actionName + "-" + "Payload values: " + payloadValues); + String actionValue = input.getRequestInfo().getAction(); + if (actionName.equalsIgnoreCase(actionValue)) { + JsonNode template = nodes.path("payload-fields"); + logger.debug("Payload template:" + template); + payload = generatePayloadFromTemplate(template.toString(),input,url); + break; + + } + + } + } + + } + + return payload; + } + + public String generatePayloadFromTemplate(String template,SequenceGeneratorInput input,String vmId) throws ParseException { + + String payload = null; + + RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices(); + StringReader reader = new StringReader(template); + SimpleNode node = runtimeServices.parse(reader,template); + + Template templateData = new Template(); + templateData.setRuntimeServices(runtimeServices); + templateData.setData(node); + templateData.initDocument(); + + VelocityContext vc = new VelocityContext(); + String identityUrl = input.getInventoryModel().getVnf().getIdentityUrl(); + logger.debug("IdentityUrl:" + identityUrl); + logger.debug("Vm-Id:" + vmId); + vc.put("identity-url", identityUrl); + vc.put("vm-id", vmId); + + StringWriter stringWriter = new StringWriter(); + templateData.merge(vc, stringWriter); + + payload= stringWriter.toString(); + logger.debug("Payload Data:" +stringWriter.toString()); + + return payload; + + } +} diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java index 83ed9627d..85d5bc923 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java @@ -43,16 +43,18 @@ public class RestartSequenceGenerator implements SequenceGenerator{ private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestartSequenceGenerator.class); @Override - public List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException { + public List<Transaction> generateSequence(SequenceGeneratorInput input) throws Exception { logger.info("Generating sequence without dependency model"); return generateSequenceWithOutDependency(input); } - private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) { + private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) throws Exception{ + String payload = null; List<Transaction> transactionList = new LinkedList<>(); Integer transactionId = 1; List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers(); List<Integer> transactionIds = new LinkedList<>(); + PayloadGenerator payloadGenerator = new PayloadGenerator(); for (Vserver vm : vservers) { Transaction transactionStop = new Transaction(); transactionStop.setTransactionId(transactionId); @@ -62,7 +64,10 @@ public class RestartSequenceGenerator implements SequenceGenerator{ ActionIdentifier actionIdentifier = new ActionIdentifier(); actionIdentifier.setvServerId(vm.getId()); transactionStop.setActionIdentifier(actionIdentifier); - transactionStop.setPayload(input.getRequestInfo().getPayload()); + String vmId = vm.getId(); + String url = vm.getUrl(); + payload = payloadGenerator.getPayload(input, vmId, url); + transactionStop.setPayload(payload); if (vservers.size()>1) { Response failureResponse = new Response(); failureResponse.setResponseMessage(Constants.ResponseMessage.FAILURE.getResponse()); @@ -83,7 +88,8 @@ public class RestartSequenceGenerator implements SequenceGenerator{ ActionIdentifier actionIdentifierStart = new ActionIdentifier(); actionIdentifierStart.setvServerId(vm.getId()); transactionStart.setActionIdentifier(actionIdentifierStart); - transactionStart.setPayload(input.getRequestInfo().getPayload()); + payload = payloadGenerator.getPayload(input, vmId, url); + transactionStart.setPayload(payload); if (vservers.size()>1) { Response failureResponse = new Response(); failureResponse.setResponseMessage(Constants.ResponseMessage.FAILURE.getResponse()); diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java index 02e5f7fbd..8c24fe24c 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java @@ -67,8 +67,10 @@ public class StartSequenceGenerator implements SequenceGenerator { private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class); - private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) throws APPCException { + private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) throws Exception { + String payload = null; + PayloadGenerator payloadGenerator = new PayloadGenerator(); List<Transaction> transactionList = new LinkedList<>(); Integer transactionId = 1; List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers(); @@ -82,7 +84,10 @@ public class StartSequenceGenerator implements SequenceGenerator { ActionIdentifier actionIdentifier = new ActionIdentifier(); actionIdentifier.setvServerId(vm.getId()); transaction.setActionIdentifier(actionIdentifier); - transaction.setPayload(input.getRequestInfo().getPayload()); + String vmId = vm.getUrl(); + String url = vm.getUrl(); + payload = payloadGenerator.getPayload(input, vmId, url); + transaction.setPayload(payload); if(vservers.size()>1){ Response ignoreResponse = new Response(); ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); @@ -213,7 +218,7 @@ public class StartSequenceGenerator implements SequenceGenerator { } @Override - public List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException { + public List<Transaction> generateSequence(SequenceGeneratorInput input) throws Exception { if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) { if(isVnfcPresent(input)) { FlowStrategies flowStrategy = readFlowStrategy(input); diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java index ec1105d88..63ec1731e 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java @@ -60,7 +60,7 @@ public class StopSequenceGenerator implements SequenceGenerator { private static final EELFLogger logger = EELFManager.getInstance().getLogger(StopSequenceGenerator.class); @Override - public List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException { + public List<Transaction> generateSequence(SequenceGeneratorInput input) throws Exception { if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null ) { if(isVnfcPresent(input)) { FlowStrategies flowStrategy = readFlowStrategy(input); @@ -81,7 +81,9 @@ public class StopSequenceGenerator implements SequenceGenerator { } } - private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input){ + private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input)throws Exception{ + String payload = null; + PayloadGenerator payloadGenerator = new PayloadGenerator(); List<Transaction> transactionList = new LinkedList<>(); Integer transactionId = 1; List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers(); @@ -95,7 +97,10 @@ public class StopSequenceGenerator implements SequenceGenerator { ActionIdentifier actionIdentifier = new ActionIdentifier(); actionIdentifier.setvServerId(vm.getId()); transaction.setActionIdentifier(actionIdentifier); - transaction.setPayload(input.getRequestInfo().getPayload()); + String vmId = vm.getId(); + String url = vm.getUrl(); + payload = payloadGenerator.getPayload(input, vmId, url); + transaction.setPayload(payload); if(vservers.size()>1){ Response failureResponse = new Response(); failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java index 86691a3fe..f00a05455 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java @@ -123,7 +123,7 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato SequenceGeneratorInput seqGenInput = buildSeqGenInput(input); List<Transaction> transactions = seqGenerator.generateSequence(seqGenInput); rpcResult = buildSuccessResponse(transactions); - } catch (APPCException e) { + } catch (Exception e) { log.error("Error Generating Sequence",e); rpcResult = buildFailureResponse(e.getMessage()); } @@ -471,6 +471,7 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato Vnf vnf=new Vnf(); vnf.setVnfId(input.getInventoryInfo().getVnfInfo().getVnfId()); vnf.setVnfType(input.getInventoryInfo().getVnfInfo().getVnfType()); + vnf.setIdentityUrl(input.getInventoryInfo().getVnfInfo().getIdentityUrl()); return vnf; } |