diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-03-14 09:22:15 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-14 09:22:15 +0000 |
commit | 09f3630ea990197e9d7b669aa2d6a63ec397bf3e (patch) | |
tree | 6625d3e9ac31600d86bf54a50e75dba61cc2c82a /mso-api-handlers/mso-requests-db/src | |
parent | a56de0e221751debd038aca5b6d20d8f9325d294 (diff) | |
parent | 38f720752af4d4aad8c4e467a288d9048659f688 (diff) |
Merge "AT&T 1712 and 1802 release code"
Diffstat (limited to 'mso-api-handlers/mso-requests-db/src')
34 files changed, 3229 insertions, 34 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml b/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml index b9ac472778..d62640525b 100644 --- a/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml +++ b/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml @@ -22,10 +22,9 @@ <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://www.hibernate.org/dtd//hibernate-reverse-engineering-3.0.dtd" > <hibernate-reverse-engineering> - - <schema-selection match-schema="MSO"/> - <table-filter match-schema="MSO" match-name=".*"/> - <type-mapping> - <sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" /> - </type-mapping> + <schema-selection match-schema="MSO" /> + <type-mapping> + <sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" /> + </type-mapping> + <table-filter match-schema="MSO" match-name=".*" /> </hibernate-reverse-engineering> 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 index 27630c5505..5089b36573 100644 --- 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 @@ -78,6 +78,10 @@ public class InfraRequests implements java.io.Serializable { private String networkName; private String networkType; private String requestorId; + private String configurationId; + private String configurationName; + private String operationalEnvId; + private String operationalEnvName; public InfraRequests() { } @@ -410,4 +414,35 @@ public class InfraRequests implements java.io.Serializable { this.requestorId = requestorId; } + public String getConfigurationId() { + return configurationId; + } + + public void setConfigurationId(String configurationId) { + this.configurationId = configurationId; + } + + public String getConfigurationName() { + return configurationName; + } + + public void setConfigurationName(String configurationName) { + this.configurationName = configurationName; + } + + public String getOperationalEnvId() { + return operationalEnvId; + } + + public void setOperationalEnvId(String operationalEnvId) { + this.operationalEnvId = operationalEnvId; + } + + public String getOperationalEnvName() { + return operationalEnvName; + } + + public void setOperationalEnvName(String operationalEnvName) { + this.operationalEnvName = operationalEnvName; + } } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatus.java new file mode 100644 index 0000000000..2818a85020 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatus.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.io.Serializable; +import java.sql.Timestamp; + +public class OperationalEnvDistributionStatus implements Serializable { + + /** + * Serialization id. + */ + private static final long serialVersionUID = 7398393659281364650L; + + private String distributionId; + private String operationalEnvId; + private String serviceModelVersionId; + private String requestId; + private String distributionIdStatus; + private String distributionIdErrorReason; + private Timestamp createTime; + private Timestamp modifyTime; + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getOperationalEnvId() { + return operationalEnvId; + } + + public void setOperationalEnvId(String operationalEnvId) { + this.operationalEnvId = operationalEnvId; + } + + public String getServiceModelVersionId() { + return serviceModelVersionId; + } + + public void setServiceModelVersionId(String serviceModelVersionId) { + this.serviceModelVersionId = serviceModelVersionId; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getDistributionIdStatus() { + return distributionIdStatus; + } + + public void setDistributionIdStatus(String distributionIdStatus) { + this.distributionIdStatus = distributionIdStatus; + } + + public String getDistributionIdErrorReason() { + return distributionIdErrorReason; + } + + public void setDistributionIdErrorReason(String distributionIdErrorReason) { + this.distributionIdErrorReason = distributionIdErrorReason; + } + + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + public Timestamp getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Timestamp modifyTime) { + this.modifyTime = modifyTime; + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusDb.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusDb.java new file mode 100644 index 0000000000..ce2e1f6906 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusDb.java @@ -0,0 +1,196 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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 org.hibernate.Query;
+import org.hibernate.Session;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+public class OperationalEnvDistributionStatusDb {
+
+ protected final AbstractSessionFactoryManager sessionFactoryRequestDB;
+
+ protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
+
+
+ protected static final String DISTRIBUTION_ID = "distributionId";
+ protected static final String OPERATIONAL_ENV_ID = "operationalEnvId";
+ protected static final String REQUEST_ID = "requestId";
+ protected static final String SERVICE_MODEL_VERSION_ID = "serviceModelVersionId";
+ protected static final String DISTRIBUTION_ID_STATUS = "distributionIdStatus";
+ protected static final String CREATE_TIME = "startTime";
+ protected static final String MODIFY_TIME = "modifyTime";
+
+
+ public static OperationalEnvDistributionStatusDb getInstance() {
+ return new OperationalEnvDistributionStatusDb(new RequestsDbSessionFactoryManager ());
+ }
+
+ protected OperationalEnvDistributionStatusDb (AbstractSessionFactoryManager sessionFactoryRequest) {
+ sessionFactoryRequestDB = sessionFactoryRequest;
+ }
+
+
+ /**
+ * Retrieve OperationalEnvDistributionStatus from getSecgiven distributionId + * @param distributionId
+ * @return
+ */
+ public OperationalEnvDistributionStatus getOperationalEnvDistributionStatus(String distributionId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Retrieve Operational Environment Distribution Status with distributionId: " + distributionId);
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ OperationalEnvDistributionStatus request = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("from OperationalEnvDistributionStatus where distributionId = :distributionId");
+ query.setParameter (DISTRIBUTION_ID, distributionId);
+ request = (OperationalEnvDistributionStatus) query.uniqueResult ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "OperationalEnvDistributionStatus", "getOperationalEnvDistributionStatus", null);
+ }
+ return request;
+ }
+
+ /**
+ * Retrieve OperationalEnvDistributionStatus from given distributionId and requestId
+ * @param distributionId
+ * @param requestId
+ * @return OperationalEnvDistributionStatus + */
+ public OperationalEnvDistributionStatus getOperationalEnvDistributionStatusPerReqId(String distributionId, String requestId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Retrieve Operational Environment Distribution Status with distributionId: " + distributionId + ", requestId: " + requestId);
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ OperationalEnvDistributionStatus request = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("from OperationalEnvDistributionStatus where distributionId = :distributionId AND requestId = :requestId");
+ query.setParameter (DISTRIBUTION_ID, distributionId);
+ query.setParameter (REQUEST_ID, requestId);
+ request = (OperationalEnvDistributionStatus) query.uniqueResult ();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "OperationalEnvDistributionStatus", "getOperationalEnvDistributionStatusPerReqId", null);
+ }
+ return request;
+ }
+
+ /**
+ * Update OperationalEnvDistributionStatus with distributionIdStatus for given distributionId, serviceModelVersionId, serviceModelVersionId
+ * @param asdcStatus
+ * @param distributionId
+ * @param operationalEnvId
+ * @param serviceModelVersionId
+ */
+ public int updateOperationalEnvDistributionStatus(String asdcStatus, String distributionId,
+ String operationalEnvId, String serviceModelVersionId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Update OperationalEnvDistributionStatus DISTRIBUTION_ID_STATUS with asdcStatus: " + asdcStatus);
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ int result = 0;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("update OperationalEnvDistributionStatus set distributionIdStatus = :distributionIdStatus, modifyTime = :modifyTime where distributionId = :distributionId and "
+ + "operationalEnvId = :operationalEnvId and serviceModelVersionId = :serviceModelVersionId ");
+ query.setParameter (DISTRIBUTION_ID_STATUS, asdcStatus);
+ query.setParameter ("distributionId", distributionId);
+ query.setParameter ("operationalEnvId", operationalEnvId);
+ query.setParameter ("serviceModelVersionId", serviceModelVersionId);
+ Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis());
+ 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", "updateOperationalEnvDistributionStatus", null);
+ }
+ return result;
+ }
+
+ /**
+ * Insert into OperationalEnvDistributionStatus with distributionId, operationalEnvId, serviceModelVersionId, distributionIdStatus
+ * @param distributionId
+ * @param operationalEnvId
+ * @param serviceModelVersionId
+ * @param distributionIdStatus
+ */
+ public void insertOperationalEnvDistributionStatus(String distributionId, String operationalEnvId, String serviceModelVersionId,
+ String distributionIdStatus, String requestId) {
+ long startTime = System.currentTimeMillis ();
+ Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
+ msoLogger.debug ("Insert into OperationalEnvDistributionStatus " );
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ OperationalEnvDistributionStatus oed = new OperationalEnvDistributionStatus ();
+
+ try {
+ session.beginTransaction ();
+
+ oed.setDistributionId (distributionId);
+ oed.setOperationalEnvId (operationalEnvId);
+ oed.setServiceModelVersionId (serviceModelVersionId);
+ oed.setDistributionIdStatus (distributionIdStatus);
+ oed.setRequestId(requestId);
+ oed.setCreateTime (startTimeStamp);
+ Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis());
+ oed.setModifyTime (modifyTimeStamp);
+
+ msoLogger.debug ("About to insert a record into OperationalEnvDistributionStatus");
+
+ session.save (oed);
+ session.getTransaction ().commit ();
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in insertOperationalEnvDistributionStatus", e);
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, e.getMessage (), "OperationalEnvDistributionStatusDB", "saveRequest", null);
+ if (session != null) {
+ session.close ();
+ }
+ // throw an Exception in the event of a DB insert failure so that the calling routine can exit
+ throw e;
+ }
+ finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "OperationalEnvDistributionStatusDB", "insertOperationalEnvDistributionStatus", null);
+ }
+ }
+
+
+} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatus.java new file mode 100644 index 0000000000..27b90ae549 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatus.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.io.Serializable; +import java.sql.Timestamp; + +/** + * @author PB6115 + * + */ +public class OperationalEnvServiceModelStatus implements Serializable { + + /** + * Serialization id. + */ + private static final long serialVersionUID = 8197084996598869656L; + + private String requestId; + private String operationalEnvId; + private String serviceModelVersionId; + private String serviceModelVersionDistrStatus; + private String recoveryAction; + private int retryCount; + private String workloadContext; + private Timestamp createTime; + private Timestamp modifyTime; + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getOperationalEnvId() { + return operationalEnvId; + } + + public void setOperationalEnvId(String operationalEnvId) { + this.operationalEnvId = operationalEnvId; + } + + public String getServiceModelVersionId() { + return serviceModelVersionId; + } + + public void setServiceModelVersionId(String serviceModelVersionId) { + this.serviceModelVersionId = serviceModelVersionId; + } + + public String getServiceModelVersionDistrStatus() { + return serviceModelVersionDistrStatus; + } + + public void setServiceModelVersionDistrStatus(String serviceModelVersionDistrStatus) { + this.serviceModelVersionDistrStatus = serviceModelVersionDistrStatus; + } + + public String getRecoveryAction() { + return recoveryAction; + } + + public void setRecoveryAction(String recoveryAction) { + this.recoveryAction = recoveryAction; + } + + public int getRetryCount() { + return retryCount; + } + + public void setRetryCount(int retryCount) { + this.retryCount = retryCount; + } + + public String getWorkloadContext() { + return workloadContext; + } + + public void setWorkloadContext(String workloadContext) { + this.workloadContext = workloadContext; + } + + public Timestamp getCreateTime() { + return createTime; + } + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + public Timestamp getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Timestamp modifyTime) { + this.modifyTime = modifyTime; + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusDb.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusDb.java new file mode 100644 index 0000000000..1c2055ee91 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusDb.java @@ -0,0 +1,243 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.List; + +import org.hibernate.Query; +import org.hibernate.Session; +import org.openecomp.mso.db.AbstractSessionFactoryManager; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; + +public class OperationalEnvServiceModelStatusDb { + + protected final AbstractSessionFactoryManager sessionFactoryRequestDB; + + protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); + + + protected static final String REQUEST_ID = "requestId"; + protected static final String OPERATIONAL_ENV_ID = "operationalEnvId"; + protected static final String SERVICE_MODEL_VERSION_ID = "serviceModelVersionId"; + protected static final String SERVICE_MOD_VER_DISTR_STATUS = "serviceModelVersionDistrStatus"; + protected static final String RECOVERY_ACTION = "recoveryAction"; + protected static final int RETRY_COUNT_LEFT = 0; + protected static final String CREATE_TIME = "startTime"; + protected static final String MODIFY_TIME = "modifyTime"; + + + public static OperationalEnvServiceModelStatusDb getInstance() { + return new OperationalEnvServiceModelStatusDb(new RequestsDbSessionFactoryManager ()); + } + + protected OperationalEnvServiceModelStatusDb (AbstractSessionFactoryManager sessionFactoryRequest) { + sessionFactoryRequestDB = sessionFactoryRequest; + } + + + /** + * Retrieve OperationalEnvServiceModelStatus from given OperationalEnvironmentId and serviceModelVersionId + * @param operationalEnvId + * @param serviceModelVersionId + * @return + */ + public OperationalEnvServiceModelStatus getOperationalEnvServiceModelStatus(String operationalEnvId, String serviceModelVersionId) { + long startTime = System.currentTimeMillis (); + msoLogger.debug ("Retrieve OperationalEnvironmentServiceModel with operationalEnvironmentId: " + operationalEnvId + ", serviceModelVersionId: " + serviceModelVersionId); + + Session session = sessionFactoryRequestDB.getSessionFactory ().openSession (); + OperationalEnvServiceModelStatus request = null; + try { + session.beginTransaction (); + Query query = session.createQuery ("FROM OperationalEnvServiceModelStatus WHERE operationalEnvId = :operationalEnvId AND serviceModelVersionId = :serviceModelVersionId"); + query.setParameter ("operationalEnvId", operationalEnvId); + query.setParameter ("serviceModelVersionId", serviceModelVersionId); + request = (OperationalEnvServiceModelStatus) query.uniqueResult (); + } finally { + if (session != null && session.isOpen ()) { + session.close (); + } + msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "OperationalEnvServiceModelStatus", "getOperationalEnvServiceModelStatus", null); + } + return request; + } + + + /** + * Retrieve OperationalEnvServiceModelStatus from given OperationalEnvironmentId and serviceModelVersionId + * @param operationalEnvId + * @param serviceModelVersionId + * @return + */ + @SuppressWarnings("unchecked") + public List<OperationalEnvServiceModelStatus> getOperationalEnvIdStatus(String operationalEnvId, String requestId) { + long startTime = System.currentTimeMillis (); + msoLogger.debug ("Retrieve OperationalEnvironmentServiceModel with operationalEnvironmentId: " + operationalEnvId + ", requestId: " + requestId); + + Session session = sessionFactoryRequestDB.getSessionFactory ().openSession (); + List<OperationalEnvServiceModelStatus> requests = new ArrayList<OperationalEnvServiceModelStatus>(); + + try { + session.beginTransaction (); + Query query = session.createQuery ("FROM OperationalEnvServiceModelStatus WHERE operationalEnvId = :operationalEnvId AND requestId = :requestId"); + query.setParameter ("operationalEnvId", operationalEnvId); + query.setParameter ("requestId", requestId); + requests = query.list(); + } finally { + if (session != null && session.isOpen ()) { + session.close (); + } + msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "OperationalEnvServiceModelStatus", "getOperationalEnvIdStatus", null); + } + return requests; + } + + + /** + * Update OperationalEnvServiceModelStatus serviceModelVersionDistrStatus with asdcStatus and retryCount for given operationalEnvId, serviceModelVersionId + * @param operationalEnvId + * @param serviceModelVersionId + * @param asdcStatus + * @param retryCount + */ + public int updateOperationalEnvRetryCountStatus(String operationalEnvId, String serviceModelVersionId, String asdcStatus, int retryCount) { + long startTime = System.currentTimeMillis (); + msoLogger.debug ("Update OperationalEnvServiceModelStatus retryCount: " + retryCount + " and serviceModelVersionDistrStatus :" + asdcStatus); + + Session session = sessionFactoryRequestDB.getSessionFactory ().openSession (); + int result = 0; + try { + session.beginTransaction (); + Query query = session.createQuery ("update OperationalEnvServiceModelStatus set serviceModelVersionDistrStatus = :serviceModelVersionDistrStatus, retryCount = :retryCount, modifyTime = :modifyTime where " + + "operationalEnvId = :operationalEnvId and serviceModelVersionId = :serviceModelVersionId "); + query.setParameter ("retryCount", retryCount); + query.setParameter (SERVICE_MOD_VER_DISTR_STATUS, asdcStatus); + query.setParameter ("operationalEnvId", operationalEnvId); + query.setParameter ("serviceModelVersionId", serviceModelVersionId); + Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis()); + 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", "OperationalEnvServiceModelDB", "updateOperationalEnvRetryCountStatus", null); + } + return result; + } + + /** + * Update OperationalEnvServiceModelStatus serviceModelVersionDistrStatus with asdcStatus and retryCount for given operationalEnvId, serviceModelVersionId, requestId + * @param operationalEnvId + * @param serviceModelVersionId + * @param asdcStatus + * @param retryCount + * @param requestId + */ + public int updateOperationalEnvRetryCountStatusPerReqId(String operationalEnvId, String serviceModelVersionId, String asdcStatus, int retryCount, String requestId) { + long startTime = System.currentTimeMillis (); + msoLogger.debug ("Update OperationalEnvServiceModelStatus retryCount: " + retryCount + " and serviceModelVersionDistrStatus :" + asdcStatus); + + Session session = sessionFactoryRequestDB.getSessionFactory ().openSession (); + int result = 0; + try { + session.beginTransaction (); + Query query = session.createQuery ("update OperationalEnvServiceModelStatus set serviceModelVersionDistrStatus = :asdcStatus, retryCount = :retryCount, modifyTime = :modifyTime where " + + "operationalEnvId = :operationalEnvId and serviceModelVersionId = :serviceModelVersionId and requestId = :requestId "); + query.setParameter ("retryCount", retryCount); + query.setParameter (SERVICE_MOD_VER_DISTR_STATUS, asdcStatus); + query.setParameter ("operationalEnvId", operationalEnvId); + query.setParameter ("serviceModelVersionId", serviceModelVersionId); + query.setParameter ("requestId", requestId); + Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis()); + 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", "OperationalEnvServiceModelDB", "updateOperationalEnvRetryCountStatusPerReqId", null); + } + return result; + } + + + /** + * Insert into OperationalEnvServiceModelStatus with operationalEnvId, serviceModelVersionId, distributionIdStatus, recoveryAction, retryCount + * @param operationalEnvId + * @param serviceModelVersionId + * @param distributionIdStatus + * @param distributionId + * @param recoveryAction + * @param retryCount + */ + public void insertOperationalEnvServiceModelStatus(String requestId, String operationalEnvId, String serviceModelVersionId, + String distributionIdStatus, String recoveryAction, int retryCount, String workloadContext) { + long startTime = System.currentTimeMillis (); + Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis()); + msoLogger.debug ("Insert into OperationalEnvServiceModelStatus " ); + + Session session = sessionFactoryRequestDB.getSessionFactory ().openSession (); + OperationalEnvServiceModelStatus oesm = new OperationalEnvServiceModelStatus (); + + try { + session.beginTransaction (); + + oesm.setRequestId (requestId); + oesm.setOperationalEnvId (operationalEnvId); + oesm.setServiceModelVersionId (serviceModelVersionId); + oesm.setServiceModelVersionDistrStatus (distributionIdStatus); + oesm.setRecoveryAction (recoveryAction); + oesm.setRetryCount (retryCount); + oesm.setWorkloadContext(workloadContext); + oesm.setCreateTime (startTimeStamp); + Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis()); + oesm.setModifyTime (modifyTimeStamp); + + msoLogger.debug ("About to insert a record into OperationalEnvServiceModelStatus"); + + session.save (oesm); + session.getTransaction ().commit (); + } catch (Exception e) { + msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in insertOperationalEnvServiceModelStatus", e); + msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, e.getMessage (), "OperationalEnvServiceModelStatusDB", "saveRequest", null); + if (session != null) { + session.close (); + } + // throw an Exception in the event of a DB insert failure so that the calling routine can exit + throw e; + } finally { + if (session != null && session.isOpen ()) { + session.close (); + } + msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "OperationalEnvServiceModelStatusDB", "insertOperationalEnvServiceModelStatus", null); + } + + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDBHelper.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDBHelper.java new file mode 100644 index 0000000000..29e55b8042 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDBHelper.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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;
+
+public class RequestsDBHelper {
+
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
+ private String className = this.getClass().getSimpleName() +" class\'s ";
+ private String methodName = "";
+ private String classMethodMessage = "";
+
+ /**
+ * This util method is to update the InfraRequest table to Complete
+ * @param msg - string, unique message for each caller
+ * @param requestId - string
+ * @param operationalEnvironmentId - string
+ * @return void - nothing
+ * @throws Exception
+ */
+ public void updateInfraSuccessCompletion(String msg, String requestId, String operationalEnvironmentId) {
+ methodName = "updateInfraSuccessCompletion() method.";
+ classMethodMessage = className + " " + methodName;
+ msoLogger.debug("Begin of " + classMethodMessage);
+
+ RequestsDatabase requestDB = RequestsDatabase.getInstance();
+ requestDB.updateInfraFinalStatus(requestId, "COMPLETE", "SUCCESSFUL, operationalEnvironmentId - " + operationalEnvironmentId + "; Success Message: " + msg,
+ 100L, null, "APIH");
+ msoLogger.debug("End of " + classMethodMessage);
+
+ }
+
+ /**
+ * This util method is to update the InfraRequest table to Failure
+ * @param msg - string, unique message for each caller
+ * @param requestId - string
+ * @param operationalEnvironmentId - string
+ * @return void - nothing
+ * @throws Exception
+ */
+ public void updateInfraFailureCompletion(String msg, String requestId, String operationalEnvironmentId) {
+ methodName = "updateInfraFailureCompletion() method.";
+ classMethodMessage = className + " " + methodName;
+ msoLogger.debug("Begin of " + classMethodMessage);
+
+ RequestsDatabase requestDB = RequestsDatabase.getInstance();
+ requestDB.updateInfraFinalStatus(requestId, "FAILED", "FAILURE, operationalEnvironmentId - " + operationalEnvironmentId + "; Error message: " + msg,
+ 100L, null, "APIH");
+ msoLogger.debug("End of " + classMethodMessage);
+
+ }
+}
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 d6b0b6b419..f69378ec65 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 @@ -21,10 +21,10 @@ package org.openecomp.mso.requestsdb; -import java.util.Date; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -60,13 +60,18 @@ public class RequestsDatabase { protected static final String VFMODULE_INSTANCE_NAME = "vfModuleName"; protected static final String VFMODULE_INSTANCE_ID = "vfModuleId"; protected static final String NETWORK_INSTANCE_NAME = "networkName"; + protected static final String CONFIGURATION_INSTANCE_ID = "configurationId"; + protected static final String CONFIGURATION_INSTANCE_NAME= "configurationName"; + protected static final String OPERATIONAL_ENV_ID = "operationalEnvId"; + protected static final String OPERATIONAL_ENV_NAME = "operationalEnvName"; protected static final String NETWORK_INSTANCE_ID = "networkId"; protected static final String GLOBAL_SUBSCRIBER_ID = "globalSubscriberId"; protected static final String SERVICE_NAME_VERSION_ID = "serviceNameVersionId"; protected static final String SERVICE_ID = "serviceId"; protected static final String SERVICE_VERSION = "serviceVersion"; - protected static final String REQUEST_ID = "requestId"; + protected static final String REQUESTOR_ID = "requestorId"; + protected static MockRequestsDatabase mockDB = null; public static RequestsDatabase getInstance() { @@ -237,6 +242,10 @@ public class RequestsDatabase { criteria.add (Restrictions.eq (VFMODULE_INSTANCE_NAME, instanceName)); } else if("network".equals(requestScope)){ criteria.add (Restrictions.eq (NETWORK_INSTANCE_NAME, instanceName)); + } else if(requestScope.equals("configuration")) { + criteria.add (Restrictions.eq (CONFIGURATION_INSTANCE_NAME, instanceName)); + } else if(requestScope.equals("operationalEnvironment")) { + criteria.add (Restrictions.eq (OPERATIONAL_ENV_NAME, instanceName)); } } else { @@ -260,10 +269,18 @@ public class RequestsDatabase { if("network".equals(requestScope) && instanceIdMap.get("networkInstanceId") != null){ criteria.add (Restrictions.eq (NETWORK_INSTANCE_ID, instanceIdMap.get("networkInstanceId"))); } + + if(requestScope.equals("configuration") && instanceIdMap.get("configurationInstanceId") != null){ + criteria.add (Restrictions.eq (CONFIGURATION_INSTANCE_ID, instanceIdMap.get("configurationInstanceId"))); + } + + if(requestScope.equals("operationalEnvironment") && instanceIdMap.get("operationalEnvironmentId") != null) { + criteria.add (Restrictions.eq (OPERATIONAL_ENV_ID, instanceIdMap.get("operationalEnvironmentId"))); + } } } - criteria.add (Restrictions.in ("requestStatus", new String[] { "PENDING", "IN_PROGRESS", "TIMEOUT" })); + criteria.add (Restrictions.in ("requestStatus", new String[] { "PENDING", "IN_PROGRESS", "TIMEOUT", "PENDING_MANUAL_TASK" })); Order order = Order.desc (START_TIME); @@ -305,6 +322,10 @@ public class RequestsDatabase { mapKey = "networkId"; } else if("networkInstanceName".equalsIgnoreCase(mapKey)) { mapKey = "networkName"; + } else if(mapKey.equalsIgnoreCase("configurationInstanceId")) { + mapKey = "configurationId"; + } else if(mapKey.equalsIgnoreCase("configurationInstanceName")) { + mapKey = "configurationName"; } else if("lcpCloudRegionId".equalsIgnoreCase(mapKey)) { mapKey = "aicCloudRegion"; } else if("tenantId".equalsIgnoreCase(mapKey)) { @@ -350,6 +371,54 @@ public class RequestsDatabase { return executeInfraQuery (criteria, order); } + // Added this method for Tenant Isolation project ( 1802-295491a) to query the mso_requests DB + // (infra_active_requests table) for operationalEnvId and OperationalEnvName + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive (Map<String, String> orchestrationMap) { + List <Criterion> criteria = new LinkedList <> (); + + // Add criteria on OperationalEnvironment RequestScope when requestorId is only specified in the filter + // as the same requestorId can also match on different API methods + String resourceType = orchestrationMap.get("resourceType"); + if(resourceType == null) { + criteria.add(Restrictions.eq("requestScope", "operationalEnvironment")); + } + + for (Map.Entry<String, String> entry : orchestrationMap.entrySet()) { + String mapKey = entry.getKey(); + if(mapKey.equalsIgnoreCase("requestorId")) { + mapKey = "requestorId"; + } else if(mapKey.equalsIgnoreCase("requestExecutionDate")) { + mapKey = "startTime"; + } else if(mapKey.equalsIgnoreCase("operationalEnvironmentId")) { + mapKey = "operationalEnvId"; + } else if(mapKey.equalsIgnoreCase("operationalEnvironmentName")) { + mapKey = "operationalEnvName"; + } else if(mapKey.equalsIgnoreCase("resourceType")) { + mapKey = "requestScope"; + } + + String propertyValue = entry.getValue(); + 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)); + + criteria.add(Restrictions.between(mapKey, minTime, maxTime)); + } + catch (Exception e){ + msoLogger.debug("Exception in getCloudOrchestrationFiltersFromInfraActive(): + " + e.getMessage()); + return null; + } + } else { + criteria.add(Restrictions.eq(mapKey, propertyValue)); + } + } + + Order order = Order.asc (START_TIME); + return executeInfraQuery (criteria, order); + } public List <InfraActiveRequests> getRequestListFromInfraActive (String queryAttributeName, String queryValue, @@ -412,7 +481,7 @@ public class RequestsDatabase { 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 query = session.createQuery ("from InfraActiveRequests where vnfName = :vnfName and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT' or requestStatus = 'PENDING_MANUAL_TASK') and requestType = :requestType ORDER BY startTime DESC"); query.setParameter ("vnfName", vnfName); query.setParameter ("action", action); query.setParameter (REQUEST_TYPE, requestType); @@ -441,7 +510,7 @@ public class RequestsDatabase { 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 query = session.createQuery ("from InfraActiveRequests where vnfId = :vnfId and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT' or requestStatus = 'PENDING_MANUAL_TASK') and requestType = :requestType ORDER BY startTime DESC"); query.setParameter ("vnfId", vnfId); query.setParameter ("action", action); query.setParameter (REQUEST_TYPE, requestType); @@ -686,8 +755,8 @@ public class RequestsDatabase { operStatus = (ResourceOperationStatus)query.uniqueResult(); } finally { - if(session != null && session.isOpen()) { - session.close(); + if (session != null && session.isOpen ()) { + session.close (); } msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getOperationStatus", null); @@ -785,4 +854,31 @@ public class RequestsDatabase { "Successfully", "RequestDB", "updateResOperStatus", null); } } + + public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) { + long startTime = System.currentTimeMillis (); + msoLogger.debug ("Get Infra request from DB for OperationalEnvironmentId " + operationalEnvironmentId); + + InfraActiveRequests ar = null; + Session session = sessionFactoryRequestDB.getSessionFactory ().openSession (); + + try { + session.beginTransaction (); + Query query = session.createQuery ("FROM InfraActiveRequests WHERE operationalEnvId = :operationalEnvId AND requestStatus != 'COMPLETE' AND action = 'create' ORDER BY startTime DESC"); + query.setParameter ("operationalEnvId", operationalEnvironmentId); + + @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; + } } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatus.java new file mode 100644 index 0000000000..c52fe5013c --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatus.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.io.Serializable; +import java.sql.Timestamp; + +public class WatchdogComponentDistributionStatus implements Serializable { + + + /** + * Serialization id. + */ + private static final long serialVersionUID = -4344508954204488669L; + + private String distributionId; + private String componentName; + private String componentDistributionStatus; + private Timestamp createTime; + private Timestamp modifyTime; + + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getComponentName() { + return componentName; + } + + public void setComponentName(String componentName) { + this.componentName = componentName; + } + + public String getComponentDistributionStatus() { + return componentDistributionStatus; + } + + public void setComponentDistributionStatus(String componentDistributionStatus) { + this.componentDistributionStatus = componentDistributionStatus; + } + + public Timestamp getCreateTime() { + return createTime; + } + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + public Timestamp getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Timestamp modifyTime) { + this.modifyTime = modifyTime; + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusDb.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusDb.java new file mode 100644 index 0000000000..10114348a0 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusDb.java @@ -0,0 +1,194 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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.List;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+public class WatchdogComponentDistributionStatusDb {
+
+ protected final AbstractSessionFactoryManager sessionFactoryRequestDB;
+
+ protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
+
+
+ protected static final String DISTRIBUTION_ID = "distributionId";
+ protected static final String COMPONENT_NAME = "componentName";
+ protected static final String COMPONENT_DISTRIBUTION_STATUS = "componentDistributionIdStatus";
+ protected static final String CREATE_TIME = "startTime";
+ protected static final String MODIFY_TIME = "modifyTime";
+
+
+ public static WatchdogComponentDistributionStatusDb getInstance() {
+ return new WatchdogComponentDistributionStatusDb(new RequestsDbSessionFactoryManager ());
+ }
+
+ protected WatchdogComponentDistributionStatusDb (AbstractSessionFactoryManager sessionFactoryRequest) {
+ sessionFactoryRequestDB = sessionFactoryRequest;
+ }
+
+
+ /**
+ * Insert into watchdog_per_component_distribution_status.
+ *
+ * @param distributionId
+ * @param componentName
+ * @param componentDistributionStatus
+ * @return void
+ */
+ public void insertWatchdogComponentDistributionStatus(String distributionId, String componentName, String componentDistributionStatus ) {
+ long startTime = System.currentTimeMillis ();
+ Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
+ msoLogger.debug ("Insert into WatchdogPerComponentDistributionStatus for DistributionId: " + distributionId + " ComponentName: " + componentName + " and ComponentDistributionStatus: " + componentDistributionStatus);
+
+ List<WatchdogComponentDistributionStatus> componentList = getWatchdogComponentDistributionStatus(distributionId, componentName);
+
+ if((componentList == null) || componentList.isEmpty())
+ {
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ WatchdogComponentDistributionStatus wdcds = new WatchdogComponentDistributionStatus ();
+
+ try {
+ session.beginTransaction ();
+
+ wdcds.setDistributionId (distributionId);
+ wdcds.setComponentName (componentName);
+ wdcds.setComponentDistributionStatus (componentDistributionStatus);
+ wdcds.setCreateTime (startTimeStamp);
+ Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis());
+ wdcds.setModifyTime (modifyTimeStamp);
+
+ msoLogger.debug ("About to insert a record into WatchdogPerComponentDistributionStatus");
+
+ session.save (wdcds);
+ session.getTransaction ().commit ();
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in insertWatchdogComponentDistributionStatus", e);
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, e.getMessage (), "WatchdogComponentDistributionStatusDB", "saveRequest", null);
+ if (session != null) {
+ session.close ();
+ }
+ // throw an Exception in the event of a DB insert failure so that the calling routine can exit
+ throw e;
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "WatchdogComponentDistributionStatusDB", "insertWatchdogComponentDistributionStatus", null);
+ }
+ }
+
+ }
+
+ /**
+ * Retrieve records from WatchdogComponentDistributionStatus.
+ *
+ * @param distributionId
+ * @return WatchdogComponentDistributionStatus
+ */
+ @SuppressWarnings("unchecked")
+ public List<WatchdogComponentDistributionStatus> getWatchdogComponentDistributionStatus(String distributionId) {
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
+ session.beginTransaction();
+
+ List<WatchdogComponentDistributionStatus> results = new ArrayList<WatchdogComponentDistributionStatus>();
+ msoLogger.debug("Request database - getWatchdogComponentDistributionStatus:" + distributionId);
+ try {
+ String hql = "FROM WatchdogComponentDistributionStatus WHERE distributionId = :distributionId";
+ Query query = session.createQuery(hql);
+ query.setParameter("distributionId", distributionId);
+ results = query.list();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.debug ("getWatchdogComponentDistributionStatus - Successfully");
+ }
+ return results;
+ }
+
+ /**
+ * Retrieve records from WatchdogComponentDistributionStatus.
+ *
+ * @param distributionId
+ * @param componentName
+ * @return WatchdogComponentDistributionStatus
+ */
+ @SuppressWarnings("unchecked")
+ public List<WatchdogComponentDistributionStatus> getWatchdogComponentDistributionStatus(String distributionId, String componentName) {
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
+ session.beginTransaction();
+
+ List<WatchdogComponentDistributionStatus> results = new ArrayList<WatchdogComponentDistributionStatus>();
+ msoLogger.debug("Request database - getWatchdogComponentDistributionStatus:" + distributionId + " and componentName:" + componentName);
+ try {
+ String hql = "FROM WatchdogComponentDistributionStatus WHERE distributionId = :distributionId AND componentName = :componentName";
+ Query query = session.createQuery(hql);
+ query.setParameter("distributionId", distributionId);
+ query.setParameter("componentName", componentName);
+ results = query.list();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.debug ("getWatchdogComponentDistributionStatus by ComponentName - Successfully");
+ }
+ return results;
+ }
+
+ /**
+ * Retrieve records from getWatchdogComponentNames.
+ *
+ * @param distributionId
+ * @return String
+ */
+ @SuppressWarnings("unchecked")
+ public List<String> getWatchdogComponentNames(String distributionId) {
+ Session session = sessionFactoryRequestDB.getSessionFactory().openSession();
+ session.beginTransaction();
+
+ List<String> results = new ArrayList<String>();
+ msoLogger.debug("Request database - getWatchdogComponentNames:" + distributionId);
+ try {
+ String hql = "Select componentName FROM WatchdogComponentDistributionStatus WHERE distributionId = :distributionId";
+ Query query = session.createQuery(hql);
+ query.setParameter("distributionId", distributionId);
+ results = query.list();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.debug ("getWatchdogComponentNames - Successfully");
+ }
+ return results;
+ }
+
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatus.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatus.java new file mode 100644 index 0000000000..60f123a781 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatus.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.io.Serializable; +import java.sql.Timestamp; + +public class WatchdogDistributionStatus implements Serializable { + + /** + * Serialization id. + */ + private static final long serialVersionUID = -4449711060885719079L; + + + private String distributionId; + private String distributionIdStatus; + private Timestamp createTime; + private Timestamp modifyTime; + + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getDistributionIdStatus() { + return distributionIdStatus; + } + + public void setDistributionIdStatus(String distributionIdStatus) { + this.distributionIdStatus = distributionIdStatus; + } + + public Timestamp getCreateTime() { + return createTime; + } + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + public Timestamp getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Timestamp modifyTime) { + this.modifyTime = modifyTime; + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusDb.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusDb.java new file mode 100644 index 0000000000..f1fab18df0 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusDb.java @@ -0,0 +1,197 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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 org.hibernate.Query;
+import org.hibernate.Session;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+public class WatchdogDistributionStatusDb {
+
+ protected final AbstractSessionFactoryManager sessionFactoryRequestDB;
+
+ protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
+
+
+ protected static final String DISTRIBUTION_ID = "distributionId";
+ protected static final String DISTRIBUTION_ID_STATUS = "distributionIdStatus";
+ protected static final String CREATE_TIME = "startTime";
+ protected static final String MODIFY_TIME = "modifyTime";
+
+
+ public static WatchdogDistributionStatusDb getInstance() {
+ return new WatchdogDistributionStatusDb(new RequestsDbSessionFactoryManager ());
+ }
+
+ protected WatchdogDistributionStatusDb (AbstractSessionFactoryManager sessionFactoryRequest) {
+ sessionFactoryRequestDB = sessionFactoryRequest;
+ }
+
+
+ /**
+ * Insert into WATCHDOG_DISTRIBUTIONID_STATUS.
+ *
+ * @param distributionId
+ * @return void
+ */
+ public void insertWatchdogDistributionId(String distributionId ) {
+ long startTime = System.currentTimeMillis ();
+ Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
+ msoLogger.debug ("Insert into WatchdogDistributionStatus - DistributionId: " + distributionId);
+
+ if(getWatchdogDistributionId(distributionId) == null){
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ WatchdogDistributionStatus wds = new WatchdogDistributionStatus ();
+
+ try {
+ session.beginTransaction ();
+
+ wds.setDistributionId (distributionId);
+ wds.setCreateTime (startTimeStamp);
+ Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis());
+ wds.setModifyTime (modifyTimeStamp);
+
+ msoLogger.debug ("About to insert a record into WatchdogDistributionStatus ");
+
+ session.save (wds);
+ session.getTransaction ().commit ();
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in insertWatchdogDistributionId", e);
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, e.getMessage (), "WatchdogDistributionStatusDB", "saveRequest", null);
+ if (session != null) {
+ session.close ();
+ }
+ // throw an Exception in the event of a DB insert failure so that the calling routine can exit
+ throw e;
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "WatchdogDistributionStatusDB", "insertWatchdogDistributionId", null);
+ }
+
+ }
+
+ }
+
+
+ /**
+ * Update WATCHDOG_DISTRIBUTIONID_STATUS with new status for a given distributionid.
+ *
+ * @param distributionId
+ * @param distributionStatus
+ * @return void
+ */
+ public void updateWatchdogDistributionIdStatus(String distributionId, String distributionIdStatus ) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Update WatchdogDistributionStatus status with distributionId: " + distributionId + " and distributionStatus: " + distributionIdStatus );
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("update WatchdogDistributionStatus set distributionIdStatus = :distributionIdStatus where "
+ + "distributionId = :distributionId ");
+
+ query.setParameter ("distributionId", distributionId);
+ query.setParameter ("distributionIdStatus", distributionIdStatus);
+
+ //Timestamp modifyTimeStamp = new Timestamp (System.currentTimeMillis());
+ //query.setParameter ("modifyTime", modifyTimeStamp);
+ query.executeUpdate ();
+ session.getTransaction ().commit ();
+
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in updateWatchdogDistributionStatus", e);
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, e.getMessage (), "WatchdogDistributionStatusDB", "saveRequest", null);
+ if (session != null) {
+ session.close ();
+ }
+ // throw an Exception in the event of a DB insert failure so that the calling routine can exit
+ throw e;
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "WatchdogDistributionStatusDB", "insertWatchdogDistributionStatus", null);
+ }
+ }
+
+ /**
+ * Retrieve records from WatchdogDistributionIdStatus.
+ *
+ * @param distributionId
+ * @return WatchdogDistributionIdStatus
+ */
+ public String getWatchdogDistributionIdStatus(String distributionId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Retrieve records from WatchdogDistributionStatus for distributionId : " + distributionId );
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ String distributionStatus = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("SELECT distributionIdStatus FROM WatchdogDistributionStatus WHERE distributionId = :distributionId ");
+ query.setParameter ("distributionId", distributionId);
+ distributionStatus = (String) query.uniqueResult();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "WatchdogDistributionStatusDB", "getWatchdogDistributionIdStatus", null);
+ }
+ return distributionStatus;
+ }
+
+ /**
+ * Retrieve records from WatchdogDistributionId.
+ *
+ * @param distributionId
+ * @return WatchdogDistributionIdStatus
+ */
+ public String getWatchdogDistributionId(String distributionId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Retrieve distributionId from WatchdogDistributionStatus for distributionId : " + distributionId );
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ String existingDistributionId = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("SELECT distributionId FROM WatchdogDistributionStatus WHERE distributionId = :distributionId ");
+ query.setParameter ("distributionId", distributionId);
+ existingDistributionId = (String) query.uniqueResult();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "WatchdogDistributionStatusDB", "getWatchdogDistributionIdStatus", null);
+ }
+ return existingDistributionId;
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookup.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookup.java new file mode 100644 index 0000000000..a19b2db942 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookup.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.io.Serializable; +import java.sql.Timestamp; + +public class WatchdogServiceModVerIdLookup implements Serializable { + + /** + * Serialization id. + */ + private static final long serialVersionUID = 7783869906430250355L; + + private String distributionId; + private String serviceModelVersionId; + private Timestamp createTime; + + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getServiceModelVersionId() { + return serviceModelVersionId; + } + + public void setServiceModelVersionId(String serviceModelVersionId) { + this.serviceModelVersionId = serviceModelVersionId; + } + + public Timestamp getCreateTime() { + return createTime; + } + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupDb.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupDb.java new file mode 100644 index 0000000000..f081bbf55c --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupDb.java @@ -0,0 +1,124 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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 org.hibernate.Query;
+import org.hibernate.Session;
+import org.openecomp.mso.db.AbstractSessionFactoryManager;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+public class WatchdogServiceModVerIdLookupDb {
+
+ protected final AbstractSessionFactoryManager sessionFactoryRequestDB;
+
+ protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL);
+
+ protected static final String DISTRIBUTION_ID = "distributionId";
+ protected static final String SERVICE_MODEL_VERSION_ID = "serviceModelVersionId";
+ protected static final String CREATE_TIME = "startTime";
+
+
+ public static WatchdogServiceModVerIdLookupDb getInstance() {
+ return new WatchdogServiceModVerIdLookupDb(new RequestsDbSessionFactoryManager ());
+ }
+
+ protected WatchdogServiceModVerIdLookupDb (AbstractSessionFactoryManager sessionFactoryRequest) {
+ sessionFactoryRequestDB = sessionFactoryRequest;
+ }
+
+
+ /**
+ * Insert into WATCHDOG_SERVICE_MOD_VER_ID_LOOKUP.
+ *
+ * @param distributionId
+ * @param serviceModelVersionId
+ * @return void
+ */
+ public void insertWatchdogServiceModVerIdLookup(String distributionId, String serviceModelVersionId ) {
+ long startTime = System.currentTimeMillis ();
+ Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
+ msoLogger.debug ("Insert into WatchdogServiceModVerIdLookup for DistributionId: " + distributionId + " and ServiceModelVersionId: " + serviceModelVersionId );
+
+ if(getWatchdogServiceModVerId(distributionId) == null){
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ WatchdogServiceModVerIdLookup wdsm = new WatchdogServiceModVerIdLookup ();
+
+ try {
+ session.beginTransaction ();
+
+ wdsm.setDistributionId (distributionId);
+ wdsm.setServiceModelVersionId (serviceModelVersionId);
+ wdsm.setCreateTime (startTimeStamp);
+
+ msoLogger.debug ("About to insert a record into WatchdogServiceModVerIdLookup");
+
+ session.save (wdsm);
+ session.getTransaction ().commit ();
+ } catch (Exception e) {
+ msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in insertWatchdogServiceModVerIdLookup", e);
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, e.getMessage (), "WatchdogServiceModVerIdLookupDB", "saveRequest", null);
+ if (session != null) {
+ session.close ();
+ }
+ // throw an Exception in the event of a DB insert failure so that the calling routine can exit
+ throw e;
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "WatchdogServiceModVerIdLookupDB", "insertWatchdogServiceModVerIdLookup", null);
+ }
+ }
+
+ }
+
+ /**
+ * Retrieve from WATCHDOG_SERVICE_MOD_VER_ID_LOOKUP.
+ *
+ * @param distributionId
+ * @return WatchdogServiceModVerIdLookup
+ */
+ public String getWatchdogServiceModVerId(String distributionId) {
+ long startTime = System.currentTimeMillis ();
+ msoLogger.debug ("Retrieve WatchdogServiceModVerIdLookup with distributionId: " + distributionId );
+
+ Session session = sessionFactoryRequestDB.getSessionFactory ().openSession ();
+ String serviceModelVersionId = null;
+ try {
+ session.beginTransaction ();
+ Query query = session.createQuery ("Select serviceModelVersionId FROM WatchdogServiceModVerIdLookup WHERE distributionId = :distributionId ");
+ query.setParameter ("distributionId", distributionId);
+ serviceModelVersionId = (String) query.uniqueResult();
+ } finally {
+ if (session != null && session.isOpen ()) {
+ session.close ();
+ }
+ msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "WatchdogServiceModVerIdLookupDB", "getWatchdogServiceModVerId", null);
+ }
+ return serviceModelVersionId;
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/InfraActiveRequests.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/InfraActiveRequests.hbm.xml index 8ee3dddef9..fcc6b2843e 100644 --- a/mso-api-handlers/mso-requests-db/src/main/resources/InfraActiveRequests.hbm.xml +++ b/mso-api-handlers/mso-requests-db/src/main/resources/InfraActiveRequests.hbm.xml @@ -128,7 +128,7 @@ <column name="SERVICE_INSTANCE_NAME" length="80"/> </property> <property name="requestScope" type="string"> - <column name="REQUEST_SCOPE" length="20"/> + <column name="REQUEST_SCOPE" length="45"/> </property> <property name="requestAction" type="string"> <column name="REQUEST_ACTION" length="45" not-null="true"/> @@ -145,5 +145,17 @@ <property name="requestorId" type="string"> <column name="REQUESTOR_ID" length="80"/> </property> + <property name="configurationId" type="string"> + <column name="CONFIGURATION_ID" length="45"/> + </property> + <property name="configurationName" type="string"> + <column name="CONFIGURATION_NAME" length="200"/> + </property> + <property name="operationalEnvId" type="string"> + <column name="OPERATIONAL_ENV_ID" length="45"/> + </property> + <property name="operationalEnvName" type="string"> + <column name="OPERATIONAL_ENV_NAME" length="200"/> + </property> </class> </hibernate-mapping> diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml index d4eccdab33..8d80f76649 100644 --- a/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml +++ b/mso-api-handlers/mso-requests-db/src/main/resources/OperationStatus.hbm.xml @@ -24,24 +24,23 @@ <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.openecomp.mso.requestsdb"> - <class name="OperationStatus" table="OPERATION_STATUS"> - <meta attribute="class-description"> - This class describes a operation status - </meta> - <composite-id> - <key-property name="serviceId" type="string" column="SERVICE_ID"/> - <key-property name="operationId" column="OPERATION_ID" type="string" length="256"/> - </composite-id> - <property name="serviceName" column="SERVICE_NAME" type="string" length="256"/> - <property name="operation" column="OPERATION_TYPE" type="string" length="256"/> - <property name="userId" column="USER_ID" type="string" length="256"/> - <property name="result" column="RESULT" type="string" length="256"/> - <property name="operationContent" column="OPERATION_CONTENT" type="string" length="256"/> - <property name="progress" column="PROGRESS" type="string" length="256"/> - <property name="reason" column="REASON" type="string" length="256"/> - <property name="operateAt" type="timestamp"> - <column name="OPERATE_AT"/> + <class name="OperationStatus" table="OPERATION_STATUS"> + <meta attribute="class-description"> + This class describes a operation status + </meta> + <composite-id> + <key-property name="serviceId" type="string" column="SERVICE_ID"/> + <key-property name="operationId" column="OPERATION_ID" type="string" length="256"/> + </composite-id> + <property name="operation" column="OPERATION_TYPE" type="string" length="256"/> + <property name="userId" column="USER_ID" type="string" length="256"/> + <property name="result" column="RESULT" type="string" length="256"/> + <property name="operationContent" column="OPERATION_CONTENT" type="string" length="256"/> + <property name="progress" column="PROGRESS" type="string" length="256"/> + <property name="reason" column="REASON" type="string" length="256"/> + <property name="operateAt" type="timestamp" generated="insert" insert="false" update="false" not-null="true"> + <column name="OPERATE_AT" default="CURRENT_TIMESTAMP"/> </property> - <property name="finishedAt" column="FINISHED_AT" type="timestamp" /> - </class> + <property name="finishedAt" column="FINISHED_AT" type="timestamp" generated="always" insert="false" update="false"/> + </class> </hibernate-mapping> diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/OperationalEnvDistributionStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/OperationalEnvDistributionStatus.hbm.xml new file mode 100644 index 0000000000..08e60b2641 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/resources/OperationalEnvDistributionStatus.hbm.xml @@ -0,0 +1,56 @@ +<?xml version="1.0"?> +<!-- + ============LICENSE_START======================================================= + ECOMP 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========================================================= + --> + +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> +<!-- Generated Jul 27, 2015 3:05:00 PM by Hibernate Tools 3.4.0.CR1 --> +<hibernate-mapping> + <class name="org.openecomp.mso.requestsdb.OperationalEnvDistributionStatus" table="ACTIVATE_OPERATIONAL_ENV_PER_DISTRIBUTIONID_STATUS"> + + <id name="distributionId" type="string"> + <column name="DISTRIBUTION_ID" length="45"/> + <generator class="assigned"/> + </id> + + <property name="operationalEnvId" type="string"> + <column name="OPERATIONAL_ENV_ID" length="45"/> + </property> + <property name="serviceModelVersionId" type="string"> + <column name="SERVICE_MODEL_VERSION_ID" length="45"/> + </property> + <property name="distributionIdStatus" type="string"> + <column name="DISTRIBUTION_ID_STATUS" length="45" /> + </property> + <property name="distributionIdErrorReason" type="string"> + <column name="DISTRIBUTION_ID_ERROR_REASON" length="250" /> + </property> + <property name="requestId" type="string"> + <column name="REQUEST_ID" length="45" /> + </property> + <property name="createTime" type="timestamp"> + <column name="CREATE_TIME"/> + </property> + <property name="modifyTime" type="timestamp"> + <column name="MODIFY_TIME"/> + </property> + + </class> +</hibernate-mapping>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/OperationalEnvServiceModelStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/OperationalEnvServiceModelStatus.hbm.xml new file mode 100644 index 0000000000..99a6232e0e --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/resources/OperationalEnvServiceModelStatus.hbm.xml @@ -0,0 +1,54 @@ +<?xml version="1.0"?> +<!-- + ============LICENSE_START======================================================= + ECOMP 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========================================================= + --> + +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> +<!-- Generated Jul 27, 2015 3:05:00 PM by Hibernate Tools 3.4.0.CR1 --> +<hibernate-mapping> + <class name="org.openecomp.mso.requestsdb.OperationalEnvServiceModelStatus" table="ACTIVATE_OPERATIONAL_ENV_SERVICE_MODEL_DISTRIBUTION_STATUS"> + + <composite-id> + <key-property name="operationalEnvId" column="OPERATIONAL_ENV_ID" type="string" length="45" /> + <key-property name="serviceModelVersionId" column="SERVICE_MODEL_VERSION_ID" type="string" length="45"/> + <key-property name="requestId" column="REQUEST_ID" type="string" length="45"/> + </composite-id> + + <property name="serviceModelVersionDistrStatus" type="string"> + <column name="SERVICE_MOD_VER_FINAL_DISTR_STATUS" length="45"/> + </property> + <property name="recoveryAction" type="string"> + <column name="RECOVERY_ACTION" length="30" /> + </property> + <property name="retryCount" type="integer"> + <column name="RETRY_COUNT_LEFT"/> + </property> + <property name="workloadContext" type="string"> + <column name="WORKLOAD_CONTEXT" length="80" /> + </property> + <property name="createTime" type="timestamp"> + <column name="CREATE_TIME"/> + </property> + <property name="modifyTime" type="timestamp"> + <column name="MODIFY_TIME"/> + </property> + + </class> +</hibernate-mapping>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogComponentDistributionStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogComponentDistributionStatus.hbm.xml new file mode 100644 index 0000000000..ea66153157 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogComponentDistributionStatus.hbm.xml @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- + ============LICENSE_START======================================================= + ECOMP 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========================================================= + --> + +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> +<!-- Generated Jul 27, 2015 3:05:00 PM by Hibernate Tools 3.4.0.CR1 --> +<hibernate-mapping> + <class name="org.openecomp.mso.requestsdb.WatchdogComponentDistributionStatus" table="WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS"> + + <composite-id> + <key-property name="distributionId" column="DISTRIBUTION_ID" type="string" length="45" /> + <key-property name="componentName" column="COMPONENT_NAME" type="string" length="45"/> + </composite-id> + + <property name="componentDistributionStatus" type="string"> + <column name="COMPONENT_DISTRIBUTION_STATUS" length="45" /> + </property> + + <property name="createTime" type="timestamp"> + <column name="CREATE_TIME"/> + </property> + + <property name="modifyTime" type="timestamp"> + <column name="MODIFY_TIME"/> + </property> + + </class> +</hibernate-mapping>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogDistributionStatus.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogDistributionStatus.hbm.xml new file mode 100644 index 0000000000..2da3071c71 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogDistributionStatus.hbm.xml @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- + ============LICENSE_START======================================================= + ECOMP 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========================================================= + --> + +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> +<!-- Generated Jul 27, 2015 3:05:00 PM by Hibernate Tools 3.4.0.CR1 --> +<hibernate-mapping> + <class name="org.openecomp.mso.requestsdb.WatchdogDistributionStatus" table="WATCHDOG_DISTRIBUTIONID_STATUS"> + + <id name="distributionId" type="string"> + <column name="DISTRIBUTION_ID" length="45"/> + <generator class="assigned"/> + </id> + + <property name="distributionIdStatus" type="string"> + <column name="DISTRIBUTION_ID_STATUS" length="45" /> + </property> + + <property name="createTime" type="timestamp"> + <column name="CREATE_TIME"/> + </property> + + <property name="modifyTime" type="timestamp"> + <column name="MODIFY_TIME"/> + </property> + + </class> +</hibernate-mapping>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogServiceModVerIdLookup.hbm.xml b/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogServiceModVerIdLookup.hbm.xml new file mode 100644 index 0000000000..b6b1d9bf58 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/resources/WatchdogServiceModVerIdLookup.hbm.xml @@ -0,0 +1,38 @@ +<?xml version="1.0"?> +<!-- + ============LICENSE_START======================================================= + ECOMP 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========================================================= + --> + +<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" + "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> +<!-- Generated Jul 27, 2015 3:05:00 PM by Hibernate Tools 3.4.0.CR1 --> +<hibernate-mapping> + <class name="org.openecomp.mso.requestsdb.WatchdogServiceModVerIdLookup" table="WATCHDOG_SERVICE_MOD_VER_ID_LOOKUP"> + + <composite-id> + <key-property name="distributionId" column="DISTRIBUTION_ID" type="string" length="45" /> + <key-property name="serviceModelVersionId" column="SERVICE_MODEL_VERSION_ID" type="string" length="45"/> + </composite-id> + + <property name="createTime" type="timestamp"> + <column name="CREATE_TIME"/> + </property> + + </class> +</hibernate-mapping>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml b/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml index edf8333016..1305dfb97b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml +++ b/mso-api-handlers/mso-requests-db/src/main/resources/hibernate-requests-core-mysql.cfg.xml @@ -32,8 +32,13 @@ <!-- <property name="hibernate.hbm2ddl.auto">create</property> --> <mapping resource="InfraActiveRequests.hbm.xml"></mapping> - <mapping resource="SiteStatus.hbm.xml"></mapping> + <mapping resource="OperationalEnvServiceModelStatus.hbm.xml"></mapping> + <mapping resource="OperationalEnvDistributionStatus.hbm.xml"></mapping> <mapping resource="OperationStatus.hbm.xml"></mapping> <mapping resource="ResourceOperationStatus.hbm.xml"></mapping> + <mapping resource="SiteStatus.hbm.xml"></mapping> + <mapping resource="WatchdogDistributionStatus.hbm.xml"></mapping> + <mapping resource="WatchdogComponentDistributionStatus.hbm.xml"></mapping> + <mapping resource="WatchdogServiceModVerIdLookup.hbm.xml"></mapping> </session-factory> </hibernate-configuration> diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusDbTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusDbTest.java new file mode 100644 index 0000000000..77f5a1d699 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusDbTest.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.Test; +import org.mockito.Mockito; + + +public class OperationalEnvDistributionStatusDbTest { + + + private static final String distributionId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; + private static final String operationalEnvId = "12abad84e7ff"; + private static final String serviceModelVersionId = "ff305d54-75b4-431b-adb2-eb6b9e5ff001"; + private static final String requestId = "431b-adb2-eb6b9e5ff001"; + private static final String status = "SENT"; + private OperationalEnvDistributionStatus operEnvDistStatus; + + + @Test + public void testGetOperationalEnvDistributionStatus() { + + OperationalEnvDistributionStatusDb oeds = Mockito.mock(OperationalEnvDistributionStatusDb.class); + Mockito.when(oeds.getOperationalEnvDistributionStatus("ff3514e3-5a33-55df-13ab-12abad84e7ff")).thenReturn(operEnvDistStatus); + OperationalEnvDistributionStatus actual = oeds.getOperationalEnvDistributionStatus(distributionId); + assertEquals(actual, operEnvDistStatus); + verify(oeds, times(1)).getOperationalEnvDistributionStatus(any(String.class)); + } + + @Test + public void testGetOperationalEnvDistributionStatusPerReqId() { + + OperationalEnvDistributionStatusDb oeds = Mockito.mock(OperationalEnvDistributionStatusDb.class); + Mockito.when(oeds.getOperationalEnvDistributionStatusPerReqId("ff3514e3-5a33-55df-13ab-12abad84e7ff", "431b-adb2-eb6b9e5ff001")).thenReturn(operEnvDistStatus); + OperationalEnvDistributionStatus actual = oeds.getOperationalEnvDistributionStatusPerReqId(distributionId, requestId); + assertEquals(actual, operEnvDistStatus); + verify(oeds, times(1)).getOperationalEnvDistributionStatusPerReqId(any(String.class), any(String.class)); + } + + @Test + public void testUpdateOperationalEnvDistributionStatus() { + + int val = 1; + OperationalEnvDistributionStatusDb oeds = Mockito.mock(OperationalEnvDistributionStatusDb.class); + Mockito.when(oeds.updateOperationalEnvDistributionStatus("OK", "ff3514e3-5a33", "ff3514e3-5a33", "ff3514e3-5a33-55df-13ab-12abad84e7ff")).thenReturn(val); + int actual = oeds.updateOperationalEnvDistributionStatus("OK", "ff3514e3-5a33", "ff3514e3-5a33", "ff3514e3-5a33-55df-13ab-12abad84e7ff"); + assertEquals(actual, val); + verify(oeds, times(1)).updateOperationalEnvDistributionStatus(any(String.class), any(String.class), any(String.class), any(String.class)); + } + + @Test + public void testInsertOperationalEnvDistributionStatus() { + + OperationalEnvDistributionStatusDb oeds = mock(OperationalEnvDistributionStatusDb.class); + + oeds.insertOperationalEnvDistributionStatus(distributionId, operationalEnvId, serviceModelVersionId, status, requestId); + doNothing().when(oeds).insertOperationalEnvDistributionStatus(any(String.class), any(String.class), any(String.class), any(String.class), any(String.class)); + verify(oeds, times(1)).insertOperationalEnvDistributionStatus(any(String.class), any(String.class), any(String.class), any(String.class), any(String.class)); + + } + +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusTest.java new file mode 100644 index 0000000000..b0c1c02e7f --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvDistributionStatusTest.java @@ -0,0 +1,232 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.Timestamp; + +public class OperationalEnvDistributionStatusTest { + + OperationalEnvDistributionStatus _operationalEnvDistributionStatus; + + protected String _distributionId; + protected String _operationalEnvId; + protected String _serviceModelVersionId; + protected String _requestId; + protected String _distributionIdStatus; + protected String _distributionIdErrorReason; + protected Timestamp _createTime; + protected Timestamp _modifyTime; + + public OperationalEnvDistributionStatusTest() { + } + + @Before + public void setUp() { + _operationalEnvDistributionStatus = mock(OperationalEnvDistributionStatus.class); + _distributionId = "12abad84e7ff"; + _operationalEnvId = "28122015552391"; + _serviceModelVersionId = "28122015552391-aa"; + _requestId = "1234"; + _distributionIdStatus = "SENT"; + _distributionIdErrorReason = "Fail"; + _createTime = new Timestamp (System.currentTimeMillis()); + _modifyTime = new Timestamp (System.currentTimeMillis()); + + when(_operationalEnvDistributionStatus.getDistributionId()).thenReturn(_distributionId); + when(_operationalEnvDistributionStatus.getOperationalEnvId()).thenReturn(_operationalEnvId); + when(_operationalEnvDistributionStatus.getServiceModelVersionId()).thenReturn(_serviceModelVersionId); + when(_operationalEnvDistributionStatus.getRequestId()).thenReturn(_requestId); + when(_operationalEnvDistributionStatus.getDistributionIdStatus()).thenReturn(_distributionIdStatus); + when(_operationalEnvDistributionStatus.getDistributionIdErrorReason()).thenReturn(_distributionIdErrorReason); + when(_operationalEnvDistributionStatus.getCreateTime()).thenReturn(_createTime); + when(_operationalEnvDistributionStatus.getModifyTime()).thenReturn(_modifyTime); + } + + + @After + public void tearDown() { + _operationalEnvDistributionStatus = null; + } + + /** + * Test of getDistributionId method + */ + @Test + public void testGetDistributionId() { + _operationalEnvDistributionStatus.setDistributionId(_distributionId); + assertEquals(_operationalEnvDistributionStatus.getDistributionId(),_distributionId); + + } + + /** + * Test setDistributionId method + */ + @Test + public void testSetDistributionId() { + _operationalEnvDistributionStatus.setDistributionId(_distributionId); + verify(_operationalEnvDistributionStatus).setDistributionId(_distributionId); + } + + /** + * Test of getOperationalEnvId method + */ + @Test + public void testGetOperationalEnvId() { + _operationalEnvDistributionStatus.setOperationalEnvId(_operationalEnvId); + assertEquals(_operationalEnvDistributionStatus.getOperationalEnvId(),_operationalEnvId); + + } + + /** + * Test setOperationalEnvId method + */ + @Test + public void testSetOperationalEnvId() { + _operationalEnvDistributionStatus.setOperationalEnvId(_operationalEnvId); + verify(_operationalEnvDistributionStatus).setOperationalEnvId(_operationalEnvId); + } + + /** + * Test of getServiceModelVersionId method + */ + @Test + public void testGetServiceModelVersionId() { + _operationalEnvDistributionStatus.setServiceModelVersionId(_serviceModelVersionId); + assertEquals(_operationalEnvDistributionStatus.getServiceModelVersionId(),_serviceModelVersionId); + + } + + /** + * Test setServiceModelVersionId method + */ + @Test + public void testSetServiceModelVersionId() { + _operationalEnvDistributionStatus.setServiceModelVersionId(_serviceModelVersionId); + verify(_operationalEnvDistributionStatus).setServiceModelVersionId(_serviceModelVersionId); + } + + /** + * Test of getRequestId method + */ + @Test + public void testGetRequestId() { + _operationalEnvDistributionStatus.setRequestId(_requestId); + assertEquals(_operationalEnvDistributionStatus.getRequestId(),_requestId); + + } + + /** + * Test setRequestId method + */ + @Test + public void testSetRequestId() { + _operationalEnvDistributionStatus.setRequestId(_requestId); + verify(_operationalEnvDistributionStatus).setRequestId(_requestId); + } + + /** + * Test of getDistributionIdStatus method + */ + @Test + public void testGetDistributionIdStatus() { + _operationalEnvDistributionStatus.setDistributionIdStatus(_distributionIdStatus); + assertEquals(_operationalEnvDistributionStatus.getDistributionIdStatus(),_distributionIdStatus); + + } + + /** + * Test setDistributionIdStatus method + */ + @Test + public void testSetDistributionIdStatus() { + _operationalEnvDistributionStatus.setDistributionIdStatus(_distributionIdStatus); + verify(_operationalEnvDistributionStatus).setDistributionIdStatus(_distributionIdStatus); + } + + /** + * Test of getDistributionIdErrorReason method + */ + @Test + public void testGetDistributionIdErrorReason() { + _operationalEnvDistributionStatus.setDistributionIdErrorReason(_distributionIdErrorReason); + assertEquals(_operationalEnvDistributionStatus.getDistributionIdErrorReason(),_distributionIdErrorReason); + + } + + /** + * Test setDistributionIdErrorReason method + */ + @Test + public void testSetDistributionIdErrorReason() { + _operationalEnvDistributionStatus.setDistributionIdErrorReason(_distributionIdErrorReason); + verify(_operationalEnvDistributionStatus).setDistributionIdErrorReason(_distributionIdErrorReason); + } + + /** + * Test of getCreateTime method + */ + @Test + public void testGetCreateTime() { + _operationalEnvDistributionStatus.setCreateTime(_createTime); + System.out.println("CreateTime : " + _createTime); + assertEquals(_operationalEnvDistributionStatus.getCreateTime(),_createTime); + + } + + /** + * Test setCreateTime method + */ + @Test + public void testSetCreateTime() { + _operationalEnvDistributionStatus.setCreateTime(_createTime); + verify(_operationalEnvDistributionStatus).setCreateTime(_createTime); + } + + /** + * Test of getModifyTime method + */ + @Test + public void testGetModifyTime() { + _operationalEnvDistributionStatus.setModifyTime(_modifyTime); + System.out.println("ModifyTime : " + _modifyTime); + assertEquals(_operationalEnvDistributionStatus.getModifyTime(),_modifyTime); + + } + + /** + * Test setModifyTime method + */ + @Test + public void testSetModifyTime() { + _operationalEnvDistributionStatus.setModifyTime(_modifyTime); + verify(_operationalEnvDistributionStatus).setModifyTime(_modifyTime); + } + + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusDbTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusDbTest.java new file mode 100644 index 0000000000..77776c2fe1 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusDbTest.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.mockito.Mockito; + +public class OperationalEnvServiceModelStatusDbTest { + + + private static final String operationalEnvId = "12abad84e7ff"; + private static final String serviceModelVersionId = "ff305d54-75b4-431b-adb2-eb6b9e5ff001"; + private static final String requestId = "431b-adb2-eb6b9e5ff001"; + private static final String status = "SENT"; + private static final int retryCount = 1; + private static final String recoveryAction = "Retry"; + private static final String workloadContext = "VNF_D2D"; + + private OperationalEnvServiceModelStatus operEnvDistStatus; + + + @Test + public void testGetOperationalEnvDistributionStatus() { + + OperationalEnvServiceModelStatusDb oesms = Mockito.mock(OperationalEnvServiceModelStatusDb.class); + Mockito.when(oesms.getOperationalEnvServiceModelStatus("12abad84e7ff", "ff305d54-75b4-431b-adb2-eb6b9e5ff001")).thenReturn(operEnvDistStatus); + OperationalEnvServiceModelStatus actual = oesms.getOperationalEnvServiceModelStatus(operationalEnvId, serviceModelVersionId); + assertEquals(actual, operEnvDistStatus); + verify(oesms, times(1)).getOperationalEnvServiceModelStatus(any(String.class), any(String.class)); + } + + @Test + public void testGetOperationalEnvIdStatus() { + + List<OperationalEnvServiceModelStatus> operEnvSvcModelStatus = new ArrayList<>(); + OperationalEnvServiceModelStatusDb oesms = Mockito.mock(OperationalEnvServiceModelStatusDb.class); + Mockito.when(oesms.getOperationalEnvIdStatus("12abad84e7ff", "ff305d54-75b4-431b-adb2-eb6b9e5ff001")).thenReturn(operEnvSvcModelStatus); + List<OperationalEnvServiceModelStatus> actual = oesms.getOperationalEnvIdStatus(operationalEnvId, requestId); + assertEquals(actual, operEnvSvcModelStatus); + verify(oesms, times(1)).getOperationalEnvIdStatus(any(String.class), any(String.class)); + + } + + @Test + public void testUpdateOperationalEnvRetryCountStatus() { + + int val = 1; + OperationalEnvServiceModelStatusDb oesms = Mockito.mock(OperationalEnvServiceModelStatusDb.class); + Mockito.when(oesms.updateOperationalEnvRetryCountStatus("12abad84e7ff", "ff305d54-75b4-431b-adb2-eb6b9e5ff001", "SENT", 1)).thenReturn(val); + int actual = oesms.updateOperationalEnvRetryCountStatus(operationalEnvId, serviceModelVersionId, status, retryCount); + assertEquals(actual, val); + verify(oesms, times(1)).updateOperationalEnvRetryCountStatus(any(String.class), any(String.class), any(String.class), any(int.class)); + } + + @Test + public void testUpdateOperationalEnvRetryCountStatusPerReqId() { + + int val = 1; + OperationalEnvServiceModelStatusDb oesms = Mockito.mock(OperationalEnvServiceModelStatusDb.class); + Mockito.when(oesms.updateOperationalEnvRetryCountStatusPerReqId("12abad84e7ff", "ff305d54-75b4-431b-adb2-eb6b9e5ff001", "SENT", 1, "431b-adb2-eb6b9e5ff001")).thenReturn(val); + int actual = oesms.updateOperationalEnvRetryCountStatusPerReqId(operationalEnvId, serviceModelVersionId, status, retryCount, requestId); + assertEquals(actual, val); + verify(oesms, times(1)).updateOperationalEnvRetryCountStatusPerReqId(any(String.class), any(String.class), any(String.class), + any(int.class), any(String.class)); + } + + + @Test + public void testInsertOperationalEnvServiceModelStatus() { + + OperationalEnvServiceModelStatusDb oesms = mock(OperationalEnvServiceModelStatusDb.class); + + oesms.insertOperationalEnvServiceModelStatus(requestId, operationalEnvId, serviceModelVersionId, status, recoveryAction, retryCount, workloadContext); + doNothing().when(oesms).insertOperationalEnvServiceModelStatus(any(String.class), any(String.class), any(String.class), + any(String.class), any(String.class), any(int.class), any(String.class)); + verify(oesms, times(1)).insertOperationalEnvServiceModelStatus(any(String.class), any(String.class), any(String.class), + any(String.class), any(String.class), any(int.class), any(String.class)); + + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusTest.java new file mode 100644 index 0000000000..eb6a9f1d82 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/OperationalEnvServiceModelStatusTest.java @@ -0,0 +1,253 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.Timestamp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class OperationalEnvServiceModelStatusTest { + + OperationalEnvServiceModelStatus _operationalEnvServiceModelStatus; + + protected String _requestId; + protected String _operationalEnvId; + protected String _serviceModelVersionId; + protected String _serviceModelVersionDistrStatus; + protected String _recoveryAction; + private int _retryCount; + private String _workloadContext; + protected Timestamp _createTime; + protected Timestamp _modifyTime; + + + public OperationalEnvServiceModelStatusTest() { + } + + @Before + public void setUp() { + _operationalEnvServiceModelStatus = mock(OperationalEnvServiceModelStatus.class); + _requestId = "1234"; + _operationalEnvId = "28122015552391"; + _serviceModelVersionId = "28122015552391-aa"; + _serviceModelVersionDistrStatus = "SENT"; + _recoveryAction = "Retry"; + _retryCount = 0; + _workloadContext = "VNF_E2E-IST"; + _createTime = new Timestamp (System.currentTimeMillis()); + _modifyTime = new Timestamp (System.currentTimeMillis()); + + when(_operationalEnvServiceModelStatus.getRequestId()).thenReturn(_requestId); + when(_operationalEnvServiceModelStatus.getOperationalEnvId()).thenReturn(_operationalEnvId); + when(_operationalEnvServiceModelStatus.getServiceModelVersionId()).thenReturn(_serviceModelVersionId); + when(_operationalEnvServiceModelStatus.getServiceModelVersionDistrStatus()).thenReturn(_serviceModelVersionDistrStatus); + when(_operationalEnvServiceModelStatus.getRecoveryAction()).thenReturn(_recoveryAction); + when(_operationalEnvServiceModelStatus.getRetryCount()).thenReturn(_retryCount); + when(_operationalEnvServiceModelStatus.getWorkloadContext()).thenReturn(_workloadContext); + when(_operationalEnvServiceModelStatus.getCreateTime()).thenReturn(_createTime); + when(_operationalEnvServiceModelStatus.getModifyTime()).thenReturn(_modifyTime); + } + + + @After + public void tearDown() { + _operationalEnvServiceModelStatus = null; + } + + /** + * Test of getRequestId method + */ + @Test + public void testGetRequestId() { + _operationalEnvServiceModelStatus.setRequestId(_requestId); + assertEquals(_operationalEnvServiceModelStatus.getRequestId(),_requestId); + + } + + /** + * Test setRequestId method + */ + @Test + public void testSetRequestId() { + _operationalEnvServiceModelStatus.setRequestId(_requestId); + verify(_operationalEnvServiceModelStatus).setRequestId(_requestId); + } + + /** + * Test of getOperationalEnvId method + */ + @Test + public void testGetOperationalEnvId() { + _operationalEnvServiceModelStatus.setOperationalEnvId(_operationalEnvId); + assertEquals(_operationalEnvServiceModelStatus.getOperationalEnvId(),_operationalEnvId); + + } + + /** + * Test setOperationalEnvId method + */ + @Test + public void testSetOperationalEnvId() { + _operationalEnvServiceModelStatus.setOperationalEnvId(_operationalEnvId); + verify(_operationalEnvServiceModelStatus).setOperationalEnvId(_operationalEnvId); + } + + /** + * Test of getServiceModelVersionId method + */ + @Test + public void testGetServiceModelVersionId() { + _operationalEnvServiceModelStatus.setServiceModelVersionId(_serviceModelVersionId); + assertEquals(_operationalEnvServiceModelStatus.getServiceModelVersionId(),_serviceModelVersionId); + + } + + /** + * Test setServiceModelVersionId method + */ + @Test + public void testSetServiceModelVersionId() { + _operationalEnvServiceModelStatus.setServiceModelVersionId(_serviceModelVersionId); + verify(_operationalEnvServiceModelStatus).setServiceModelVersionId(_serviceModelVersionId); + } + + /** + * Test of getServiceModelVersionId method + */ + @Test + public void testGetServiceModelVersionDistrStatus() { + _operationalEnvServiceModelStatus.setServiceModelVersionDistrStatus(_serviceModelVersionDistrStatus); + assertEquals(_operationalEnvServiceModelStatus.getServiceModelVersionDistrStatus(),_serviceModelVersionDistrStatus); + + } + + /** + * Test setServiceModelVersionId method + */ + @Test + public void testSetServiceModelVersionDistrStatus() { + _operationalEnvServiceModelStatus.setServiceModelVersionDistrStatus(_serviceModelVersionDistrStatus); + verify(_operationalEnvServiceModelStatus).setServiceModelVersionDistrStatus(_serviceModelVersionDistrStatus); + } + + /** + * Test of getOperationalEnvId method + */ + @Test + public void testGetRecoveryAction() { + _operationalEnvServiceModelStatus.setRecoveryAction(_recoveryAction); + assertEquals(_operationalEnvServiceModelStatus.getRecoveryAction(),_recoveryAction); + + } + + /** + * Test setOperationalEnvId method + */ + @Test + public void testSetRecoveryAction() { + _operationalEnvServiceModelStatus.setRecoveryAction(_recoveryAction); + verify(_operationalEnvServiceModelStatus).setRecoveryAction(_recoveryAction); + } + + /** + * Test of getOperationalEnvId method + */ + @Test + public void testGetRetryCount() { + _operationalEnvServiceModelStatus.setRetryCount(_retryCount); + assertEquals(_operationalEnvServiceModelStatus.getRetryCount(),_retryCount); + + } + + /** + * Test setOperationalEnvId method + */ + @Test + public void testSetRetryCount() { + _operationalEnvServiceModelStatus.setRetryCount(_retryCount); + verify(_operationalEnvServiceModelStatus).setRetryCount(_retryCount); + } + + /** + * Test of getOperationalEnvId method + */ + @Test + public void testGetWorkloadContext() { + _operationalEnvServiceModelStatus.setWorkloadContext(_workloadContext); + assertEquals(_operationalEnvServiceModelStatus.getWorkloadContext(),_workloadContext); + + } + + /** + * Test setOperationalEnvId method + */ + @Test + public void testSetWorkloadContext() { + _operationalEnvServiceModelStatus.setWorkloadContext(_workloadContext); + verify(_operationalEnvServiceModelStatus).setWorkloadContext(_workloadContext); + } + + /** + * Test of getCreateTime method + */ + @Test + public void testGetCreateTime() { + _operationalEnvServiceModelStatus.setCreateTime(_createTime); + assertEquals(_operationalEnvServiceModelStatus.getCreateTime(),_createTime); + + } + + /** + * Test setCreateTime method + */ + @Test + public void testSetCreateTime() { + _operationalEnvServiceModelStatus.setCreateTime(_createTime); + verify(_operationalEnvServiceModelStatus).setCreateTime(_createTime); + } + + /** + * Test of getModifyTime method + */ + @Test + public void testGetModifyTime() { + _operationalEnvServiceModelStatus.setModifyTime(_modifyTime); + assertEquals(_operationalEnvServiceModelStatus.getModifyTime(),_modifyTime); + + } + + /** + * Test setModifyTime method + */ + @Test + public void testSetModifyTime() { + _operationalEnvServiceModelStatus.setModifyTime(_modifyTime); + verify(_operationalEnvServiceModelStatus).setModifyTime(_modifyTime); + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestDatabaseTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestDatabaseTest.java new file mode 100644 index 0000000000..a26f417634 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestDatabaseTest.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+
+public class RequestDatabaseTest {
+
+ @Test
+ public void testCheckVnfIdStatus() {
+ RequestsDatabase reqDb = mock(RequestsDatabase.class);
+ when(reqDb.checkVnfIdStatus(any(String.class))).thenReturn(new InfraActiveRequests());
+
+ InfraActiveRequests response = reqDb.checkVnfIdStatus("123456");
+ assertNotNull(response);
+ }
+}
diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java index 0bb126fa42..005a28ec52 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/RequestsDatabaseTest.java @@ -27,6 +27,7 @@ import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.openecomp.mso.db.AbstractSessionFactoryManager; @@ -155,6 +156,7 @@ public class RequestsDatabaseTest { } @Test + @Ignore // 1802 merge public void checkDuplicateByVnfNameTest(@Mocked AbstractSessionFactoryManager sessionFactoryManager, @Mocked Session session, @Mocked Query query) throws Exception { @@ -170,6 +172,7 @@ public class RequestsDatabaseTest { } @Test + @Ignore // 1802 merge public void checkDuplicateByVnfIdTest(@Mocked AbstractSessionFactoryManager sessionFactoryManager, @Mocked Session session, @Mocked Query query) throws Exception { diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusDbTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusDbTest.java new file mode 100644 index 0000000000..cc0a5983b6 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusDbTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.junit.Test; +import org.mockito.Mockito; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; +import java.util.List; + + +public class WatchdogComponentDistributionStatusDbTest { + + private static final String distributionId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; + private static final String componentName = "MSO"; + private static final String componentDistributionStatus = "SENT"; + + + @Test + public void testGetWatchdogComponentDistributionStatus() { + List<WatchdogComponentDistributionStatus> watchDogCompDistStatus = new ArrayList<>(); + WatchdogComponentDistributionStatusDb wdcds = Mockito.mock(WatchdogComponentDistributionStatusDb.class); + Mockito.when(wdcds.getWatchdogComponentDistributionStatus("ff3514e3-5a33-55df-13ab-12abad84e7ff")).thenReturn(watchDogCompDistStatus); + List<WatchdogComponentDistributionStatus> actual = wdcds.getWatchdogComponentDistributionStatus(distributionId); + + assertEquals(actual, watchDogCompDistStatus); + verify(wdcds, times(1)).getWatchdogComponentDistributionStatus(any(String.class)); + } + + + @Test + public void testInsertWatchdogComponentDistributionStatus() { + + WatchdogComponentDistributionStatusDb wdcds = mock(WatchdogComponentDistributionStatusDb.class); + + wdcds.insertWatchdogComponentDistributionStatus(distributionId, componentName, componentDistributionStatus); + doNothing().when(wdcds).insertWatchdogComponentDistributionStatus(any(String.class), any(String.class), any(String.class)); + verify(wdcds, times(1)).insertWatchdogComponentDistributionStatus(any(String.class), any(String.class), any(String.class)); + + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusTest.java new file mode 100644 index 0000000000..b36166942d --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogComponentDistributionStatusTest.java @@ -0,0 +1,165 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.Timestamp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class WatchdogComponentDistributionStatusTest { + + WatchdogComponentDistributionStatus _watchdogComponentDistributionStatus; + + protected String _distributionId; + protected String _componentName; + protected String _componentDistributionStatus; + protected Timestamp _createTime; + protected Timestamp _modifyTime; + + public WatchdogComponentDistributionStatusTest() { + } + + @Before + public void setUp() { + _watchdogComponentDistributionStatus = mock(WatchdogComponentDistributionStatus.class); + _distributionId = "12abad84e7ff"; + _componentName = "MSO"; + _componentDistributionStatus = "SENT"; + _createTime = new Timestamp (System.currentTimeMillis()); + _modifyTime = new Timestamp (System.currentTimeMillis()); + + when(_watchdogComponentDistributionStatus.getDistributionId()).thenReturn(_distributionId); + when(_watchdogComponentDistributionStatus.getComponentName()).thenReturn(_componentName); + when(_watchdogComponentDistributionStatus.getComponentDistributionStatus()).thenReturn(_componentDistributionStatus); + when(_watchdogComponentDistributionStatus.getCreateTime()).thenReturn(_createTime); + when(_watchdogComponentDistributionStatus.getModifyTime()).thenReturn(_modifyTime); + } + + @After + public void tearDown() { + _watchdogComponentDistributionStatus = null; + } + + /** + * Test of getDistributionId method + */ + @Test + public void testGetDistributionId() { + _watchdogComponentDistributionStatus.setDistributionId(_distributionId); + assertEquals(_watchdogComponentDistributionStatus.getDistributionId(),_distributionId); + + } + + /** + * Test setDistributionId method + */ + @Test + public void testSetDistributionId() { + _watchdogComponentDistributionStatus.setDistributionId(_distributionId); + verify(_watchdogComponentDistributionStatus).setDistributionId(_distributionId); + } + + /** + * Test of getDistributionId method + */ + @Test + public void testGetComponentName() { + _watchdogComponentDistributionStatus.setComponentName(_componentName); + assertEquals(_watchdogComponentDistributionStatus.getComponentName(),_componentName); + + } + + /** + * Test setDistributionId method + */ + @Test + public void testSetComponentName() { + _watchdogComponentDistributionStatus.setComponentName(_componentName); + verify(_watchdogComponentDistributionStatus).setComponentName(_componentName); + } + + /** + * Test of getDistributionId method + */ + @Test + public void testGetComponentDistributionStatus() { + _watchdogComponentDistributionStatus.setComponentDistributionStatus(_componentDistributionStatus); + assertEquals(_watchdogComponentDistributionStatus.getComponentDistributionStatus(),_componentDistributionStatus); + + } + + /** + * Test setDistributionId method + */ + @Test + public void testSetComponentDistributionStatus() { + _watchdogComponentDistributionStatus.setComponentDistributionStatus(_componentDistributionStatus); + verify(_watchdogComponentDistributionStatus).setComponentDistributionStatus(_componentDistributionStatus); + } + + /** + * Test of getCreateTime method + */ + @Test + public void testGetCreateTime() { + _watchdogComponentDistributionStatus.setCreateTime(_createTime); + System.out.println("CreateTime : " + _createTime); + assertEquals(_watchdogComponentDistributionStatus.getCreateTime(),_createTime); + + } + + /** + * Test setCreateTime method + */ + @Test + public void testSetCreateTime() { + _watchdogComponentDistributionStatus.setCreateTime(_createTime); + verify(_watchdogComponentDistributionStatus).setCreateTime(_createTime); + } + + /** + * Test of getModifyTime method + */ + @Test + public void testGetModifyTime() { + _watchdogComponentDistributionStatus.setModifyTime(_modifyTime); + System.out.println("ModifyTime : " + _modifyTime); + assertEquals(_watchdogComponentDistributionStatus.getModifyTime(),_modifyTime); + + } + + /** + * Test setModifyTime method + */ + @Test + public void testSetModifyTime() { + _watchdogComponentDistributionStatus.setModifyTime(_modifyTime); + verify(_watchdogComponentDistributionStatus).setModifyTime(_modifyTime); + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusDbTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusDbTest.java new file mode 100644 index 0000000000..3343e0aaf6 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusDbTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.junit.Test; +import org.mockito.Mockito; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class WatchdogDistributionStatusDbTest { + + private static final String distributionId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; + + @Test + public void testUpdateWatchdogDistributionIdStatus() { + WatchdogDistributionStatusDb wdds = Mockito.mock(WatchdogDistributionStatusDb.class); + + doNothing().when(wdds).updateWatchdogDistributionIdStatus("ff3514e3-5a33-55df-13ab-12abad84e7ff", "SENT"); + wdds.updateWatchdogDistributionIdStatus(any(String.class), any(String.class)); + verify(wdds, times(1)).updateWatchdogDistributionIdStatus(any(String.class), any(String.class)); + } + + @Test + public void testInsertWatchdogDistributionId() { + + WatchdogDistributionStatusDb wdds = mock(WatchdogDistributionStatusDb.class); + + wdds.insertWatchdogDistributionId(distributionId); + doNothing().when(wdds).insertWatchdogDistributionId(any(String.class)); + verify(wdds, times(1)).insertWatchdogDistributionId(any(String.class)); + + } + + @Test + public void testGetWatchdogDistributionIdStatus() { + + WatchdogDistributionStatusDb wdds = Mockito.mock(WatchdogDistributionStatusDb.class); + Mockito.when(wdds.getWatchdogDistributionIdStatus("ff305d54-75b4-431b-adb2-eb6b9e5ff001")).thenReturn("ff3514e3-5a33-55df-13ab-12abad84e7ff"); + String actual = wdds.getWatchdogDistributionIdStatus("ff305d54-75b4-431b-adb2-eb6b9e5ff001"); + assertEquals(actual, distributionId); + verify(wdds, times(1)).getWatchdogDistributionIdStatus(any(String.class)); + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusTest.java new file mode 100644 index 0000000000..85ac4bba4a --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogDistributionStatusTest.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.Timestamp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class WatchdogDistributionStatusTest { + + WatchdogDistributionStatus _watchdogDistributionStatus; + + protected String _distributionId; + protected String _distributionIdStatus; + protected Timestamp _createTime; + protected Timestamp _modifyTime; + + public WatchdogDistributionStatusTest() { + } + + @Before + public void setUp() { + _watchdogDistributionStatus = mock(WatchdogDistributionStatus.class); + _distributionId = "12abad84e7ff"; + _distributionIdStatus = "SENT"; + _createTime = new Timestamp (System.currentTimeMillis()); + _modifyTime = new Timestamp (System.currentTimeMillis()); + + when(_watchdogDistributionStatus.getDistributionId()).thenReturn(_distributionId); + when(_watchdogDistributionStatus.getDistributionIdStatus()).thenReturn(_distributionIdStatus); + when(_watchdogDistributionStatus.getCreateTime()).thenReturn(_createTime); + when(_watchdogDistributionStatus.getModifyTime()).thenReturn(_modifyTime); + } + + @After + public void tearDown() { + _watchdogDistributionStatus = null; + } + + /** + * Test of getDistributionId method + */ + @Test + public void testGetDistributionId() { + _watchdogDistributionStatus.setDistributionId(_distributionId); + assertEquals(_watchdogDistributionStatus.getDistributionId(),_distributionId); + + } + + /** + * Test setDistributionId method + */ + @Test + public void testSetDistributionId() { + _watchdogDistributionStatus.setDistributionId(_distributionId); + verify(_watchdogDistributionStatus).setDistributionId(_distributionId); + } + + /** + * Test of getDistributionIdStatus method + */ + @Test + public void testGetComponentDistributionStatus() { + _watchdogDistributionStatus.setDistributionIdStatus(_distributionIdStatus); + assertEquals(_watchdogDistributionStatus.getDistributionIdStatus(),_distributionIdStatus); + + } + + /** + * Test setDistributionIdStatus method + */ + @Test + public void testSetComponentDistributionStatus() { + _watchdogDistributionStatus.setDistributionIdStatus(_distributionIdStatus); + verify(_watchdogDistributionStatus).setDistributionIdStatus(_distributionIdStatus); + } + + /** + * Test of getCreateTime method + */ + @Test + public void testGetCreateTime() { + _watchdogDistributionStatus.setCreateTime(_createTime); + assertEquals(_watchdogDistributionStatus.getCreateTime(),_createTime); + + } + + /** + * Test setCreateTime method + */ + @Test + public void testSetCreateTime() { + _watchdogDistributionStatus.setCreateTime(_createTime); + verify(_watchdogDistributionStatus).setCreateTime(_createTime); + } + + /** + * Test of getModifyTime method + */ + @Test + public void testGetModifyTime() { + _watchdogDistributionStatus.setModifyTime(_modifyTime); + assertEquals(_watchdogDistributionStatus.getModifyTime(),_modifyTime); + + } + + /** + * Test setModifyTime method + */ + @Test + public void testSetModifyTime() { + _watchdogDistributionStatus.setModifyTime(_modifyTime); + verify(_watchdogDistributionStatus).setModifyTime(_modifyTime); + } +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupDbTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupDbTest.java new file mode 100644 index 0000000000..9e09aeed00 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupDbTest.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.junit.Test; +import org.mockito.Mockito; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + + +public class WatchdogServiceModVerIdLookupDbTest { + + private static final String distributionId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; + private static final String serviceModelVersionId = "SENT"; + + @Test + public void testInsertWatchdogServiceModVerIdLookup() { + + WatchdogServiceModVerIdLookupDb wdsm = mock(WatchdogServiceModVerIdLookupDb.class); + + wdsm.insertWatchdogServiceModVerIdLookup(distributionId, serviceModelVersionId); + doNothing().when(wdsm).insertWatchdogServiceModVerIdLookup(any(String.class), any(String.class)); + verify(wdsm, times(1)).insertWatchdogServiceModVerIdLookup(any(String.class), any(String.class)); + + } + + @Test + public void testGetWatchdogServiceModVerId() { + + WatchdogServiceModVerIdLookupDb wdsm = Mockito.mock(WatchdogServiceModVerIdLookupDb.class); + Mockito.when(wdsm.getWatchdogServiceModVerId("ff305d54-75b4-431b-adb2-eb6b9e5ff001")).thenReturn("ff3514e3-5a33-55df-13ab-12abad84e7ff"); + String actual = wdsm.getWatchdogServiceModVerId("ff305d54-75b4-431b-adb2-eb6b9e5ff001"); + assertEquals(actual, "ff3514e3-5a33-55df-13ab-12abad84e7ff"); + verify(wdsm, times(1)).getWatchdogServiceModVerId(any(String.class)); + } + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupTest.java new file mode 100644 index 0000000000..beda191194 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/openecomp/mso/requestsdb/WatchdogServiceModVerIdLookupTest.java @@ -0,0 +1,118 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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 static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.Timestamp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class WatchdogServiceModVerIdLookupTest { + + WatchdogServiceModVerIdLookup _watchdogServiceModVerIdLookup; + + protected String _distributionId; + protected String _serviceModelVersionId; + protected Timestamp _createTime; + + public WatchdogServiceModVerIdLookupTest() { + } + + @Before + public void setUp() { + _watchdogServiceModVerIdLookup = mock(WatchdogServiceModVerIdLookup.class); + _serviceModelVersionId = "12abad84e7ff"; + _createTime = new Timestamp (System.currentTimeMillis()); + + when(_watchdogServiceModVerIdLookup.getDistributionId()).thenReturn(_distributionId); + when(_watchdogServiceModVerIdLookup.getServiceModelVersionId()).thenReturn(_serviceModelVersionId); + when(_watchdogServiceModVerIdLookup.getCreateTime()).thenReturn(_createTime); + } + + @After + public void tearDown() { + _watchdogServiceModVerIdLookup = null; + } + + /** + * Test of getDistributionId method + */ + @Test + public void testGetDistributionId() { + _watchdogServiceModVerIdLookup.setDistributionId(_distributionId); + assertEquals(_watchdogServiceModVerIdLookup.getDistributionId(),_distributionId); + + } + + /** + * Test setDistributionId method + */ + @Test + public void testSetDistributionId() { + _watchdogServiceModVerIdLookup.setDistributionId(_distributionId); + verify(_watchdogServiceModVerIdLookup).setDistributionId(_distributionId); + } + + /** + * Test of getServiceModelVersionId method + */ + @Test + public void testGetServiceModelVersionId() { + _watchdogServiceModVerIdLookup.setServiceModelVersionId(_serviceModelVersionId); + assertEquals(_watchdogServiceModVerIdLookup.getServiceModelVersionId(),_serviceModelVersionId); + + } + + /** + * Test setServiceModelVersionId method + */ + @Test + public void testSetServiceModelVersionId() { + _watchdogServiceModVerIdLookup.setServiceModelVersionId(_serviceModelVersionId); + verify(_watchdogServiceModVerIdLookup).setServiceModelVersionId(_serviceModelVersionId); + } + + /** + * Test of getCreateTime method + */ + @Test + public void testGetCreateTime() { + _watchdogServiceModVerIdLookup.setCreateTime(_createTime); + assertEquals(_watchdogServiceModVerIdLookup.getCreateTime(),_createTime); + + } + + /** + * Test setCreateTime method + */ + @Test + public void testSetCreateTime() { + _watchdogServiceModVerIdLookup.setCreateTime(_createTime); + verify(_watchdogServiceModVerIdLookup).setCreateTime(_createTime); + } + +}
\ No newline at end of file |