summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-requests-db/src/main
diff options
context:
space:
mode:
authorArthur Martella <amartell@research.att.com>2017-09-08 13:27:46 -0400
committerArthur Martella <amartell@research.att.com>2017-09-08 13:32:24 -0400
commit62cd6aaaf74aa91ee0037c0e155c8e7284f07567 (patch)
tree68c0c53c9156f5aa3c6b3599ac940770f986633d /mso-api-handlers/mso-requests-db/src/main
parentfa1a211d28a912892fcd888569df033900eb01ee (diff)
1710 Rebase - Second Attempt
This commit rebases changes from openecomp-mso/internal-staging-1710 up to and including this codecloud commit: 54483fc6606ddb1591a2e9da61bff8712325f924 Wed Sep 6 18:12:56 2017 -0400 Rebasing was done on a branch on top of this commit in so/master in ONAP: 93fbdfbe46104f8859d4754040f979cb7997c157 Thu Sep 7 16:42:59 2017 +0000 Change-Id: I4ad9abf40da32bf5bdca43e868b8fa2dbcd9dc59 Issue-id: SO-107 Signed-off-by: Arthur Martella <amartell@research.att.com>
Diffstat (limited to 'mso-api-handlers/mso-requests-db/src/main')
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java205
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDbSessionFactoryManager.java (renamed from mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtilsRequestsDb.java)4
2 files changed, 126 insertions, 83 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java
index a08f7cb535..1f1882aa3a 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java
@@ -20,12 +20,15 @@
package org.openecomp.mso.requestsdb;
+import java.util.Date;
import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import org.hibernate.Criteria;
import org.hibernate.Query;
@@ -33,12 +36,13 @@ import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
-import org.openecomp.mso.db.HibernateUtils;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
import org.openecomp.mso.logger.MsoLogger;
public class RequestsDatabase {
- protected static HibernateUtils hibernateUtils = new HibernateUtilsRequestsDb ();
+ protected final AbstractSessionFactoryManager sessionFactoryRequestDB;
protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
@@ -63,34 +67,16 @@ public class RequestsDatabase {
protected static final String REQUEST_ID = "requestId";
protected static MockRequestsDatabase mockDB = null;
- protected static enum Scope {
- SERVICE("service", SERVICE_INSTANCE_NAME, SERVICE_INSTANCE_ID, "serviceInstanceId"),
- VNF_INSTANCE("vnf", VNF_INSTANCE_NAME, VNF_INSTANCE_ID, "vnfInstanceId"),
- VOLUME_GROUP("volumeGroup", VOLUME_GROUP_INSTANCE_NAME, VOLUME_GROUP_INSTANCE_ID, "volumeGroupInstanceId"),
- VFMODULE("vfModule", VFMODULE_INSTANCE_NAME, VFMODULE_INSTANCE_ID, "vfModuleInstanceId"),
- NETWORK("network", NETWORK_INSTANCE_NAME, NETWORK_INSTANCE_ID, "networkInstanceId");
-
- public final String type;
- public final String nameColumn;
- public final String idColumn;
- public final String idMapKey;
-
- private Scope(String type, String nameColumn, String idColumn, String idMapKey) {
- this.type = type;
- this.nameColumn = nameColumn;
- this.idColumn = idColumn;
- this.idMapKey = idMapKey;
- }
+ public static RequestsDatabase getInstance() {
+ return new RequestsDatabase(new RequestsDbSessionFactoryManager ());
}
- /**
- * Avoids creating an instance of this utility class.
- */
- protected RequestsDatabase () {
+ protected RequestsDatabase (AbstractSessionFactoryManager sessionFactoryRequest) {
+ sessionFactoryRequestDB = sessionFactoryRequest;
}
- public static boolean healthCheck () {
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ public boolean healthCheck () {
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
try {
Query query = session.createSQLQuery (" show tables ");
@@ -105,10 +91,10 @@ public class RequestsDatabase {
}
- public static int updateInfraStatus (String requestId, String requestStatus, String lastModifiedBy) {
+ public int updateInfraStatus (String requestId, String requestStatus, String lastModifiedBy) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Update infra request record " + requestId + " with status " + requestStatus);
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
int result = 0;
try {
@@ -130,10 +116,10 @@ public class RequestsDatabase {
return result;
}
- public static int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) {
+ public int updateInfraStatus (String requestId, String requestStatus, long progress, String lastModifiedBy) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Update infra request record " + requestId + " with status " + requestStatus);
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
int result = 0;
try {
@@ -156,10 +142,10 @@ public class RequestsDatabase {
return result;
}
- public static int updateInfraFinalStatus (String requestId, String requestStatus, String statusMessage, long progress, String responseBody, String lastModifiedBy) {
+ public int updateInfraFinalStatus (String requestId, String requestStatus, String statusMessage, long progress, String responseBody, String lastModifiedBy) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Update infra request record " + requestId + " with status " + requestStatus);
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
int result = 0;
try {
@@ -185,14 +171,14 @@ public class RequestsDatabase {
}
- private static List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
+ private List<InfraActiveRequests> executeInfraQuery (List <Criterion> criteria, Order order) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Execute query on infra active request table");
List <InfraActiveRequests> results = new ArrayList<InfraActiveRequests>();
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
try {
session.beginTransaction ();
Criteria crit = session.createCriteria (InfraActiveRequests.class);
@@ -213,11 +199,11 @@ public class RequestsDatabase {
return results;
}
- public static InfraActiveRequests getRequestFromInfraActive (String requestId) {
+ public InfraActiveRequests getRequestFromInfraActive (String requestId) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Get request " + requestId + " from InfraActiveRequests DB");
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
InfraActiveRequests ar = null;
try {
session.beginTransaction ();
@@ -233,24 +219,48 @@ public class RequestsDatabase {
return ar;
}
- public static InfraActiveRequests checkInstanceNameDuplicate (Map<String,String> instanceIdMap, String instanceName, String requestScope) {
+ public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
List <Criterion> criteria = new LinkedList <> ();
- if (instanceName != null && !instanceName.equals("")) {
-
- Arrays.stream(Scope.values()) //
- .filter(scope -> scope.type.equals(requestScope)) //
- .forEach(scope -> criteria.add(Restrictions.eq(scope.nameColumn, instanceName)));
-
- } else if (instanceIdMap != null) {
-
- Arrays.stream(Scope.values()) //
- .filter(scope -> scope.type.equals(requestScope) && instanceIdMap.get(scope.idMapKey) != null) //
- .forEach(scope -> criteria.add(Restrictions.eq(scope.idColumn, instanceIdMap.get(scope.idMapKey))));
-
+ if(instanceName != null && !instanceName.equals("")) {
+
+ if(requestScope.equals("service")){
+ criteria.add (Restrictions.eq (SERVICE_INSTANCE_NAME, instanceName));
+ } else if(requestScope.equals("vnf")){
+ criteria.add (Restrictions.eq (VNF_INSTANCE_NAME, instanceName));
+ } else if(requestScope.equals("volumeGroup")){
+ criteria.add (Restrictions.eq (VOLUME_GROUP_INSTANCE_NAME, instanceName));
+ } else if(requestScope.equals("vfModule")){
+ criteria.add (Restrictions.eq (VFMODULE_INSTANCE_NAME, instanceName));
+ } else if(requestScope.equals("network")){
+ criteria.add (Restrictions.eq (NETWORK_INSTANCE_NAME, instanceName));
+ }
+
+ } else {
+ if(instanceIdMap != null){
+ if(requestScope.equals("service") && instanceIdMap.get("serviceInstanceId") != null){
+ criteria.add (Restrictions.eq (SERVICE_INSTANCE_ID, instanceIdMap.get("serviceInstanceId")));
+ }
+
+ if(requestScope.equals("vnf") && instanceIdMap.get("vnfInstanceId") != null){
+ criteria.add (Restrictions.eq (VNF_INSTANCE_ID, instanceIdMap.get("vnfInstanceId")));
+ }
+
+ if(requestScope.equals("vfModule") && instanceIdMap.get("vfModuleInstanceId") != null){
+ criteria.add (Restrictions.eq (VFMODULE_INSTANCE_ID, instanceIdMap.get("vfModuleInstanceId")));
+ }
+
+ if(requestScope.equals("volumeGroup") && instanceIdMap.get("volumeGroupInstanceId") != null){
+ criteria.add (Restrictions.eq (VOLUME_GROUP_INSTANCE_ID, instanceIdMap.get("volumeGroupInstanceId")));
+ }
+
+ if(requestScope.equals("network") && instanceIdMap.get("networkInstanceId") != null){
+ criteria.add (Restrictions.eq (NETWORK_INSTANCE_ID, instanceIdMap.get("networkInstanceId")));
+ }
+ }
}
-
+
criteria.add (Restrictions.in ("requestStatus", new String[] { "PENDING", "IN_PROGRESS", "TIMEOUT" }));
Order order = Order.desc (START_TIME);
@@ -266,15 +276,18 @@ public class RequestsDatabase {
return infraActiveRequests;
}
- public static List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive (Map<String, List<String>> orchestrationMap) {
+ public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive (Map<String, List<String>> orchestrationMap) {
List <Criterion> criteria = new LinkedList <> ();
for (Map.Entry<String, List<String>> entry : orchestrationMap.entrySet())
{
String mapKey = entry.getKey();
-
- if(mapKey.equalsIgnoreCase("vnfInstanceId")){
+ if(mapKey.equalsIgnoreCase("serviceInstanceId")) {
+ mapKey = "serviceInstanceId";
+ } else if(mapKey.equalsIgnoreCase("serviceInstanceName")) {
+ mapKey = "serviceInstanceName";
+ } else if(mapKey.equalsIgnoreCase("vnfInstanceId")){
mapKey = "vnfId";
} else if(mapKey.equalsIgnoreCase("vnfInstanceName")) {
mapKey = "vnfName";
@@ -292,9 +305,41 @@ public class RequestsDatabase {
mapKey = "networkName";
} else if(mapKey.equalsIgnoreCase("lcpCloudRegionId")) {
mapKey = "aicCloudRegion";
- }
+ } else if(mapKey.equalsIgnoreCase("tenantId")) {
+ mapKey = "tenantId";
+ } else if(mapKey.equalsIgnoreCase("modelType")) {
+ mapKey = "requestScope";
+ } else if(mapKey.equalsIgnoreCase("requestorId")) {
+ mapKey = "requestorId";
+ } else if(mapKey.equalsIgnoreCase("requestExecutionDate")) {
+ mapKey = "startTime";
+ }
- criteria.add(Restrictions.eq(mapKey, entry.getValue().get(1)));
+ String propertyValue = entry.getValue().get(1);
+ if (mapKey.equals("startTime")) {
+ SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
+ try {
+ Date thisDate = format.parse(propertyValue);
+ Timestamp minTime = new Timestamp(thisDate.getTime());
+ Timestamp maxTime = new Timestamp(thisDate.getTime() + TimeUnit.DAYS.toMillis(1));
+
+ if("DOES_NOT_EQUAL".equalsIgnoreCase(entry.getValue().get(0))) {
+ criteria.add(Restrictions.or(Restrictions.lt(mapKey, minTime),
+ Restrictions.ge(mapKey, maxTime)));
+ } else {
+ criteria.add(Restrictions.between(mapKey, minTime, maxTime));
+ }
+ }
+ catch (Exception e){
+ msoLogger.debug("Exception in getOrchestrationFiltersFromInfraActive(): + " + e.getMessage());
+ return null;
+ }
+ }
+ else if("DOES_NOT_EQUAL".equalsIgnoreCase(entry.getValue().get(0))) {
+ criteria.add(Restrictions.ne(mapKey, propertyValue));
+ } else {
+ criteria.add(Restrictions.eq(mapKey, propertyValue));
+ }
}
@@ -304,13 +349,12 @@ public class RequestsDatabase {
}
- public static List <InfraActiveRequests> getRequestListFromInfraActive (String queryAttributeName,
+ public List <InfraActiveRequests> getRequestListFromInfraActive (String queryAttributeName,
String queryValue,
String requestType) {
- long startTime = System.currentTimeMillis ();
msoLogger.debug ("Get list of infra requests from DB with " + queryAttributeName + " = " + queryValue);
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
try {
session.beginTransaction ();
Criteria crit = session.createCriteria (InfraActiveRequests.class)
@@ -334,11 +378,11 @@ public class RequestsDatabase {
}
- public static InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) {
+ public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Get infra request from DB with id " + requestId);
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
InfraActiveRequests ar = null;
try {
session.beginTransaction ();
@@ -356,13 +400,13 @@ public class RequestsDatabase {
}
- public static InfraActiveRequests checkDuplicateByVnfName (String vnfName, String action, String requestType) {
+ public InfraActiveRequests checkDuplicateByVnfName (String vnfName, String action, String requestType) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Get infra request from DB for VNF " + vnfName + " and action " + action + " and requestType " + requestType);
InfraActiveRequests ar = null;
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
try {
session.beginTransaction ();
@@ -385,13 +429,13 @@ public class RequestsDatabase {
return ar;
}
- public static InfraActiveRequests checkDuplicateByVnfId (String vnfId, String action, String requestType) {
+ public InfraActiveRequests checkDuplicateByVnfId (String vnfId, String action, String requestType) {
long startTime = System.currentTimeMillis ();
msoLogger.debug ("Get list of infra requests from DB for VNF " + vnfId + " and action " + action);
InfraActiveRequests ar = null;
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
try {
session.beginTransaction ();
@@ -414,7 +458,7 @@ public class RequestsDatabase {
return ar;
}
- public static void setMockDB(MockRequestsDatabase mockDB) {
+ public void setMockDB(MockRequestsDatabase mockDB) {
RequestsDatabase.mockDB = mockDB;
}
@@ -424,10 +468,9 @@ public class RequestsDatabase {
* @param siteName The unique name of the site
* @return SiteStatus object or null if none found
*/
- public static SiteStatus getSiteStatus (String siteName) {
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ public SiteStatus getSiteStatus (String siteName) {
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
- long startTime = System.currentTimeMillis ();
SiteStatus siteStatus = null;
msoLogger.debug ("Request database - get Site Status with Site name:" + siteName);
try {
@@ -451,8 +494,8 @@ public class RequestsDatabase {
* @param siteName The unique name of the site
* @param status The updated status of the Site
*/
- public static void updateSiteStatus (String siteName, boolean status) {
- Session session = hibernateUtils.getSessionFactory ().openSession ();
+ public void updateSiteStatus (String siteName, boolean status) {
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
session.beginTransaction ();
long startTime = System.currentTimeMillis ();
@@ -492,13 +535,13 @@ public class RequestsDatabase {
* @return current progress of the operation
* @since ONAP Amsterdam Release
*/
- public static OperationStatus getOperationStatus(String serviceId, String operationId) {
+ public OperationStatus getOperationStatus(String serviceId, String operationId) {
long startTime = System.currentTimeMillis();
msoLogger.debug("Execute query on infra active request table");
OperationStatus operStatus = null;
- Session session = hibernateUtils.getSessionFactory().openSession();
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
try {
session.beginTransaction();
String hql = "FROM OperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id";
@@ -524,8 +567,8 @@ public class RequestsDatabase {
* @param operstatus the operation object
* @since ONAP Amsterdam Release
*/
- public static void updateOperationStatus(OperationStatus operstatus) {
- Session session = hibernateUtils.getSessionFactory().openSession();
+ public void updateOperationStatus(OperationStatus operstatus) {
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
session.beginTransaction();
long startTime = System.currentTimeMillis();
@@ -563,13 +606,13 @@ public class RequestsDatabase {
* @return the progress status of a resource
* @since ONAP Amsterdam Release
*/
- public static ResourceOperationStatus getResourceOperationStatus(String serviceId, String operationId,
+ public ResourceOperationStatus getResourceOperationStatus(String serviceId, String operationId,
String resourceTemplateUUID) {
long startTime = System.currentTimeMillis();
msoLogger.debug("Execute query on infra active request table");
ResourceOperationStatus operStatus = null;
- Session session = hibernateUtils.getSessionFactory().openSession();
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
try {
session.beginTransaction();
String hql =
@@ -597,8 +640,8 @@ public class RequestsDatabase {
* @param operstatus the resource operation object
* @since ONAP Amsterdam Release
*/
- public static void updateResOperStatus(ResourceOperationStatus operStatus) {
- Session session = hibernateUtils.getSessionFactory().openSession();
+ public void updateResOperStatus(ResourceOperationStatus operStatus) {
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
session.beginTransaction();
long startTime = System.currentTimeMillis();
@@ -636,8 +679,8 @@ public class RequestsDatabase {
* @param operStatus the resource operation status
* @since ONAP Amsterdam Release
*/
- private static void updateOperationStatusBasedOnResourceStatus(ResourceOperationStatus operStatus) {
- Session session = hibernateUtils.getSessionFactory().openSession();
+ private void updateOperationStatusBasedOnResourceStatus(ResourceOperationStatus operStatus) {
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
session.beginTransaction();
long startTime = System.currentTimeMillis();
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtilsRequestsDb.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDbSessionFactoryManager.java
index 09548116c5..efe9e908a2 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtilsRequestsDb.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDbSessionFactoryManager.java
@@ -19,12 +19,12 @@
*/
package org.openecomp.mso.requestsdb;
-import org.openecomp.mso.db.HibernateUtils;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
import java.net.URL;
-public class HibernateUtilsRequestsDb extends HibernateUtils {
+public class RequestsDbSessionFactoryManager extends AbstractSessionFactoryManager {
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);