diff options
author | Balaji, Ramya (rb111y) <rb111y@att.com> | 2018-09-07 16:00:46 -0400 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-09-11 15:10:09 +0000 |
commit | f1b353074c937b473e23e717966d97602bc981f8 (patch) | |
tree | f35ef0d0571f898ac7c9bf1d435da9d47effe944 /appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main | |
parent | 99043712640be0ffc317f95d0630b2119998cb2b (diff) |
In progress trxns criteria fix
Changed the criteria for inprogress
transactions to the last X hours.
This will eliminate stale transactions
causing an incorrect scope
overlap error.
Issue-ID: APPC-1194
Change-Id: I2f3147503f4202e8e8931b2615e626e3b9af8261
Signed-off-by: Balaji, Ramya (rb111y) <rb111y@att.com>
Diffstat (limited to 'appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main')
-rw-r--r-- | appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java index 53f15a092..e97f7c05f 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/RequestValidatorImpl.java @@ -9,15 +9,15 @@ * 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========================================================= */ @@ -93,21 +93,26 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { private RequestValidationPolicy requestValidationPolicy; private RestClientInvoker client; private String path; + private int transactionWindowInterval=0; static final String SCOPE_OVERLAP_ENDPOINT = "appc.LCM.scopeOverlap.endpoint"; static final String ODL_USER = "appc.LCM.provider.user"; static final String ODL_PASS = "appc.LCM.provider.pass"; - + static final String TRANSACTION_WINDOW_HOURS = "appc.inProgressTransactionWindow.hours"; + public void initialize() throws APPCException { logger.info("Initializing RequestValidatorImpl."); String endpoint = null; String user = null; String pass =null; + String transactionWindow = null; + Properties properties = configuration.getProperties(); if (properties != null) { endpoint = properties.getProperty(SCOPE_OVERLAP_ENDPOINT); user = properties.getProperty(ODL_USER); pass = properties.getProperty(ODL_PASS); + transactionWindow = properties.getProperty(TRANSACTION_WINDOW_HOURS); } if (endpoint == null) { String message = "End point is not defined for scope over lap service in appc.properties."; @@ -122,12 +127,24 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { return; } + if (StringUtils.isNotBlank(transactionWindow)) { + logger.info("RequestValidatorImpl::TransactionWindow defined !!!"); + try { + transactionWindowInterval = Integer.parseInt(transactionWindow); + } + catch (NumberFormatException e) { + String message = "RequestValidatorImpl:::Error parsing transaction window interval!"; + logger.error(message, e); + throw new APPCException(message); + } + } + try { URL url = new URL(endpoint); client = new RestClientInvoker(url); client.setAuthentication(user, pass); - path = url.getPath(); - + path = url.getPath(); + } catch (MalformedURLException e) { String message = "Invalid endpoint " + endpoint; logger.error(message, e); @@ -199,10 +216,22 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { return; } + List<TransactionRecord> inProgressTransactionsAll = transactionRecorder + .getInProgressRequests(runtimeContext.getTransactionRecord(),0); List<TransactionRecord> inProgressTransactions = transactionRecorder - .getInProgressRequests(runtimeContext.getTransactionRecord()); + .getInProgressRequests(runtimeContext.getTransactionRecord(),transactionWindowInterval); + + long inProgressTransactionsAllCount = inProgressTransactionsAll.size(); + long inProgressTransactionsRelevant = inProgressTransactions.size(); logger.debug("In progress requests " + inProgressTransactions.toString()); + if ( inProgressTransactions.isEmpty()){ //No need to check for scope overlap + return; + } + + logInProgressTransactions(inProgressTransactions,inProgressTransactionsAllCount, + inProgressTransactionsRelevant ); + Long exclusiveRequestCount = inProgressTransactions.stream() .filter(record -> record.getMode().equals(Flags.Mode.EXCLUSIVE.name())).count(); if (exclusiveRequestCount > 0) { @@ -319,7 +348,7 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { ObjectMapper objectMapper = new ObjectMapper(); ScopeOverlapModel scopeOverlapModel = getScopeOverlapModel(requestContext, inProgressTransactions); // Added for change in interface for action level - + JsonNode jsonObject = objectMapper.valueToTree(scopeOverlapModel); return jsonObject; @@ -375,7 +404,7 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { Request request = new Request(); Date date = new Date(); - request.setRequestID("RequestId-ScopeOverlap " + date.toString()); + request.setRequestID("RequestId-ScopeOverlap " + date.toString()); request.setAction("isScopeOverlap"); ObjectMapper objectMapper = new ObjectMapper(); JsonNode json = objectMapper.valueToTree(requestData); @@ -383,7 +412,7 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { Input input = new Input(); input.setRequest(request); scopeOverlapModel.setInput(input); - + return scopeOverlapModel; } @@ -497,4 +526,28 @@ public class RequestValidatorImpl extends AbstractRequestValidatorImpl { } return workflowRequest; } + + public String logInProgressTransactions(List<TransactionRecord> inProgressTransactions, + long inProgressTransactionsAllCount, long inProgressTransactionsRelevant) { + if (inProgressTransactionsAllCount > inProgressTransactionsRelevant) { + logger.info("Found Stale Transactions! Ignoring Stale Transactions for target, only considering " + + "transactions within the last " + transactionWindowInterval + " hours as transactions in-progress"); + } + String logMsg=""; + for (TransactionRecord tr: inProgressTransactions) { + logMsg = ("In Progress transaction for Target ID - "+ tr.getTargetId() + + " in state " + tr.getRequestState() + + " with Start time " + tr.getStartTime().toString() + + " for more than configurable time period " + transactionWindowInterval + + " hours [transaction details - Request ID - " + tr.getTransactionId() + + ", Service Instance Id -" + tr.getServiceInstanceId() + + ", Vserver_id - " + tr.getVserverId() + + ", VNFC_name - "+ tr.getVnfcName() + + ", VF module Id - " + tr.getVfModuleId() + + " Start time " + tr.getStartTime().toString() + + "]" ); + } + return logMsg; + + } } |