--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.mso.requestsdb;\r
+\r
+import java.sql.Timestamp;\r
+\r
+/**\r
+ * The service operation status \r
+ * <br>\r
+ * <p>\r
+ * </p>\r
+ * \r
+ * @author\r
+ * @version ONAP Amsterdam Release 2017-08-28\r
+ */\r
+public class OperationStatus {\r
+ \r
+ private String serviceId;\r
+ \r
+ private String operationId;\r
+ \r
+ private String operation;\r
+ \r
+ private String userId;\r
+ \r
+ private String result;\r
+ \r
+ private String operationContent;\r
+ \r
+ private String progress = "0";\r
+ \r
+ private String reason;\r
+\r
+ private Timestamp operateAt;\r
+ \r
+ private Timestamp finishedAt;\r
+\r
+ \r
+ public String getServiceId() {\r
+ return serviceId;\r
+ }\r
+\r
+ \r
+ public void setServiceId(String serviceId) {\r
+ this.serviceId = serviceId;\r
+ }\r
+\r
+ \r
+ public String getOperationId() {\r
+ return operationId;\r
+ }\r
+\r
+ \r
+ public void setOperationId(String operationId) {\r
+ this.operationId = operationId;\r
+ }\r
+\r
+ \r
+ public String getOperation() {\r
+ return operation;\r
+ }\r
+\r
+ \r
+ public void setOperation(String operation) {\r
+ this.operation = operation;\r
+ }\r
+\r
+ \r
+ public String getUserId() {\r
+ return userId;\r
+ }\r
+\r
+ \r
+ public void setUserId(String userId) {\r
+ this.userId = userId;\r
+ }\r
+\r
+ \r
+ public String getResult() {\r
+ return result;\r
+ }\r
+\r
+ \r
+ public void setResult(String result) {\r
+ this.result = result;\r
+ }\r
+\r
+ \r
+ public String getOperationContent() {\r
+ return operationContent;\r
+ }\r
+\r
+ \r
+ public void setOperationContent(String operationContent) {\r
+ this.operationContent = operationContent;\r
+ }\r
+\r
+ \r
+ public String getProgress() {\r
+ return progress;\r
+ }\r
+\r
+ \r
+ public void setProgress(String progress) {\r
+ this.progress = progress;\r
+ }\r
+\r
+ \r
+ public String getReason() {\r
+ return reason;\r
+ }\r
+\r
+ \r
+ public void setReason(String reason) {\r
+ this.reason = reason;\r
+ }\r
+\r
+ \r
+ public Timestamp getOperateAt() {\r
+ return operateAt;\r
+ }\r
+\r
+ \r
+ public void setOperateAt(Timestamp operateAt) {\r
+ this.operateAt = operateAt;\r
+ }\r
+\r
+ \r
+ public Timestamp getFinishedAt() {\r
+ return finishedAt;\r
+ }\r
+\r
+ \r
+ public void setFinishedAt(Timestamp finishedAt) {\r
+ this.finishedAt = finishedAt;\r
+ }\r
+\r
+}\r
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
}
}
+ /**
+ * get the operation progress
+ * <br>
+ *
+ * @param serviceId the serviceId
+ * @param operationId the operation id
+ * @return current progress of the operation
+ * @since ONAP Amsterdam Release
+ */
+ public static OperationStatus getOperationStatus(String serviceId, String operationId) {
+
+ long startTime = System.currentTimeMillis();
+ msoLogger.debug("Execute query on infra active request table");
+
+ OperationStatus operStatus = null;
+ Session session = hibernateUtils.getSessionFactory().openSession();
+ try {
+ session.beginTransaction();
+ String hql = "FROM OperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id";
+ Query query = session.createQuery(hql);
+ query.setParameter("service_id", serviceId);
+ query.setParameter("operation_id", operationId);
+ operStatus = (OperationStatus)query.uniqueResult();
+
+ } finally {
+ if(session != null && session.isOpen()) {
+ session.close();
+ }
+ msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "RequestDB", "getOperationStatus", null);
+ }
+ return operStatus;
+ }
+
+ /**
+ * update the operation status
+ * <br>
+ *
+ * @param operstatus the operation object
+ * @since ONAP Amsterdam Release
+ */
+ public static void updateOperationStatus(OperationStatus operstatus) {
+ Session session = hibernateUtils.getSessionFactory().openSession();
+ session.beginTransaction();
+
+ long startTime = System.currentTimeMillis();
+ msoLogger.debug("Request database - save Operation Status with service Id:" + operstatus.getServiceId()
+ + ", operationId:" + operstatus.getOperationId());
+ try {
+ String hql =
+ "FROM OperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id";
+ Query query = session.createQuery(hql);
+ query.setParameter("service_id", operstatus.getServiceId());
+ query.setParameter("operation_id", operstatus.getOperationId());
+ OperationStatus exsitingStatus = (OperationStatus)query.uniqueResult();
+ if(exsitingStatus == null) {
+ session.save(operstatus);
+ } else {
+ session.merge(operstatus);
+ }
+ session.getTransaction().commit();
+ } finally {
+ if(session != null && session.isOpen()) {
+ session.close();
+ }
+ msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "RequestDB", "updateOperationStatus", null);
+ }
+ }
+
+ /**
+ * get a operation status of a resource
+ * <br>
+ *
+ * @param serviceId the service Id
+ * @param operationId the operation id
+ * @param resourceTemplateUUID the resource template uuid
+ * @return the progress status of a resource
+ * @since ONAP Amsterdam Release
+ */
+ public static ResourceOperationStatus getResourceOperationStatus(String serviceId, String operationId,
+ String resourceTemplateUUID) {
+ long startTime = System.currentTimeMillis();
+ msoLogger.debug("Execute query on infra active request table");
+
+ ResourceOperationStatus operStatus = null;
+ Session session = hibernateUtils.getSessionFactory().openSession();
+ try {
+ session.beginTransaction();
+ String hql =
+ "FROM ResourceOperationStatus WHERE serviceId = :service_id and operationId = :operation_id and resourceTemplateUUID= :uuid";
+ Query query = session.createQuery(hql);
+ query.setParameter("service_id", serviceId);
+ query.setParameter("operation_id", operationId);
+ query.setParameter("uuid", resourceTemplateUUID);
+ operStatus = (ResourceOperationStatus)query.uniqueResult();
+
+ } finally {
+ if(session != null && session.isOpen()) {
+ session.close();
+ }
+ msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "RequestDB", "getOperationStatus", null);
+ }
+ return operStatus;
+ }
+
+ /**
+ * update the resource operation
+ * <br>
+ *
+ * @param operstatus the resource operation object
+ * @since ONAP Amsterdam Release
+ */
+ public static void updateResOperStatus(ResourceOperationStatus operStatus) {
+ Session session = hibernateUtils.getSessionFactory().openSession();
+ session.beginTransaction();
+
+ long startTime = System.currentTimeMillis();
+ msoLogger.debug("Request database - save Resource Operation Status with service Id:" + operStatus.getServiceId()
+ + ", operationId:" + operStatus.getOperationId() + ", resourceUUId:"
+ + operStatus.getResourceTemplateUUID());
+ try {
+ String hql =
+ "FROM ResourceOperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id and RESOURCE_TEMPLATE_UUID = : res_uuid";
+ Query query = session.createQuery(hql);
+ query.setParameter("service_id", operStatus.getServiceId());
+ query.setParameter("operation_id", operStatus.getOperationId());
+ query.setParameter("res_uuid", operStatus.getResourceTemplateUUID());
+ ResourceOperationStatus exsitingStatus = (ResourceOperationStatus)query.uniqueResult();
+ if(exsitingStatus == null) {
+ session.save(operStatus);
+ } else {
+ session.merge(operStatus);
+ }
+ session.getTransaction().commit();
+ } finally {
+ if(session != null && session.isOpen()) {
+ session.close();
+ }
+ msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "RequestDB", "updateResOperStatus", null);
+ }
+ updateOperationStatusBasedOnResourceStatus(operStatus);
+ }
+
+ /**
+ * update service operation status when a operation resource status updated
+ * <br>
+ *
+ * @param operStatus the resource operation status
+ * @since ONAP Amsterdam Release
+ */
+ private static void updateOperationStatusBasedOnResourceStatus(ResourceOperationStatus operStatus) {
+ Session session = hibernateUtils.getSessionFactory().openSession();
+ session.beginTransaction();
+
+ long startTime = System.currentTimeMillis();
+ msoLogger.debug("Request database - query Resource Operation Status with service Id:"
+ + operStatus.getServiceId() + ", operationId:" + operStatus.getOperationId());
+ try {
+ // query all resources of the service
+ String hql = "FROM ResourceOperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id";
+ Query query = session.createQuery(hql);
+ query.setParameter("service_id", operStatus.getServiceId());
+ query.setParameter("operation_id", operStatus.getOperationId());
+ @SuppressWarnings("unchecked")
+ List<ResourceOperationStatus> lstResourceStatus = (List<ResourceOperationStatus>)query.list();
+ // count the total progress
+ int resourceCount = lstResourceStatus.size();
+ int progress = 0;
+ boolean isFinished = true;
+ for(int i = 0; i < resourceCount; i++) {
+ progress = progress + Integer.valueOf(lstResourceStatus.get(i).getProgress()) / resourceCount;
+ if(RequestsDbConstant.Status.PROCESSING.equals(lstResourceStatus.get(i).getStatus())) {
+ isFinished = false;
+ }
+ }
+ OperationStatus serviceOperStatus =
+ getOperationStatus(operStatus.getServiceId(), operStatus.getOperationId());
+ progress = progress > 100 ? 100 : progress;
+ serviceOperStatus.setProgress(String.valueOf(progress));
+ serviceOperStatus.setOperationContent(operStatus.getStatusDescription());
+ // if current resource failed. service failed.
+ if(RequestsDbConstant.Status.ERROR.equals(operStatus.getStatus())) {
+ serviceOperStatus.setResult(RequestsDbConstant.Status.ERROR);
+ serviceOperStatus.setReason(operStatus.getStatusDescription());
+ } else if(isFinished) {
+ // if finished
+ serviceOperStatus.setResult(RequestsDbConstant.Status.FINISHED);
+ serviceOperStatus.setProgress(RequestsDbConstant.Progress.ONE_HUNDRED);
+ }
+ updateOperationStatus(serviceOperStatus);
+ } finally {
+ if(session != null && session.isOpen()) {
+ session.close();
+ }
+ msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully", "RequestDB", "updateResOperStatus", null);
+ }
+ }
}
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.mso.requestsdb;\r
+\r
+/**\r
+ * The constants of the request db\r
+ * <br>\r
+ * <p>\r
+ * </p>\r
+ * \r
+ * @author\r
+ * @version ONAP Amsterdam Release 2017-08-28\r
+ */\r
+public class RequestsDbConstant {\r
+\r
+ public static class Progress {\r
+\r
+ public static final String ONE_HUNDRED = "100";\r
+\r
+ private Progress() {\r
+\r
+ }\r
+ }\r
+\r
+ public static class Status {\r
+\r
+ public static final String FINISHED = "finished";\r
+\r
+ public static final String PROCESSING = "processing";\r
+\r
+ public static final String ERROR = "error";\r
+\r
+ private Status() {\r
+\r
+ }\r
+ }\r
+\r
+ public static class OperationType {\r
+\r
+ public static final String CREATE = "create";\r
+\r
+ public static final String DELETE = "delete";\r
+\r
+ private OperationType() {\r
+\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.mso.requestsdb;\r
+\r
+/**\r
+ * The Resource operation status\r
+ * <br>\r
+ * <p>\r
+ * </p>\r
+ * \r
+ * @author\r
+ * @version ONAP Amsterdam Release 2017-08-28\r
+ */\r
+public class ResourceOperationStatus {\r
+\r
+ private String serviceId;\r
+ \r
+ private String operationId;\r
+ \r
+ private String resourceTemplateUUID;\r
+ \r
+ private String operType;\r
+ \r
+ private String resourceInstanceID;\r
+ \r
+ private String jobId;\r
+ \r
+ private String status;\r
+ \r
+ private String progress = "0";\r
+ \r
+ private String errorCode;\r
+ \r
+ private String statusDescription;\r
+\r
+ public ResourceOperationStatus(){\r
+ \r
+ }\r
+ \r
+ public ResourceOperationStatus(String serviceId, String operationId, String resourceTemplateUUID)\r
+ {\r
+ this.serviceId = serviceId;\r
+ this.operationId = operationId;\r
+ this.resourceTemplateUUID = resourceTemplateUUID;\r
+ }\r
+ \r
+ public String getServiceId() {\r
+ return serviceId;\r
+ }\r
+\r
+ \r
+ public void setServiceId(String serviceId) {\r
+ this.serviceId = serviceId;\r
+ }\r
+\r
+ \r
+ public String getOperationId() {\r
+ return operationId;\r
+ }\r
+\r
+ \r
+ public void setOperationId(String operationId) {\r
+ this.operationId = operationId;\r
+ }\r
+\r
+ \r
+ public String getResourceTemplateUUID() {\r
+ return resourceTemplateUUID;\r
+ }\r
+\r
+ \r
+ public void setResourceTemplateUUID(String resourceTemplateUUId) {\r
+ this.resourceTemplateUUID = resourceTemplateUUId;\r
+ }\r
+\r
+ \r
+ public String getJobId() {\r
+ return jobId;\r
+ }\r
+\r
+ \r
+ public void setJobId(String jobId) {\r
+ this.jobId = jobId;\r
+ }\r
+\r
+ \r
+ public String getStatus() {\r
+ return status;\r
+ }\r
+\r
+ \r
+ public void setStatus(String status) {\r
+ this.status = status;\r
+ }\r
+\r
+ \r
+ public String getProgress() {\r
+ return progress;\r
+ }\r
+\r
+ \r
+ public void setProgress(String progress) {\r
+ this.progress = progress;\r
+ }\r
+\r
+ \r
+ public String getErrorCode() {\r
+ return errorCode;\r
+ }\r
+\r
+ \r
+ public void setErrorCode(String errorCode) {\r
+ this.errorCode = errorCode;\r
+ }\r
+\r
+ \r
+ public String getStatusDescription() {\r
+ return statusDescription;\r
+ }\r
+\r
+ \r
+ public void setStatusDescription(String statusDescription) {\r
+ this.statusDescription = statusDescription;\r
+ }\r
+\r
+\r
+ \r
+ public String getResourceInstanceID() {\r
+ return resourceInstanceID;\r
+ }\r
+\r
+\r
+ \r
+ public void setResourceInstanceID(String resourceInstanceID) {\r
+ this.resourceInstanceID = resourceInstanceID;\r
+ }\r
+\r
+ \r
+ public String getOperType() {\r
+ return operType;\r
+ }\r
+\r
+ \r
+ public void setOperType(String operType) {\r
+ this.operType = operType;\r
+ }\r
+ \r
+ \r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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//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>
+ <id name="serviceId" type="string" column="SERVICE_ID"/>
+ <id name="operationId" column="OPERATION_ID" 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" column="OPERATE_AT" type="timestamp" generated="insert" insert="false" update="false"/>
+ <property name="finishedAt" column="FINISHED_AT" type="timestamp" generated="update" insert="false" update="false"/>
+ </class>
+</hibernate-mapping>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.openecomp.mso.requestsdb">
+ <class name="ResourceOperationStatus" table="RESOURCE_OPERATION_STATUS">
+ <meta attribute="class-description">
+ This class describes a progress status
+ </meta>
+ <id name="serviceId" type="string" column="SERVICE_ID"/>
+ <id name="operationId" column="OPERATION_ID" type="string" length="256"/>
+ <id name="resourceTemplateUUID" type="string" column="RESOURCE_TEMPLATE_UUID"/>
+ <property name="operType" column="OPER_TYPE" type="string" length="256"/>
+ <property name="resourceInstanceID" column="RESOURCE_INSTANCE_ID" type="string" length="256"/>
+ <property name="jobId" column="JOB_ID" type="string" length="256"/>
+ <property name="status" column="STATUS" type="string" length="256"/>
+ <property name="progress" column="PROGRESS" type="string" length="256"/>
+ <property name="errorCode" column="ERROR_CODE" type="string" length="256"/>
+ <property name="statusDescription" column="STATUS_DESCRIPOTION" type="string" length="256"/>
+ </class>
+</hibernate-mapping>