aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-requests-db/src/main/java
diff options
context:
space:
mode:
authorChrisC <cc697w@intl.att.com>2017-01-31 11:40:03 +0100
committerChrisC <cc697w@intl.att.com>2017-01-31 12:59:33 +0100
commit025301d08b061482c1f046d562bf017c8cbcfe8d (patch)
tree68a2a549736c9bf0f7cd4e71c76e40ef7e2606f2 /mso-api-handlers/mso-requests-db/src/main/java
parent2754ad52f833278a5c925bd788a16d1dce16a598 (diff)
Initial OpenECOMP MSO commit
Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'mso-api-handlers/mso-requests-db/src/main/java')
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF3
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtil.java59
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraActiveRequests.java41
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraRequests.java405
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/MockRequestsDatabase.java72
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java494
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/SiteStatus.java72
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/TimestampXMLAdapter.java42
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/package-info.java26
9 files changed, 1214 insertions, 0 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF b/mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..5e9495128c
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtil.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtil.java
new file mode 100644
index 0000000000..21bece9b10
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/HibernateUtil.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb;
+
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+@SuppressWarnings("deprecation")
+public class HibernateUtil {
+
+ //private static SessionFactory SESSION_FACTORY;
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
+
+ private static SessionFactory SESSION_FACTORY;
+
+
+ static {
+ try {
+
+ if ("MYSQL".equals (System.getProperty ("mso.db")) || "MARIADB".equals(System.getProperty("mso.db"))) {
+ SESSION_FACTORY = new Configuration ().configure ("hibernate-mysql.cfg.xml").buildSessionFactory ();
+ } else {
+ LOGGER.error (MessageEnum.APIH_DB_ACCESS_EXC_REASON, "DB Connection not specified to the JVM,choose either:-Dmso.db=MARIADB, -Dmso.db=MYSQL or -Dmso.container=AJSC", "", "", MsoLogger.ErrorCode.DataError , "DB Connection not specified to the JVM,choose either:-Dmso.db=MARIADB, -Dmso.db=MYSQL or -Dmso.container=AJSC");
+ }
+ } catch (Exception ex) {
+ LOGGER.error (MessageEnum.APIH_DB_ACCESS_EXC_REASON, ex.getMessage (), "", "", MsoLogger.ErrorCode.DataError , "Problem in getting DB connection type", ex);
+ throw ex;
+ }
+ }
+
+ public static SessionFactory getSessionFactory () {
+ return SESSION_FACTORY;
+ }
+
+ private HibernateUtil () {
+ // Avoid creation of an instance
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraActiveRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraActiveRequests.java
new file mode 100644
index 0000000000..992cf6afc1
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraActiveRequests.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb;
+
+
+/**
+ * InfraActiveRequests
+ */
+public class InfraActiveRequests extends InfraRequests {
+
+ /**
+ * Serialization id.
+ */
+ private static final long serialVersionUID = 5003555140088137254L;
+
+ public InfraActiveRequests() {
+ super ();
+ }
+
+ public InfraActiveRequests(String requestId, String action) {
+ super (requestId, action);
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraRequests.java
new file mode 100644
index 0000000000..43128192d9
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/InfraRequests.java
@@ -0,0 +1,405 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb;
+
+// Generated Jul 27, 2015 3:05:00 PM by Hibernate Tools 3.4.0.CR1
+
+import java.sql.Timestamp;
+
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.openecomp.mso.requestsdb.adapter.TimestampXMLAdapter;
+
+/**
+ * InfraActiveRequests generated by hbm2java
+ */
+public class InfraRequests implements java.io.Serializable {
+
+ /**
+ * Serialization id.
+ */
+ private static final long serialVersionUID = -661307666798018192L;
+
+ private String requestId;
+ private String clientRequestId;
+ private String action;
+ private String requestStatus;
+ private String statusMessage;
+ private Long progress;
+ private Timestamp startTime;
+ private Timestamp endTime;
+ private String source;
+ private String vnfId;
+ private String vnfName;
+ private String vnfType;
+ private String serviceType;
+ private String aicNodeClli;
+ private String tenantId;
+ private String provStatus;
+ private String vnfParams;
+ private String vnfOutputs;
+ private String requestBody;
+ private String responseBody;
+ private String lastModifiedBy;
+ private Timestamp modifyTime;
+ private String requestType;
+ private String volumeGroupId;
+ private String volumeGroupName;
+ private String vfModuleId;
+ private String vfModuleName;
+ private String vfModuleModelName;
+ private String aaiServiceId;
+ private String aicCloudRegion;
+ private String callBackUrl;
+ private String correlator;
+ private String serviceInstanceId;
+ private String serviceInstanceName;
+ private String requestScope;
+ private String requestAction;
+ private String networkId;
+ private String networkName;
+ private String networkType;
+
+
+ public InfraRequests() {
+ }
+
+ public InfraRequests(String requestId, String action) {
+ this.requestId = requestId;
+ this.action = action;
+ }
+
+ public String getRequestId() {
+ return this.requestId;
+ }
+
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
+
+ public String getClientRequestId() {
+ return clientRequestId;
+ }
+
+ public void setClientRequestId(String clientRequestId) {
+ this.clientRequestId = clientRequestId;
+ }
+
+ public String getAction() {
+ return this.action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getRequestStatus() {
+ return this.requestStatus;
+ }
+
+ public void setRequestStatus(String requestStatus) {
+ this.requestStatus = requestStatus;
+ }
+
+ public String getStatusMessage() {
+ return this.statusMessage;
+ }
+
+ public void setStatusMessage(String statusMessage) {
+ this.statusMessage = statusMessage;
+ }
+
+ public Long getProgress() {
+ return this.progress;
+ }
+
+ public void setProgress(Long progress) {
+ this.progress = progress;
+ }
+
+ @XmlJavaTypeAdapter(TimestampXMLAdapter.class)
+ public Timestamp getStartTime() {
+ return this.startTime;
+ }
+
+ public void setStartTime(Timestamp startTime) {
+ this.startTime = startTime;
+ }
+
+ @XmlJavaTypeAdapter(TimestampXMLAdapter.class)
+ public Timestamp getEndTime() {
+ return this.endTime;
+ }
+
+ public void setEndTime(Timestamp endTime) {
+ this.endTime = endTime;
+ }
+
+ public String getSource() {
+ return this.source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getVnfId() {
+ return this.vnfId;
+ }
+
+ public void setVnfId(String vnfId) {
+ this.vnfId = vnfId;
+ }
+
+ public String getVnfName() {
+ return this.vnfName;
+ }
+
+ public void setVnfName(String vnfName) {
+ this.vnfName = vnfName;
+ }
+
+ public String getVnfType() {
+ return this.vnfType;
+ }
+
+ public void setVnfType(String vnfType) {
+ this.vnfType = vnfType;
+ }
+
+ public String getServiceType() {
+ return this.serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getAicNodeClli() {
+ return this.aicNodeClli;
+ }
+
+ public void setAicNodeClli(String aicNodeClli) {
+ this.aicNodeClli = aicNodeClli;
+ }
+
+ public String getTenantId() {
+ return this.tenantId;
+ }
+
+ public void setTenantId(String tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getProvStatus() {
+ return this.provStatus;
+ }
+
+ public void setProvStatus(String provStatus) {
+ this.provStatus = provStatus;
+ }
+
+ public String getVnfParams() {
+ return this.vnfParams;
+ }
+
+ public void setVnfParams(String vnfParams) {
+ this.vnfParams = vnfParams;
+ }
+
+ public String getVnfOutputs() {
+ return this.vnfOutputs;
+ }
+
+ public void setVnfOutputs(String vnfOutputs) {
+ this.vnfOutputs = vnfOutputs;
+ }
+
+ public String getRequestBody() {
+ return this.requestBody;
+ }
+
+ public void setRequestBody(String requestBody) {
+ this.requestBody = requestBody;
+ }
+
+ public String getResponseBody() {
+ return this.responseBody;
+ }
+
+ public void setResponseBody(String responseBody) {
+ this.responseBody = responseBody;
+ }
+
+ public String getLastModifiedBy() {
+ return this.lastModifiedBy;
+ }
+
+ public void setLastModifiedBy(String lastModifiedBy) {
+ this.lastModifiedBy = lastModifiedBy;
+ }
+
+ @XmlJavaTypeAdapter(TimestampXMLAdapter.class)
+ public Timestamp getModifyTime() {
+ return this.modifyTime;
+ }
+
+ public void setModifyTime(Timestamp modifyTime) {
+ this.modifyTime = modifyTime;
+ }
+
+ public String getRequestType() {
+ return this.requestType;
+ }
+
+ public void setRequestType(String requestType) {
+ this.requestType = requestType;
+ }
+
+ public String getVolumeGroupId() {
+ return this.volumeGroupId;
+ }
+
+ public void setVolumeGroupId(String volumeGroupId) {
+ this.volumeGroupId = volumeGroupId;
+ }
+
+ public String getVolumeGroupName() {
+ return this.volumeGroupName;
+ }
+
+ public void setVolumeGroupName(String volumeGroupName) {
+ this.volumeGroupName = volumeGroupName;
+ }
+
+ public String getVfModuleId() {
+ return this.vfModuleId;
+ }
+
+ public void setVfModuleId(String vfModuleId) {
+ this.vfModuleId = vfModuleId;
+ }
+
+ public String getVfModuleName() {
+ return this.vfModuleName;
+ }
+
+ public void setVfModuleName(String vfModuleName) {
+ this.vfModuleName = vfModuleName;
+ }
+
+ public String getVfModuleModelName() {
+ return this.vfModuleModelName;
+ }
+
+ public void setVfModuleModelName(String vfModuleModelName) {
+ this.vfModuleModelName = vfModuleModelName;
+ }
+
+ public String getAaiServiceId() {
+ return this.aaiServiceId;
+ }
+
+ public void setAaiServiceId(String aaiServiceId) {
+ this.aaiServiceId = aaiServiceId;
+ }
+
+ public String getAicCloudRegion() {
+ return this.aicCloudRegion;
+ }
+
+ public void setAicCloudRegion(String aicCloudRegion) {
+ this.aicCloudRegion = aicCloudRegion;
+ }
+
+ public String getCallBackUrl() {
+ return callBackUrl;
+ }
+
+ public void setCallBackUrl(String callBackUrl) {
+ this.callBackUrl = callBackUrl;
+ }
+
+ public String getCorrelator() {
+ return correlator;
+ }
+
+ public void setCorrelator(String correlator) {
+ this.correlator = correlator;
+ }
+
+ public String getServiceInstanceId() {
+ return serviceInstanceId;
+ }
+
+ public void setServiceInstanceId(String serviceInstanceId) {
+ this.serviceInstanceId = serviceInstanceId;
+ }
+
+ public String getServiceInstanceName() {
+ return serviceInstanceName;
+ }
+
+ public void setServiceInstanceName(String serviceInstanceName) {
+ this.serviceInstanceName = serviceInstanceName;
+ }
+
+ public String getRequestScope() {
+ return requestScope;
+ }
+
+ public void setRequestScope(String requestScope) {
+ this.requestScope = requestScope;
+ }
+
+ public String getRequestAction() {
+ return requestAction;
+ }
+
+ public void setRequestAction(String requestAction) {
+ this.requestAction = requestAction;
+ }
+
+ public String getNetworkId() {
+ return networkId;
+ }
+
+ public void setNetworkId(String networkId) {
+ this.networkId = networkId;
+ }
+
+ public String getNetworkName() {
+ return networkName;
+ }
+
+ public void setNetworkName(String networkName) {
+ this.networkName = networkName;
+ }
+
+ public String getNetworkType() {
+ return networkType;
+ }
+
+ public void setNetworkType(String networkType) {
+ this.networkType = networkType;
+ }
+
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/MockRequestsDatabase.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/MockRequestsDatabase.java
new file mode 100644
index 0000000000..22179e95f8
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/MockRequestsDatabase.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb;
+
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MockRequestsDatabase {
+
+ private Map<String, InfraActiveRequests> activeRequests;
+
+ public MockRequestsDatabase() {
+ activeRequests = new HashMap<String, InfraActiveRequests>();
+ }
+
+ public void addRecord(InfraActiveRequests record) {
+ String serviceType = record.getServiceType();
+ String serviceInstanceId = record.getServiceInstanceId();
+ String key = serviceType + "::" + serviceInstanceId;
+ activeRequests.put(key, record);
+ }
+
+ public void deleteRecord(String serviceType, String serviceInstanceId) {
+ String key = serviceType + "::" + serviceInstanceId;
+ activeRequests.remove(key);
+ }
+
+ public InfraActiveRequests getRecord(String serviceType, String serviceInstanceId) {
+ String key = serviceType + "::" + serviceInstanceId;
+ InfraActiveRequests record = activeRequests.get(key);
+ return record;
+ }
+
+ public InfraActiveRequests checkDuplicate(String serviceType, String serviceInstanceId) {
+ return getRecord(serviceType, serviceInstanceId);
+ }
+
+ public InfraActiveRequests checkRetry(String serviceType, String serviceInstanceId) {
+ InfraActiveRequests record = getRecord(serviceType, serviceInstanceId);
+ InfraActiveRequests returnRecord = null;
+ if (record != null) {
+ String requestAction = record.getRequestAction();
+ if (requestAction == null || !requestAction.equals("GetLayer3ServiceDetailsRequest")) {
+ String status = record.getRequestStatus();
+ if (status != null && status.equals("COMPLETED")) {
+ return returnRecord = record;
+ }
+ }
+ }
+ return returnRecord;
+ }
+}
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
new file mode 100644
index 0000000000..8961b26a80
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java
@@ -0,0 +1,494 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.http.HttpStatus;
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.persister.entity.AbstractEntityPersister;
+
+import org.openecomp.mso.logger.MsoLogger;
+
+public final class RequestsDatabase {
+
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
+
+ private static final String SOURCE = "source";
+ private static final String START_TIME = "startTime";
+ private static final String REQUEST_TYPE = "requestType";
+ private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName";
+ private static final String VNF_INSTANCE_NAME = "vnfName";
+ private static final String VNF_INSTANCE_ID = "vnfId";
+ private static final String VOLUME_GROUP_INSTANCE_NAME = "volumeGroupName";
+ private static final String VOLUME_GROUP_INSTANCE_ID = "volumeGroupId";
+ private static final String VFMODULE_INSTANCE_NAME = "vfModuleName";
+ private static final String VFMODULE_INSTANCE_ID = "vfModuleId";
+ private static final String NETWORK_INSTANCE_NAME = "networkName";
+ private static final String NETWORK_INSTANCE_ID = "networkId";
+ private static final String GLOBAL_SUBSCRIBER_ID = "globalSubscriberId";
+ private static final String SERVICE_NAME_VERSION_ID = "serviceNameVersionId";
+ private static final String SERVICE_ID = "serviceId";
+ private static final String SERVICE_VERSION = "serviceVersion";
+ private static final String SERVICE_TYPE = "serviceType";
+ private static final String REQUEST_ID = "requestId";
+ private static MockRequestsDatabase mockDB = null;
+
+ /**
+ * Avoids creating an instance of this utility class.
+ */
+ private RequestsDatabase () {
+ }
+
+ public static boolean healthCheck () {
+ Session session = HibernateUtil.getSessionFactory ().openSession ();
+ try {
+ Query query = session.createSQLQuery (" show tables ");
+
+ List<?> list = query.list();
+
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ }
+ return true;
+ }
+
+
+ public static int updateInfraStatus (String requestId, String requestStatus, String lastModifiedBy) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Update infra request record " + requestId + " with status " + requestStatus);
+ Session session = HibernateUtil.getSessionFactory ().openSession ();
+
+ int result = 0;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("update InfraActiveRequests set requestStatus = :requestStatus, modifyTime = :modifyTime, lastModifiedBy = :lastModifiedBy where requestId = :requestId ");
+ query.setParameter ("requestStatus", requestStatus);
+ query.setParameter (REQUEST_ID, requestId);
+ query.setParameter ("lastModifiedBy", lastModifiedBy);
+ Calendar modifyTime = Calendar.getInstance ();
+ Timestamp modifyTimeStamp = new Timestamp (modifyTime.getTimeInMillis ());
+ query.setParameter ("modifyTime", modifyTimeStamp);
+ result = query.executeUpdate ();
+ session.getTransaction ().commit ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "updateInfraStatus", null);
+ }
+ return result;
+ }
+
+ public static 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 = HibernateUtil.getSessionFactory ().openSession ();
+
+ int result = 0;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("update InfraActiveRequests set requestStatus = :requestStatus, modifyTime = :modifyTime, progress = :progress, lastModifiedBy = :lastModifiedBy where requestId = :requestId ");
+ query.setParameter ("requestStatus", requestStatus);
+ query.setParameter (REQUEST_ID, requestId);
+ query.setParameter ("progress", progress);
+ query.setParameter ("lastModifiedBy", lastModifiedBy);
+ Calendar modifyTime = Calendar.getInstance ();
+ Timestamp modifyTimeStamp = new Timestamp (modifyTime.getTimeInMillis ());
+ query.setParameter ("modifyTime", modifyTimeStamp);
+ result = query.executeUpdate ();
+ session.getTransaction ().commit ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "updateInfraStatus", null);
+ }
+ return result;
+ }
+
+ public static 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 = HibernateUtil.getSessionFactory ().openSession ();
+
+ int result = 0;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("update InfraActiveRequests set requestStatus = :requestStatus, statusMessage = :statusMessage, progress = :progress, endTime = :endTime, responseBody = :responseBody, lastModifiedBy = :lastModifiedBy where id.requestId = :requestId ");
+ query.setParameter ("requestStatus", requestStatus);
+ query.setParameter ("requestId", requestId);
+ Calendar endTime = Calendar.getInstance ();
+ Timestamp endTimeStamp = new Timestamp (endTime.getTimeInMillis ());
+ query.setParameter ("endTime", endTimeStamp);
+ query.setParameter ("statusMessage", statusMessage);
+ query.setParameter ("progress", progress);
+ query.setParameter ("responseBody", responseBody);
+ query.setParameter ("lastModifiedBy", lastModifiedBy);
+ result = query.executeUpdate ();
+ session.getTransaction ().commit ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "updateInfraFinalStatus", null);
+ }
+ return result;
+ }
+
+
+ private static 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 = HibernateUtil.getSessionFactory ().openSession ();
+ try {
+ session.beginTransaction ();
+ Criteria crit = session.createCriteria (InfraActiveRequests.class);
+ for (Criterion criterion : criteria) {
+ crit.add (criterion);
+ }
+ crit.addOrder (order);
+
+ // @SuppressWarnings("unchecked")
+ results = crit.list ();
+
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getInfraActiveRequest", null);
+ }
+ return results;
+ }
+
+ public static InfraActiveRequests getRequestFromInfraActive (String requestId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Get request " + requestId + " from InfraActiveRequests DB");
+
+ Session session = HibernateUtil.getSessionFactory ().openSession ();
+ InfraActiveRequests ar = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("from InfraActiveRequests where requestId = :requestId OR clientRequestId = :requestId");
+ query.setParameter (REQUEST_ID, requestId);
+ ar = (InfraActiveRequests) query.uniqueResult ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "InfraRequestDB", "getRequestFromInfraActive", null);
+ }
+ return ar;
+ }
+
+ public static InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) {
+
+ List <Criterion> criteria = new LinkedList <> ();
+
+ 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);
+
+ List<InfraActiveRequests> dupList = executeInfraQuery(criteria, order);
+
+ InfraActiveRequests infraActiveRequests = null;
+
+ if(dupList != null && dupList.size() > 0){
+ infraActiveRequests = dupList.get(0);
+ }
+
+ return infraActiveRequests;
+ }
+
+ public static 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")){
+ mapKey = "vnfId";
+ } else if(mapKey.equalsIgnoreCase("vnfInstanceName")) {
+ mapKey = "vnfName";
+ } else if(mapKey.equalsIgnoreCase("vfModuleInstanceId")) {
+ mapKey = "vfModuleId";
+ } else if(mapKey.equalsIgnoreCase("vfModuleInstanceName")) {
+ mapKey = "vfModuleName";
+ } else if(mapKey.equalsIgnoreCase("volumeGroupInstanceId")) {
+ mapKey = "volumeGroupId";
+ } else if(mapKey.equalsIgnoreCase("volumeGroupInstanceName")) {
+ mapKey = "volumeGroupName";
+ } else if(mapKey.equalsIgnoreCase("networkInstanceId")) {
+ mapKey = "networkId";
+ } else if(mapKey.equalsIgnoreCase("networkInstanceName")) {
+ mapKey = "networkName";
+ } else if(mapKey.equalsIgnoreCase("lcpCloudRegionId")) {
+ mapKey = "aicCloudRegion";
+ }
+
+ criteria.add(Restrictions.eq(mapKey, entry.getValue().get(1)));
+
+ }
+
+ Order order = Order.asc (START_TIME);
+
+ return executeInfraQuery (criteria, order);
+ }
+
+
+ public static 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 = HibernateUtil.getSessionFactory ().openSession ();
+ try {
+ session.beginTransaction ();
+ Criteria crit = session.createCriteria (InfraActiveRequests.class)
+ .add (Restrictions.eq (queryAttributeName, queryValue));
+ crit.add (Restrictions.eqOrIsNull (REQUEST_TYPE, requestType));
+ crit.addOrder (Order.desc (START_TIME));
+ crit.addOrder (Order.asc (SOURCE));
+
+ @SuppressWarnings("unchecked")
+ List <InfraActiveRequests> arList = crit.list ();
+ if (arList != null && !arList.isEmpty ()) {
+ return arList;
+ }
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ // msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getRequestListFromInfraActive", null);
+ }
+ return null;
+ }
+
+
+ public static InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Get infra request from DB with id " + requestId);
+
+ Session session = HibernateUtil.getSessionFactory ().openSession ();
+ InfraActiveRequests ar = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("from InfraActiveRequests where (requestId = :requestId OR clientRequestId = :requestId) and requestType = :requestType");
+ query.setParameter (REQUEST_ID, requestId);
+ query.setParameter (REQUEST_TYPE, requestType);
+ ar = (InfraActiveRequests) query.uniqueResult ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getRequestFromInfraActive", null);
+ }
+ return ar;
+ }
+
+
+ public static 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 = HibernateUtil.getSessionFactory ().openSession ();
+
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("from InfraActiveRequests where vnfName = :vnfName and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT') and requestType = :requestType ORDER BY startTime DESC");
+ query.setParameter ("vnfName", vnfName);
+ query.setParameter ("action", action);
+ query.setParameter (REQUEST_TYPE, requestType);
+ @SuppressWarnings("unchecked")
+ List <InfraActiveRequests> results = query.list ();
+ if (!results.isEmpty ()) {
+ ar = results.get (0);
+ }
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "checkDuplicateByVnfName", null);
+ }
+
+ return ar;
+ }
+
+ public static 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 = HibernateUtil.getSessionFactory ().openSession ();
+
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("from InfraActiveRequests where vnfId = :vnfId and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT') and requestType = :requestType ORDER BY startTime DESC");
+ query.setParameter ("vnfId", vnfId);
+ query.setParameter ("action", action);
+ query.setParameter (REQUEST_TYPE, requestType);
+ @SuppressWarnings("unchecked")
+ List <InfraActiveRequests> results = query.list ();
+ if (!results.isEmpty ()) {
+ ar = results.get (0);
+ }
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "checkDuplicateByVnfId", null);
+ }
+
+ return ar;
+ }
+
+ public static void setMockDB(MockRequestsDatabase mockDB) {
+ RequestsDatabase.mockDB = mockDB;
+ }
+
+ /**
+ * Fetch a specific SiteStatus by SiteName.
+ *
+ * @param siteName The unique name of the site
+ * @return SiteStatus object or null if none found
+ */
+ public static SiteStatus getSiteStatus (String siteName) {
+ Session session = HibernateUtil.getSessionFactory ().openSession ();
+
+ long startTime = System.currentTimeMillis ();
+ SiteStatus siteStatus = null;
+ msoLogger.debug ("Request database - get Site Status with Site name:" + siteName);
+ try {
+ String hql = "FROM SiteStatus WHERE siteName = :site_name";
+ Query query = session.createQuery (hql);
+ query.setParameter ("site_name", siteName);
+
+ siteStatus = (SiteStatus) query.uniqueResult ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.debug ("getSiteStatus - Successfully: " + siteStatus);
+ }
+ return siteStatus;
+ }
+
+ /**
+ * Fetch a specific SiteStatus by SiteName.
+ *
+ * @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 = HibernateUtil.getSessionFactory ().openSession ();
+ session.beginTransaction ();
+
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Request database - save Site Status with Site name:" + siteName);
+ try {
+ String hql = "FROM SiteStatus WHERE siteName = :site_name";
+ Query query = session.createQuery (hql);
+ query.setParameter ("site_name", siteName);
+
+ SiteStatus siteStatus = (SiteStatus) query.uniqueResult ();
+ if (siteStatus == null) {
+ siteStatus = new SiteStatus ();
+ siteStatus.setSiteName (siteName);
+ siteStatus.setStatus (status);
+ //siteStatus.setCreated(new Timestamp(new Date().getTime()));
+ session.save (siteStatus);
+ } else {
+ siteStatus.setStatus(status);
+ //siteStatus.setCreated(new Timestamp(new Date().getTime()));
+ session.merge (siteStatus);
+ }
+ session.getTransaction ().commit ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "updateSiteStatus", null);
+ }
+ }
+
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/SiteStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/SiteStatus.java
new file mode 100644
index 0000000000..421809612c
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/SiteStatus.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb;
+
+
+import org.openecomp.mso.logger.MsoLogger;
+
+import java.sql.Timestamp;
+
+
+public class SiteStatus {
+
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL);
+
+ private boolean status;
+ private String siteName;
+ private Timestamp created;
+
+ public SiteStatus() {
+ }
+
+ public Timestamp getCreated() {
+ return created;
+ }
+
+ public void setCreated(Timestamp created) {
+ this.created = created;
+ }
+
+ public String getSiteName() {
+ return siteName;
+ }
+
+ public void setSiteName(String siteName) {
+ this.siteName = siteName;
+ }
+
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+
+ public boolean getStatus() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ return "SiteStatus{" +
+ "status=" + status +
+ ", siteName='" + siteName + '\'' +
+ ", created=" + created +
+ '}';
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/TimestampXMLAdapter.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/TimestampXMLAdapter.java
new file mode 100644
index 0000000000..1e3f46db4b
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/TimestampXMLAdapter.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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.openecomp.mso.requestsdb.adapter;
+
+
+import java.sql.Timestamp;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+public class TimestampXMLAdapter extends XmlAdapter <Long, Timestamp> {
+
+ @Override
+ public Long marshal (Timestamp v) throws Exception {
+ return v.getTime ();
+ }
+
+ @Override
+ public Timestamp unmarshal (Long v) throws Exception {
+ if (v == null) {
+ return new Timestamp(0);
+ }
+ return new Timestamp (v);
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/package-info.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/package-info.java
new file mode 100644
index 0000000000..542d711ab1
--- /dev/null
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/adapter/package-info.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 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=========================================================
+ */
+
+/**
+ * XML adapters.
+ */
+
+package org.openecomp.mso.requestsdb.adapter;
+