diff options
author | guochuyicmri <guochuyi@chinamobile.com> | 2019-04-03 16:25:54 +0800 |
---|---|---|
committer | guochuyicmri <guochuyi@chinamobile.com> | 2019-04-03 17:16:45 +0800 |
commit | 706ab0b0bb9d44cde82edc6cfdb6659bf207bdfd (patch) | |
tree | 369b835b365754de34821b990290ade0559c5ef0 | |
parent | 5cfce4879635df7cfc58a234277900470b536174 (diff) |
Change backend Code for LCM UI page of service list
Change-Id: Ic47d0d4f883c7b6a1bb917726eec7e8de421f413
Issue-ID: USECASEUI-219
Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
9 files changed, 457 insertions, 62 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/ServiceBean.java b/server/src/main/java/org/onap/usecaseui/server/bean/ServiceBean.java index af53ab25..34c756d2 100644 --- a/server/src/main/java/org/onap/usecaseui/server/bean/ServiceBean.java +++ b/server/src/main/java/org/onap/usecaseui/server/bean/ServiceBean.java @@ -28,26 +28,41 @@ public class ServiceBean { @Column(name = "id") private String id; - @Column(name = "serviceInstanceId") + @Column(name = "service_instance_id") private String serviceInstanceId; - @Column(name = "customerId") + @Column(name = "customer_id") private String customerId; - @Column(name = "serviceType") + @Column(name = "service_type") private String serviceType; - @Column(name = "serviceDomain") + @Column(name = "usecase_type") private String serviceDomain; - @Column(name = "operationId") - private String operationId; - - @Column(name = "parentServiceInstanceId") + @Column(name = "parent_service_instance_id") private String parentServiceInstanceId; - @Column(name = "status") - private String status; + @Column(name = "uuid") + private String uuid; + + @Column(name = "invariant_uuid") + private String invariantUuuid; + + public ServiceBean() { + } + + public ServiceBean(String id, String serviceInstanceId, String customerId, String serviceType, String serviceDomain, + String parentServiceInstanceId, String uuid, String invariantUuuid) { + this.id = id; + this.serviceInstanceId = serviceInstanceId; + this.customerId = customerId; + this.serviceType = serviceType; + this.serviceDomain = serviceDomain; + this.parentServiceInstanceId = parentServiceInstanceId; + this.uuid = uuid; + this.invariantUuuid = invariantUuuid; + } public String getId() { return id; @@ -89,14 +104,6 @@ public class ServiceBean { this.serviceDomain = serviceDomain; } - public String getOperationId() { - return operationId; - } - - public void setOperationId(String operationId) { - this.operationId = operationId; - } - public String getParentServiceInstanceId() { return parentServiceInstanceId; } @@ -105,34 +112,21 @@ public class ServiceBean { this.parentServiceInstanceId = parentServiceInstanceId; } - public String getStatus() { - return status; + public String getUuid() { + return uuid; } - public void setStatus(String status) { - this.status = status; + public void setUuid(String uuid) { + this.uuid = uuid; } - public ServiceBean() { + public String getInvariantUuuid() { + return invariantUuuid; } - public ServiceBean(String id, String serviceInstanceId, String customerId, String serviceType, String serviceDomain, - String operationId, String parentServiceInstanceId, String status) { - this.id = id; - this.serviceInstanceId = serviceInstanceId; - this.customerId = customerId; - this.serviceType = serviceType; - this.serviceDomain = serviceDomain; - this.operationId = operationId; - this.parentServiceInstanceId = parentServiceInstanceId; - this.status = status; + public void setInvariantUuuid(String invariantUuuid) { + this.invariantUuuid = invariantUuuid; } - @Override - public String toString() { - return "ServiceBean [id=" + id + ", serviceInstanceId=" + serviceInstanceId + ", customerId=" + customerId - + ", serviceType=" + serviceType + ", serviceDomain=" + serviceDomain + ", operationId=" + operationId - + ", parentServiceInstanceId=" + parentServiceInstanceId + ", status=" + status + "]"; - } } diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/ServiceInstanceOperations.java b/server/src/main/java/org/onap/usecaseui/server/bean/ServiceInstanceOperations.java new file mode 100644 index 00000000..313e2361 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/ServiceInstanceOperations.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. 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. + */ +package org.onap.usecaseui.server.bean; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="service_instance_operations") +public class ServiceInstanceOperations implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "service_instance_id") + private String serviceInstanceId; + + @Id + @Column(name = "operation_id") + private String operationId; + + @Column(name = "operation_type") + private String operationType; + + @Column(name = "operation_progress") + private String operationProgress; + + @Column(name = "operation_result") + private String operationResult; + + @Column(name = "start_time") + private String startTime; + + @Column(name = "end_time") + private String endTime; + + public ServiceInstanceOperations() { + } + + public ServiceInstanceOperations(String serviceInstanceId, String operationId, String operationType, + String operationProgress, String operationResult, String startTime, String endTime) { + super(); + this.serviceInstanceId = serviceInstanceId; + this.operationId = operationId; + this.operationType = operationType; + this.operationProgress = operationProgress; + this.operationResult = operationResult; + this.startTime = startTime; + this.endTime = endTime; + } + + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + public String getOperationId() { + return operationId; + } + + public void setOperationId(String operationId) { + this.operationId = operationId; + } + + public String getOperationType() { + return operationType; + } + + public void setOperationType(String operationType) { + this.operationType = operationType; + } + + public String getOperationProgress() { + return operationProgress; + } + + public void setOperationProgress(String operationProgress) { + this.operationProgress = operationProgress; + } + + public String getOperationResult() { + return operationResult; + } + + public void setOperationResult(String operationResult) { + this.operationResult = operationResult; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((operationId == null) ? 0 : operationId.hashCode()); + result = prime * result + ((serviceInstanceId == null) ? 0 : serviceInstanceId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceInstanceOperations other = (ServiceInstanceOperations) obj; + if (operationId == null) { + if (other.operationId != null) + return false; + } else if (!operationId.equals(other.operationId)) + return false; + if (serviceInstanceId == null) { + if (other.serviceInstanceId != null) + return false; + } else if (!serviceInstanceId.equals(other.serviceInstanceId)) + return false; + return true; + } +} diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/SortMaster.java b/server/src/main/java/org/onap/usecaseui/server/bean/SortMaster.java new file mode 100644 index 00000000..28a94e24 --- /dev/null +++ b/server/src/main/java/org/onap/usecaseui/server/bean/SortMaster.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2018 CMCC, Inc. and others. 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. + */ +package org.onap.usecaseui.server.bean; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="sort_master") +public class SortMaster implements Serializable{ + + @Id + @Column(name = "sort_type") + private String sortType; + + @Id + @Column(name = "sort_code") + private String sortCode; + + + @Column(name = "sort_value") + private String sortValue; + + @Id + @Column(name = "language") + private String language; + + public SortMaster() { + } + + public SortMaster(String sortType, String sortCode, String sortValue, String language) { + this.sortType = sortType; + this.sortCode = sortCode; + this.sortValue = sortValue; + this.language = language; + } + + public String getSortType() { + return sortType; + } + + public void setSortType(String sortType) { + this.sortType = sortType; + } + + public String getSortCode() { + return sortCode; + } + + public void setSortCode(String sortCode) { + this.sortCode = sortCode; + } + + public String getSortValue() { + return sortValue; + } + + public void setSortValue(String sortValue) { + this.sortValue = sortValue; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + @Override + public String toString() { + return "SortMaster [sortType=" + sortType + ", sortCode=" + sortCode + ", sortValue=" + sortValue + + ", language=" + language + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((language == null) ? 0 : language.hashCode()); + result = prime * result + ((sortCode == null) ? 0 : sortCode.hashCode()); + result = prime * result + ((sortType == null) ? 0 : sortType.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SortMaster other = (SortMaster) obj; + if (language == null) { + if (other.language != null) + return false; + } else if (!language.equals(other.language)) + return false; + if (sortCode == null) { + if (other.sortCode != null) + return false; + } else if (!sortCode.equals(other.sortCode)) + return false; + if (sortType == null) { + if (other.sortType != null) + return false; + } else if (!sortType.equals(other.sortType)) + return false; + return true; + } +} diff --git a/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java b/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java index f1babd68..b384b80b 100755 --- a/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java +++ b/server/src/main/java/org/onap/usecaseui/server/constant/Constant.java @@ -32,4 +32,22 @@ public final class Constant public static final String CONSTANT_SUCCESS="{\"status\":\"SUCCESS\"}";
public static final String CONSTANT_FAILED="{\"status\":\"FAILED\"}";
+
+ public static final String CREATING_CODE="1001";
+
+ public static final String DELETING_CODE="1002";
+
+ public static final String SCALING_CODE="1003";
+
+ public static final String HEALING_CODE="1004";
+
+ public static final String SUCCESS_CODE="2001";
+
+ public static final String FAIL_CODE="2002";
+
+ public static final String IN_PROGRESS_CODE="2003";
+
+ public static final String ALARM_TOPIC="unauthenticated.SEC_FAULT_OUTPUT";
+
+ public static final String PERFORMANCE_TOPIC="unauthenticated.SEC_MEASUREMENT_OUTPUT";
}
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java index 77c7ec55..6206ffbc 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmController.java @@ -16,11 +16,14 @@ package org.onap.usecaseui.server.controller.lcm; import org.onap.usecaseui.server.bean.ServiceBean; +import org.onap.usecaseui.server.bean.ServiceInstanceOperations; +import org.onap.usecaseui.server.constant.Constant; import org.onap.usecaseui.server.service.lcm.ServiceLcmService; import org.onap.usecaseui.server.service.lcm.domain.so.bean.DeleteOperationRsp; import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation; import org.onap.usecaseui.server.service.lcm.domain.so.bean.SaveOrUpdateOperationRsp; import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation; +import org.onap.usecaseui.server.util.DateUtils; import org.onap.usecaseui.server.util.UuiCommonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,6 +34,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import java.text.ParseException; + import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -50,33 +55,50 @@ public class ServiceLcmController { @ResponseBody @RequestMapping(value = {"/uui-lcm/services"}, method = RequestMethod.POST , produces = "application/json") - public ServiceOperation instantiateService(HttpServletRequest request){ + public ServiceOperation instantiateService(HttpServletRequest request) throws ParseException{ String customerId = request.getParameter("customerId"); String serviceType = request.getParameter("serviceType"); String serviceDomain = request.getParameter("serviceDomain"); + String uuid = request.getParameter("uuid"); + String invariantUuuid = request.getParameter("invariantUuuid"); String parentServiceInstanceId = request.getParameter("parentServiceInstanceId"); - ServiceBean serviceBean = new ServiceBean(UuiCommonUtil.getUUID(),null,customerId,serviceType,serviceDomain,null,parentServiceInstanceId,null); + ServiceBean serviceBean = new ServiceBean(UuiCommonUtil.getUUID(),null,customerId,serviceType,serviceDomain,parentServiceInstanceId,uuid,invariantUuuid); ServiceOperation serviceOperation = serviceLcmService.instantiateService(request); - serviceBean.setServiceInstanceId(serviceOperation.getService().getServiceId()); - serviceBean.setOperationId(serviceOperation.getService().getOperationId()); + String serviceId = serviceOperation.getService().getServiceId(); + String operationId = serviceOperation.getService().getOperationId(); + serviceBean.setServiceInstanceId(serviceId); + ServiceInstanceOperations serviceOpera = new ServiceInstanceOperations(serviceId,operationId,Constant.CREATING_CODE,"0",Constant.IN_PROGRESS_CODE,DateUtils.dateToString(DateUtils.now()),null); serviceLcmService.saveOrUpdateServiceBean(serviceBean); + serviceLcmService.saveOrUpdateServiceInstanceOperation(serviceOpera); return serviceOperation; } @ResponseBody @RequestMapping(value = {"/uui-lcm/services/{serviceId}/operations/{operationId}"}, method = RequestMethod.GET , produces = "application/json") - public OperationProgressInformation queryOperationProgress(@PathVariable(value="serviceId") String serviceId, @PathVariable(value="operationId") String operationId){ + public OperationProgressInformation queryOperationProgress(HttpServletRequest request,@PathVariable(value="serviceId") String serviceId, @PathVariable(value="operationId") String operationId){ + String operationType = request.getParameter("operationType"); + String operationResult = Constant.IN_PROGRESS_CODE; OperationProgressInformation operationProgressInformation =serviceLcmService.queryOperationProgress(serviceId, operationId); - if(UuiCommonUtil.isNotNullOrEmpty(operationProgressInformation)&&UuiCommonUtil.isNotNullOrEmpty(operationProgressInformation.getOperationStatus())&&"CREATE".equals(operationProgressInformation.getOperationStatus().getOperation())){ - serviceLcmService.updateServiceInstanceStatusById(operationProgressInformation.getOperationStatus().getResult(), serviceId); + if(UuiCommonUtil.isNotNullOrEmpty(operationProgressInformation)&&UuiCommonUtil.isNotNullOrEmpty(operationProgressInformation.getOperationStatus())){ + //serviceLcmService.updateServiceInstanceStatusById(operationProgressInformation.getOperationStatus().getResult(), serviceId); + int progress =operationProgressInformation.getOperationStatus().getProgress(); + if(0<=progress&&progress<100){ + operationResult=Constant.IN_PROGRESS_CODE; + }else if(progress==100){ + operationResult=Constant.SUCCESS_CODE; + } + serviceLcmService.updateServiceInstanceOperation(serviceId,operationType,progress+"",operationResult); } return operationProgressInformation; } @ResponseBody @RequestMapping(value = {"/uui-lcm/services/{serviceId}"}, method = RequestMethod.DELETE , produces = "application/json") - public DeleteOperationRsp terminateService(@PathVariable(value = "serviceId") String serviceId, HttpServletRequest request){ - return serviceLcmService.terminateService(serviceId, request); + public DeleteOperationRsp terminateService(@PathVariable(value = "serviceId") String serviceId, HttpServletRequest request) throws ParseException{ + DeleteOperationRsp deleteOperationRsp = serviceLcmService.terminateService(serviceId, request); + ServiceInstanceOperations serviceOpera = new ServiceInstanceOperations(serviceId,deleteOperationRsp.getOperationId(),Constant.DELETING_CODE,"0",Constant.IN_PROGRESS_CODE,DateUtils.dateToString(DateUtils.now()),null); + serviceLcmService.saveOrUpdateServiceInstanceOperation(serviceOpera); + return deleteOperationRsp; } /** @@ -90,11 +112,15 @@ public class ServiceLcmController { * @param serviceId * @param request * @return + * @throws ParseException */ @ResponseBody @RequestMapping(value = {"/uui-lcm/services/scaleServices/{serviceId}"}, method = RequestMethod.POST , produces = "application/json") - public SaveOrUpdateOperationRsp scaleServices(@PathVariable(value = "serviceId") String serviceId, HttpServletRequest request){ - return serviceLcmService.scaleService(serviceId, request); + public SaveOrUpdateOperationRsp scaleServices(@PathVariable(value = "serviceId") String serviceId, HttpServletRequest request) throws ParseException{ + SaveOrUpdateOperationRsp saveOrUpdateOperationRsp =serviceLcmService.scaleService(serviceId, request); + ServiceInstanceOperations serviceOpera = new ServiceInstanceOperations(serviceId,saveOrUpdateOperationRsp.getOperationId(),Constant.SCALING_CODE,"0",Constant.IN_PROGRESS_CODE,DateUtils.dateToString(DateUtils.now()),null); + serviceLcmService.saveOrUpdateServiceInstanceOperation(serviceOpera); + return saveOrUpdateOperationRsp; } /** @@ -108,10 +134,14 @@ public class ServiceLcmController { * @param serviceId * @param request * @return + * @throws ParseException */ @ResponseBody @RequestMapping(value = {"/uui-lcm/services/updateService/{serviceId}"}, method = RequestMethod.PUT , produces = "application/json") - public SaveOrUpdateOperationRsp updateServices(@PathVariable(value = "serviceId") String serviceId, HttpServletRequest request){ - return serviceLcmService.updateService(serviceId, request); + public SaveOrUpdateOperationRsp updateServices(@PathVariable(value = "serviceId") String serviceId, HttpServletRequest request) throws ParseException{ + SaveOrUpdateOperationRsp saveOrUpdateOperationRsp =serviceLcmService.scaleService(serviceId, request); + ServiceInstanceOperations serviceOpera = new ServiceInstanceOperations(serviceId,saveOrUpdateOperationRsp.getOperationId(),"UPDATING","0",Constant.IN_PROGRESS_CODE,DateUtils.dateToString(DateUtils.now()),null); + serviceLcmService.saveOrUpdateServiceInstanceOperation(serviceOpera); + return saveOrUpdateOperationRsp; } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java index e9557cee..e4a0b014 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java @@ -16,6 +16,7 @@ package org.onap.usecaseui.server.service.lcm; import org.onap.usecaseui.server.bean.ServiceBean; +import org.onap.usecaseui.server.bean.ServiceInstanceOperations; import org.onap.usecaseui.server.service.lcm.domain.so.bean.DeleteOperationRsp; import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation; import org.onap.usecaseui.server.service.lcm.domain.so.bean.SaveOrUpdateOperationRsp; @@ -44,4 +45,10 @@ public interface ServiceLcmService { ServiceBean getServiceBeanByServiceInStanceId(String serviceInstanceId); List<String> getServiceInstanceIdByParentId(String serviceInstanceId); + + void saveOrUpdateServiceInstanceOperation(ServiceInstanceOperations serviceOperation); + + void updateServiceInstanceOperation(String serviceInstanceId,String operationType,String progress,String operationResult); + + ServiceInstanceOperations getServiceInstanceOperationById(String serviceId); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java index 04561302..8a6f7aa2 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java @@ -25,6 +25,7 @@ import java.util.Map; import javax.annotation.Resource; import org.onap.usecaseui.server.bean.ServiceBean; +import org.onap.usecaseui.server.bean.ServiceInstanceOperations; import org.onap.usecaseui.server.service.lcm.CustomerService; import org.onap.usecaseui.server.service.lcm.ServiceInstanceService; import org.onap.usecaseui.server.service.lcm.ServiceLcmService; @@ -109,13 +110,15 @@ public class DefaultServiceInstanceService implements ServiceInstanceService { JSONObject object = JSON.parseObject(serviceInstance+""); String serviceInstanceId=object.get("service-instance-id").toString(); ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId); + ServiceInstanceOperations serviceInstanceOperations = serviceLcmService.getServiceInstanceOperationById(serviceInstanceId); if(!UuiCommonUtil.isNotNullOrEmpty(serviceBean)){ continue; } String serviceDomain = serviceBean.getServiceDomain(); object.put("serviceDomain",serviceDomain); - object.put("serviceStatus",serviceBean.getStatus()); - object.put("operationId",serviceBean.getOperationId()); + object.put("operationResult",serviceInstanceOperations.getOperationResult()); + object.put("operationId",serviceInstanceOperations.getOperationId()); + object.put("operationType",serviceInstanceOperations.getOperationType()); if("SOTN".equals(serviceDomain)||"CCVPN".equals(serviceDomain)||"E2E Service".equals(serviceDomain)||"Network Service".equals(serviceDomain)){ List<String> parentIds = serviceLcmService.getServiceInstanceIdByParentId(serviceInstanceId); List<String> parentServiceInstances = new ArrayList<>(); diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java index f8243e5d..a66ea9f0 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java @@ -28,8 +28,8 @@ import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; -import org.onap.usecaseui.server.bean.AlarmsHeader; import org.onap.usecaseui.server.bean.ServiceBean; +import org.onap.usecaseui.server.bean.ServiceInstanceOperations; import org.onap.usecaseui.server.service.lcm.ServiceLcmService; import org.onap.usecaseui.server.service.lcm.domain.so.SOService; import org.onap.usecaseui.server.service.lcm.domain.so.bean.DeleteOperationRsp; @@ -37,19 +37,16 @@ import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInf import org.onap.usecaseui.server.service.lcm.domain.so.bean.SaveOrUpdateOperationRsp; import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation; import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException; -import org.onap.usecaseui.server.util.UuiCommonUtil; +import org.onap.usecaseui.server.util.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Service; import okhttp3.RequestBody; import retrofit2.Response; @Service("ServiceLcmService") -@org.springframework.context.annotation.Configuration -@EnableAspectJAutoProxy public class DefaultServiceLcmService implements ServiceLcmService { private static final Logger logger = LoggerFactory.getLogger(DefaultServiceLcmService.class); @@ -186,7 +183,7 @@ public class DefaultServiceLcmService implements ServiceLcmService { session.flush(); }catch (Exception e){ - logger.error("exception occurred while performing DefaultServiceLcmService updateServiceInstanceStatusByIdDetail."+e.getMessage()); + logger.error("exception occurred while performing DefaultServiceLcmService updateServiceInstanceStatusById.Detail."+e.getMessage()); } } @@ -204,7 +201,7 @@ public class DefaultServiceLcmService implements ServiceLcmService { serviceBean = list.get(0); } }catch (Exception e){ - logger.error("exception occurred while performing DefaultServiceLcmService updateServiceInstanceStatusByIdDetail."+e.getMessage()); + logger.error("exception occurred while performing DefaultServiceLcmService getServiceBeanByServiceInStanceId.Detail."+e.getMessage()); serviceBean = new ServiceBean();; } return serviceBean; @@ -228,4 +225,62 @@ public class DefaultServiceLcmService implements ServiceLcmService { return list; } + + @Override + public void saveOrUpdateServiceInstanceOperation(ServiceInstanceOperations serviceOperation) { + try(Session session = getSession()){ + if (null == serviceOperation) { + logger.error("DefaultServiceLcmService saveOrUpdateServiceBean serviceOperation is null!"); + } + session.saveOrUpdate(serviceOperation); + session.flush(); + } catch (Exception e) { + e.printStackTrace(); + logger.error("exception occurred while performing DefaultServiceLcmService saveOrUpdateServiceInstanceOperation. Details:" + e.getMessage()); + } + } + + @Override + public void updateServiceInstanceOperation(String serviceInstanceId, String operationType, String progress, + String operationResult) { + List<ServiceInstanceOperations> list = new ArrayList<>(); + try(Session session = getSession()) { + String hql="select a.* from service_instance_operations a where service_instance_id =:serviceId and operation_type =:operationType and start_time = (select max(start_time) from service_instance_operations where service_instance_id=:serviceInstanceId )"; + Query q = session.createSQLQuery(hql).addEntity(ServiceInstanceOperations.class); + q.setString("serviceId",serviceInstanceId); + q.setString("serviceInstanceId",serviceInstanceId); + q.setString("operationType",operationType); + list = q.list(); + ServiceInstanceOperations serviceOperation =list.get(0); + serviceOperation.setOperationResult(operationResult); + serviceOperation.setOperationProgress(progress); + if("100".equals(progress)){ + serviceOperation.setEndTime(DateUtils.dateToString(DateUtils.now())); + } + session.saveOrUpdate(serviceOperation); + session.flush(); + + }catch (Exception e){ + logger.error("exception occurred while performing DefaultServiceLcmService updateServiceInstanceOperation.Detail."+e.getMessage()); + } + } + + @Override + public ServiceInstanceOperations getServiceInstanceOperationById(String serviceId) { + ServiceInstanceOperations serviceOperation = null; + List<ServiceInstanceOperations> list = new ArrayList<>(); + try(Session session = getSession()) { + String hql="select a.* from service_instance_operations a where service_instance_id =:serviceId and start_time = (select max(start_time) from service_instance_operations where service_instance_id=:serviceInstanceId)"; + Query q = session.createSQLQuery(hql).addEntity(ServiceInstanceOperations.class); + q.setString("serviceId",serviceId); + q.setString("serviceInstanceId",serviceId); + list = q.list(); + serviceOperation =list.get(0); + session.flush(); + + }catch (Exception e){ + logger.error("exception occurred while performing DefaultServiceLcmService getServiceInstanceOperationById."+e.getMessage()); + } + return serviceOperation; + } } diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java index 0fc9e500..17e04b6d 100644 --- a/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/controller/lcm/ServiceLcmControllerTest.java @@ -47,7 +47,8 @@ public class ServiceLcmControllerTest { public void testQueryOperationProgress() throws Exception { String serviceId = "1"; String operationId = "1"; - controller.queryOperationProgress(serviceId, operationId); + HttpServletRequest request = mock(HttpServletRequest.class); + controller.queryOperationProgress(request,serviceId, operationId); verify(service, times(1)).queryOperationProgress(serviceId, operationId); } |