diff options
author | Jim Hahn <jrh3@att.com> | 2021-04-13 14:22:19 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-04-13 14:23:53 -0400 |
commit | 9496f31d3b2a1674f57a0395d050be0d9c6b87f0 (patch) | |
tree | 374fc3402a011573f75e87168d98ec31f2ab1013 /controlloop/common/eventmanager/src/main | |
parent | 6a394bb781d6e6216cf6f9ac2d2d8d788f9691ad (diff) |
Make op history classes work with generic events
Issue-ID: POLICY-3198
Change-Id: I5b80d35fbb523094ae5464e9c058fd8f2c71ff50
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/main')
3 files changed, 27 insertions, 34 deletions
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java index 091c38ef3..6dd372dc5 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.ophistory; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; /** * Data manager for the Operation History table. @@ -33,11 +32,13 @@ public interface OperationHistoryDataManager { * discarded. * * @param requestId request ID - * @param event event with which the operation is associated + * @param clName control loop name + * @param event event with which the operation is associated, typically just used for + * logging * @param targetEntity target entity associated with the operation * @param operation operation to be stored */ - void store(String requestId, VirtualControlLoopEvent event, String targetEntity, ControlLoopOperation operation); + void store(String requestId, String clName, Object event, String targetEntity, ControlLoopOperation operation); /** * Starts the background thread. diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java index 52a869597..7632a087f 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java @@ -38,7 +38,6 @@ import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.utils.jpa.EntityMgrCloser; import org.onap.policy.common.utils.jpa.EntityTransCloser; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.guard.OperationsHistory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -149,7 +148,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana } @Override - public synchronized void store(String requestId, VirtualControlLoopEvent event, String targetEntity, + public synchronized void store(String requestId, String clName, Object event, String targetEntity, ControlLoopOperation operation) { if (stopped) { @@ -158,7 +157,7 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana return; } - operations.add(new Record(requestId, event, targetEntity, operation)); + operations.add(new Record(requestId, clName, event, targetEntity, operation)); if (operations.size() > maxQueueLength) { Record discarded = operations.remove(); @@ -255,35 +254,28 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana */ private void storeRecord(EntityManager entityMgr, Record record) { - final VirtualControlLoopEvent event = record.getEvent(); + final String reqId = record.getRequestId(); + final String clName = record.getClName(); final ControlLoopOperation operation = record.getOperation(); - logger.info("store operation history record for {}", event.getRequestId()); - - List<OperationsHistory> results = - entityMgr.createQuery("select e from OperationsHistory e" - + " where e.closedLoopName= ?1" - + " and e.requestId= ?2" - + " and e.subrequestId= ?3" - + " and e.actor= ?4" - + " and e.operation= ?5" - + " and e.target= ?6", - OperationsHistory.class) - .setParameter(1, event.getClosedLoopControlName()) - .setParameter(2, record.getRequestId()) - .setParameter(3, operation.getSubRequestId()) - .setParameter(4, operation.getActor()) - .setParameter(5, operation.getOperation()) - .setParameter(6, record.getTargetEntity()) - .getResultList(); + logger.info("store operation history record for {}", reqId); + + List<OperationsHistory> results = entityMgr + .createQuery("select e from OperationsHistory e" + " where e.closedLoopName= ?1" + + " and e.requestId= ?2" + " and e.subrequestId= ?3" + " and e.actor= ?4" + + " and e.operation= ?5" + " and e.target= ?6", OperationsHistory.class) + .setParameter(1, clName).setParameter(2, record.getRequestId()) + .setParameter(3, operation.getSubRequestId()).setParameter(4, operation.getActor()) + .setParameter(5, operation.getOperation()).setParameter(6, record.getTargetEntity()) + .getResultList(); if (results.size() > 1) { - logger.warn("unexpected operation history record count {} for {}", results.size(), event.getRequestId()); + logger.warn("unexpected operation history record count {} for {}", results.size(), reqId); } OperationsHistory entry = (results.isEmpty() ? new OperationsHistory() : results.get(0)); - entry.setClosedLoopName(event.getClosedLoopControlName()); + entry.setClosedLoopName(clName); entry.setRequestId(record.getRequestId()); entry.setActor(operation.getActor()); entry.setOperation(operation.getOperation()); @@ -303,11 +295,11 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana } if (results.isEmpty()) { - logger.info("insert operation history record for {}", event.getRequestId()); + logger.info("insert operation history record for {}", reqId); ++recordsInserted; entityMgr.persist(entry); } else { - logger.info("update operation history record for {}", event.getRequestId()); + logger.info("update operation history record for {}", reqId); ++recordsUpdated; entityMgr.merge(entry); } @@ -337,7 +329,8 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana @ToString private static class Record { private String requestId; - private VirtualControlLoopEvent event; + private String clName; + private Object event; private String targetEntity; private ControlLoopOperation operation; } diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java index bd2ee043c..ce5f1c100 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStub.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 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. @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.ophistory; import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; /** * Stub implementation of a data manager; all methods return without doing anything. @@ -29,7 +28,7 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent; public class OperationHistoryDataManagerStub implements OperationHistoryDataManager { @Override - public void store(String requestId, VirtualControlLoopEvent event, String targetEntity, + public void store(String requestId, String clName, Object event, String targetEntity, ControlLoopOperation operation) { // do nothing } |